Skip to content

Commit ef439d7

Browse files
redone update function, logo decorations
1 parent 3ad6894 commit ef439d7

12 files changed

Lines changed: 146 additions & 32 deletions

AdvancedSettings.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
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"/>
15+
<Button x:Name="UpdateBtn" Margin="0,4,0,0" Content="{x:Static lang:Resources.UpdateBtn}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Click="UpdateBtn_OnClick"/>
1616
</StackPanel>
1717
</Window>

AdvancedSettings.axaml.cs

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
5+
using System.IO.Compression;
6+
using System.Net.Http;
47
using System.Runtime.InteropServices.JavaScript;
8+
using System.Threading.Tasks;
59
using Avalonia.Controls;
610
using Avalonia.Interactivity;
711
using MsBox.Avalonia;
@@ -42,21 +46,71 @@ private void WikiBtn_OnClick(object? sender, RoutedEventArgs e)
4246

4347
private async void UpdateBtn_OnClick(object? sender, RoutedEventArgs e)
4448
{
45-
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
49+
UpdateBtn.IsEnabled = false;
50+
string tmpDir = Path.Join(Path.GetTempPath(), Path.GetRandomFileName());
51+
string basePath = MainWindow.AppConfiguration.MoSpeedPath.Replace("\\dist", "\\").Replace("/dist", "/");
52+
Directory.CreateDirectory(tmpDir);
53+
string outputPath = Path.Join(tmpDir, "mospeed.zip");
54+
try
4655
{
47-
ContentMessage = String.Format(Lang.Resources.ConfirmReset, MainWindow.ConfigFolder),
56+
using var client = new HttpClient();
57+
using var response =
58+
await client.GetAsync("https://github.com/EgonOlsen71/basicv2/archive/refs/heads/master.zip",
59+
HttpCompletionOption.ResponseHeadersRead);
60+
response.EnsureSuccessStatusCode();
61+
await using var contentStream = await response.Content.ReadAsStreamAsync();
62+
await using var fileStream =
63+
new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true);
64+
var buffer = new byte[8192];
65+
long totalBytesRead = 0;
66+
int bytesRead;
67+
while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
68+
{
69+
await fileStream.WriteAsync(buffer.AsMemory(0, bytesRead));
70+
totalBytesRead += bytesRead;
71+
}
72+
fileStream.Close();
73+
await Task.Run(() =>
74+
{
75+
ZipFile.ExtractToDirectory(Path.Join(tmpDir, "mospeed.zip"),
76+
tmpDir, true);
77+
});
78+
try
79+
{
80+
Directory.Delete(basePath, true);
81+
}
82+
catch{}
83+
Shared.CopyFilesRecursively(Path.Join(tmpDir, "basicv2-master"),
84+
basePath);
85+
}
86+
catch (Exception ex)
87+
{
88+
Console.WriteLine(ex + "//" + ex.Message);
89+
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
90+
{
91+
ContentMessage = Lang.Resources.MSDownloadError + $" {ex.Message}",
92+
ButtonDefinitions = new List<ButtonDefinition>
93+
{
94+
new ButtonDefinition { Name = "Ok" }
95+
},
96+
Icon = MsBox.Avalonia.Enums.Icon.Error
97+
});
98+
await box.ShowAsPopupAsync(this);
99+
return;
100+
}
101+
finally
102+
{
103+
UpdateBtn.IsEnabled = true;
104+
}
105+
var sBox = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
106+
{
107+
ContentMessage = Lang.Resources.MSDownloadSuccess + $" {MainWindow.AppConfiguration.MoSpeedPath}",
48108
ButtonDefinitions = new List<ButtonDefinition>
49109
{
50-
new ButtonDefinition {Name = Lang.Resources.Abort, IsCancel = true},
51-
new ButtonDefinition { Name = Lang.Resources.Yes }
110+
new ButtonDefinition { Name = "Ok" }
52111
},
53-
Icon = MsBox.Avalonia.Enums.Icon.Question
112+
Icon = MsBox.Avalonia.Enums.Icon.Success
54113
});
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-
}
114+
await sBox.ShowAsPopupAsync(this);
61115
}
62116
}
22 KB
Loading
18.7 KB
Loading

Assets/Images/mospeed_pride.png

6.34 KB
Loading

Configuration.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ public class Configuration
66
{
77
[XmlElement("mospeed")]
88
public string MoSpeedPath { get; set; }
9-
10-
/*[XmlElement("javaskip")]
11-
public bool SkipJavaCheck { get; set; }*/
129
[XmlElement("javapath")]
1310
public string JavaPath { get; set; }
11+
[XmlElement("logodec")]
12+
public bool LogoDecoration { get; set; } = true;
1413
}

Lang/Resources.Designer.cs

Lines changed: 2 additions & 2 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@
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>
266+
<data name="UpdateBtn" xml:space="preserve">
267+
<value>Update MoSpeed (überschreibt aktuell ausgewähltes MoSpeed)</value>
268268
</data>
269269
<data name="ConfirmReset" xml:space="preserve">
270270
<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>
@@ -273,7 +273,7 @@
273273
<value>Ja</value>
274274
</data>
275275
<data name="ConfigReadError" xml:space="preserve">
276-
<value>Es gab einen Fehler beim lesen der Konfigurationsdatei. SObald du dieses Pop-Up schließt, wird alles in {0} gelöscht und der Einrichtungsdialog wird erscheinen.</value>
276+
<value>Es gab einen Fehler beim lesen der Konfigurationsdatei. Sobald du dieses Pop-Up schließt, wird alles in {0} gelöscht und der Einrichtungsdialog wird erscheinen. ({1})</value>
277277
</data>
278278
<data name="Ignore" xml:space="preserve">
279279
<value>Ignorieren</value>

