Skip to content

Commit

Permalink
version display issues
Browse files Browse the repository at this point in the history
  • Loading branch information
KaddaOK committed Jul 3, 2024
1 parent 4fcdec0 commit f4c9060
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions KaddaOK.AvaloniaApp/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.Input;
using System;
using CommunityToolkit.Mvvm.Input;
using KaddaOK.AvaloniaApp.Services;
using System.Reflection;
using KaddaOK.AvaloniaApp.Models;
Expand All @@ -12,7 +13,49 @@ public AboutViewModel(KaraokeProcess karaokeProcess) : base(karaokeProcess)
{
}

public string? AssemblyVersion => FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
public string? AssemblyVersion
{
get
{
// Getting the informational version has proven surprisingly difficult when published in single file mode.
// It seems to want to just be the same as the numbers-only version, which is infuriating and not as designed.
// So we have to resort to FileVersionInfo, which will not be very cross-platform I'm sure. ☹

// First, we will try getting the KaddaOK.AvaloniaApp assembly, and see if it has a location.
// In single-file mode, it won't.
var avaloniaAppAssembly = Assembly.GetAssembly(typeof(AboutViewModel));

// but we'll set a fallback value from it at least, marked with an asterisk so we know it's not complete
var returnValue = @$"{avaloniaAppAssembly?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
?? avaloniaAppAssembly?.GetName().Version?.ToString()}*";

var locationToLoad = avaloniaAppAssembly?.Location;
if (string.IsNullOrWhiteSpace(locationToLoad))
{
// we resort to asking nicely for "KaddaOKTools.exe", which probably isn't even the right thing on other platforms
locationToLoad = "KaddaOKTools.exe";
}


try
{
// this would throw a FileNotFoundException so we'll have to do it in a try
var fileVersionInfo = FileVersionInfo.GetVersionInfo(locationToLoad);
if (!string.IsNullOrWhiteSpace(fileVersionInfo?.ProductVersion))
{
returnValue = fileVersionInfo.ProductVersion;
}
}
catch (Exception e)
{
// actually don't care about this but we could log it for more information I guess
}

return returnValue;
}
}



[RelayCommand]
private void LinkToLantern()
Expand Down

0 comments on commit f4c9060

Please sign in to comment.