Skip to content

Commit 826530d

Browse files
committed
refactored settings and dev
1 parent c515d00 commit 826530d

File tree

10 files changed

+192
-187
lines changed

10 files changed

+192
-187
lines changed

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
<PackageVersion Include="SharpCompress" Version="0.39.0" />
3232
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
3333
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
34+
<PackageVersion Include="System.IO.Hashing" Version="9.0.4" />
3435
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
3536
<PackageVersion Include="xunit" Version="2.9.3" />
36-
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
37+
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.0" />
3738
<PackageVersion Include="AWSSDK.S3" Version="4.0.0.1" />
3839
<PackageVersion Include="ConfigureAwaitAnalyzer" Version="1.1.0" />
3940
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.1" />

src/Avalonia.Desktop/Avalonia.Desktop.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<AvaloniaResource Include="Assets\issues.png" />
2323
<AvaloniaResource Include="Assets\logo.png" />
2424
<AvaloniaResource Include="Assets\nam.png" />
25+
<AvaloniaResource Include="Assets\overlay.png" />
2526
<AvaloniaResource Include="Assets\redneck.png" />
2627
<AvaloniaResource Include="Assets\slave.png" />
2728
<AvaloniaResource Include="Assets\sw.png" />

src/Avalonia.Desktop/Helpers/Converters.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Avalonia.Data;
22
using Avalonia.Data.Converters;
33
using Avalonia.Media.Imaging;
4+
using Common.Common.Helpers;
45
using Common.Enums;
56
using Common.Helpers;
67
using System.Globalization;
@@ -41,12 +42,7 @@ public object Convert(object? value, Type targetType, object? parameter, Culture
4142
return false;
4243
}
4344

44-
if (parameter is not string paramStr)
45-
{
46-
throw new NotImplementedException();
47-
}
48-
49-
if (!Enum.TryParse<GameEnum>(paramStr, out var gameEnum))
45+
if (!EnumHelper.TryParse<GameEnum>(parameter, out var gameEnum))
5046
{
5147
throw new NotImplementedException();
5248
}
@@ -61,17 +57,12 @@ public object ConvertBack(object? value, Type targetType, object? parameter, Cul
6157
return AvaloniaProperty.UnsetValue;
6258
}
6359

64-
if (parameter is not string paramStr)
65-
{
66-
throw new NotImplementedException();
67-
}
68-
6960
if (!valueBool)
7061
{
7162
return AvaloniaProperty.UnsetValue;
7263
}
7364

74-
if (!Enum.TryParse<GameEnum>(paramStr, out var gameEnum))
65+
if (!EnumHelper.TryParse<GameEnum>(parameter, out var gameEnum))
7566
{
7667
throw new NotImplementedException();
7768
}

src/Avalonia.Desktop/Pages/SettingsPage.axaml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@
2424
Theme
2525
</TextBlock>
2626

27-
<RadioButton GroupName="theme"
27+
<RadioButton Content="System"
28+
GroupName="theme"
2829
Margin="5"
29-
Command="{Binding SetDefaultThemeCommand}"
30-
IsChecked="{Binding IsDefaultTheme}">
31-
System
32-
</RadioButton>
30+
Command="{Binding SetThemeCommand}"
31+
CommandParameter="System"
32+
IsChecked="{Binding IsDefaultTheme}"/>
3333

34-
<RadioButton GroupName="theme"
34+
<RadioButton Content="Light"
35+
GroupName="theme"
3536
Margin="5"
36-
Command="{Binding SetLightThemeCommand}"
37-
IsChecked="{Binding IsLightTheme}">
38-
Light
39-
</RadioButton>
37+
Command="{Binding SetThemeCommand}"
38+
CommandParameter="Light"
39+
IsChecked="{Binding IsLightTheme}"/>
4040

41-
<RadioButton GroupName="theme"
41+
<RadioButton Content="Dark"
42+
GroupName="theme"
4243
Margin="5"
43-
Command="{Binding SetDarkThemeCommand}"
44-
IsChecked="{Binding IsDarkTheme}">
45-
Dark
46-
</RadioButton>
44+
Command="{Binding SetThemeCommand}"
45+
CommandParameter="Dark"
46+
IsChecked="{Binding IsDarkTheme}"/>
4747

4848
</StackPanel>
4949