Lang/Resources.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@
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>
273+
<data name="UpdateBtn" xml:space="preserve">
274+
<value>Update MoSpeed (overrides currently selected MoSpeed)</value>
275275
</data>
276276
<data name="ConfirmReset" xml:space="preserve">
277277
<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>
@@ -280,7 +280,7 @@
280280
<value>Yes</value>
281281
</data>
282282
<data name="ConfigReadError" xml:space="preserve">
283-
<value>There has been an error reading the config file. Once you close this pop-up, everything in {0} will be deleted and the Setup will reappear.</value>
283+
<value>There has been an error reading the config file. Once you close this pop-up, everything in {0} will be deleted and the Setup will reappear. ({1})</value>
284284
</data>
285285
<data name="Ignore" xml:space="preserve">
286286
<value>Ignore</value>

MainWindow.axaml.cs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
using Avalonia.Layout;
1717
using Avalonia.LogicalTree;
1818
using Avalonia.Media.Imaging;
19+
using Avalonia.Platform;
1920
using Avalonia.Platform.Storage;
2021
using Avalonia.VisualTree;
2122
using MsBox.Avalonia;
2223
using MsBox.Avalonia.Dto;
2324
using MsBox.Avalonia.Models;
25+
using SkiaSharp;
2426

2527
namespace MoSpeedUI;
2628

@@ -55,17 +57,18 @@ public MainWindow()
5557
ControlPanel.MaxWidth = (int)(e.ClientSize.Width * 0.75);
5658
ControlPanel.Width = ControlPanel.MaxWidth;
5759
};
58-
this.Opened += (sender, args) =>
60+
this.Opened += async (sender, args) =>
5961
{
6062
if (!Directory.Exists(ConfigFolder))
6163
{
6264
Directory.CreateDirectory(ConfigFolder);
63-
SetupRoutine(true);
65+
await SetupRoutine();
6466
ReadConfig();
67+
return;
6568
}
66-
else if (!File.Exists(ConfigFile))
69+
if (!File.Exists(ConfigFile))
6770
{
68-
SetupRoutine(true);
71+
await SetupRoutine(true);
6972
ReadConfig();
7073
}
7174
else
@@ -131,29 +134,60 @@ public MainWindow()
131134
}
132135
};
133136
AboutLink.Cursor = new Cursor(StandardCursorType.Hand);
137+
if (AppConfiguration.LogoDecoration)
138+
{
139+
DateTime dt = DateTime.Today;
140+
if (dt.Month == 6)
141+
{
142+
MoSpeedLogo.Source =
143+
new Bitmap(AssetLoader.Open(new Uri("avares://MoSpeedUI/Assets/Images/mospeed_pride.png")));
144+
}
145+
else if (dt.Month == 12)
146+
{
147+
MoSpeedLogo.Source =
148+
new Bitmap(AssetLoader.Open(new Uri("avares://MoSpeedUI/Assets/Images/mospeed_christmas.png")));
149+
}
150+
else if (dt.Month == 10 && Enumerable.Range(20, 31).Contains(dt.Day))
151+
{
152+
MoSpeedLogo.Source =
153+
new Bitmap(AssetLoader.Open(new Uri("avares://MoSpeedUI/Assets/Images/mospeed_halloween.png")));
154+
}
155+
}
134156
PlatformSelect.SelectedIndex = 0;
135157
}
136158

137159
private void ReadConfig()
138160
{
139161
try
140162
{
163+
Configuration propConfig = new();
164+
bool redoConfig = false;
141165
XmlSerializer ser = new XmlSerializer(typeof(Configuration));
142166
StreamReader r = new StreamReader(ConfigFile);
143167
AppConfiguration = (Configuration)ser.Deserialize(r)!;
144168
r.Close();
145169
foreach(PropertyDescriptor descriptor in TypeDescriptor.GetProperties(AppConfiguration))
146170
{
147171
string name = descriptor.Name;
148-
object value = descriptor.GetValue(AppConfiguration);
172+
object? value = descriptor.GetValue(AppConfiguration);
149173
Console.WriteLine("{0}={1}", name, value);
174+
if (Equals(value, descriptor.GetValue(propConfig)))
175+
{
176+
Console.WriteLine("{0} not configured, will be saved with default value {1}", name, value);
177+
redoConfig = true;
178+
}
150179
}
180+
if (redoConfig)
181+
{
182+
SetupWindow.RegenerateConfig(AppConfiguration);
183+
}
151184
}
152-
catch
185+
catch (Exception e)
153186
{
187+
Console.WriteLine(e + "//"+e.Message);
154188
var box = MessageBoxManager.GetMessageBoxCustom(new MessageBoxCustomParams
155189
{
156-
ContentMessage = Lang.Resources.ConfigReadError,
190+
ContentMessage = String.Format(Lang.Resources.ConfigReadError, ConfigFolder, e.Message),
157191
ButtonDefinitions = new List<ButtonDefinition>
158192
{
159193
new ButtonDefinition { Name = "Ok" }
@@ -500,10 +534,10 @@ private string GenerateMemHolesString()
500534
}
501535
return String.Join(",",memholes);
502536
}
503-
private void SetupRoutine(bool restart = false)
537+
private async Task SetupRoutine(bool restart = false)
504538
{
505539
SetupWindow setupWindow = new(restart);
506-
setupWindow.ShowDialog(this);
540+
await setupWindow.ShowDialog(this);
507541
}
508542

509543
private void AdvSettings_OnClick(object? sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)