Skip to content

Commit

Permalink
Merge pull request #367 from CasperH2O/Win10RegistryFix
Browse files Browse the repository at this point in the history
Registry robustness improvements, ported from mapper.
  • Loading branch information
CasperH2O authored Feb 15, 2023
2 parents ccd4434 + 6fc1eaf commit a25f065
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
50 changes: 31 additions & 19 deletions ControllerCommon/HidHide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,35 @@ static HidHide()
{
var service = new HidHideControlService();

// verifying HidHide is installed
if (!service.IsInstalled)
{
LogManager.LogCritical("HidHide is missing. Please get it from: {0}", "https://github.com/ViGEm/HidHide/releases");
throw new InvalidOperationException();
}

// verifying HidHide is installed
string InstallPath = RegistryUtils.GetHKLM(@"SOFTWARE\Nefarius Software Solutions e.U.\HidHide", "Path");
if (!string.IsNullOrEmpty(InstallPath))
}

// prepare backup path
string InstallPath = RegistryUtils.GetString(@"SOFTWARE\Nefarius Software Solutions e.U.\HidHide", "Path");
if (!string.IsNullOrEmpty(InstallPath))
{
InstallPath = Path.Combine(InstallPath, "x64", "HidHideCLI.exe");

process = new Process
{
StartInfo =
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
FileName = InstallPath,
Verb = "runas"
}
};
if (File.Exists(InstallPath))
{
process = new Process
{
StartInfo =
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
FileName = InstallPath,
Verb = "runas"
}
};
}
}
}

public static List<string> GetRegisteredApplications()
Expand Down Expand Up @@ -89,7 +95,10 @@ public static void UnregisterApplication(string fileName)
}
}
catch
{
{
if (process is null)
return;

process.StartInfo.Arguments = $"--app-unreg \"{fileName}\"";
process.Start();
process.WaitForExit();
Expand All @@ -111,7 +120,10 @@ public static void RegisterApplication(string fileName)
}
}
catch
{
{
if (process is null)
return;

process.StartInfo.Arguments = $"--app-reg \"{fileName}\"";
process.Start();
process.WaitForExit();
Expand Down
31 changes: 29 additions & 2 deletions ControllerCommon/Utils/RegistryUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,37 @@ public static class RegistryUtils
{
private const string HKLM = @"HKEY_LOCAL_MACHINE";

public static string GetHKLM(string key, string value)
private static object GetValue(string key, string value)
{
string keyName = HKLM + "\\" + key;
return Convert.ToString(Registry.GetValue(keyName, value, string.Empty));
return Registry.GetValue(keyName, value, string.Empty);
}

public static string GetString(string key, string value)
{
return Convert.ToString(GetValue(key, value));
}

public static int GetInt(string key, string value)
{
try
{
return Convert.ToInt32(GetValue(key, value));
}
catch { }

return 0;
}

public static bool GetBoolean(string key, string value)
{
try
{
return Convert.ToBoolean(GetValue(key, value));
}
catch { }

return false;
}
}
}
6 changes: 4 additions & 2 deletions HandheldCompanion/Managers/PerformanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,15 @@ public override void Start()
if (!processor.IsInitialized)
return;

// read OS specific values
bool VulnerableDriverBlocklistEnable = RegistryUtils.GetBoolean(@"SYSTEM\CurrentControlSet\Control\CI\Config", "VulnerableDriverBlocklistEnabled");

// higher interval on Intel CPUs to avoid CPU overload
if (processor.GetType() == typeof(IntelProcessor))
{
cpuWatchdog.Interval = INTERVAL_INTEL;

int VulnerableDriverBlocklistEnable = Convert.ToInt32(RegistryUtils.GetHKLM(@"SYSTEM\CurrentControlSet\Control\CI\Config", "VulnerableDriverBlocklistEnable"));
if (VulnerableDriverBlocklistEnable == 1)
if (VulnerableDriverBlocklistEnable)
{
cpuWatchdog.Stop();
processor.Stop();
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Platforms/SteamPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SteamPlatform()
};

// check if platform is installed
InstallPath = RegistryUtils.GetHKLM(@"SOFTWARE\Wow6432Node\Valve\Steam", "InstallPath");
InstallPath = RegistryUtils.GetString(@"SOFTWARE\Wow6432Node\Valve\Steam", "InstallPath");

if (Path.Exists(InstallPath))
{
Expand Down

0 comments on commit a25f065

Please sign in to comment.