Skip to content

Commit

Permalink
Autoupdate functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdtrekkie committed Jul 10, 2024
1 parent 45303d9 commit 4e0daed
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion XRFAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions docs/ErrorCodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

6021 - Update check failed
6022 - Update failed
6023 - Update starting (informational)

6031 - External process start error
6032 - Registry access error
Expand Down
4 changes: 4 additions & 0 deletions modCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions modUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static int UpdateAgent()
int updateNeeded = CheckVersion();
if (updateNeeded >= 1)
{
modLogging.LogEvent("Updating agent", EventLogEntryType.Information, 6023);
try
{
try
Expand All @@ -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";
}
}
}

0 comments on commit 4e0daed

Please sign in to comment.