Skip to content

Commit

Permalink
Windows: Fixed a bug checking if a key exists in the registry
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoole committed Aug 12, 2019
1 parent d8638fd commit 7dde0b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modules/juce_core/misc/juce_WindowsRegistry.h
Expand Up @@ -90,7 +90,7 @@ class JUCE_API WindowsRegistry
static bool JUCE_CALLTYPE valueExists (const String& regValuePath, WoW64Mode mode = WoW64_Default);

/** Returns true if the given key exists in the registry. */
static bool JUCE_CALLTYPE keyExists (const String& regValuePath, WoW64Mode mode = WoW64_Default);
static bool JUCE_CALLTYPE keyExists (const String& regKeyPath, WoW64Mode mode = WoW64_Default);

/** Deletes a registry value. */
static bool JUCE_CALLTYPE deleteValue (const String& regValuePath, WoW64Mode mode = WoW64_Default);
Expand Down
22 changes: 11 additions & 11 deletions modules/juce_core/native/juce_win32_Registry.cpp
Expand Up @@ -49,7 +49,7 @@ struct RegistryKeyWrapper

~RegistryKeyWrapper()
{
if (key != 0)
if (key != nullptr)
RegCloseKey (key);
}

Expand All @@ -73,7 +73,7 @@ struct RegistryKeyWrapper
{
const RegistryKeyWrapper key (regValuePath, true, wow64Flags);

return key.key != 0
return key.key != nullptr
&& RegSetValueEx (key.key, key.wideCharValueName, 0, type,
reinterpret_cast<const BYTE*> (data),
(DWORD) dataSize) == ERROR_SUCCESS;
Expand All @@ -83,7 +83,7 @@ struct RegistryKeyWrapper
{
const RegistryKeyWrapper key (regValuePath, false, wow64Flags);

if (key.key != 0)
if (key.key != nullptr)
{
for (unsigned long bufferSize = 1024; ; bufferSize *= 2)
{
Expand Down Expand Up @@ -121,16 +121,16 @@ struct RegistryKeyWrapper
return defaultValue;
}

static bool keyExists (const String& regValuePath, const DWORD wow64Flags)
static bool keyExists (const String& regKeyPath, const DWORD wow64Flags)
{
return RegistryKeyWrapper (regValuePath, false, wow64Flags).key != 0;
return RegistryKeyWrapper (regKeyPath + "\\", false, wow64Flags).key != nullptr;
}

static bool valueExists (const String& regValuePath, const DWORD wow64Flags)
{
const RegistryKeyWrapper key (regValuePath, false, wow64Flags);

if (key.key == 0)
if (key.key == nullptr)
return false;

unsigned char buffer [512];
Expand All @@ -143,7 +143,7 @@ struct RegistryKeyWrapper
return result == ERROR_SUCCESS || result == ERROR_MORE_DATA;
}

HKEY key = 0;
HKEY key = nullptr;
const wchar_t* wideCharValueName = nullptr;
String valueName;

Expand Down Expand Up @@ -186,23 +186,23 @@ bool JUCE_CALLTYPE WindowsRegistry::valueExists (const String& regValuePath, WoW
return RegistryKeyWrapper::valueExists (regValuePath, (DWORD) mode);
}

bool JUCE_CALLTYPE WindowsRegistry::keyExists (const String& regValuePath, WoW64Mode mode)
bool JUCE_CALLTYPE WindowsRegistry::keyExists (const String& regKeyPath, WoW64Mode mode)
{
return RegistryKeyWrapper::keyExists (regValuePath, (DWORD) mode);
return RegistryKeyWrapper::keyExists (regKeyPath, (DWORD) mode);
}

bool JUCE_CALLTYPE WindowsRegistry::deleteValue (const String& regValuePath, WoW64Mode mode)
{
const RegistryKeyWrapper key (regValuePath, true, (DWORD) mode);

return key.key != 0 && RegDeleteValue (key.key, key.wideCharValueName) == ERROR_SUCCESS;
return key.key != nullptr && RegDeleteValue (key.key, key.wideCharValueName) == ERROR_SUCCESS;
}

static bool deleteKeyNonRecursive (const String& regKeyPath, WindowsRegistry::WoW64Mode mode)
{
const RegistryKeyWrapper key (regKeyPath, true, (DWORD) mode);

return key.key != 0 && RegDeleteKey (key.key, key.wideCharValueName) == ERROR_SUCCESS;
return key.key != nullptr && RegDeleteKey (key.key, key.wideCharValueName) == ERROR_SUCCESS;
}

bool JUCE_CALLTYPE WindowsRegistry::deleteKey (const String& regKeyPath, WoW64Mode mode)
Expand Down

0 comments on commit 7dde0b2

Please sign in to comment.