diff --git a/ModpackUpdater.Apps.Client.Gui/MainForm.axaml.cs b/ModpackUpdater.Apps.Client.Gui/MainForm.axaml.cs index 6d3f967..e6e280c 100644 --- a/ModpackUpdater.Apps.Client.Gui/MainForm.axaml.cs +++ b/ModpackUpdater.Apps.Client.Gui/MainForm.axaml.cs @@ -272,47 +272,12 @@ public partial class MainForm : Window AppConfig.Instance.LastMinecraftProfilePath = TextBoxMinecraftProfileFolder.Text?.Trim(); } - private async Task UpdateApp() - { - if (Debugger.IsAttached) - return; - - var myAppPath = EnvironmentEx.ProcessPath!; - var updater = new UpdateClient(Program.UpdateUrl, Assembly.GetEntryAssembly()!.GetAppVersion(), AppChannel.Stable) - { - Distro = RuntimeInformationsEx.GetRuntimeIdentifier(), - }; - - if (await updater.CheckForUpdate() is {} packageToInstall - && await MessageBoxManager.GetMessageBoxStandard(MsgBoxLangRes.UpdateAvailable_Title, MsgBoxLangRes.UpdateAvailable, ButtonEnum.YesNo, MsBox.Avalonia.Enums.Icon.Info).ShowWindowDialogAsync(this) == ButtonResult.Yes) - { - SetStatus(GeneralLangRes.DownloadProgramUpdate, AppGlobals.Symbols.GetImageSource(AppSymbols.software_installer)); - IsEnabled = false; - if (await updater.DownloadPackageAsync(packageToInstall) - && await updater.InstallPackageAsync(packageToInstall, myAppPath)) - { - IsVisible = false; - await Process.Start(myAppPath).WaitForExitAsync(); - Environment.Exit(0); - return; - } - IsEnabled = true; - } - } - private async void MainForm_Loaded(object? sender, RoutedEventArgs e) { -#if !DISABLE_UPDATE - try - { - await UpdateApp(); - } - catch (Exception ex) - { - await MessageBoxManager.GetMessageBoxStandard(MsgBoxLangRes.UpdateAvailable_Title, string.Format(MsgBoxLangRes.UpdateAvailable, ex.Message), ButtonEnum.YesNo, MsBox.Avalonia.Enums.Icon.Info).ShowWindowAsync(); - IsEnabled = true; - } -#endif + var updates = new AppUpdates(Program.UpdateUrl, this); + updates.OnDownloadProgramUpdate += (o, args) => SetStatus(GeneralLangRes.DownloadProgramUpdate, AppGlobals.Symbols.GetImageSource(AppSymbols.software_installer)); + await updates.UpdateApp(); + ClearStatus(); CheckStatusAndUpdate(true); } diff --git a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs index c86be1c..78ab203 100644 --- a/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs +++ b/ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs @@ -51,7 +51,7 @@ internal static class SharedFunctions api.Model.Progress.Set(i); } - api.Model.Progress.End(); + api.Model.Progress.Stop(); } public static async Task CollectUpdates(IMainApi api, params InstallAction[] actions) @@ -122,7 +122,7 @@ internal static class SharedFunctions api.Model.Progress.Set(i); } - api.Model.Progress.End(); + api.Model.Progress.Stop(); } public static void ClearDirectLinks(IMainApi api, params MainWindowGridRow[] rows) @@ -138,7 +138,7 @@ internal static class SharedFunctions api.Model.Progress.Set(i); } - api.Model.Progress.End(); + api.Model.Progress.Stop(); } public static string GenerateChangelog(InstallInfos installInfos, UpdateInfo updateInfos) diff --git a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs index d3d3e26..7fa6723 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs +++ b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.Designer.cs @@ -1,10 +1,9 @@ //------------------------------------------------------------------------------ // -// Dieser Code wurde von einem Tool generiert. -// Laufzeitversion:4.0.30319.42000 +// This code was generated by a tool. // -// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -// der Code erneut generiert wird. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -12,46 +11,32 @@ namespace ModpackUpdater.Apps.Manager.LangRes { using System; - /// - /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. - /// - // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class MsgBoxLangRes { + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class MsgBoxLangRes { - private static global::System.Resources.ResourceManager resourceMan; + private static System.Resources.ResourceManager resourceMan; - private static global::System.Globalization.CultureInfo resourceCulture; + private static System.Globalization.CultureInfo resourceCulture; - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal MsgBoxLangRes() { } - /// - /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Resources.ResourceManager ResourceManager { get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ModpackUpdater.Apps.Manager.LangRes.MsgBoxLangRes", typeof(MsgBoxLangRes).Assembly); + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("ModpackUpdater.Apps.Manager.LangRes.MsgBoxLangRes", typeof(MsgBoxLangRes).Assembly); resourceMan = temp; } return resourceMan; } } - /// - /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -60,76 +45,64 @@ namespace ModpackUpdater.Apps.Manager.LangRes { } } - /// - /// Sucht eine lokalisierte Zeichenfolge, die The changelog for the selected version has been generated and copied to the clipboard. ähnelt. - /// - internal static string ChangelogCopiedToClipboard { + public static string ChangelogCopiedToClipboard { get { return ResourceManager.GetString("ChangelogCopiedToClipboard", resourceCulture); } } - /// - /// Sucht eine lokalisierte Zeichenfolge, die Changelog generated successfully ähnelt. - /// - internal static string ChangelogCopiedToClipboard_Title { + public static string ChangelogCopiedToClipboard_Title { get { return ResourceManager.GetString("ChangelogCopiedToClipboard_Title", resourceCulture); } } - /// - /// Sucht eine lokalisierte Zeichenfolge, die The modlist has been generated and copied to the clipboard. ähnelt. - /// - internal static string ModlistCopiedToClipboard { + public static string ModlistCopiedToClipboard { get { return ResourceManager.GetString("ModlistCopiedToClipboard", resourceCulture); } } - /// - /// Sucht eine lokalisierte Zeichenfolge, die Modlist generated successfully ähnelt. - /// - internal static string ModlistCopiedToClipboard_Title { + public static string ModlistCopiedToClipboard_Title { get { return ResourceManager.GetString("ModlistCopiedToClipboard_Title", resourceCulture); } } - /// - /// Sucht eine lokalisierte Zeichenfolge, die The modlist has been generated successfully and saved to the selected location. ähnelt. - /// - internal static string ModlistGenerated { + public static string ModlistGenerated { get { return ResourceManager.GetString("ModlistGenerated", resourceCulture); } } - /// - /// Sucht eine lokalisierte Zeichenfolge, die Modlist generated successfully ähnelt. - /// - internal static string ModlistGenerated_Title { + public static string ModlistGenerated_Title { get { return ResourceManager.GetString("ModlistGenerated_Title", resourceCulture); } } - /// - /// Sucht eine lokalisierte Zeichenfolge, die Are you sure that you want to delete this update? ähnelt. - /// - internal static string RemoveUpdate { + public static string RemoveUpdate { get { return ResourceManager.GetString("RemoveUpdate", resourceCulture); } } - /// - /// Sucht eine lokalisierte Zeichenfolge, die Remove update ähnelt. - /// - internal static string RemoveUpdate_Title { + public static string RemoveUpdate_Title { get { return ResourceManager.GetString("RemoveUpdate_Title", resourceCulture); } } + + public static string UpdateAvailable { + get { + return ResourceManager.GetString("UpdateAvailable", resourceCulture); + } + } + + public static string UpdateAvailable_Title { + get { + return ResourceManager.GetString("UpdateAvailable_Title", resourceCulture); + } + } } } diff --git a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx index 4b6b952..ff33635 100644 --- a/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx +++ b/ModpackUpdater.Apps.Manager/LangRes/MsgBoxLangRes.resx @@ -141,4 +141,11 @@ Remove update + + A new version of this program is available! Install now? +If you confirm, the update will be installed automatically within a few seconds. + + + New program version available + \ No newline at end of file diff --git a/ModpackUpdater.Apps.Manager/Program.cs b/ModpackUpdater.Apps.Manager/Program.cs index 6046a8a..09be226 100644 --- a/ModpackUpdater.Apps.Manager/Program.cs +++ b/ModpackUpdater.Apps.Manager/Program.cs @@ -7,6 +7,8 @@ namespace ModpackUpdater.Apps.Manager; public static class Program { + public const string UpdateUrl = "https://git.pilzinsel64.de/litw-refined/minecraft-modpack-updater/-/snippets/3/raw/main/updates-manager.json"; + internal static readonly SettingsManager settingsManager; public static ISettings Settings => settingsManager.Instance; diff --git a/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml.cs b/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml.cs index 4e9fa1e..8e49b0d 100644 --- a/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml.cs +++ b/ModpackUpdater.Apps.Manager/Ui/MainWindow.axaml.cs @@ -7,8 +7,11 @@ using ModpackUpdater.Apps.Manager.Api; using ModpackUpdater.Apps.Manager.Api.Model; using ModpackUpdater.Apps.Manager.Api.Plugins.Features; using ModpackUpdater.Apps.Manager.Api.Plugins.Params; +using ModpackUpdater.Apps.Manager.LangRes; using ModpackUpdater.Apps.Manager.Settings; using ModpackUpdater.Apps.Manager.Ui.Models.MainWindow; +using MsBox.Avalonia; +using MsBox.Avalonia.Enums; using Pilz.Extensions; using Pilz.Features; using Pilz.UI.AvaloniaUI.Features; @@ -91,7 +94,7 @@ public partial class MainWindow : Window, IMainApi Model.Progress.Start(); await ws.Save(); - Model.Progress.End(); + Model.Progress.Stop(); } private void LoadRecentWorkspaces() @@ -126,8 +129,13 @@ public partial class MainWindow : Window, IMainApi settings.Workspaces.RemoveAt(20); } - private void Window_OnLoaded(object? sender, RoutedEventArgs e) + private async void Window_OnLoaded(object? sender, RoutedEventArgs e) { + var updater = new AppUpdates(Program.UpdateUrl, this); + updater.OnDownloadProgramUpdate += (o, args) => Model.Progress.Start(); + await updater.UpdateApp(); + Model.Progress.Stop(); + LoadRecentWorkspaces(); } diff --git a/ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs b/ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs index d4a6b95..beade55 100644 --- a/ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs +++ b/ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs @@ -40,7 +40,7 @@ public class ProgressInfos : INotifyPropertyChanged Value += 1; } - public void End() + public void Stop() { IsVisible = false; IsGeneric = false; diff --git a/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml.cs b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml.cs index 3a28e03..c0d7077 100644 --- a/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml.cs +++ b/ModpackUpdater.Apps.Manager/Ui/UpdatesCollectorView.axaml.cs @@ -42,7 +42,7 @@ public partial class UpdatesCollectorView : AvaloniaFlyoutBase break; } - Model.Progress.End(); + Model.Progress.Stop(); } protected override object GetResult() diff --git a/ModpackUpdater.Apps/AppUpdates.cs b/ModpackUpdater.Apps/AppUpdates.cs new file mode 100644 index 0000000..d75d0d9 --- /dev/null +++ b/ModpackUpdater.Apps/AppUpdates.cs @@ -0,0 +1,59 @@ +using System.Diagnostics; +using System.Reflection; +using Avalonia.Controls; +using MsBox.Avalonia; +using MsBox.Avalonia.Enums; +using Pilz; +using Pilz.Extensions; +using Pilz.Runtime; +using Pilz.Updating.Client; + +namespace ModpackUpdater.Apps; + +public class AppUpdates(string updateUrl, Window mainWindow) +{ + public event EventHandler? OnDownloadProgramUpdate; + + public async Task UpdateApp() + { +#if !DISABLE_UPDATE + try + { + await UpdateAppCore(); + } + catch (Exception ex) + { + await MessageBoxManager.GetMessageBoxStandard(MsgBoxLangRes.UpdateAvailable_Title, string.Format(MsgBoxLangRes.UpdateAvailable, ex.Message), ButtonEnum.YesNo, MsBox.Avalonia.Enums.Icon.Info).ShowWindowAsync(); + mainWindow.IsEnabled = true; + } +#endif + } + + private async Task UpdateAppCore() + { + if (Debugger.IsAttached) + return; + + var myAppPath = EnvironmentEx.ProcessPath!; + var updater = new UpdateClient(updateUrl, Assembly.GetEntryAssembly()!.GetAppVersion(), AppChannel.Stable) + { + Distro = RuntimeInformationsEx.GetRuntimeIdentifier(), + }; + + if (await updater.CheckForUpdate() is {} packageToInstall + && await MessageBoxManager.GetMessageBoxStandard(MsgBoxLangRes.UpdateAvailable_Title, MsgBoxLangRes.UpdateAvailable, ButtonEnum.YesNo, MsBox.Avalonia.Enums.Icon.Info).ShowWindowDialogAsync(mainWindow) == ButtonResult.Yes) + { + OnDownloadProgramUpdate?.Invoke(this, EventArgs.Empty); + mainWindow.IsEnabled = false; + if (await updater.DownloadPackageAsync(packageToInstall) + && await updater.InstallPackageAsync(packageToInstall, myAppPath)) + { + mainWindow.IsVisible = false; + await Process.Start(myAppPath).WaitForExitAsync(); + Environment.Exit(0); + return; + } + mainWindow.IsEnabled = true; + } + } +} \ No newline at end of file diff --git a/ModpackUpdater.Apps/LangRes/MsgBoxLangRes.Designer.cs b/ModpackUpdater.Apps/LangRes/MsgBoxLangRes.Designer.cs new file mode 100644 index 0000000..7af782a --- /dev/null +++ b/ModpackUpdater.Apps/LangRes/MsgBoxLangRes.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ModpackUpdater.Apps { + using System; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class MsgBoxLangRes { + + private static System.Resources.ResourceManager resourceMan; + + private static System.Globalization.CultureInfo resourceCulture; + + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal MsgBoxLangRes() { + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Resources.ResourceManager ResourceManager { + get { + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("ModpackUpdater.Apps.LangRes.MsgBoxLangRes", typeof(MsgBoxLangRes).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + public static string UpdateAvailable { + get { + return ResourceManager.GetString("UpdateAvailable", resourceCulture); + } + } + + public static string UpdateAvailable_Title { + get { + return ResourceManager.GetString("UpdateAvailable_Title", resourceCulture); + } + } + + public static string ErrorWhileUpdate_Title { + get { + return ResourceManager.GetString("ErrorWhileUpdate_Title", resourceCulture); + } + } + + public static string ErrorWhileUpdate { + get { + return ResourceManager.GetString("ErrorWhileUpdate", resourceCulture); + } + } + } +} diff --git a/ModpackUpdater.Apps/LangRes/MsgBoxLangRes.resx b/ModpackUpdater.Apps/LangRes/MsgBoxLangRes.resx new file mode 100644 index 0000000..f8b87e9 --- /dev/null +++ b/ModpackUpdater.Apps/LangRes/MsgBoxLangRes.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + A new version of this program is available! Install now? +If you confirm, the update will be installed automatically within a few seconds. + + + New program version available + + + Error while updating + + + An error happened while updating the program. Error message:\n{0} + + \ No newline at end of file diff --git a/ModpackUpdater.Apps/ModpackUpdater.Apps.csproj b/ModpackUpdater.Apps/ModpackUpdater.Apps.csproj index 789c7b2..49750fb 100644 --- a/ModpackUpdater.Apps/ModpackUpdater.Apps.csproj +++ b/ModpackUpdater.Apps/ModpackUpdater.Apps.csproj @@ -12,12 +12,17 @@ + + PublicResXFileCodeGenerator + MsgBoxLangRes.Designer.cs + + @@ -28,6 +33,26 @@ None All + + + + + + + True + True + GeneralLangRes.resx + + + True + True + MsgBoxLangRes.resx + + + True + True + MsgBoxLangRes.resx +