Skip to content

Commit 61686ec

Browse files
committed
temp saved
1 parent cc73b96 commit 61686ec

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

Avalonia.CpuLimiter/Icons.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<Styles>
1111
<Styles.Resources>
1212
<StreamGeometry x:Key="GamesRegular">M14.9978834,5 C18.8638767,5 21.9978834,8.13400675 21.9978834,12 C21.9978834,15.7854517 18.9931001,18.8690987 15.2385332,18.995941 L14.9978834,19 L9.00211656,19 C5.13612331,19 2.00211656,15.8659932 2.00211656,12 C2.00211656,8.21454828 5.00689994,5.13090132 8.76146681,5.00405902 L9.00211656,5 L14.9978834,5 Z M14.9978834,6.5 L9.00211656,6.5 C5.96455044,6.5 3.50211656,8.96243388 3.50211656,12 C3.50211656,14.9634791 5.84589657,17.3795391 8.78090942,17.4956328 L9.00211656,17.5 L14.9978834,17.5 C18.0354496,17.5 20.4978834,15.0375661 20.4978834,12 C20.4978834,9.03652085 18.1541034,6.62046086 15.2190906,6.5043672 L14.9978834,6.5 Z M8,9 C8.41421356,9 8.75,9.33578644 8.75,9.75 L8.74911656,11.248 L10.25,11.2487458 C10.6642136,11.2487458 11,11.5845322 11,11.9987458 C11,12.4129593 10.6642136,12.7487458 10.25,12.7487458 L8.74911656,12.748 L8.75,14.25 C8.75,14.6642136 8.41421356,15 8,15 C7.58578644,15 7.25,14.6642136 7.25,14.25 L7.24911656,12.748 L5.75,12.7487458 C5.33578644,12.7487458 5,12.4129593 5,11.9987458 C5,11.5845322 5.33578644,11.2487458 5.75,11.2487458 L7.24911656,11.248 L7.25,9.75 C7.25,9.33578644 7.58578644,9 8,9 Z M14.75,12.5 C15.4403559,12.5 16,13.0596441 16,13.75 C16,14.4403559 15.4403559,15 14.75,15 C14.0596441,15 13.5,14.4403559 13.5,13.75 C13.5,13.0596441 14.0596441,12.5 14.75,12.5 Z M16.75,9 C17.4403559,9 18,9.55964406 18,10.25 C18,10.9403559 17.4403559,11.5 16.75,11.5 C16.0596441,11.5 15.5,10.9403559 15.5,10.25 C15.5,9.55964406 16.0596441,9 16.75,9 Z</StreamGeometry>
13+
<StreamGeometry x:Key="DeleteRegular">M24,7.25 C27.1017853,7.25 29.629937,9.70601719 29.7458479,12.7794443 L29.75,13 L37,13 C37.6903559,13 38.25,13.5596441 38.25,14.25 C38.25,14.8972087 37.7581253,15.4295339 37.1278052,15.4935464 L37,15.5 L35.909,15.5 L34.2058308,38.0698451 C34.0385226,40.2866784 32.1910211,42 29.9678833,42 L18.0321167,42 C15.8089789,42 13.9614774,40.2866784 13.7941692,38.0698451 L12.09,15.5 L11,15.5 C10.3527913,15.5 9.8204661,15.0081253 9.75645361,14.3778052 L9.75,14.25 C9.75,13.6027913 10.2418747,13.0704661 10.8721948,13.0064536 L11,13 L18.25,13 C18.25,9.82436269 20.8243627,7.25 24,7.25 Z M33.4021054,15.5 L14.5978946,15.5 L16.2870795,37.8817009 C16.3559711,38.7945146 17.116707,39.5 18.0321167,39.5 L29.9678833,39.5 C30.883293,39.5 31.6440289,38.7945146 31.7129205,37.8817009 L33.4021054,15.5 Z M27.25,20.75 C27.8972087,20.75 28.4295339,21.2418747 28.4935464,21.8721948 L28.5,22 L28.5,33 C28.5,33.6903559 27.9403559,34.25 27.25,34.25 C26.6027913,34.25 26.0704661,33.7581253 26.0064536,33.1278052 L26,33 L26,22 C26,21.3096441 26.5596441,20.75 27.25,20.75 Z M20.75,20.75 C21.3972087,20.75 21.9295339,21.2418747 21.9935464,21.8721948 L22,22 L22,33 C22,33.6903559 21.4403559,34.25 20.75,34.25 C20.1027913,34.25 19.5704661,33.7581253 19.5064536,33.1278052 L19.5,33 L19.5,22 C19.5,21.3096441 20.0596441,20.75 20.75,20.75 Z M24,9.75 C22.2669685,9.75 20.8507541,11.1064548 20.7551448,12.8155761 L20.75,13 L27.25,13 C27.25,11.2050746 25.7949254,9.75 24,9.75 Z</StreamGeometry>
1314
</Styles.Resources>
1415
</Styles>
1516
</Styles>

Avalonia.CpuLimiter/ViewModels/MainWindowViewModel.cs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
using System.ComponentModel.DataAnnotations;
88
using System.Diagnostics;
99
using System.IO;
10+
using System.Reactive;
1011
using System.Runtime.InteropServices;
1112
using Avalonia.Controls;
1213
using Avalonia.CpuLimiter.Models;
1314
using Avalonia.CpuLimiter.Services;
1415
using Avalonia.CpuLimiter.Views;
16+
using Microsoft.VisualBasic;
1517
using ArgumentNullException = System.ArgumentNullException;
1618

