From 1f685ae8a016470ea4493cc80a003cd395bbf834 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Wed, 27 Jul 2022 09:49:58 -0600 Subject: [PATCH] Add release index download --- Source/AppScaffolding/LibationScaffolding.cs | 28 +++++++++++++------ .../Views/MainWindow/MainWindow.axaml.cs | 4 +-- Source/LibationWinForms/Program.cs | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Source/AppScaffolding/LibationScaffolding.cs b/Source/AppScaffolding/LibationScaffolding.cs index f90b5bd3..3ee0687e 100644 --- a/Source/AppScaffolding/LibationScaffolding.cs +++ b/Source/AppScaffolding/LibationScaffolding.cs @@ -309,10 +309,17 @@ namespace AppScaffolding LibraryCommands.BookUserDefinedItemCommitted += (_, books) => SearchEngineCommands.UpdateBooks(books); } - public static UpgradeProperties GetLatestRelease(string regexpattern = ".*") + public enum ReleaseIdentifier + { + WindowsClassic, + WindowsAvalonia, + Linux + } + + public static UpgradeProperties GetLatestRelease(ReleaseIdentifier releaseID = ReleaseIdentifier.WindowsClassic) { // timed out - var latest = getLatestRelease(TimeSpan.FromSeconds(10), regexpattern); + var latest = getLatestRelease(TimeSpan.FromSeconds(100), releaseID); if (latest is null) return null; @@ -337,11 +344,11 @@ namespace AppScaffolding return new(zipUrl, latest.HtmlUrl, zip.Name, latestRelease); } - private static Octokit.Release getLatestRelease(TimeSpan timeout, string regexpattern) + private static Octokit.Release getLatestRelease(TimeSpan timeout, ReleaseIdentifier releaseID) { try { - var task = System.Threading.Tasks.Task.Run(() => getLatestRelease(regexpattern)); + var task = getLatestRelease(releaseID); if (task.Wait(timeout)) return task.Result; @@ -353,14 +360,19 @@ namespace AppScaffolding } return null; } - private static Octokit.Release getLatestRelease(string regexpattern) + private static async System.Threading.Tasks.Task getLatestRelease(ReleaseIdentifier releaseID) { var gitHubClient = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("Libation")); - // https://octokitnet.readthedocs.io/en/latest/releases/ - var releases = gitHubClient.Repository.Release.GetAll("rmcrackan", "Libation").GetAwaiter().GetResult(); + //Download the release index + var bts = await gitHubClient.Repository.Content.GetRawContent("Mbucari", "Libation", ".releaseindex.json"); + var releaseIndex = JObject.Parse(System.Text.Encoding.ASCII.GetString(bts)); + var regexPattern = releaseIndex.Value(releaseID.ToString()); - var regex = new System.Text.RegularExpressions.Regex(regexpattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); + // https://octokitnet.readthedocs.io/en/latest/releases/ + var releases = await gitHubClient.Repository.Release.GetAll("rmcrackan", "Libation"); + + var regex = new System.Text.RegularExpressions.Regex(regexPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); var latest = releases.FirstOrDefault(r => !r.Draft && !r.Prerelease && r.Assets.Any(a => regex.IsMatch(a.Name))); return latest; } diff --git a/Source/LibationAvalonia/Views/MainWindow/MainWindow.axaml.cs b/Source/LibationAvalonia/Views/MainWindow/MainWindow.axaml.cs index 0bf8611f..7f6cd23d 100644 --- a/Source/LibationAvalonia/Views/MainWindow/MainWindow.axaml.cs +++ b/Source/LibationAvalonia/Views/MainWindow/MainWindow.axaml.cs @@ -87,7 +87,7 @@ namespace LibationAvalonia.Views AppScaffolding.UpgradeProperties upgradeProperties; try { - upgradeProperties = AppScaffolding.LibationScaffolding.GetLatestRelease(@"Libation\.\d+\.\d+\.\d+-win-avalonia.zip"); + upgradeProperties = AppScaffolding.LibationScaffolding.GetLatestRelease(AppScaffolding.LibationScaffolding.ReleaseIdentifier.WindowsAvalonia); if (upgradeProperties is null) return; @@ -104,7 +104,7 @@ namespace LibationAvalonia.Views return; } - //Silently download the update in the background, ave it to a temp file. + //Silently download the update in the background, save it to a temp file. var zipPath = System.IO.Path.GetTempFileName(); try diff --git a/Source/LibationWinForms/Program.cs b/Source/LibationWinForms/Program.cs index 8ffff7cb..36b174a2 100644 --- a/Source/LibationWinForms/Program.cs +++ b/Source/LibationWinForms/Program.cs @@ -170,7 +170,7 @@ namespace LibationWinForms try { - upgradeProperties = AppScaffolding.LibationScaffolding.GetLatestRelease(@"Libation\.\d+\.\d+\.\d+-win.zip"); + upgradeProperties = AppScaffolding.LibationScaffolding.GetLatestRelease(AppScaffolding.LibationScaffolding.ReleaseIdentifier.WindowsClassic); if (upgradeProperties is null) return; }