Skip to content

Commit d845d99

Browse files
committed
fixed task scheduler bug and setup file version
1 parent 8babcf9 commit d845d99

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

Diff for: GPUPrefSwitcher/TaskSchedulerUtils.cs

+21-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class TaskSchedulerUtils
1212

1313
public static void RunOnBatteryTask()
1414
{
15-
if (!TaskExists(TASK_NAME_ON_BATTERY))
15+
if (!TaskAndFolderExists(TASK_NAME_ON_BATTERY))
1616
{
1717
string description = "The GPUPrefSwitcher service runs this task once when the system is considered on battery." +
1818
"\n It is up to you to add actions (e.g. start a script).";
@@ -25,7 +25,7 @@ public static void RunOnBatteryTask()
2525

2626
public static void RunPluggedInTask()
2727
{
28-
if (!TaskExists(TASK_NAME_PLUGGED_IN))
28+
if (!TaskAndFolderExists(TASK_NAME_PLUGGED_IN))
2929
{
3030
string description = "The GPUPrefSwitcher service runs this task once when the system is considered plugged in." +
3131
"\n It is up to you to add actions (e.g. start a script).";
@@ -36,11 +36,28 @@ public static void RunPluggedInTask()
3636
RunTask(TASK_NAME_PLUGGED_IN);
3737
}
3838

39-
public static bool TaskExists(string taskName)
39+
public static bool TaskAndFolderExists(string taskName)
4040
{
4141
using (TaskService taskService = new())
4242
{
43-
return taskService.FindTask(taskName, false) != null;
43+
44+
TaskFolder gpuPrefSwitcherFolder = taskService.GetFolder(FOLDER_NAME);
45+
if (gpuPrefSwitcherFolder == null) return false;
46+
47+
// Get the folder with the specified name
48+
TaskFolder folder = taskService.RootFolder.SubFolders[FOLDER_NAME];
49+
50+
// Iterate through the tasks in the folder
51+
foreach (Task task in folder.Tasks)
52+
{
53+
// Check if the task has the specified name
54+
if (task.Name.Equals(taskName, StringComparison.OrdinalIgnoreCase))
55+
{
56+
return true; // Return the task if found
57+
}
58+
}
59+
return false;
60+
//return taskService.FindTask(taskName, true) != null;
4461
}
4562
}
4663

Diff for: Setup/Setup.vdproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -966,15 +966,15 @@
966966
{
967967
"Name" = "8:Microsoft Visual Studio"
968968
"ProductName" = "8:GPUPrefSwitcher"
969-
"ProductCode" = "8:{7165D190-212D-43B7-8D9A-5837D45E7231}"
970-
"PackageCode" = "8:{51F0819C-D9D0-4AAD-8251-7AEBFEAAEAE8}"
971-
"UpgradeCode" = "8:{4C9420BE-E1DC-48F5-8166-8BC7B5369296}"
969+
"ProductCode" = "8:{9B15834B-FFC2-4520-8896-D0B4C8EB7B9C}"
970+
"PackageCode" = "8:{7B87958C-0F09-4365-B947-A3C5F2B54BD4}"
971+
"UpgradeCode" = "8:{73B436D1-68D9-4CCD-B89A-045E7B260369}"
972972
"AspNetVersion" = "8:4.0.30319.0"
973973
"RestartWWWService" = "11:FALSE"
974974
"RemovePreviousVersions" = "11:TRUE"
975975
"DetectNewerInstalledVersion" = "11:TRUE"
976976
"InstallAllUsers" = "11:FALSE"
977-
"ProductVersion" = "8:0.1.1"
977+
"ProductVersion" = "8:0.2.1"
978978
"Manufacturer" = "8:sharpjd"
979979
"ARPHELPTELEPHONE" = "8:"
980980
"ARPHELPLINK" = "8:"

0 commit comments

Comments
 (0)