1719
namespace Avalonia.CpuLimiter.ViewModels
@@ -32,13 +34,45 @@ public MainWindowViewModel()
3234

3335
ChooseExeFileCommand = ReactiveCommand.CreateFromTask(ChooseExeFile);
3436
RunGameCommand = ReactiveCommand.Create(RunGame);
35-
ExitProgramCommand = ReactiveCommand.Create(ExitProgram);
3637
OpenAboutWindowCommand = ReactiveCommand.CreateFromTask(OpenAboutWindowAsync);
3738
OpenProjWebsiteCommand = ReactiveCommand.CreateFromTask(OpenProjWebsiteAsync);
3839
OpenDocsCommand = ReactiveCommand.CreateFromTask(OpenDocsAsync);
40+
RemoveHistoryItemCommand = ReactiveCommand.CreateFromTask<HistoryItemViewModel>( item => RemoveHistoryItemAsync(item) );
3941

4042
this.WhenAnyValue(x => x.CpuCoreCount)
4143
.Subscribe(x => Console.WriteLine($"CPU core count: {x}"));
44+
45+
this.WhenAnyValue(x => x.GamePath)
46+
.Subscribe( x => Console.WriteLine($"Game path: {x}"));
47+
48+
49+
if (Design.IsDesignMode)
50+
{
51+
HistoryItems.Add(new HistoryItemViewModel(new HistoryItem()
52+
{
53+
CPUCoreUsed = 1,
54+
LastUsed = new DateTime(2018, 9, 30),
55+
56+
Path = "~/App_Data/CpuCoreHistory.json"
57+
}));
58+
HistoryItems.Add(new HistoryItemViewModel(new HistoryItem()
59+
{
60+
CPUCoreUsed = 2,
61+
LastUsed = new DateTime(2018, 9, 30),
62+
63+
Path = "~/App_Data/CpuCoreHistory.json"
64+
}));
65+
HistoryItems.Add(new HistoryItemViewModel(new HistoryItem()
66+
{
67+
CPUCoreUsed = 3,
68+
LastUsed = new DateTime(2018, 9, 30),
69+
70+
Path = "~/App_Data/CpuCoreHistory.json"
71+
}));
72+
73+
}
74+
75+
4276
}
4377

4478
public void RunGame() => AdminRunner.RunAsAdmin(4, GamePath);
@@ -59,10 +93,10 @@ public string GamePath
5993
{
6094
// Path Validation
6195
if (string.IsNullOrWhiteSpace(value))
62-
throw new ArgumentNullException(nameof(GamePath), "Path cannot be null or empty.");
96+
throw new ArgumentNullException(nameof(GamePath), $@"Path: '{GamePath}' cannot be null or empty.");
6397

6498
else if (!File.Exists(value) && !Directory.Exists(value))
65-
throw new FileNotFoundException(nameof(GamePath),"Path does not exist.");
99+
throw new FileNotFoundException(nameof(GamePath),$@"Path: '{GamePath}' does not exist.");
66100
else
67101
this.RaiseAndSetIfChanged(ref _gamePath, value);
68102
}
@@ -97,8 +131,6 @@ private async Task ChooseExeFile()
97131

98132
// Exit command
99133

100-
public ICommand ExitProgramCommand { get; }
101-
102134
private void ExitProgram()
103135
{
104136
Environment.Exit(0);
@@ -193,8 +225,10 @@ private void AddHistoryItem()
193225
HistoryItems.Add(NewHistoryItem);
194226

195227
}
228+
229+
public ICommand RemoveHistoryItemCommand { get; }
196230

197-
private void RemoveHistoryItem(HistoryItemViewModel historyItem)
231+
private async Task RemoveHistoryItemAsync(HistoryItemViewModel historyItem)
198232
{
199233
HistoryItems.Remove(historyItem);
200234
}

Avalonia.CpuLimiter/Views/MainWindow.axaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System;
22
using System.Threading.Tasks;
33
using Avalonia.Controls;
4+
using Avalonia.CpuLimiter.Models;
45
using Avalonia.CpuLimiter.ViewModels;
56
using Avalonia.Interactivity;
67
using Avalonia.ReactiveUI;
78
using MsBox.Avalonia;
89
using MsBox.Avalonia.Dto;
910
using MsBox.Avalonia.Enums;
11+
using ReactiveUI;
1012

1113
namespace Avalonia.CpuLimiter.Views
1214
{
@@ -15,6 +17,15 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
1517
public MainWindow()
1618
{
1719
InitializeComponent();
20+
// HistoryBox.Items =
21+
this.WhenAnyValue(x => x.HistoryComboBox.SelectionBoxItem)
22+
.Subscribe(Console.WriteLine);
23+
this.WhenAnyValue(x => x.HistoryComboBox.SelectedIndex)
24+
.Subscribe( x => Console.WriteLine($@"history combobox selected index {x}"));
25+
this.WhenAnyValue(x => x.HistoryComboBox.SelectedValue)
26+
.Subscribe(x => Console.WriteLine($@"history combobox selected value {x}"));
27+
28+
1829
}
1930

2031
public static async Task DoOpenAboutWindowAsync()

0 commit comments

Comments
 (0)