summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
authorClinton Stimpson <clinton@elemtech.com>2013-12-05 05:17:24 (GMT)
committerBrad King <brad.king@kitware.com>2013-12-09 15:29:43 (GMT)
commit0b9906c2fba3fa7d2aebc5e217da31cd129b2bfc (patch)
tree512d1177b107bba94ddd7b016530f0c6a140b531 /Source/cmFindPackageCommand.cxx
parentce598cc838c717132a122a97c5e21b99f11fe23b (diff)
downloadCMake-0b9906c2fba3fa7d2aebc5e217da31cd129b2bfc.zip
CMake-0b9906c2fba3fa7d2aebc5e217da31cd129b2bfc.tar.gz
CMake-0b9906c2fba3fa7d2aebc5e217da31cd129b2bfc.tar.bz2
Windows: Use wide-character system APIs
Make CMake compile with -DUNICODE. Make it possible for the 8 bit encoding to eventually be UTF-8 instead ANSI.
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx29
1 files changed, 15 insertions, 14 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 12f04d6..55c20d6 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -13,6 +13,7 @@
#include <cmsys/Directory.hxx>
#include <cmsys/RegularExpression.hxx>
+#include <cmsys/Encoding.hxx>
#ifdef CMAKE_BUILD_WITH_CMAKE
#include "cmVariableWatch.h"
@@ -1245,23 +1246,23 @@ void cmFindPackageCommand::LoadPackageRegistryWinSystem()
void cmFindPackageCommand::LoadPackageRegistryWin(bool user,
unsigned int view)
{
- std::string key = "Software\\Kitware\\CMake\\Packages\\";
- key += this->Name;
- std::set<cmStdString> bad;
+ std::wstring key = L"Software\\Kitware\\CMake\\Packages\\";
+ key += cmsys::Encoding::ToWide(this->Name);
+ std::set<std::wstring> bad;
HKEY hKey;
- if(RegOpenKeyEx(user? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
- 0, KEY_QUERY_VALUE|view, &hKey) == ERROR_SUCCESS)
+ if(RegOpenKeyExW(user? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(),
+ 0, KEY_QUERY_VALUE|view, &hKey) == ERROR_SUCCESS)
{
DWORD valueType = REG_NONE;
- char name[16384];
- std::vector<char> data(512);
+ wchar_t name[16383]; // RegEnumValue docs limit name to 32767 _bytes_
+ std::vector<wchar_t> data(512);
bool done = false;
DWORD index = 0;
while(!done)
{
DWORD nameSize = static_cast<DWORD>(sizeof(name));
- DWORD dataSize = static_cast<DWORD>(data.size()-1);
- switch(RegEnumValue(hKey, index, name, &nameSize,
+ DWORD dataSize = static_cast<DWORD>(data.size()*sizeof(data[0]));
+ switch(RegEnumValueW(hKey, index, name, &nameSize,
0, &valueType, (BYTE*)&data[0], &dataSize))
{
case ERROR_SUCCESS:
@@ -1269,7 +1270,7 @@ void cmFindPackageCommand::LoadPackageRegistryWin(bool user,
if(valueType == REG_SZ)
{
data[dataSize] = 0;
- cmsys_ios::stringstream ss(&data[0]);
+ cmsys_ios::stringstream ss(cmsys::Encoding::ToNarrow(&data[0]));
if(!this->CheckPackageRegistryEntry(ss))
{
// The entry is invalid.
@@ -1278,7 +1279,7 @@ void cmFindPackageCommand::LoadPackageRegistryWin(bool user,
}
break;
case ERROR_MORE_DATA:
- data.resize(dataSize+1);
+ data.resize((dataSize+sizeof(data[0])-1)/sizeof(data[0]));
break;
case ERROR_NO_MORE_ITEMS: default: done = true; break;
}
@@ -1288,13 +1289,13 @@ void cmFindPackageCommand::LoadPackageRegistryWin(bool user,
// Remove bad values if possible.
if(user && !bad.empty() &&
- RegOpenKeyEx(HKEY_CURRENT_USER, key.c_str(),
+ RegOpenKeyExW(HKEY_CURRENT_USER, key.c_str(),
0, KEY_SET_VALUE|view, &hKey) == ERROR_SUCCESS)
{
- for(std::set<cmStdString>::const_iterator vi = bad.begin();
+ for(std::set<std::wstring>::const_iterator vi = bad.begin();
vi != bad.end(); ++vi)
{
- RegDeleteValue(hKey, vi->c_str());
+ RegDeleteValueW(hKey, vi->c_str());
}
RegCloseKey(hKey);
}