From 774525ed501ddd76703f636640c9db62de3d17cb Mon Sep 17 00:00:00 2001 From: Asval Date: Sun, 6 Oct 2024 15:31:04 +0200 Subject: [PATCH] actually implementing dotnet features --- FModel/App.xaml.cs | 2 +- FModel/Constants.cs | 12 ++++++++++-- FModel/Settings/UserSettings.cs | 9 --------- .../ViewModels/ApiEndpoints/FModelApiEndpoint.cs | 4 ++-- .../ApiEndpoints/Models/GitHubResponse.cs | 16 +++++++++++++--- FModel/ViewModels/ApplicationViewModel.cs | 4 ++-- FModel/ViewModels/UpdateViewModel.cs | 7 ++++++- 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/FModel/App.xaml.cs b/FModel/App.xaml.cs index 0efe2b16..4781e951 100644 --- a/FModel/App.xaml.cs +++ b/FModel/App.xaml.cs @@ -106,7 +106,7 @@ public partial class App outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [FModel] [{Level:u3}] {Message:lj}{NewLine}{Exception}").CreateLogger(); #endif - Log.Information("Version {Version}", Constants.APP_VERSION); + Log.Information("Version {Version} ({CommitId})", Constants.APP_VERSION, Constants.APP_COMMIT_ID); Log.Information("{OS}", GetOperatingSystemProductName()); Log.Information("{RuntimeVer}", RuntimeInformation.FrameworkDescription); Log.Information("Culture {SysLang}", CultureInfo.CurrentCulture); diff --git a/FModel/Constants.cs b/FModel/Constants.cs index 94911598..48507954 100644 --- a/FModel/Constants.cs +++ b/FModel/Constants.cs @@ -1,12 +1,20 @@ -using System.Numerics; +using System; +using System.Diagnostics; +using System.IO; +using System.Numerics; using System.Reflection; using CUE4Parse.UE4.Objects.Core.Misc; +using FModel.Extensions; namespace FModel; public static class Constants { - public static readonly string APP_VERSION = Assembly.GetExecutingAssembly().GetName().Version?.ToString(); + public static readonly string APP_PATH = Path.GetFullPath(Environment.GetCommandLineArgs()[0]); + public static readonly string APP_VERSION = FileVersionInfo.GetVersionInfo(APP_PATH).FileVersion; + public static readonly string APP_COMMIT_ID = FileVersionInfo.GetVersionInfo(APP_PATH).ProductVersion.SubstringAfter('+'); + public static readonly string APP_SHORT_COMMIT_ID = APP_COMMIT_ID[..7]; + public const string ZERO_64_CHAR = "0000000000000000000000000000000000000000000000000000000000000000"; public static readonly FGuid ZERO_GUID = new(0U); diff --git a/FModel/Settings/UserSettings.cs b/FModel/Settings/UserSettings.cs index 178abe5a..e11863fe 100644 --- a/FModel/Settings/UserSettings.cs +++ b/FModel/Settings/UserSettings.cs @@ -200,13 +200,6 @@ namespace FModel.Settings set => SetProperty(ref _nextUpdateCheck, value); } - private string _commitHash = Constants.APP_VERSION; - public string CommitHash - { - get => _commitHash; - set => SetProperty(ref _commitHash, value); - } - private bool _keepDirectoryStructure = true; public bool KeepDirectoryStructure { @@ -279,8 +272,6 @@ namespace FModel.Settings [JsonIgnore] public DirectorySettings CurrentDir { get; set; } - [JsonIgnore] - public string ShortCommitHash => CommitHash[..7]; /// /// TO DELETEEEEEEEEEEEEE diff --git a/FModel/ViewModels/ApiEndpoints/FModelApiEndpoint.cs b/FModel/ViewModels/ApiEndpoints/FModelApiEndpoint.cs index b87911e0..04691521 100644 --- a/FModel/ViewModels/ApiEndpoints/FModelApiEndpoint.cs +++ b/FModel/ViewModels/ApiEndpoints/FModelApiEndpoint.cs @@ -156,8 +156,8 @@ public class FModelApiEndpoint : AbstractApiProvider var qa = (CustomMandatory) args.Mandatory; var currentVersion = new System.Version(args.CurrentVersion); - if ((qa.Value && qa.CommitHash == UserSettings.Default.CommitHash) || // qa branch : same commit id - (!qa.Value && currentVersion == args.InstalledVersion && args.CurrentVersion == UserSettings.Default.CommitHash)) // stable - beta branch : same version + commit id = version + if ((qa.Value && qa.CommitHash == Constants.APP_COMMIT_ID) || // qa branch : same commit id + (!qa.Value && currentVersion == args.InstalledVersion)) // stable - beta branch : same version + commit id = version { if (UserSettings.Default.ShowChangelog) ShowChangelog(args); diff --git a/FModel/ViewModels/ApiEndpoints/Models/GitHubResponse.cs b/FModel/ViewModels/ApiEndpoints/Models/GitHubResponse.cs index 85c15e17..c2c15d5d 100644 --- a/FModel/ViewModels/ApiEndpoints/Models/GitHubResponse.cs +++ b/FModel/ViewModels/ApiEndpoints/Models/GitHubResponse.cs @@ -63,13 +63,24 @@ public class GitHubCommit : ViewModel } } - public bool IsCurrent => Sha == UserSettings.Default.CommitHash; + public bool IsCurrent => Sha == Constants.APP_COMMIT_ID; public string ShortSha => Sha[..7]; public bool IsDownloadable => Asset != null; public void Download() { - if (IsCurrent) return; + if (IsCurrent) + { + MessageBox.Show(new MessageBoxModel + { + Text = "You are already on the latest version.", + Caption = "Update FModel", + Icon = MessageBoxImage.Information, + Buttons = [MessageBoxButtons.Ok()], + IsSoundEnabled = false + }); + return; + } var messageBox = new MessageBoxModel { @@ -87,7 +98,6 @@ public class GitHubCommit : ViewModel { if (AutoUpdater.DownloadUpdate(new UpdateInfoEventArgs { DownloadURL = Asset.BrowserDownloadUrl })) { - UserSettings.Default.CommitHash = Sha; Application.Current.Shutdown(); } } diff --git a/FModel/ViewModels/ApplicationViewModel.cs b/FModel/ViewModels/ApplicationViewModel.cs index a96d4d22..a67df7ad 100644 --- a/FModel/ViewModels/ApplicationViewModel.cs +++ b/FModel/ViewModels/ApplicationViewModel.cs @@ -49,7 +49,7 @@ public class ApplicationViewModel : ViewModel public CopyCommand CopyCommand => _copyCommand ??= new CopyCommand(this); private CopyCommand _copyCommand; - public string InitialWindowTitle => $"FModel ({UserSettings.Default.ShortCommitHash})"; + public string InitialWindowTitle => $"FModel ({Constants.APP_SHORT_COMMIT_ID})"; public string GameDisplayName => CUE4Parse.Provider.GameDisplayName ?? "Unknown"; public string TitleExtra => $"({UserSettings.Default.CurrentDir.UeVersion}){(Build != EBuildKind.Release ? $" ({Build})" : "")}"; @@ -143,7 +143,7 @@ public class ApplicationViewModel : ViewModel StartInfo = new ProcessStartInfo { FileName = "dotnet", - Arguments = $"\"{Path.GetFullPath(Environment.GetCommandLineArgs()[0])}\"", + Arguments = $"\"{path}\"", UseShellExecute = false, RedirectStandardOutput = false, RedirectStandardError = false, diff --git a/FModel/ViewModels/UpdateViewModel.cs b/FModel/ViewModels/UpdateViewModel.cs index 96d0a49f..55d85209 100644 --- a/FModel/ViewModels/UpdateViewModel.cs +++ b/FModel/ViewModels/UpdateViewModel.cs @@ -1,10 +1,12 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using System.Windows.Data; using FModel.Extensions; using FModel.Framework; using FModel.Services; +using FModel.Settings; using FModel.ViewModels.ApiEndpoints.Models; using FModel.ViewModels.Commands; using FModel.Views.Resources.Converters; @@ -28,6 +30,9 @@ public class UpdateViewModel : ViewModel { GroupDescriptions = { new PropertyGroupDescription("Commit.Author.Date", new DateTimeToDateConverter()) } }; + + if (UserSettings.Default.NextUpdateCheck < DateTime.Now) + RemindMeCommand.Execute(this, null); } public async Task Load()