From e3b7cbcc2a25ba45197807ad1fca131eb363f0e5 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Sat, 7 Jan 2023 18:09:37 -0700 Subject: [PATCH] Add proper Upgrade form --- Source/AppScaffolding/LibationScaffolding.cs | 10 +- Source/AppScaffolding/UpgradeProperties.cs | 30 ++- .../Dialogs/UpgradeNotification.axaml | 54 ----- .../Dialogs/UpgradeNotification.axaml.cs | 42 ---- .../Dialogs/UpgradeNotificationDialog.axaml | 91 ++++++++ .../UpgradeNotificationDialog.axaml.cs | 51 ++++ .../Views/MainWindow.Update.cs | 62 +++-- .../UpgradeNotificationDialog.Designer.cs | 221 ++++++++++++++++++ .../Dialogs/UpgradeNotificationDialog.cs | 71 ++++++ .../Dialogs/UpgradeNotificationDialog.resx | 78 +++++++ Source/LibationWinForms/FormSaveExtension.cs | 17 +- Source/LibationWinForms/Program.cs | 2 +- Source/LibationWinForms/Updater.cs | 69 +++--- 13 files changed, 623 insertions(+), 175 deletions(-) delete mode 100644 Source/LibationAvalonia/Dialogs/UpgradeNotification.axaml delete mode 100644 Source/LibationAvalonia/Dialogs/UpgradeNotification.axaml.cs create mode 100644 Source/LibationAvalonia/Dialogs/UpgradeNotificationDialog.axaml create mode 100644 Source/LibationAvalonia/Dialogs/UpgradeNotificationDialog.axaml.cs create mode 100644 Source/LibationWinForms/Dialogs/UpgradeNotificationDialog.Designer.cs create mode 100644 Source/LibationWinForms/Dialogs/UpgradeNotificationDialog.cs create mode 100644 Source/LibationWinForms/Dialogs/UpgradeNotificationDialog.resx diff --git a/Source/AppScaffolding/LibationScaffolding.cs b/Source/AppScaffolding/LibationScaffolding.cs index 31eaa833..84ec6fe4 100644 --- a/Source/AppScaffolding/LibationScaffolding.cs +++ b/Source/AppScaffolding/LibationScaffolding.cs @@ -29,6 +29,9 @@ namespace AppScaffolding public static class LibationScaffolding { + public const string RepositoryUrl = "ht" + "tps://github.com/rmcrackan/Libation"; + public const string WebsiteUrl = "ht" + "tps://getlibation.com"; + public const string RepositoryLatestUrl = "ht" + "tps://github.com/rmcrackan/Libation/releases/latest"; public static ReleaseIdentifier ReleaseIdentifier { get; private set; } public static VarietyType Variety => ReleaseIdentifier == ReleaseIdentifier.WindowsClassic ? VarietyType.Classic @@ -354,7 +357,7 @@ namespace AppScaffolding public static UpgradeProperties GetLatestRelease() { // timed out - (var latest, var zip) = getLatestRelease(TimeSpan.FromSeconds(10)); + (var latest, var zip) = getLatestRelease(TimeSpan.FromSeconds(10000)); if (latest is null || zip is null) return null; @@ -363,9 +366,6 @@ namespace AppScaffolding if (!Version.TryParse(latestVersionString, out var latestRelease)) return null; - // we're up to date - if (latestRelease <= BuildVersion) - return null; // we have an update @@ -378,7 +378,7 @@ namespace AppScaffolding zipUrl }); - return new(zipUrl, latest.HtmlUrl, zip.Name, latestRelease); + return new(zipUrl, latest.HtmlUrl, zip.Name, latestRelease, latest.Body); } private static (Octokit.Release, Octokit.ReleaseAsset) getLatestRelease(TimeSpan timeout) { diff --git a/Source/AppScaffolding/UpgradeProperties.cs b/Source/AppScaffolding/UpgradeProperties.cs index f1ca062f..d3a040f2 100644 --- a/Source/AppScaffolding/UpgradeProperties.cs +++ b/Source/AppScaffolding/UpgradeProperties.cs @@ -1,6 +1,34 @@ using System; +using System.Text.RegularExpressions; namespace AppScaffolding { - public record UpgradeProperties(string ZipUrl, string HtmlUrl, string ZipName, Version LatestRelease); + public record UpgradeProperties + { + private static readonly Regex linkstripper = new Regex(@"\[(.*)\]\(.*\)"); + public string ZipUrl { get; } + public string HtmlUrl { get; } + public string ZipName { get; } + public Version LatestRelease { get; } + public string Notes { get; } + + public UpgradeProperties(string zipUrl, string htmlUrl, string zipName, Version latestRelease, string notes) + { + ZipName = zipName; + HtmlUrl = htmlUrl; + ZipUrl = zipUrl; + LatestRelease = latestRelease; + Notes = stripMarkdownLinks(notes); + } + private string stripMarkdownLinks(string body) + { + body = body.Replace(@"\", ""); + var matches = linkstripper.Matches(body); + + foreach (Match match in matches) + body = body.Replace(match.Groups[0].Value, match.Groups[1].Value); + + return body; + } + } } diff --git a/Source/LibationAvalonia/Dialogs/UpgradeNotification.axaml b/Source/LibationAvalonia/Dialogs/UpgradeNotification.axaml deleted file mode 100644 index 7318396d..00000000 --- a/Source/LibationAvalonia/Dialogs/UpgradeNotification.axaml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - -