Files

109 lines
3.4 KiB
C#
Raw Permalink Normal View History

2023-12-26 19:54:05 +00:00
#pragma warning disable CA1416 // Validate platform compatibility
using System.Diagnostics;
2023-12-31 11:09:44 +00:00
using Velopack;
using Velopack.Locators;
2025-03-03 10:46:36 +00:00
using Velopack.Logging;
var locator = VelopackLocator.CreateDefaultForPlatform(new ConsoleVelopackLogger());
2023-12-23 15:08:47 +00:00
try {
2023-12-26 19:54:05 +00:00
bool shouldExit = false;
2023-12-26 20:45:38 +00:00
bool shouldAutoUpdate = args.Any(a => a.Equals("--autoupdate", StringComparison.OrdinalIgnoreCase));
#if USE_ASYNC_MAIN
await Task.Delay(10).ConfigureAwait(false);
#endif
2024-01-25 15:17:37 +00:00
#if !NO_VELO_BUILDER
2023-12-31 11:09:44 +00:00
VelopackApp.Build()
2023-12-26 20:45:38 +00:00
.SetAutoApplyOnStartup(shouldAutoUpdate)
2025-03-03 10:46:36 +00:00
.OnFirstRun(
(v) => {
debugFile("firstrun", v.ToString());
Console.WriteLine("was first run");
shouldExit = true;
})
.OnRestarted(
(v) => {
debugFile("restarted", v.ToString() + "," + String.Join(",", args));
Console.WriteLine("app just restarted");
shouldExit = true;
})
.SetLocator(locator)
.OnAfterInstallFastCallback((v) => debugFile("args.txt", String.Join(" ", args)))
.OnBeforeUpdateFastCallback((v) => debugFile("args.txt", String.Join(" ", args)))
.OnAfterUpdateFastCallback((v) => debugFile("args.txt", String.Join(" ", args)))
.OnBeforeUninstallFastCallback((v) => debugFile("args.txt", String.Join(" ", args)))
.Run();
2023-12-26 19:54:05 +00:00
2023-12-26 20:45:38 +00:00
if (shouldAutoUpdate) {
// this shouldn't be reached
return -1;
}
2023-12-26 19:54:05 +00:00
if (shouldExit) {
2023-12-23 15:08:47 +00:00
return 0;
}
2024-01-25 15:17:37 +00:00
#endif
2023-12-23 15:08:47 +00:00
if (args.Length == 1 && args[0] == "version") {
2023-12-23 20:35:56 +00:00
Console.WriteLine(locator.CurrentlyInstalledVersion?.ToString() ?? "unknown_version");
2023-12-23 15:08:47 +00:00
return 0;
}
if (args.Length == 1 && args[0] == "test") {
2023-12-23 20:35:56 +00:00
Console.WriteLine(Const.TEST_STRING ?? "no_test_string");
2023-12-23 15:08:47 +00:00
return 0;
}
if (args.Length == 2) {
if (args[0] == "check") {
2025-03-03 10:46:36 +00:00
var um = new UpdateManager(args[1], null, locator);
2023-12-23 15:08:47 +00:00
var info = um.CheckForUpdates();
if (info == null) {
Console.WriteLine("no updates");
return 0;
} else {
Console.WriteLine("update: " + info.TargetFullRelease.Version);
return 0;
}
}
if (args[0] == "download") {
2025-03-03 10:46:36 +00:00
var um = new UpdateManager(args[1], null, locator);
2023-12-23 15:08:47 +00:00
var info = um.CheckForUpdates();
if (info == null) {
Console.WriteLine("no updates");
return -1;
}
2025-03-03 10:46:36 +00:00
2023-12-23 15:08:47 +00:00
um.DownloadUpdates(info, (x) => Console.WriteLine(x));
return 0;
}
if (args[0] == "apply") {
2025-03-03 10:46:36 +00:00
var um = new UpdateManager(args[1], null, locator);
if (um.UpdatePendingRestart == null) {
2023-12-23 15:08:47 +00:00
Console.WriteLine("not pending restart");
return -1;
}
2025-03-03 10:46:36 +00:00
2023-12-23 15:08:47 +00:00
Console.WriteLine("applying...");
um.ApplyUpdatesAndRestart((VelopackAsset) null, new[] { "test", "args !!" });
2023-12-23 15:08:47 +00:00
return 0;
}
}
} catch (Exception ex) {
Console.WriteLine("exception: " + ex.ToString());
2023-12-26 19:54:05 +00:00
if (Debugger.IsAttached) throw;
2023-12-23 15:08:47 +00:00
return -1;
}
Console.WriteLine("Invalid args: " + String.Join(", ", args));
2023-12-26 19:54:05 +00:00
return -1;
void debugFile(string name, string message)
{
var path = Path.Combine(AppContext.BaseDirectory, "..", name);
File.AppendAllText(path, message + Environment.NewLine);
2025-03-03 10:46:36 +00:00
}