From 065d915d464c048b0cbe8b26835492e7d4279264 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Sat, 8 Nov 2025 15:46:56 +0100 Subject: [PATCH] improvements & deployment --- Directory.Build.props | 16 ++++ ModpackUpdater.Apps.Client.Gui/AppUpdater.cs | 83 ----------------- ModpackUpdater.Apps.Client.Gui/MainForm.axaml | 22 ++--- .../MainForm.axaml.cs | 48 +++++++--- .../ModpackUpdater.Apps.Client.Gui.csproj | 14 ++- ModpackUpdater.Apps.Client.Gui/Program.cs | 2 +- .../{Windows.pubxml => Release.pubxml} | 0 .../app.pupnet.conf | 89 +++++++++++++++++++ Version.cs | 2 +- publish.sh | 9 ++ 10 files changed, 173 insertions(+), 112 deletions(-) create mode 100644 Directory.Build.props delete mode 100644 ModpackUpdater.Apps.Client.Gui/AppUpdater.cs rename ModpackUpdater.Apps.Client.Gui/Properties/PublishProfiles/{Windows.pubxml => Release.pubxml} (100%) create mode 100644 ModpackUpdater.Apps.Client.Gui/app.pupnet.conf create mode 100755 publish.sh diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..d8283d3 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,16 @@ + + + + https://git.pilzinsel64.de/litw-refined/minecraft-modpack-updater + MIT + False + True + 1591 + + + + False + None + + + \ No newline at end of file diff --git a/ModpackUpdater.Apps.Client.Gui/AppUpdater.cs b/ModpackUpdater.Apps.Client.Gui/AppUpdater.cs deleted file mode 100644 index ba988aa..0000000 --- a/ModpackUpdater.Apps.Client.Gui/AppUpdater.cs +++ /dev/null @@ -1,83 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Pilz.Extensions; -using System.Reflection; - -namespace ModpackUpdater.Apps.Client.Gui; - -public class AppUpdater(string updateUrl) -{ - private class UpdateInfo - { - [JsonConverter(typeof(VersionConverter))] - public Version? Version { get; set; } - public string? DownloadUrl { get; set; } - } - - private readonly HttpClient httpClient = new(); - private UpdateInfo? info; - - public async Task Check() - { - var hasUpdate = false; - - try - { - var appVersion = Assembly.GetExecutingAssembly().GetAppVersion().Version; - var result = await httpClient.GetStringAsync(updateUrl); - info = JsonConvert.DeserializeObject(result); - - if (info is not null && info.Version > appVersion) - hasUpdate = true; - } - catch - { - } - - return hasUpdate; - } - - public async Task Install() - { - var client = new HttpClient(); - var tempFileName = Path.GetTempFileName(); - var appFileName = Environment.ProcessPath; - var oldFileName = appFileName + ".old"; - - // Delete old file - try - { - File.Delete(oldFileName); - } - catch - { - } - - // Download the new file - await using (var tempFileStream = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite)) - { - Stream? downloadStream = null; - try - { - var url = info?.DownloadUrl; - downloadStream = await client.GetStreamAsync(url); - await downloadStream.CopyToAsync(tempFileStream); - } - catch - { - } - finally - { - if (downloadStream != null) - await downloadStream.DisposeAsync(); - } - } - - // Replace current application file with new file - if (!string.IsNullOrWhiteSpace(appFileName)) - { - File.Move(appFileName, oldFileName, true); - File.Move(tempFileName, appFileName); - } - } -} \ No newline at end of file diff --git a/ModpackUpdater.Apps.Client.Gui/MainForm.axaml b/ModpackUpdater.Apps.Client.Gui/MainForm.axaml index 9967507..64b4ea8 100644 --- a/ModpackUpdater.Apps.Client.Gui/MainForm.axaml +++ b/ModpackUpdater.Apps.Client.Gui/MainForm.axaml @@ -6,7 +6,9 @@ xmlns:pilz="https://git.pilzinsel64.de/pilz-framework/pilz" mc:Ignorable="d" x:Class="ModpackUpdater.Apps.Client.Gui.MainForm" - SizeToContent="WidthAndHeight" + Width="520" + SizeToContent="Height" + WindowStartupLocation="CenterScreen" Title="Minecraft Modpack Updater" Icon="/Assets/app.ico" > @@ -21,9 +23,9 @@ > - - - + + + @@ -31,10 +33,10 @@