From 4e0daeda36d0a577b8d2304c8d1fcde574277b0c Mon Sep 17 00:00:00 2001 From: Jacob Weisz Date: Tue, 9 Jul 2024 22:30:09 -0500 Subject: [PATCH] Autoupdate functionality --- XRFAgent.cs | 2 +- docs/ErrorCodes.md | 1 + modCommand.cs | 4 ++++ modUpdate.cs | 24 ++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/XRFAgent.cs b/XRFAgent.cs index f7b3e88..d762d37 100644 --- a/XRFAgent.cs +++ b/XRFAgent.cs @@ -33,9 +33,9 @@ protected override void OnStart(string[] args) modLogging.Load(); modLogging.LogEvent("XRFAgent starting", EventLogEntryType.Information); - modUpdate.CheckVersion(); modDatabase.Load(); modLogging.LogEvent("Database connected", EventLogEntryType.Information); + modUpdate.Autoupdate(); modNetwork.Load(); modSync.Load(); modSystem.GetSystemDetails(); diff --git a/docs/ErrorCodes.md b/docs/ErrorCodes.md index 9d49aaa..254fbfe 100644 --- a/docs/ErrorCodes.md +++ b/docs/ErrorCodes.md @@ -8,6 +8,7 @@ 6021 - Update check failed 6022 - Update failed +6023 - Update starting (informational) 6031 - External process start error 6032 - Registry access error diff --git a/modCommand.cs b/modCommand.cs index 9659eb6..c1a6422 100644 --- a/modCommand.cs +++ b/modCommand.cs @@ -29,6 +29,10 @@ public static void Handle(string inputCommand, string inputSource, string reques case "check" when inputData.Length == 3: if (inputData[1] == "installed" && inputData[2] == "software") { outputResponse = modSystem.GetInstalledSoftware(); } else if (inputData[1] == "system" && inputData[2] == "details") { outputResponse = modSystem.GetSystemDetails(); } break; + case "disable" when inputData.Length == 2: + if (inputData[1] == "autoupdate") { outputResponse = modUpdate.DisableAutoupdate(); } break; + case "enable" when inputData.Length == 2: + if (inputData[1] == "autoupdate") { outputResponse = modUpdate.EnableAutoupdate(); } break; case "hac": case "hacontroller": string inputCommandTrimmed = inputCommand.Remove(0, inputData[0].Length + 1); diff --git a/modUpdate.cs b/modUpdate.cs index 4aa1b1d..e684ac4 100644 --- a/modUpdate.cs +++ b/modUpdate.cs @@ -70,6 +70,7 @@ public static int UpdateAgent() int updateNeeded = CheckVersion(); if (updateNeeded >= 1) { + modLogging.LogEvent("Updating agent", EventLogEntryType.Information, 6023); try { try @@ -96,5 +97,28 @@ public static int UpdateAgent() } return updateNeeded; } + + public static int Autoupdate() + { + if (modDatabase.GetConfig("Update_Autoupdate") == "true") + { + return UpdateAgent(); + } else + { + return CheckVersion(); + } + } + + public static string DisableAutoupdate() + { + modDatabase.AddOrUpdateConfig(new modDatabase.Config { Key = "Update_Autoupdate", Value = "false" }); + return "Autoupdate disabled"; + } + + public static string EnableAutoupdate() + { + modDatabase.AddOrUpdateConfig(new modDatabase.Config { Key = "Update_Autoupdate", Value = "true" }); + return "Autoupdate enabled"; + } } }