mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 04:17:55 +01:00
enabled WinRegistryKey and WinRegistryConfiguration for WinCE
This commit is contained in:
@@ -14,9 +14,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#if !defined(_WIN32_WCE)
|
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Util/WinRegistryConfiguration.h"
|
#include "Poco/Util/WinRegistryConfiguration.h"
|
||||||
#include "Poco/Util/WinRegistryKey.h"
|
#include "Poco/Util/WinRegistryKey.h"
|
||||||
#include "Poco/NumberFormatter.h"
|
#include "Poco/NumberFormatter.h"
|
||||||
@@ -100,12 +97,19 @@ void WinRegistryConfiguration::enumerate(const std::string& key, Keys& range) co
|
|||||||
if (fullPath.empty())
|
if (fullPath.empty())
|
||||||
{
|
{
|
||||||
// return all root level keys
|
// return all root level keys
|
||||||
|
#if defined(_WIN32_WCE)
|
||||||
range.push_back("HKEY_CLASSES_ROOT");
|
range.push_back("HKEY_CLASSES_ROOT");
|
||||||
range.push_back("HKEY_CURRENT_CONFIG");
|
range.push_back("HKEY_CURRENT_CONFIG");
|
||||||
range.push_back("HKEY_CURRENT_USER");
|
range.push_back("HKEY_CURRENT_USER");
|
||||||
range.push_back("HKEY_LOCAL_MACHINE");
|
range.push_back("HKEY_LOCAL_MACHINE");
|
||||||
range.push_back("HKEY_PERFORMANCE_DATA");
|
range.push_back("HKEY_PERFORMANCE_DATA");
|
||||||
range.push_back("HKEY_USERS");
|
range.push_back("HKEY_USERS");
|
||||||
|
#else
|
||||||
|
range.push_back("HKEY_CLASSES_ROOT");
|
||||||
|
range.push_back("HKEY_CURRENT_USER");
|
||||||
|
range.push_back("HKEY_LOCAL_MACHINE");
|
||||||
|
range.push_back("HKEY_USERS");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -140,6 +144,3 @@ std::string WinRegistryConfiguration::convertToRegFormat(const std::string& key,
|
|||||||
|
|
||||||
|
|
||||||
} } // namespace Poco::Util
|
} } // namespace Poco::Util
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(_WIN32_WCE)
|
|
||||||
|
|||||||
@@ -14,9 +14,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#if !defined(_WIN32_WCE)
|
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Util/WinRegistryKey.h"
|
#include "Poco/Util/WinRegistryKey.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/Buffer.h"
|
#include "Poco/Buffer.h"
|
||||||
@@ -176,17 +173,20 @@ std::string WinRegistryKey::getStringExpand(const std::string& name)
|
|||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
DWORD len = size/2;
|
DWORD len = size/2;
|
||||||
wchar_t* buffer = new wchar_t[len + 1];
|
Poco::Buffer<wchar_t> buffer(len + 1);
|
||||||
RegQueryValueExW(_hKey, uname.c_str(), NULL, NULL, (BYTE*) buffer, &size);
|
RegQueryValueExW(_hKey, uname.c_str(), NULL, NULL, (BYTE*) buffer.begin(), &size);
|
||||||
buffer[len] = 0;
|
buffer[len] = 0;
|
||||||
|
#if !defined(_WIN32_WCE)
|
||||||
wchar_t temp;
|
wchar_t temp;
|
||||||
DWORD expSize = ExpandEnvironmentStringsW(buffer, &temp, 1);
|
DWORD expSize = ExpandEnvironmentStringsW(buffer.begin(), &temp, 1);
|
||||||
wchar_t* expBuffer = new wchar_t[expSize];
|
Poco::Buffer<wchar_t> expBuffer(expSize);
|
||||||
ExpandEnvironmentStringsW(buffer, expBuffer, expSize);
|
ExpandEnvironmentStringsW(buffer.begin(), expBuffer.begin(), expSize);
|
||||||
std::string result;
|
std::string result;
|
||||||
UnicodeConverter::toUTF8(expBuffer, result);
|
UnicodeConverter::toUTF8(expBuffer.begin(), result);
|
||||||
delete [] buffer;
|
#else
|
||||||
delete [] expBuffer;
|
std::string result;
|
||||||
|
UnicodeConverter::toUTF8(buffer.begin(), result);
|
||||||
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -194,16 +194,14 @@ std::string WinRegistryKey::getStringExpand(const std::string& name)
|
|||||||
throw NotFoundException(key(name));
|
throw NotFoundException(key(name));
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
{
|
{
|
||||||
char* buffer = new char[size + 1];
|
Poco::Buffer<char> Buffer(size + 1);
|
||||||
RegQueryValueExA(_hKey, name.c_str(), NULL, NULL, (BYTE*) buffer, &size);
|
RegQueryValueExA(_hKey, name.c_str(), NULL, NULL, (BYTE*) Buffer.begin(), &size);
|
||||||
buffer[size] = 0;
|
buffer[size] = 0;
|
||||||
char temp;
|
char temp;
|
||||||
DWORD expSize = ExpandEnvironmentStringsA(buffer, &temp, 1);
|
DWORD expSize = ExpandEnvironmentStringsA(buffer, &temp, 1);
|
||||||
char* expBuffer = new char[expSize];
|
Poco::Buffer<char> expBuffer(expSize);
|
||||||
ExpandEnvironmentStringsA(buffer, expBuffer, expSize);
|
ExpandEnvironmentStringsA(Buffer.begin(), expBuffer.begin(), expSize);
|
||||||
std::string result(expBuffer);
|
std::string result(expBuffer.begin());
|
||||||
delete [] buffer;
|
|
||||||
delete [] expBuffer;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -291,8 +289,10 @@ int WinRegistryKey::getInt(const std::string& name)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
|
|
||||||
|
|
||||||
void WinRegistryKey::setInt64(const std::string& name, Poco::Int64 value)
|
void WinRegistryKey::setInt64(const std::string& name, Poco::Int64 value)
|
||||||
{
|
{
|
||||||
open();
|
open();
|
||||||
@@ -325,8 +325,10 @@ Poco::Int64 WinRegistryKey::getInt64(const std::string& name)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // POCO_HAVE_INT64
|
#endif // POCO_HAVE_INT64
|
||||||
|
|
||||||
|
|
||||||
void WinRegistryKey::deleteValue(const std::string& name)
|
void WinRegistryKey::deleteValue(const std::string& name)
|
||||||
{
|
{
|
||||||
open();
|
open();
|
||||||
@@ -364,6 +366,7 @@ void WinRegistryKey::deleteKey()
|
|||||||
std::wstring usubKey;
|
std::wstring usubKey;
|
||||||
Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
|
Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
|
||||||
|
|
||||||
|
#if !defined(_WIN32_WCE)
|
||||||
typedef LONG (WINAPI *RegDeleteKeyExWFunc)(HKEY hKey, const wchar_t* lpSubKey, REGSAM samDesired, DWORD Reserved);
|
typedef LONG (WINAPI *RegDeleteKeyExWFunc)(HKEY hKey, const wchar_t* lpSubKey, REGSAM samDesired, DWORD Reserved);
|
||||||
if (_extraSam != 0)
|
if (_extraSam != 0)
|
||||||
{
|
{
|
||||||
@@ -379,6 +382,7 @@ void WinRegistryKey::deleteKey()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
|
if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
|
||||||
throw NotFoundException(key());
|
throw NotFoundException(key());
|
||||||
#else
|
#else
|
||||||
@@ -520,16 +524,20 @@ std::string WinRegistryKey::key() const
|
|||||||
std::string result;
|
std::string result;
|
||||||
if (_hRootKey == HKEY_CLASSES_ROOT)
|
if (_hRootKey == HKEY_CLASSES_ROOT)
|
||||||
result = "HKEY_CLASSES_ROOT";
|
result = "HKEY_CLASSES_ROOT";
|
||||||
|
#if defined(HKEY_CURRENT_CONFIG)
|
||||||
else if (_hRootKey == HKEY_CURRENT_CONFIG)
|
else if (_hRootKey == HKEY_CURRENT_CONFIG)
|
||||||
result = "HKEY_CURRENT_CONFIG";
|
result = "HKEY_CURRENT_CONFIG";
|
||||||
|
#endif
|
||||||
else if (_hRootKey == HKEY_CURRENT_USER)
|
else if (_hRootKey == HKEY_CURRENT_USER)
|
||||||
result = "HKEY_CURRENT_USER";
|
result = "HKEY_CURRENT_USER";
|
||||||
else if (_hRootKey == HKEY_LOCAL_MACHINE)
|
else if (_hRootKey == HKEY_LOCAL_MACHINE)
|
||||||
result = "HKEY_LOCAL_MACHINE";
|
result = "HKEY_LOCAL_MACHINE";
|
||||||
else if (_hRootKey == HKEY_USERS)
|
else if (_hRootKey == HKEY_USERS)
|
||||||
result = "HKEY_USERS";
|
result = "HKEY_USERS";
|
||||||
|
#if defined(HKEY_PERFORMANCE_DATA)
|
||||||
else if (_hRootKey == HKEY_PERFORMANCE_DATA)
|
else if (_hRootKey == HKEY_PERFORMANCE_DATA)
|
||||||
result = "HKEY_PERFORMANCE_DATA";
|
result = "HKEY_PERFORMANCE_DATA";
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
result = "(UNKNOWN)";
|
result = "(UNKNOWN)";
|
||||||
result += '\\';
|
result += '\\';
|
||||||
@@ -554,16 +562,20 @@ HKEY WinRegistryKey::handleFor(const std::string& rootKey)
|
|||||||
{
|
{
|
||||||
if (rootKey == "HKEY_CLASSES_ROOT")
|
if (rootKey == "HKEY_CLASSES_ROOT")
|
||||||
return HKEY_CLASSES_ROOT;
|
return HKEY_CLASSES_ROOT;
|
||||||
|
#if defined(HKEY_CURRENT_CONFIG)
|
||||||
else if (rootKey == "HKEY_CURRENT_CONFIG")
|
else if (rootKey == "HKEY_CURRENT_CONFIG")
|
||||||
return HKEY_CURRENT_CONFIG;
|
return HKEY_CURRENT_CONFIG;
|
||||||
|
#endif
|
||||||
else if (rootKey == "HKEY_CURRENT_USER")
|
else if (rootKey == "HKEY_CURRENT_USER")
|
||||||
return HKEY_CURRENT_USER;
|
return HKEY_CURRENT_USER;
|
||||||
else if (rootKey == "HKEY_LOCAL_MACHINE")
|
else if (rootKey == "HKEY_LOCAL_MACHINE")
|
||||||
return HKEY_LOCAL_MACHINE;
|
return HKEY_LOCAL_MACHINE;
|
||||||
else if (rootKey == "HKEY_USERS")
|
else if (rootKey == "HKEY_USERS")
|
||||||
return HKEY_USERS;
|
return HKEY_USERS;
|
||||||
|
#if defined(HKEY_PERFORMANCE_DATA)
|
||||||
else if (rootKey == "HKEY_PERFORMANCE_DATA")
|
else if (rootKey == "HKEY_PERFORMANCE_DATA")
|
||||||
return HKEY_PERFORMANCE_DATA;
|
return HKEY_PERFORMANCE_DATA;
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
throw InvalidArgumentException("Not a valid root key", rootKey);
|
throw InvalidArgumentException("Not a valid root key", rootKey);
|
||||||
}
|
}
|
||||||
@@ -656,6 +668,3 @@ void WinRegistryKey::values(WinRegistryKey::Values& vals)
|
|||||||
|
|
||||||
|
|
||||||
} } // namespace Poco::Util
|
} } // namespace Poco::Util
|
||||||
|
|
||||||
|
|
||||||
#endif // !defined(_WIN32_WCE)
|
|
||||||
|
|||||||
@@ -10,9 +10,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#if !defined(_WIN32_WCE)
|
|
||||||
|
|
||||||
|
|
||||||
#include "WinConfigurationTest.h"
|
#include "WinConfigurationTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
@@ -149,6 +146,3 @@ CppUnit::Test* WinConfigurationTest::suite()
|
|||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // _WIN32_WCE
|
|
||||||
@@ -10,9 +10,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#if !defined(_WIN32_WCE)
|
|
||||||
|
|
||||||
|
|
||||||
#include "WinRegistryTest.h"
|
#include "WinRegistryTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
@@ -131,6 +128,3 @@ CppUnit::Test* WinRegistryTest::suite()
|
|||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // _WIN32_WCE
|
|
||||||
@@ -11,20 +11,16 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "WindowsTestSuite.h"
|
#include "WindowsTestSuite.h"
|
||||||
#ifndef _WIN32_WCE
|
|
||||||
#include "WinRegistryTest.h"
|
#include "WinRegistryTest.h"
|
||||||
#include "WinConfigurationTest.h"
|
#include "WinConfigurationTest.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* WindowsTestSuite::suite()
|
CppUnit::Test* WindowsTestSuite::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WindowsTestSuite");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WindowsTestSuite");
|
||||||
|
|
||||||
#ifndef _WIN32_WCE
|
|
||||||
pSuite->addTest(WinRegistryTest::suite());
|
pSuite->addTest(WinRegistryTest::suite());
|
||||||
pSuite->addTest(WinConfigurationTest::suite());
|
pSuite->addTest(WinConfigurationTest::suite());
|
||||||
#endif
|
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user