mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Couple of small win32 fixes. Cleaned up win32 registry code.
This commit is contained in:
parent
fce514266e
commit
c9cdf073dd
6 changed files with 55 additions and 79 deletions
|
|
@ -200,7 +200,7 @@ private:
|
|||
#else
|
||||
#define JUCE_ATOMICS_WINDOWS 1 // Windows with intrinsics
|
||||
|
||||
#if JUCE_USE_INTRINSICS || JUCE_64BIT
|
||||
#if JUCE_USE_INTRINSICS
|
||||
#ifndef __INTEL_COMPILER
|
||||
#pragma intrinsic (_InterlockedExchange, _InterlockedIncrement, _InterlockedDecrement, _InterlockedCompareExchange, \
|
||||
_InterlockedCompareExchange64, _InterlockedExchangeAdd, _ReadWriteBarrier)
|
||||
|
|
|
|||
|
|
@ -77,7 +77,6 @@ private:
|
|||
class WebInputStream : public InputStream
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_,
|
||||
URL::OpenStreamProgressCallback* progressCallback, void* progressCallbackContext,
|
||||
const String& headers_, int timeOutMs_, StringPairArray* responseHeaders)
|
||||
|
|
@ -373,25 +372,19 @@ namespace MACAddressHelpers
|
|||
DynamicLibrary dll ("iphlpapi.dll");
|
||||
JUCE_DLL_FUNCTION (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
|
||||
|
||||
if (getAdaptersInfo != 0)
|
||||
if (getAdaptersInfo != nullptr)
|
||||
{
|
||||
ULONG len = sizeof (IP_ADAPTER_INFO);
|
||||
MemoryBlock mb;
|
||||
PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
|
||||
HeapBlock<IP_ADAPTER_INFO> adapterInfo (1);
|
||||
|
||||
if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
mb.setSize (len);
|
||||
adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
|
||||
}
|
||||
adapterInfo.malloc (len, 1);
|
||||
|
||||
if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
|
||||
{
|
||||
for (PIP_ADAPTER_INFO adapter = adapterInfo; adapter != 0; adapter = adapter->Next)
|
||||
{
|
||||
for (PIP_ADAPTER_INFO adapter = adapterInfo; adapter != nullptr; adapter = adapter->Next)
|
||||
if (adapter->AddressLength >= 6)
|
||||
result.addIfNotAlreadyThere (MACAddress (adapter->Address));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@
|
|||
==============================================================================
|
||||
*/
|
||||
|
||||
namespace RegistryHelpers
|
||||
struct RegistryKeyWrapper
|
||||
{
|
||||
HKEY findKeyForPath (String name, const bool createForWriting, String& valueName)
|
||||
RegistryKeyWrapper (String name, const bool createForWriting)
|
||||
: key (0), wideCharValueName (nullptr)
|
||||
{
|
||||
HKEY rootKey = 0;
|
||||
|
||||
|
|
@ -39,111 +40,94 @@ namespace RegistryHelpers
|
|||
|
||||
const int lastSlash = name.lastIndexOfChar ('\\');
|
||||
valueName = name.substring (lastSlash + 1);
|
||||
name = name.substring (0, lastSlash);
|
||||
wideCharValueName = valueName.toWideCharPointer();
|
||||
|
||||
HKEY key;
|
||||
name = name.substring (0, lastSlash);
|
||||
const wchar_t* const wideCharName = name.toWideCharPointer();
|
||||
DWORD result;
|
||||
|
||||
if (createForWriting)
|
||||
{
|
||||
if (RegCreateKeyEx (rootKey, name.toWideCharPointer(), 0, 0, REG_OPTION_NON_VOLATILE,
|
||||
(KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
|
||||
return key;
|
||||
}
|
||||
RegCreateKeyEx (rootKey, wideCharName, 0, 0, REG_OPTION_NON_VOLATILE,
|
||||
(KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result);
|
||||
else
|
||||
{
|
||||
if (RegOpenKeyEx (rootKey, name.toWideCharPointer(), 0, KEY_READ, &key) == ERROR_SUCCESS)
|
||||
return key;
|
||||
}
|
||||
RegOpenKeyEx (rootKey, wideCharName, 0, KEY_READ, &key);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
~RegistryKeyWrapper()
|
||||
{
|
||||
if (key != 0)
|
||||
RegCloseKey (key);
|
||||
}
|
||||
|
||||
HKEY key;
|
||||
const wchar_t* wideCharValueName;
|
||||
String valueName;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE (RegistryKeyWrapper);
|
||||
};
|
||||
|
||||
String WindowsRegistry::getValue (const String& regValuePath, const String& defaultValue)
|
||||
{
|
||||
String valueName, result (defaultValue);
|
||||
HKEY k = RegistryHelpers::findKeyForPath (regValuePath, false, valueName);
|
||||
const RegistryKeyWrapper key (regValuePath, false);
|
||||
|
||||
if (k != 0)
|
||||
if (key.key != 0)
|
||||
{
|
||||
WCHAR buffer [2048];
|
||||
unsigned long bufferSize = sizeof (buffer);
|
||||
DWORD type = REG_SZ;
|
||||
|
||||
if (RegQueryValueEx (k, valueName.toWideCharPointer(), 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
|
||||
if (RegQueryValueEx (key.key, key.wideCharValueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
|
||||
{
|
||||
if (type == REG_SZ)
|
||||
result = buffer;
|
||||
return buffer;
|
||||
else if (type == REG_DWORD)
|
||||
result = String ((int) *(DWORD*) buffer);
|
||||
return String ((int) *(DWORD*) buffer);
|
||||
}
|
||||
|
||||
RegCloseKey (k);
|
||||
}
|
||||
|
||||
return result;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
void WindowsRegistry::setValue (const String& regValuePath, const String& value)
|
||||
{
|
||||
String valueName;
|
||||
HKEY k = RegistryHelpers::findKeyForPath (regValuePath, true, valueName);
|
||||
const RegistryKeyWrapper key (regValuePath, true);
|
||||
|
||||
if (k != 0)
|
||||
{
|
||||
RegSetValueEx (k, valueName.toWideCharPointer(), 0, REG_SZ,
|
||||
if (key.key != 0)
|
||||
RegSetValueEx (key.key, key.wideCharValueName, 0, REG_SZ,
|
||||
(const BYTE*) value.toWideCharPointer(),
|
||||
(DWORD) CharPointer_UTF16::getBytesRequiredFor (value.getCharPointer()));
|
||||
|
||||
RegCloseKey (k);
|
||||
}
|
||||
}
|
||||
|
||||
bool WindowsRegistry::valueExists (const String& regValuePath)
|
||||
{
|
||||
bool exists = false;
|
||||
String valueName;
|
||||
HKEY k = RegistryHelpers::findKeyForPath (regValuePath, false, valueName);
|
||||
const RegistryKeyWrapper key (regValuePath, false);
|
||||
|
||||
if (k != 0)
|
||||
{
|
||||
unsigned char buffer [2048];
|
||||
unsigned long bufferSize = sizeof (buffer);
|
||||
DWORD type = 0;
|
||||
if (key.key == 0)
|
||||
return false;
|
||||
|
||||
if (RegQueryValueEx (k, valueName.toWideCharPointer(), 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
|
||||
exists = true;
|
||||
unsigned char buffer [2048];
|
||||
unsigned long bufferSize = sizeof (buffer);
|
||||
DWORD type = 0;
|
||||
|
||||
RegCloseKey (k);
|
||||
}
|
||||
|
||||
return exists;
|
||||
return RegQueryValueEx (key.key, key.wideCharValueName,
|
||||
0, &type, buffer, &bufferSize) == ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
void WindowsRegistry::deleteValue (const String& regValuePath)
|
||||
{
|
||||
String valueName;
|
||||
HKEY k = RegistryHelpers::findKeyForPath (regValuePath, true, valueName);
|
||||
const RegistryKeyWrapper key (regValuePath, true);
|
||||
|
||||
if (k != 0)
|
||||
{
|
||||
RegDeleteValue (k, valueName.toWideCharPointer());
|
||||
RegCloseKey (k);
|
||||
}
|
||||
if (key.key != 0)
|
||||
RegDeleteValue (key.key, key.wideCharValueName);
|
||||
}
|
||||
|
||||
void WindowsRegistry::deleteKey (const String& regKeyPath)
|
||||
{
|
||||
String valueName;
|
||||
HKEY k = RegistryHelpers::findKeyForPath (regKeyPath, true, valueName);
|
||||
const RegistryKeyWrapper key (regKeyPath, true);
|
||||
|
||||
if (k != 0)
|
||||
{
|
||||
RegDeleteKey (k, valueName.toWideCharPointer());
|
||||
RegCloseKey (k);
|
||||
}
|
||||
if (key.key != 0)
|
||||
RegDeleteKey (key.key, key.wideCharValueName);
|
||||
}
|
||||
|
||||
void WindowsRegistry::registerFileAssociation (const String& fileExtension,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ void Logger::outputDebugString (const String& text)
|
|||
#endif
|
||||
|
||||
//==============================================================================
|
||||
#if JUCE_USE_INTRINSICS || JUCE_64BIT
|
||||
#if JUCE_USE_INTRINSICS
|
||||
|
||||
// CPU info functions using intrinsics...
|
||||
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ namespace JuceDummyNamespace {}
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if ! JUCE_VC7_OR_EARLIER
|
||||
#if JUCE_64BIT || ! JUCE_VC7_OR_EARLIER
|
||||
#define JUCE_USE_INTRINSICS 1
|
||||
#endif
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ namespace FontEnumerators
|
|||
if (lpelfe != nullptr && (type & RASTER_FONTTYPE) == 0)
|
||||
{
|
||||
const String fontName (lpelfe->elfLogFont.lfFaceName);
|
||||
|
||||
((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters ("@"));
|
||||
}
|
||||
|
||||
|
|
@ -213,8 +212,9 @@ public:
|
|||
glyphNumber = defaultGlyph;
|
||||
|
||||
GLYPHMETRICS gm;
|
||||
const DWORD bufSize = GetGlyphOutline (dc, (UINT) glyphNumber, GGO_NATIVE | GGO_GLYPH_INDEX,
|
||||
&gm, 0, 0, &identityMatrix);
|
||||
// (although GetGlyphOutline returns a DWORD, it may be -1 on failure, so treat it as signed int..)
|
||||
const int bufSize = (int) GetGlyphOutline (dc, (UINT) glyphNumber, GGO_NATIVE | GGO_GLYPH_INDEX,
|
||||
&gm, 0, 0, &identityMatrix);
|
||||
|
||||
if (bufSize > 0)
|
||||
{
|
||||
|
|
@ -414,7 +414,6 @@ private:
|
|||
|
||||
const MAT2 WindowsTypeface::identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
|
||||
|
||||
|
||||
Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
|
||||
{
|
||||
return new WindowsTypeface (font);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue