mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-16 00:34:19 +00:00
Altered WindowsRegistry to allow each method to specify an explicit WoW64 mode.
This commit is contained in:
parent
2d25f2f294
commit
d104b151cd
2 changed files with 67 additions and 66 deletions
|
|
@ -38,65 +38,69 @@
|
|||
class WindowsRegistry
|
||||
{
|
||||
public:
|
||||
/** These values can be used to specify whether the 32- or 64-bit registry should be used.
|
||||
When running on a 32-bit OS, there is no 64-bit registry, so the mode will be ignored.
|
||||
*/
|
||||
enum WoW64Mode
|
||||
{
|
||||
/** Default handling: 32-bit apps will use the 32-bit registry, and 64-bit apps
|
||||
will use the 64-bit registry. */
|
||||
WoW64_Default = 0,
|
||||
|
||||
/** Always use the 64-bit registry store. (KEY_WOW64_64KEY). */
|
||||
WoW64_64bit = 0x100,
|
||||
|
||||
/** Always use the 32-bit registry store. (KEY_WOW64_32KEY). */
|
||||
WoW64_32bit = 0x200
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
/** Returns a string from the registry.
|
||||
The path is a string for the entire path of a value in the registry,
|
||||
e.g. "HKEY_CURRENT_USER\Software\foo\bar"
|
||||
*/
|
||||
static String getValue (const String& regValuePath,
|
||||
const String& defaultValue = String::empty);
|
||||
|
||||
/** Returns a string from the WOW64 registry.
|
||||
The path is a string for the entire path of a value in the registry,
|
||||
e.g. "HKEY_CURRENT_USER\Software\foo\bar"
|
||||
*/
|
||||
static String getValueWow64 (const String& regValuePath,
|
||||
const String& defaultValue = String::empty);
|
||||
const String& defaultValue = String::empty,
|
||||
WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Reads a binary block from the registry.
|
||||
The path is a string for the entire path of a value in the registry,
|
||||
e.g. "HKEY_CURRENT_USER\Software\foo\bar"
|
||||
@returns a DWORD indicating the type of the key.
|
||||
*/
|
||||
static uint32 getBinaryValue (const String& regValuePath, MemoryBlock& resultData);
|
||||
static uint32 getBinaryValue (const String& regValuePath, MemoryBlock& resultData, WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Sets a registry value as a string.
|
||||
This will take care of creating any groups needed to get to the given registry value.
|
||||
*/
|
||||
static bool setValue (const String& regValuePath, const String& value);
|
||||
static bool setValue (const String& regValuePath, const String& value, WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Sets a registry value as a DWORD.
|
||||
This will take care of creating any groups needed to get to the given registry value.
|
||||
*/
|
||||
static bool setValue (const String& regValuePath, uint32 value);
|
||||
static bool setValue (const String& regValuePath, uint32 value, WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Sets a registry value as a QWORD.
|
||||
This will take care of creating any groups needed to get to the given registry value.
|
||||
*/
|
||||
static bool setValue (const String& regValuePath, uint64 value);
|
||||
static bool setValue (const String& regValuePath, uint64 value, WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Sets a registry value as a binary block.
|
||||
This will take care of creating any groups needed to get to the given registry value.
|
||||
*/
|
||||
static bool setValue (const String& regValuePath, const MemoryBlock& value);
|
||||
static bool setValue (const String& regValuePath, const MemoryBlock& value, WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Returns true if the given value exists in the registry. */
|
||||
static bool valueExists (const String& regValuePath);
|
||||
|
||||
/** Returns true if the given value exists in the registry. */
|
||||
static bool valueExistsWow64 (const String& regValuePath);
|
||||
static bool valueExists (const String& regValuePath, WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Returns true if the given key exists in the registry. */
|
||||
static bool keyExists (const String& regValuePath);
|
||||
|
||||
/** Returns true if the given key exists in the registry. */
|
||||
static bool keyExistsWow64 (const String& regValuePath);
|
||||
static bool keyExists (const String& regValuePath, WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Deletes a registry value. */
|
||||
static void deleteValue (const String& regValuePath);
|
||||
static void deleteValue (const String& regValuePath, WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Deletes a registry key (which is registry-talk for 'folder'). */
|
||||
static void deleteKey (const String& regKeyPath);
|
||||
static void deleteKey (const String& regKeyPath, WoW64Mode mode = WoW64_Default);
|
||||
|
||||
/** Creates a file association in the registry.
|
||||
|
||||
|
|
@ -119,10 +123,16 @@ public:
|
|||
const String& fullDescription,
|
||||
const File& targetExecutable,
|
||||
int iconResourceNumber,
|
||||
bool registerForCurrentUserOnly);
|
||||
bool registerForCurrentUserOnly,
|
||||
WoW64Mode mode = WoW64_Default);
|
||||
|
||||
// DEPRECATED: use the other methods with a WoW64Mode parameter of WoW64_64bit instead.
|
||||
JUCE_DEPRECATED (static String getValueWow64 (const String&, const String& defaultValue = String::empty));
|
||||
JUCE_DEPRECATED (static bool valueExistsWow64 (const String&));
|
||||
JUCE_DEPRECATED (static bool keyExistsWow64 (const String&));
|
||||
|
||||
private:
|
||||
WindowsRegistry();
|
||||
WindowsRegistry() JUCE_DELETED_FUNCTION;
|
||||
JUCE_DECLARE_NON_COPYABLE (WindowsRegistry)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -64,9 +64,9 @@ struct RegistryKeyWrapper
|
|||
}
|
||||
|
||||
static bool setValue (const String& regValuePath, const DWORD type,
|
||||
const void* data, size_t dataSize)
|
||||
const void* data, size_t dataSize, const DWORD wow64Flags)
|
||||
{
|
||||
const RegistryKeyWrapper key (regValuePath, true, 0);
|
||||
const RegistryKeyWrapper key (regValuePath, true, wow64Flags);
|
||||
|
||||
return key.key != 0
|
||||
&& RegSetValueEx (key.key, key.wideCharValueName, 0, type,
|
||||
|
|
@ -144,73 +144,58 @@ struct RegistryKeyWrapper
|
|||
JUCE_DECLARE_NON_COPYABLE (RegistryKeyWrapper)
|
||||
};
|
||||
|
||||
uint32 WindowsRegistry::getBinaryValue (const String& regValuePath, MemoryBlock& result)
|
||||
uint32 WindowsRegistry::getBinaryValue (const String& regValuePath, MemoryBlock& result, WoW64Mode mode)
|
||||
{
|
||||
return RegistryKeyWrapper::getBinaryValue (regValuePath, result, 0);
|
||||
return RegistryKeyWrapper::getBinaryValue (regValuePath, result, (DWORD) mode);
|
||||
}
|
||||
|
||||
String WindowsRegistry::getValue (const String& regValuePath, const String& defaultValue)
|
||||
String WindowsRegistry::getValue (const String& regValuePath, const String& defaultValue, WoW64Mode mode)
|
||||
{
|
||||
return RegistryKeyWrapper::getValue (regValuePath, defaultValue, 0);
|
||||
return RegistryKeyWrapper::getValue (regValuePath, defaultValue, (DWORD) mode);
|
||||
}
|
||||
|
||||
String WindowsRegistry::getValueWow64 (const String& regValuePath, const String& defaultValue)
|
||||
{
|
||||
return RegistryKeyWrapper::getValue (regValuePath, defaultValue, 0x100 /*KEY_WOW64_64KEY*/);
|
||||
}
|
||||
|
||||
bool WindowsRegistry::valueExistsWow64 (const String& regValuePath)
|
||||
{
|
||||
return RegistryKeyWrapper::valueExists (regValuePath, 0x100 /*KEY_WOW64_64KEY*/);
|
||||
}
|
||||
|
||||
bool WindowsRegistry::keyExistsWow64 (const String& regValuePath)
|
||||
{
|
||||
return RegistryKeyWrapper::keyExists (regValuePath, 0x100 /*KEY_WOW64_64KEY*/);
|
||||
}
|
||||
|
||||
bool WindowsRegistry::setValue (const String& regValuePath, const String& value)
|
||||
bool WindowsRegistry::setValue (const String& regValuePath, const String& value, WoW64Mode mode)
|
||||
{
|
||||
return RegistryKeyWrapper::setValue (regValuePath, REG_SZ, value.toWideCharPointer(),
|
||||
CharPointer_UTF16::getBytesRequiredFor (value.getCharPointer()));
|
||||
CharPointer_UTF16::getBytesRequiredFor (value.getCharPointer()), mode);
|
||||
}
|
||||
|
||||
bool WindowsRegistry::setValue (const String& regValuePath, const uint32 value)
|
||||
bool WindowsRegistry::setValue (const String& regValuePath, const uint32 value, WoW64Mode mode)
|
||||
{
|
||||
return RegistryKeyWrapper::setValue (regValuePath, REG_DWORD, &value, sizeof (value));
|
||||
return RegistryKeyWrapper::setValue (regValuePath, REG_DWORD, &value, sizeof (value), (DWORD) mode);
|
||||
}
|
||||
|
||||
bool WindowsRegistry::setValue (const String& regValuePath, const uint64 value)
|
||||
bool WindowsRegistry::setValue (const String& regValuePath, const uint64 value, WoW64Mode mode)
|
||||
{
|
||||
return RegistryKeyWrapper::setValue (regValuePath, REG_QWORD, &value, sizeof (value));
|
||||
return RegistryKeyWrapper::setValue (regValuePath, REG_QWORD, &value, sizeof (value), (DWORD) mode);
|
||||
}
|
||||
|
||||
bool WindowsRegistry::setValue (const String& regValuePath, const MemoryBlock& value)
|
||||
bool WindowsRegistry::setValue (const String& regValuePath, const MemoryBlock& value, WoW64Mode mode)
|
||||
{
|
||||
return RegistryKeyWrapper::setValue (regValuePath, REG_BINARY, value.getData(), value.getSize());
|
||||
return RegistryKeyWrapper::setValue (regValuePath, REG_BINARY, value.getData(), value.getSize(), (DWORD) mode);
|
||||
}
|
||||
|
||||
bool WindowsRegistry::valueExists (const String& regValuePath)
|
||||
bool WindowsRegistry::valueExists (const String& regValuePath, WoW64Mode mode)
|
||||
{
|
||||
return RegistryKeyWrapper::valueExists (regValuePath, 0);
|
||||
return RegistryKeyWrapper::valueExists (regValuePath, (DWORD) mode);
|
||||
}
|
||||
|
||||
bool WindowsRegistry::keyExists (const String& regValuePath)
|
||||
bool WindowsRegistry::keyExists (const String& regValuePath, WoW64Mode mode)
|
||||
{
|
||||
return RegistryKeyWrapper::keyExists (regValuePath, 0);
|
||||
return RegistryKeyWrapper::keyExists (regValuePath, (DWORD) mode);
|
||||
}
|
||||
|
||||
void WindowsRegistry::deleteValue (const String& regValuePath)
|
||||
void WindowsRegistry::deleteValue (const String& regValuePath, WoW64Mode mode)
|
||||
{
|
||||
const RegistryKeyWrapper key (regValuePath, true, 0);
|
||||
const RegistryKeyWrapper key (regValuePath, true, (DWORD) mode);
|
||||
|
||||
if (key.key != 0)
|
||||
RegDeleteValue (key.key, key.wideCharValueName);
|
||||
}
|
||||
|
||||
void WindowsRegistry::deleteKey (const String& regKeyPath)
|
||||
void WindowsRegistry::deleteKey (const String& regKeyPath, WoW64Mode mode)
|
||||
{
|
||||
const RegistryKeyWrapper key (regKeyPath, true, 0);
|
||||
const RegistryKeyWrapper key (regKeyPath, true, (DWORD) mode);
|
||||
|
||||
if (key.key != 0)
|
||||
RegDeleteKey (key.key, key.wideCharValueName);
|
||||
|
|
@ -221,16 +206,22 @@ bool WindowsRegistry::registerFileAssociation (const String& fileExtension,
|
|||
const String& fullDescription,
|
||||
const File& targetExecutable,
|
||||
const int iconResourceNumber,
|
||||
const bool registerForCurrentUserOnly)
|
||||
const bool registerForCurrentUserOnly,
|
||||
WoW64Mode mode)
|
||||
{
|
||||
const char* const root = registerForCurrentUserOnly ? "HKEY_CURRENT_USER\\Software\\Classes\\"
|
||||
: "HKEY_CLASSES_ROOT\\";
|
||||
const String key (root + symbolicDescription);
|
||||
|
||||
return setValue (root + fileExtension + "\\", symbolicDescription)
|
||||
&& setValue (key + "\\", fullDescription)
|
||||
&& setValue (key + "\\shell\\open\\command\\", targetExecutable.getFullPathName() + " \"%1\"")
|
||||
return setValue (root + fileExtension + "\\", symbolicDescription, mode)
|
||||
&& setValue (key + "\\", fullDescription, mode)
|
||||
&& setValue (key + "\\shell\\open\\command\\", targetExecutable.getFullPathName() + " \"%1\"", mode)
|
||||
&& (iconResourceNumber == 0
|
||||
|| setValue (key + "\\DefaultIcon\\",
|
||||
targetExecutable.getFullPathName() + "," + String (-iconResourceNumber)));
|
||||
}
|
||||
|
||||
// These methods are deprecated:
|
||||
String WindowsRegistry::getValueWow64 (const String& p, const String& defVal) { return getValue (p, defVal, WoW64_64bit); }
|
||||
bool WindowsRegistry::valueExistsWow64 (const String& p) { return valueExists (p, WoW64_64bit); }
|
||||
bool WindowsRegistry::keyExistsWow64 (const String& p) { return keyExists (p, WoW64_64bit); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue