Skip to content

Commit

Permalink
display custom value types as numbers
Browse files Browse the repository at this point in the history
bump version number
  • Loading branch information
zodiacon committed Jan 13, 2025
1 parent 0859e90 commit 0312a1b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 50 deletions.
91 changes: 46 additions & 45 deletions RegExp/DeleteKeyCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Binary file modified RegExp/RegExp.rc
Binary file not shown.
2 changes: 1 addition & 1 deletion RegExp/RegExp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
</Manifest>
<PostBuildEvent>
<Command>signtool sign /i DigiCert /n Scorpio /fd sha256 $(TargetPath)</Command>
<Command>signtool sign /a /n Scorpio /t http://timestamp.digicert.com /fd sha256 $(TargetPath)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
Expand Down
4 changes: 2 additions & 2 deletions RegExp/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion RegExp/Registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct Registry abstract final {
static DWORD EnumKeyValues(HKEY key, const std::function<void(DWORD, PCWSTR, DWORD)>& 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);
Expand Down
2 changes: 1 addition & 1 deletion WTLHelper

2 comments on commit 0312a1b

@God-damnit-all
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put out a new version? I haven't had any luck compiling this project.

@zodiacon
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Please sign in to comment.