src/Avalonia.Desktop/ViewModels/DevViewModel.cs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -401,41 +401,11 @@ private async Task SelectFileForCrcAsync()
401401
return;
402402
}
403403

404-
var source = File.ReadAllBytes(files[0].Path.LocalPath);
405-
406-
var crc_table = new uint[256];
407-
uint crc;
408-
409-
for (uint i = 0; i < 256; i++)
410-
{
411-
crc = i;
412-
413-
for (uint j = 0; j < 8; j++)
414-
{
415-
crc = (crc & 1) != 0 ? (crc >> 1) ^ 0xEDB88320 : crc >> 1;
416-
}
417-
418-
crc_table[i] = crc;
419-
}
420-
421-
crc = 0xFFFFFFFF;
422-
423-
foreach (var s in source)
424-
{
425-
crc = crc_table[(crc ^ s) & 0xFF] ^ (crc >> 8);
426-
}
427-
428-
crc ^= 0xFFFFFFFF;
429-
430-
GameCrc = "0x" + crc.ToString("X");
404+
GameCrc = Crc32Helper.GetCrc32(files[0].Path.LocalPath.ToString(), true);
431405
}
432406

433-
434407
[RelayCommand]
435-
private async Task CreateZipAsync()
436-
{
437-
_ = await CreateZipInternalAsync().ConfigureAwait(false);
438-
}
408+
private Task<string?> CreateZipAsync() => CreateZipInternalAsync();
439409

440410

441411
[RelayCommand]

src/Avalonia.Desktop/ViewModels/SettingsViewModel.cs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Avalonia.Styling;
44
using Common.Client.Enums;
55
using Common.Client.Interfaces;
6+
using Common.Common.Helpers;
67
using Common.Enums;
78
using Common.Enums.Versions;
89
using CommunityToolkit.Diagnostics;
@@ -129,7 +130,7 @@ public bool SkipIntroCheckbox
129130
set
130131
{
131132
_config.SkipIntro = value;
132-
OnPropertyChanged(nameof(SkipIntroCheckbox));
133+
OnPropertyChanged();
133134
}
134135
}
135136

@@ -142,7 +143,7 @@ public bool SkipStartupCheckbox
142143
set
143144
{
144145
_config.SkipStartup = value;
145-
OnPropertyChanged(nameof(SkipStartupCheckbox));
146+
OnPropertyChanged();
146147
}
147148
}
148149

@@ -152,32 +153,24 @@ public bool SkipStartupCheckbox
152153
#region Relay Commands
153154

154155
[RelayCommand]
155-
private void SetDefaultTheme()
156+
private void SetTheme(object? param)
156157
{
157158
Guard.IsNotNull(Application.Current);
158159

159-
Application.Current.RequestedThemeVariant = ThemeVariant.Default;
160-
_config.Theme = ThemeEnum.System;
161-
}
162-
163-
164-
[RelayCommand]
165-
private void SetLightTheme()
166-
{
167-
Guard.IsNotNull(Application.Current);
168-
169-
Application.Current.RequestedThemeVariant = ThemeVariant.Light;
170-
_config.Theme = ThemeEnum.Light;
171-
}
172-
160+
if (!EnumHelper.TryParse<ThemeEnum>(param, out var themeEnum))
161+
{
162+
ThrowHelper.ThrowInvalidOperationException();
163+
}
173164

174-
[RelayCommand]
175-
private void SetDarkTheme()
176-
{
177-
Guard.IsNotNull(Application.Current);
165+
Application.Current.RequestedThemeVariant = themeEnum.Value switch
166+
{
167+
ThemeEnum.System => ThemeVariant.Default,
168+
ThemeEnum.Light => ThemeVariant.Light,
169+
ThemeEnum.Dark => ThemeVariant.Dark,
170+
_ => ThrowHelper.ThrowArgumentOutOfRangeException<ThemeVariant>(),
171+
};
178172

179-
Application.Current.RequestedThemeVariant = ThemeVariant.Dark;
180-
_config.Theme = ThemeEnum.Dark;
173+
_config.Theme = themeEnum.Value;
181174
}
182175

183176

@@ -281,7 +274,7 @@ private async Task OpenFolderPickerAsync(string param)
281274

282275

283276
/// <summary>
284-
/// Replace path to game with autp detected one
277+
/// Replace path to game with auto detected one
285278
/// </summary>
286279
[RelayCommand]
287280
private void Autodetect(string param)

0 commit comments

Comments
 (0)