Add release index download
This commit is contained in:
parent
bbe91099cb
commit
1f685ae8a0
@ -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<Octokit.Release> 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<string>(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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user