mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-11 09:58:10 +00:00
[idd] driver: move the ExtraMode registry key now permissions are correct
This resolves the problem of this setting being essentially lost between driver upgrades.
This commit is contained in:

committed by
Geoffrey McRae

parent
b83d70a068
commit
13ae3441cf
@@ -68,76 +68,69 @@ void CSettings::LoadModes()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::SetExtraMode(const DisplayMode & mode)
|
void CSettings::SetExtraMode(const DisplayMode& mode)
|
||||||
{
|
{
|
||||||
WCHAR buf[64];
|
WCHAR buf[64];
|
||||||
_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%ux%u@%u%s",
|
_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%ux%u@%u%s",
|
||||||
mode.width, mode.height, mode.refresh, mode.preferred ? L"*" : L"");
|
mode.width, mode.height, mode.refresh,
|
||||||
|
mode.preferred ? L"*" : L"");
|
||||||
|
|
||||||
WDFKEY paramsKey = nullptr;
|
HKEY hKey = NULL;
|
||||||
NTSTATUS status = WdfDriverOpenParametersRegistryKey(
|
DWORD disp = 0;
|
||||||
WdfGetDriver(),
|
LONG ec = RegCreateKeyExW(
|
||||||
|
HKEY_LOCAL_MACHINE,
|
||||||
|
L"Software\\LookingGlass\\IDD",
|
||||||
|
0, NULL, REG_OPTION_NON_VOLATILE,
|
||||||
KEY_SET_VALUE,
|
KEY_SET_VALUE,
|
||||||
WDF_NO_OBJECT_ATTRIBUTES,
|
NULL, &hKey, &disp);
|
||||||
¶msKey
|
|
||||||
);
|
|
||||||
if (!NT_SUCCESS(status)) return;
|
|
||||||
|
|
||||||
UNICODE_STRING valName;
|
if (ec != ERROR_SUCCESS)
|
||||||
RtlInitUnicodeString(&valName, L"ExtraMode");
|
{
|
||||||
|
DEBUG_INFO("Failed to write key");
|
||||||
UNICODE_STRING uData;
|
return;
|
||||||
RtlInitUnicodeString(&uData, buf);
|
|
||||||
|
|
||||||
WDFSTRING hStr = nullptr;
|
|
||||||
status = WdfStringCreate(&uData, WDF_NO_OBJECT_ATTRIBUTES, &hStr);
|
|
||||||
if (NT_SUCCESS(status)) {
|
|
||||||
status = WdfRegistryAssignString(paramsKey, &valName, hStr);
|
|
||||||
WdfObjectDelete(hStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WdfRegistryClose(paramsKey);
|
const WCHAR* valueName = L"ExtraMode";
|
||||||
|
const DWORD cb = (DWORD)((wcslen(buf) + 1) * sizeof(WCHAR));
|
||||||
|
|
||||||
|
RegSetValueExW(hKey, valueName, 0, REG_SZ, (const BYTE*)buf, cb);
|
||||||
|
RegCloseKey(hKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSettings::GetExtraMode(DisplayMode & mode)
|
bool CSettings::GetExtraMode(DisplayMode& mode)
|
||||||
{
|
{
|
||||||
WDFKEY paramsKey = nullptr;
|
HKEY hKey = nullptr;
|
||||||
NTSTATUS st = WdfDriverOpenParametersRegistryKey(
|
LONG ec = RegOpenKeyExW(
|
||||||
WdfGetDriver(),
|
HKEY_LOCAL_MACHINE,
|
||||||
|
L"Software\\LookingGlass\\IDD",
|
||||||
|
0,
|
||||||
KEY_QUERY_VALUE,
|
KEY_QUERY_VALUE,
|
||||||
WDF_NO_OBJECT_ATTRIBUTES,
|
&hKey
|
||||||
¶msKey
|
|
||||||
);
|
);
|
||||||
if (!NT_SUCCESS(st))
|
|
||||||
|
if (ec != ERROR_SUCCESS)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
UNICODE_STRING name; RtlInitUnicodeString(&name, L"ExtraMode");
|
DWORD type = 0;
|
||||||
UNICODE_STRING empty; RtlInitUnicodeString(&empty, L"");
|
DWORD cb = 0;
|
||||||
|
|
||||||
WDFSTRING hStr = nullptr;
|
ec = RegQueryValueExW(hKey, L"ExtraMode", nullptr, &type, nullptr, &cb);
|
||||||
st = WdfStringCreate(&empty, WDF_NO_OBJECT_ATTRIBUTES, &hStr);
|
if (ec != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ) || cb == 0)
|
||||||
if (!NT_SUCCESS(st))
|
|
||||||
{
|
{
|
||||||
WdfRegistryClose(paramsKey);
|
RegCloseKey(hKey);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
st = WdfRegistryQueryString(paramsKey, &name, hStr);
|
std::vector<wchar_t> buf(cb / sizeof(wchar_t) + 1);
|
||||||
if (!NT_SUCCESS(st))
|
ec = RegQueryValueExW(hKey, L"ExtraMode", nullptr, &type,
|
||||||
{
|
reinterpret_cast<LPBYTE>(buf.data()), &cb);
|
||||||
WdfObjectDelete(hStr);
|
RegCloseKey(hKey);
|
||||||
WdfRegistryClose(paramsKey);
|
if (ec != ERROR_SUCCESS)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
UNICODE_STRING us{};
|
buf.back() = L'\0';
|
||||||
WdfStringGetUnicodeString(hStr, &us);
|
|
||||||
|
|
||||||
std::wstring s(us.Buffer, us.Length / sizeof(wchar_t));
|
|
||||||
|
|
||||||
WdfObjectDelete(hStr);
|
|
||||||
WdfRegistryClose(paramsKey);
|
|
||||||
|
|
||||||
|
std::wstring s(buf.data());
|
||||||
return ParseModeString(s, mode);
|
return ParseModeString(s, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user