From 0312a1bd96f2d78f44ad2febe3c3c6ee18f3eaed Mon Sep 17 00:00:00 2001 From: Pavel Yosifovich Date: Mon, 13 Jan 2025 10:31:03 -0500 Subject: [PATCH] display custom value types as numbers bump version number --- RegExp/DeleteKeyCommand.cpp | 91 ++++++++++++++++++------------------ RegExp/RegExp.rc | Bin 66578 -> 66578 bytes RegExp/RegExp.vcxproj | 2 +- RegExp/Registry.cpp | 4 +- RegExp/Registry.h | 2 +- WTLHelper | 2 +- 6 files changed, 51 insertions(+), 50 deletions(-) diff --git a/RegExp/DeleteKeyCommand.cpp b/RegExp/DeleteKeyCommand.cpp index d7e79ec..583c5c7 100644 --- a/RegExp/DeleteKeyCommand.cpp +++ b/RegExp/DeleteKeyCommand.cpp @@ -8,52 +8,53 @@ DeleteKeyCommand::DeleteKeyCommand(PCWSTR path, PCWSTR name, AppCommandCallback< } bool DeleteKeyCommand::Execute() { - auto key = Registry::OpenKey(_path, KEY_ENUMERATE_SUB_KEYS | DELETE | KEY_QUERY_VALUE); - if (!key) - return false; - - if (_savePath.IsEmpty()) { - LARGE_INTEGER li; - ::QueryPerformanceCounter(&li); - _savePath.Format(L"%llX", li.QuadPart); - } - CRegKey keyBackup; - auto error = keyBackup.Create(HKEY_CURRENT_USER, DeletedPathBackup + _savePath, nullptr, 0, KEY_ALL_ACCESS); - ::SetLastError(error); - if (!keyBackup) - return false; - ::SetLastError(error = ::RegCopyTree(key.Get(), _name, keyBackup)); - if (ERROR_SUCCESS != error) - return false; - - ::SetLastError(error = ::RegDeleteTree(key.Get(), _name)); - if (ERROR_SUCCESS != error) { - return false; - } - return InvokeCallback(true); + auto key = Registry::OpenKey(_path, MAXIMUM_ALLOWED); + if (!key) + return false; + + if (_savePath.IsEmpty()) { + LARGE_INTEGER li; + ::QueryPerformanceCounter(&li); + _savePath.Format(L"%llX", li.QuadPart); + } + CRegKey keyBackup; + auto error = keyBackup.Create(HKEY_CURRENT_USER, DeletedPathBackup + _savePath, nullptr, 0, MAXIMUM_ALLOWED); + ::SetLastError(error); + if (!keyBackup) + return false; + // BUG: RegCopyTree fails if key is one of the predefined keys + ::SetLastError(error = ::RegCopyTree(key.Get(), _name, keyBackup)); + if (ERROR_SUCCESS != error) + return false; + + ::SetLastError(error = ::RegDeleteTree(key.Get(), _name)); + if (ERROR_SUCCESS != error) { + return false; + } + return InvokeCallback(true); } bool DeleteKeyCommand::Undo() { - auto key = Registry::OpenKey(_path, KEY_CREATE_SUB_KEY); - if (!key) - return false; - - DWORD error; - CRegKey keyBackup; - ::SetLastError(error = keyBackup.Open(HKEY_CURRENT_USER, DeletedPathBackup + _savePath, KEY_READ)); - if (!keyBackup) - return false; - - CRegKey newKey; - DWORD disp; - error = newKey.Create(key.Get(), _name, nullptr, 0, KEY_ALL_ACCESS, nullptr, &disp); - ::SetLastError(error); - if (error != ERROR_SUCCESS) - return false; - - ::SetLastError(error = ::RegCopyTree(keyBackup, nullptr, newKey)); - if (error != ERROR_SUCCESS) - return false; - - return InvokeCallback(false); + auto key = Registry::OpenKey(_path, KEY_CREATE_SUB_KEY); + if (!key) + return false; + + DWORD error; + CRegKey keyBackup; + ::SetLastError(error = keyBackup.Open(HKEY_CURRENT_USER, DeletedPathBackup + _savePath, KEY_READ)); + if (!keyBackup) + return false; + + CRegKey newKey; + DWORD disp; + error = newKey.Create(key.Get(), _name, nullptr, 0, KEY_ALL_ACCESS, nullptr, &disp); + ::SetLastError(error); + if (error != ERROR_SUCCESS) + return false; + + ::SetLastError(error = ::RegCopyTree(keyBackup, nullptr, newKey)); + if (error != ERROR_SUCCESS) + return false; + + return InvokeCallback(false); } diff --git a/RegExp/RegExp.rc b/RegExp/RegExp.rc index cc6c1c25c018aa41a6f8365b4b51f26591446a63..5ba8a6c94d998bed20ff9cca45f24a33bf1ffbc2 100644 GIT binary patch delta 82 zcmbQ#!7{0XWy7BLtQHJ93K3QzSo7aY(GeD=J{}i3CPt0N-Q)NpS*ybW3t^RzR5zL Yr!ksLW-L|ReD1RfBSOJuzOO9&0IO{q^Z)<= diff --git a/RegExp/RegExp.vcxproj b/RegExp/RegExp.vcxproj index d281b89..44bf102 100644 --- a/RegExp/RegExp.vcxproj +++ b/RegExp/RegExp.vcxproj @@ -281,7 +281,7 @@ PerMonitorHighDPIAware - signtool sign /i DigiCert /n Scorpio /fd sha256 $(TargetPath) + signtool sign /a /n Scorpio /t http://timestamp.digicert.com /fd sha256 $(TargetPath) diff --git a/RegExp/Registry.cpp b/RegExp/Registry.cpp index ec19717..d36a2ba 100644 --- a/RegExp/Registry.cpp +++ b/RegExp/Registry.cpp @@ -244,7 +244,7 @@ bool Registry::Disconnect(PCWSTR computerName) { return true; } -PCWSTR Registry::GetRegTypeAsString(DWORD type) { +CString Registry::GetRegTypeAsString(DWORD type) { switch (type) { case REG_KEY: return L"Key"; case REG_SZ: return L"REG_SZ"; @@ -259,7 +259,7 @@ PCWSTR Registry::GetRegTypeAsString(DWORD type) { case REG_RESOURCE_LIST: return L"REG_RESOURCE_LIST"; case REG_FULL_RESOURCE_DESCRIPTOR: return L"REG_FULL_RESOURCE_DESCRIPTOR"; } - return L""; + return std::format("{} (0x{:X})", type, type).c_str(); } CString Registry::GetDataAsString(RegistryKey& key, const RegistryItem& item) { diff --git a/RegExp/Registry.h b/RegExp/Registry.h index a4915f5..325e2a9 100644 --- a/RegExp/Registry.h +++ b/RegExp/Registry.h @@ -39,7 +39,7 @@ struct Registry abstract final { static DWORD EnumKeyValues(HKEY key, const std::function& handler); static CString QueryStringValue(RegistryKey& key, PCWSTR name); static CString StdRegPathToRealPath(const CString& path); - static PCWSTR GetRegTypeAsString(DWORD type); + static CString GetRegTypeAsString(DWORD type); static CString GetDataAsString(RegistryKey& key, const RegistryItem& item); static HKEY OpenRealRegistryKey(PCWSTR path = nullptr, DWORD access = KEY_READ); static HKEY CreateRealRegistryKey(PCWSTR path, DWORD access = KEY_READ); diff --git a/WTLHelper b/WTLHelper index bc487f9..5c18cc0 160000 --- a/WTLHelper +++ b/WTLHelper @@ -1 +1 @@ -Subproject commit bc487f933a596165c6c7ccb0b3b94da9864731e0 +Subproject commit 5c18cc04399a68feb56adc7b1558cafdf5dad236