Handle deletion of the 'HKLM\Software\NVIDIA Corporation' key

This commit is contained in:
Cameron Gutman 2020-10-10 13:35:05 -05:00
parent 8a45ea2066
commit f511b830ea

View File

@ -846,26 +846,33 @@ void ResetLogFile(bool standaloneExe)
DWORD WINAPI GameStreamStateChangeThread(PVOID Context) DWORD WINAPI GameStreamStateChangeThread(PVOID Context)
{ {
HKEY key; HKEY key;
DWORD err;
// We're watching this key that way we can still detect GameStream turning on do {
// if GFE wasn't even installed when our service started // We're watching this key that way we can still detect GameStream turning on
DWORD err = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\NVIDIA Corporation", 0, KEY_READ | KEY_WOW64_64KEY, &key); // if GFE wasn't even installed when our service started
if (err != ERROR_SUCCESS) { do {
printf("RegOpenKeyExA() failed: %d" NL, err); err = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\NVIDIA Corporation", 0, KEY_READ | KEY_WOW64_64KEY, &key);
return err; if (err != ERROR_SUCCESS) {
} // Wait 10 seconds and try again
Sleep(10000);
}
} while (err != ERROR_SUCCESS);
// Notify the main thread when the GameStream state changes // Notify the main thread when the GameStream state changes
bool lastGameStreamState = IsGameStreamEnabled(); bool lastGameStreamState = IsGameStreamEnabled();
while ((err = RegNotifyChangeKeyValue(key, true, REG_NOTIFY_CHANGE_LAST_SET, nullptr, false)) == ERROR_SUCCESS) { while ((err = RegNotifyChangeKeyValue(key, true, REG_NOTIFY_CHANGE_LAST_SET, nullptr, false)) == ERROR_SUCCESS) {
bool currentGameStreamState = IsGameStreamEnabled(); bool currentGameStreamState = IsGameStreamEnabled();
if (lastGameStreamState != currentGameStreamState) { if (lastGameStreamState != currentGameStreamState) {
SetEvent((HANDLE)Context); SetEvent((HANDLE)Context);
}
lastGameStreamState = currentGameStreamState;
} }
lastGameStreamState = currentGameStreamState;
}
printf("RegNotifyChangeKeyValue() failed: %d" NL, err); // If the key is deleted (by DDU or similar), we will hit this code path and poll until it comes back.
RegCloseKey(key);
} while (err == ERROR_KEY_DELETED);
return err; return err;
} }