29 lines
1.7 KiB
C#
29 lines
1.7 KiB
C#
using System.Text.Json;
|
|
using Velopack;
|
|
|
|
namespace AstroFrame.Desktop;
|
|
|
|
// Explicit local-feed probe used to verify installed package lifecycle without publishing test releases.
|
|
internal static class UpdateDiagnostics
|
|
{
|
|
public static async Task<int> Run(string[] args)
|
|
{
|
|
string report = Path.GetFullPath(args[2]);
|
|
try
|
|
{
|
|
string feed = args[1] == ReleaseUpdateBackend.Repository ? args[1] : Path.GetFullPath(args[1]);
|
|
var options = new UpdateOptions { ExplicitChannel = OperatingSystem.IsWindows() ? "win-x64" : "linux-x64" };
|
|
var manager = feed == ReleaseUpdateBackend.Repository
|
|
? new UpdateManager(new Velopack.Sources.GiteaSource(feed, null, false), options)
|
|
: new UpdateManager(feed, options);
|
|
if (!manager.IsInstalled) throw new InvalidOperationException("Probe requires an installed Windows package or Linux AppImage.");
|
|
var update = await manager.CheckForUpdatesAsync();
|
|
if (update != null) await manager.DownloadUpdatesAsync(update);
|
|
var record = new { version = manager.CurrentVersion?.ToString(), available = update?.TargetFullRelease.Version.ToString(), downloaded = manager.UpdatePendingRestart?.Version.ToString() };
|
|
File.AppendAllText(report, JsonSerializer.Serialize(record) + Environment.NewLine);
|
|
if (update != null && args.Contains("--apply")) manager.WaitExitThenApplyUpdates(update.TargetFullRelease, silent: true, restart: true, restartArgs: ["--verify-update", feed, report]);
|
|
return 0;
|
|
}
|
|
catch (Exception e) { File.AppendAllText(report, e + Environment.NewLine); return 1; }
|
|
}
|
|
}
|