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 @@