11using Avalonia ;
22using Avalonia . Platform ;
33using Avalonia . Platform . Storage ;
4+ using NuGet . Versioning ;
45using OpenLoco . Common . Logging ;
56using OpenLoco . Dat ;
67using OpenLoco . Dat . Data ;
@@ -66,7 +67,8 @@ public class MainWindowViewModel : ViewModelBase
6667 public string WindowTitle => $ "{ ObjectEditorModel . ApplicationName } - { ApplicationVersion } ({ LatestVersionText } )";
6768
6869 [ Reactive ]
69- public Version ApplicationVersion { get ; set ; }
70+ public SemanticVersion ApplicationVersion { get ; set ; }
71+ public static readonly SemanticVersion UnknownVersion = new ( 0 , 0 , 0 , "unknown" ) ;
7072
7173 [ Reactive ]
7274 public string LatestVersionText { get ; set ; } = "Development build" ;
@@ -291,21 +293,22 @@ async Task LoadLanguage()
291293 }
292294 }
293295
294- static Version GetCurrentAppVersion ( Assembly assembly )
296+ static SemanticVersion GetCurrentAppVersion ( Assembly assembly )
295297 {
296- // grab current appl version from assembly
298+ // grab current app version from assembly
297299 const string versionFilename = "Gui.version.txt" ;
298300 using ( var stream = assembly . GetManifestResourceStream ( versionFilename ) )
299301 using ( var ms = new MemoryStream ( ) )
300302 {
301303 stream ! . CopyTo ( ms ) ;
302- return Version . Parse ( Encoding . ASCII . GetString ( ms . ToArray ( ) ) ) ;
304+ var versionText = Encoding . ASCII . GetString ( ms . ToArray ( ) ) ;
305+ return GetVersionFromText ( versionText ) ;
303306 }
304307 }
305308
306309#if ! DEBUG
307310 // thanks for this one @IntelOrca, https://github.com/IntelOrca/PeggleEdit/blob/master/src/peggleedit/Forms/MainMDIForm.cs#L848-L861
308- Version GetLatestAppVersion ( )
311+ SemanticVersion GetLatestAppVersion ( )
309312 {
310313 var client = new HttpClient ( ) ;
311314 client . DefaultRequestHeaders . UserAgent . Add ( new ProductInfoHeaderValue ( GithubApplicationName , ApplicationVersion . ToString ( ) ) ) ;
@@ -314,11 +317,8 @@ Version GetLatestAppVersion()
314317 {
315318 var jsonResponse = response . Content . ReadAsStringAsync ( ) . Result ;
316319 var body = JsonSerializer . Deserialize < VersionCheckBody > ( jsonResponse ) ;
317- var tagName = body ? . TagName ;
318- if ( tagName != null )
319- {
320- return Version . Parse ( tagName ) ;
321- }
320+ var versionText = body ? . TagName ;
321+ return GetVersionFromText ( versionText ) ;
322322 }
323323
324324#pragma warning disable CA2201 // Do not raise reserved exception types
@@ -327,6 +327,19 @@ Version GetLatestAppVersion()
327327 }
328328#endif
329329
330+ static SemanticVersion GetVersionFromText ( string ? versionText )
331+ {
332+ if ( string . IsNullOrEmpty ( versionText ) )
333+ {
334+ return UnknownVersion ;
335+ }
336+
337+ return
338+ SemanticVersion . TryParse ( versionText . Trim ( ) , out var version )
339+ ? version
340+ : UnknownVersion ;
341+ }
342+
330343 public async Task SelectNewFolder ( )
331344 {
332345 var folders = await PlatformSpecific . OpenFolderPicker ( ) ;
0 commit comments