From 2d7009d8fb419cce4e1a43c1d925929142ceaf3b Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:22:47 +0200 Subject: [PATCH] Startup re-scheduling https://github.com/seerge/g-helper/issues/1410 --- app/GHelper.csproj | 2 +- app/Helpers/Startup.cs | 24 ++++++++++++++++++++++-- app/Program.cs | 3 +++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/GHelper.csproj b/app/GHelper.csproj index a9d436bcb..b0e6e7d42 100644 --- a/app/GHelper.csproj +++ b/app/GHelper.csproj @@ -15,7 +15,7 @@ AnyCPU False True - 0.127 + 0.128 diff --git a/app/Helpers/Startup.cs b/app/Helpers/Startup.cs index e0639bdcb..7a8b00c2e 100644 --- a/app/Helpers/Startup.cs +++ b/app/Helpers/Startup.cs @@ -10,8 +10,8 @@ public class Startup public static bool IsScheduled() { - TaskService taskService = new TaskService(); - return (taskService.RootFolder.AllTasks.Any(t => t.Name == taskName)); + using (TaskService taskService = new TaskService()) + return (taskService.RootFolder.AllTasks.Any(t => t.Name == taskName)); } public static void ReScheduleAdmin() @@ -23,6 +23,26 @@ public static void ReScheduleAdmin() } } + public static void StartupCheck() + { + using (TaskService taskService = new TaskService()) + { + var task = taskService.RootFolder.AllTasks.FirstOrDefault(t => t.Name == taskName); + if (task != null) + { + string strExeFilePath = Application.ExecutablePath.Trim(); + string action = task.Definition.Actions.FirstOrDefault()!.ToString().Trim(); + if (!strExeFilePath.Equals(action, StringComparison.OrdinalIgnoreCase)) + { + Logger.WriteLine(action); + Logger.WriteLine("Rescheduling to: " + strExeFilePath); + UnSchedule(); + Schedule(); + } + } + } + } + public static void Schedule() { diff --git a/app/Program.cs b/app/Program.cs index 5127a5107..b068f834d 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -265,6 +265,9 @@ public static void SettingsToggle(string action = "", bool checkForFocus = true) settingsForm.FansToggle(2); modeControl.SetRyzen(); break; + default: + Startup.StartupCheck(); + break; } } }