Prepare Pro 1.0.1 imports and license tooling
This commit is contained in:
1 parent
62f28c5621
commit
0b5017739c
13 files changed
+437
-48
No files matched your search
@@ -1,12 +1,16 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace LMEMappeCatastaliApp.Services;
|
||||
|
||||
public sealed class AppUpdateService
|
||||
{
|
||||
private const string LatestReleaseUrl = "https://gitea.lmcloud.it/api/v1/repos/livio/LMEMappeCatastaliApp/releases/latest";
|
||||
private const string ReleasesUrl = "https://gitea.lmcloud.it/api/v1/repos/livio/LMEMappeCatastaliProApp/releases?limit=50";
|
||||
private static readonly Regex ProTagPattern = new(
|
||||
@"^v?(?<version>\d+\.\d+\.\d+)-pro(?:[-.].*)?$",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
||||
private readonly HttpClient _httpClient = new() { Timeout = TimeSpan.FromSeconds(20) };
|
||||
|
||||
public static string CurrentVersion =>
|
||||
@@ -17,21 +21,53 @@ public sealed class AppUpdateService
|
||||
|
||||
public async Task<AppUpdateResult> CheckAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var release = await _httpClient.GetFromJsonAsync<GiteaRelease>(LatestReleaseUrl, cancellationToken)
|
||||
var releases = await _httpClient.GetFromJsonAsync<GiteaRelease[]>(ReleasesUrl, cancellationToken)
|
||||
?? throw new InvalidDataException("Risposta aggiornamenti non valida.");
|
||||
var latestText = (release.TagName ?? string.Empty).TrimStart('v', 'V');
|
||||
GiteaRelease? selectedRelease = null;
|
||||
GiteaAsset? selectedApk = null;
|
||||
Version? selectedVersion = null;
|
||||
foreach (var release in releases.Where(item => !item.Draft))
|
||||
{
|
||||
var match = ProTagPattern.Match(release.TagName ?? string.Empty);
|
||||
var apk = release.Assets?.FirstOrDefault(item => IsProApk(item.Name));
|
||||
if (!match.Success || apk is null || !Version.TryParse(match.Groups["version"].Value, out var version))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (selectedVersion is null || version > selectedVersion)
|
||||
{
|
||||
selectedRelease = release;
|
||||
selectedApk = apk;
|
||||
selectedVersion = version;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedRelease is null || selectedApk is null || selectedVersion is null)
|
||||
{
|
||||
throw new InvalidDataException("Nessuna release compatibile con LME Mappe Catastali Pro trovata.");
|
||||
}
|
||||
|
||||
_ = Version.TryParse(CurrentVersion, out var current);
|
||||
_ = Version.TryParse(latestText, out var latest);
|
||||
var apk = release.Assets?.FirstOrDefault(item => item.Name?.EndsWith(".apk", StringComparison.OrdinalIgnoreCase) == true);
|
||||
return new(latest is not null && current is not null && latest > current, latestText, release.HtmlUrl ?? string.Empty, apk?.BrowserDownloadUrl ?? release.HtmlUrl ?? string.Empty, release.Body ?? string.Empty);
|
||||
return new(
|
||||
current is not null && selectedVersion > current,
|
||||
selectedVersion.ToString(3),
|
||||
selectedRelease.HtmlUrl ?? string.Empty,
|
||||
selectedApk.BrowserDownloadUrl ?? selectedRelease.HtmlUrl ?? string.Empty,
|
||||
selectedRelease.Body ?? string.Empty);
|
||||
}
|
||||
|
||||
private static bool IsProApk(string? name) =>
|
||||
name?.StartsWith("LME-Mappe-Catastali-Pro-", StringComparison.OrdinalIgnoreCase) == true
|
||||
&& name.EndsWith(".apk", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private sealed class GiteaRelease
|
||||
{
|
||||
[JsonPropertyName("tag_name")] public string? TagName { get; set; }
|
||||
[JsonPropertyName("html_url")] public string? HtmlUrl { get; set; }
|
||||
[JsonPropertyName("assets")] public GiteaAsset[]? Assets { get; set; }
|
||||
[JsonPropertyName("body")] public string? Body { get; set; }
|
||||
[JsonPropertyName("draft")] public bool Draft { get; set; }
|
||||
}
|
||||
|
||||
private sealed class GiteaAsset
|
||||
|
||||
Reference in new issue
Block a user