Skip to content

Portable Tool for an Ideal Windows Setup

#55 add alternative paths

Greedeks617d5d085a6f
diff --git a/.Source/GTweak/Utilities/Controls/PathLocator.cs b/.Source/GTweak/Utilities/Controls/PathLocator.cs
index 4c2f7562..110e6741 100644
--- a/.Source/GTweak/Utilities/Controls/PathLocator.cs
+++ b/.Source/GTweak/Utilities/Controls/PathLocator.cs
@@ -19,14 +19,14 @@ namespace GTweak.Utilities.Controls
{
private static string FindExecutablePath(string name)
{
- string path = Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator).Select(dir => Path.Combine(dir, name)).FirstOrDefault(File.Exists);
-
- if (!string.IsNullOrWhiteSpace(path))
- return path;
-
- path = new[] { Environment.SystemDirectory, Environment.GetFolderPath(Environment.SpecialFolder.Windows) }.Select(dir => Path.Combine(dir, name)).FirstOrDefault(File.Exists);
-
- return path;
+ string[] searchDir = Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator) ?? Array.Empty<string>();
+ searchDir = searchDir.Concat(new[] { Environment.SystemDirectory, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "System32"),
+ Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Sysnative"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "SysWOW64")})
+ .Concat(Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)) ? Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "PowerShell*", SearchOption.TopDirectoryOnly) : Array.Empty<string>())
+ .Concat(Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)) ? Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "PowerShell*", SearchOption.TopDirectoryOnly) : Array.Empty<string>()
+ ).Where(dir => !string.IsNullOrEmpty(dir)).ToArray();
+
+ return searchDir.Select(dir => Path.Combine(dir, name)).FirstOrDefault(File.Exists);
}
internal static readonly string CommandShell = FindExecutablePath("cmd.exe");
diff --git a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs b/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs
index 05d7befe..b28f4737 100644
--- a/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs
+++ b/.Source/GTweak/Utilities/Helpers/CommandExecutor.cs
@@ -1,6 +1,7 @@
using GTweak.Utilities.Controls;
using System;
using System.Diagnostics;
+using System.Text;
using System.Threading.Tasks;
namespace GTweak.Utilities.Helpers
@@ -21,7 +22,10 @@ namespace GTweak.Utilities.Helpers
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
- CreateNoWindow = true
+ CreateNoWindow = true,
+ StandardOutputEncoding = Encoding.UTF8,
+ StandardErrorEncoding = Encoding.UTF8,
+ WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System)
};
using Process process = new Process { StartInfo = startInfo };
diff --git a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs
index e39876f7..3bbcab73 100644
--- a/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs
+++ b/.Source/GTweak/Utilities/Managers/TaskSchedulerManager.cs
@@ -30,13 +30,10 @@ namespace GTweak.Utilities.Managers
foreach (string taskname in tasklist)
{
using Microsoft.Win32.TaskScheduler.Task task = taskService.GetTask(taskname);
- if (task != null)
+ if (task != null && task.Enabled != state)
{
- if (task.Enabled != state)
- {
- task.Definition.Settings.Enabled = state;
- task.RegisterChanges();
- }
+ task.Definition.Settings.Enabled = state;
+ task.RegisterChanges();
}
}
});