Skip to content

Commit 44db996

Browse files
committed
Added more robust app version class
1 parent 0a11a78 commit 44db996

4 files changed

Lines changed: 499 additions & 23 deletions

File tree

ZuneModdingHelper/App.xaml.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Windows;
1+
using System.Windows;
32
using Microsoft.AppCenter;
43
using Microsoft.AppCenter.Analytics;
54
using Microsoft.AppCenter.Crashes;
@@ -13,9 +12,8 @@ public partial class App : Application
1312
{
1413
public const string Title = "Zune Modding Helper";
1514

16-
public static readonly Version VersionNum = new(2021, 10, 23, 0);
17-
public const string VersionStatus = "alpha";
18-
public static readonly string Version = VersionNum.ToString() + (VersionStatus != string.Empty ? "-" + VersionStatus : string.Empty);
15+
public static readonly ReleaseVersion Version = new(2021, 11, 14, 0, Phase.Alpha);
16+
public static readonly string VersionStr = Version.ToString();
1917

2018
public const string DonateLink = "https://www.paypal.me/YoshiAsk";
2119

@@ -40,17 +38,5 @@ public static void OpenInBrowser(string url)
4038
UseShellExecute = true
4139
});
4240
}
43-
44-
public static bool CheckIfNewerVersion(string otherStr)
45-
{
46-
int idxSplit = otherStr.IndexOf('-');
47-
Version otherNum = new(otherStr[..idxSplit]);
48-
string otherStatus = otherStr[(idxSplit + 1)..];
49-
50-
// TODO: This assumes that the VersionStatus is "alpha"
51-
bool isNotAlpha = otherStatus != VersionStatus;
52-
bool isNewer = otherNum > VersionNum;
53-
return isNotAlpha || isNewer;
54-
}
5541
}
5642
}

ZuneModdingHelper/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</mah:Flyout.Header>
3535
<TextBlock FontSize="14" Padding="16" TextWrapping="Wrap">
3636
<Run Text="{x:Static local:App.Title}" FontWeight="Bold" FontSize="16"/><LineBreak/>
37-
<Run Text="{x:Static local:App.Version}"/><LineBreak/>
37+
<Run Text="{x:Static local:App.VersionStr}"/><LineBreak/>
3838
<Hyperlink NavigateUri="https://github.com/ZuneDev/ZuneModdingHelper" RequestNavigate="Link_RequestNavigate">
3939
<Run Text="View source"/>
4040
</Hyperlink><LineBreak/>

ZuneModdingHelper/MainWindow.xaml.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.WindowsAPICodePack.Dialogs;
77
using Newtonsoft.Json.Linq;
88
using OwlCore.AbstractUI.Models;
9+
using Syroot.Windows.IO;
910
using System;
1011
using System.Collections.Generic;
1112
using System.IO;
@@ -166,10 +167,11 @@ private async void UpdatesButton_Click(object sender, RoutedEventArgs e)
166167
{
167168
// Get releases list from GitHub
168169
List<JObject> releases = await "https://api.github.com/repos/ZuneDev/ZuneModdingHelper/releases"
169-
.WithHeader("User-Agent", App.Title.Replace(" ", "") + "/" + App.Version)
170+
.WithHeader("User-Agent", App.Title.Replace(" ", "") + "/" + App.VersionStr)
170171
.GetJsonAsync<List<JObject>>();
171172
JObject latest = releases[0];
172-
if (!App.CheckIfNewerVersion(latest["tag_name"].Value<string>()))
173+
string latestVerStr = latest["tag_name"].Value<string>();
174+
if (!ReleaseVersion.TryParse(latestVerStr, out var latestVer) || App.Version >= latestVer)
173175
{
174176
// Already up-to-date
175177

@@ -192,7 +194,7 @@ private async void UpdatesButton_Click(object sender, RoutedEventArgs e)
192194
NegativeButtonText = "Later"
193195
};
194196
await checkDialog.CloseAsync();
195-
var promptResult = await this.ShowMessageAsync("Update available", $"Relase {latest["name"]} is available. Would you like to download it now?",
197+
var promptResult = await this.ShowMessageAsync("Update available", $"Release {latest["name"]} is available. Would you like to download it now?",
196198
MessageDialogStyle.AffirmativeAndNegative, promptSettings);
197199
bool acceptedUpdate = promptResult == MessageDialogResult.Affirmative;
198200

@@ -221,7 +223,8 @@ private async void UpdatesButton_Click(object sender, RoutedEventArgs e)
221223
// Ask user to save file
222224
Microsoft.Win32.SaveFileDialog saveFileDialog = new()
223225
{
224-
FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", assetName)
226+
FileName = assetName,
227+
InitialDirectory = new KnownFolder(KnownFolderType.Downloads).Path
225228
};
226229
bool dialogResult = saveFileDialog.ShowDialog() ?? false;
227230
await progDialog.CloseAsync();
@@ -240,6 +243,9 @@ private async void UpdatesButton_Click(object sender, RoutedEventArgs e)
240243
catch
241244
{
242245
App.OpenInBrowser("https://github.com/ZuneDev/ZuneModdingHelper/releases");
246+
}
247+
finally
248+
{
243249
if (checkDialog.IsOpen)
244250
await checkDialog.CloseAsync();
245251
}
@@ -266,7 +272,7 @@ private void LocateZuneButton_Click(object sender, RoutedEventArgs e)
266272
{
267273
// TODO: Fallback to pre-Vista dialog
268274
this.ShowMessageAsync("Error",
269-
"Please use File Explorer to locate an copy the path.",
275+
"Please use File Explorer to locate and copy the path.",
270276
settings: defaultMetroDialogSettings);
271277
}
272278
}

0 commit comments

Comments
 (0)