Skip to content

Commit a82f27c

Browse files
add update option
1 parent 90bc7e0 commit a82f27c

6 files changed

Lines changed: 97 additions & 15 deletions

File tree

AdvancedSettings.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
66
x:Class="MoSpeedUI.AdvancedSettings"
77
xmlns:lang="clr-namespace:MoSpeedUI.Lang"
8-
Title="{x:Static lang:Resources.Compiling}">
8+
Title="{x:Static lang:Resources.Advanced}">
99
<StackPanel Margin="8">
1010
<TextBlock Text="{x:Static lang:Resources.Advanced}" FontSize="24" FontWeight="Medium"/>
1111
<TextBlock Text="{x:Static lang:Resources.AdvWelcome}" FontSize="16" TextWrapping="Wrap"/>
1212
<TextBox x:Name="AdvBox" Margin="0,8,0,0" Watermark="{x:Static lang:Resources.AdvWatermark}"/>
1313
<Button Margin="0,8,0,0" Content="{x:Static lang:Resources.Apply}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Click="Button_OnClick"/>
1414
<Button Margin="0,8,0,0" Content="{x:Static lang:Resources.OpenParameterWiki}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Click="WikiBtn_OnClick"/>
15+
<Button Margin="0,4,0,0" Content="{x:Static lang:Resources.RestartSetup}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Click="UpdateBtn_OnClick"/>
1516
</StackPanel>
1617
</Window>

AdvancedSettings.axaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
13
using System.Diagnostics;
4+
using System.Runtime.InteropServices.JavaScript;
25
using Avalonia.Controls;
36
using Avalonia.Interactivity;
7+
using MsBox.Avalonia;
8+
using MsBox.Avalonia.Dto;
9+
using MsBox.Avalonia.Models;
410
using SkiaSharp;
511

612
namespace MoSpeedUI;
@@ -33,4 +39,24 @@ private void WikiBtn_OnClick(object? sender, RoutedEventArgs e)
3339
p.StartInfo.UseShellExecute = true;
3440
p.Start();
3541
}
42+
43+
private async void UpdateBtn_OnClick(object? sender, RoutedEventArgs e)
44+
{
45+
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
46+
{
47+
ContentMessage = String.Format(Lang.Resources.ConfirmReset, MainWindow.ConfigFolder),
48+
ButtonDefinitions = new List<ButtonDefinition>
49+
{
50+
new ButtonDefinition {Name = Lang.Resources.Abort, IsCancel = true},
51+
new ButtonDefinition { Name = Lang.Resources.Yes }
52+
},
53+
Icon = MsBox.Avalonia.Enums.Icon.Question
54+
});
55+
var res = await box.ShowAsPopupAsync(this);
56+
if (res == Lang.Resources.Yes)
57+
{
58+
SetupWindow sw = new SetupWindow(true);
59+
sw.ShowDialog(this);
60+
}
61+
}
3662
}

Lang/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lang/Resources.de.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,13 @@
263263
<data name="CompileCancel" xml:space="preserve">
264264
<value>Kompilieren abgebrochen</value>
265265
</data>
266+
<data name="RestartSetup" xml:space="preserve">
267+
<value>Setup neustarten (MoSpeed updaten)</value>
268+
</data>
269+
<data name="ConfirmReset" xml:space="preserve">
270+
<value>Wenn du updatest, wird der Inhalt von '{0}' gelöscht. Danach wird der Setup-Dialog erscheinen und du kannst eine neue Setup-Option auswählen. Möchtest du fortfahren?</value>
271+
</data>
272+
<data name="Yes" xml:space="preserve">
273+
<value>Ja</value>
274+
</data>
266275
</root>

Lang/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,13 @@
270270
<data name="CompileCancel" xml:space="preserve">
271271
<value>Compilation canceled</value>
272272
</data>
273+
<data name="RestartSetup" xml:space="preserve">
274+
<value>Restart Setup (Update MoSpeed)</value>
275+
</data>
276+
<data name="ConfirmReset" xml:space="preserve">
277+
<value>By updating, everything in '{0}' will be deleted if you choose to continue. The setup dialog will appear and you can choose a setup option again. Do you want to continue?</value>
278+
</data>
279+
<data name="Yes" xml:space="preserve">
280+
<value>Yes</value>
281+
</data>
273282
</root>

SetupWindow.axaml.cs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,47 @@ namespace MoSpeedUI;
2121

2222
public partial class SetupWindow : Window
2323
{
24-
public SetupWindow()
24+
public SetupWindow(bool restart = false)
2525
{
2626
InitializeComponent();
27-
this.Width = 600;
28-
this.Height = 300;
29-
DwnldMsRBtn.IsCheckedChanged += ((sender, args) =>
27+
if (restart)
3028
{
31-
if (DwnldMsRBtn.IsChecked != null)
32-
if ((bool)DwnldMsRBtn.IsChecked)
29+
if (Directory.Exists(MainWindow.ConfigFolder))
30+
{
31+
DirectoryInfo di = new DirectoryInfo(MainWindow.ConfigFolder);
32+
foreach (FileInfo file in di.GetFiles())
3333
{
34-
Step2B.IsVisible = false;
35-
Step2A.IsVisible = true;
34+
file.Delete();
3635
}
37-
else
36+
37+
foreach (DirectoryInfo dir in di.GetDirectories())
3838
{
39-
Step2A.IsVisible = false;
40-
Step2B.IsVisible = true;
39+
dir.Delete(true);
4140
}
42-
});
43-
DwnldMsRBtn.IsChecked = true;
41+
}
42+
}
43+
Prepare();
44+
}
45+
public void Prepare()
46+
{
47+
this.Width = 600;
48+
this.Height = 300;
49+
DwnldMsRBtn.IsCheckedChanged += ((sender, args) =>
50+
{
51+
if (DwnldMsRBtn.IsChecked != null)
52+
if ((bool)DwnldMsRBtn.IsChecked)
53+
{
54+
Step2B.IsVisible = false;
55+
Step2A.IsVisible = true;
56+
}
57+
else
58+
{
59+
Step2A.IsVisible = false;
60+
Step2B.IsVisible = true;
61+
}
62+
});
63+
DwnldMsRBtn.IsChecked = true;
4464
}
45-
4665
async private void DwnldBtn_OnClick(object? sender, RoutedEventArgs e)
4766
{
4867
DwnldBar.IsVisible = true;

0 commit comments

Comments
 (0)