|
|
@@ -194,17 +194,17 @@ void cmSystemTools::ReplaceString(std::string& source,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
-
|
|
|
-// Get the data of key value.
|
|
|
+// Read a registry value.
|
|
|
// Example :
|
|
|
// HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath
|
|
|
// => will return the data of the "default" value of the key
|
|
|
// HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root
|
|
|
// => will return the data of the "Root" value of the key
|
|
|
-bool ReadAValue(std::string &res, const char *key)
|
|
|
+
|
|
|
+bool cmSystemTools::ReadRegistryValue(const char *key, std::string &value)
|
|
|
{
|
|
|
- // find the primary key
|
|
|
+#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
+
|
|
|
std::string primary = key;
|
|
|
std::string second;
|
|
|
std::string valuename;
|
|
|
@@ -214,11 +214,13 @@ bool ReadAValue(std::string &res, const char *key)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
size_t valuenamepos = primary.find(";");
|
|
|
if (valuenamepos != std::string::npos)
|
|
|
{
|
|
|
valuename = primary.substr(valuenamepos+1);
|
|
|
}
|
|
|
+
|
|
|
second = primary.substr(start+1, valuenamepos-start-1);
|
|
|
primary = primary.substr(0, start);
|
|
|
|
|
|
@@ -245,8 +247,11 @@ bool ReadAValue(std::string &res, const char *key)
|
|
|
}
|
|
|
|
|
|
HKEY hKey;
|
|
|
- if(RegOpenKeyEx(primaryKey, second.c_str(),
|
|
|
- 0, KEY_READ, &hKey) != ERROR_SUCCESS)
|
|
|
+ if(RegOpenKeyEx(primaryKey,
|
|
|
+ second.c_str(),
|
|
|
+ 0,
|
|
|
+ KEY_READ,
|
|
|
+ &hKey) != ERROR_SUCCESS)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
@@ -255,19 +260,181 @@ bool ReadAValue(std::string &res, const char *key)
|
|
|
DWORD dwType, dwSize;
|
|
|
dwSize = 1023;
|
|
|
char data[1024];
|
|
|
- if(RegQueryValueEx(hKey, (LPTSTR)valuename.c_str(), NULL, &dwType,
|
|
|
- (BYTE *)data, &dwSize) == ERROR_SUCCESS)
|
|
|
+ if(RegQueryValueEx(hKey,
|
|
|
+ (LPTSTR)valuename.c_str(),
|
|
|
+ NULL,
|
|
|
+ &dwType,
|
|
|
+ (BYTE *)data,
|
|
|
+ &dwSize) == ERROR_SUCCESS)
|
|
|
{
|
|
|
if (dwType == REG_SZ)
|
|
|
{
|
|
|
- res = data;
|
|
|
+ value = data;
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// Write a registry value.
|
|
|
+// Example :
|
|
|
+// HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath
|
|
|
+// => will set the data of the "default" value of the key
|
|
|
+// HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root
|
|
|
+// => will set the data of the "Root" value of the key
|
|
|
+
|
|
|
+bool cmSystemTools::WriteRegistryValue(const char *key, const char *value)
|
|
|
+{
|
|
|
+#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
+
|
|
|
+ std::string primary = key;
|
|
|
+ std::string second;
|
|
|
+ std::string valuename;
|
|
|
+
|
|
|
+ size_t start = primary.find("\\");
|
|
|
+ if (start == std::string::npos)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ size_t valuenamepos = primary.find(";");
|
|
|
+ if (valuenamepos != std::string::npos)
|
|
|
+ {
|
|
|
+ valuename = primary.substr(valuenamepos+1);
|
|
|
+ }
|
|
|
+
|
|
|
+ second = primary.substr(start+1, valuenamepos-start-1);
|
|
|
+ primary = primary.substr(0, start);
|
|
|
+
|
|
|
+ HKEY primaryKey;
|
|
|
+ if (primary == "HKEY_CURRENT_USER")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_CURRENT_USER;
|
|
|
+ }
|
|
|
+ if (primary == "HKEY_CURRENT_CONFIG")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_CURRENT_CONFIG;
|
|
|
+ }
|
|
|
+ if (primary == "HKEY_CLASSES_ROOT")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_CLASSES_ROOT;
|
|
|
+ }
|
|
|
+ if (primary == "HKEY_LOCAL_MACHINE")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_LOCAL_MACHINE;
|
|
|
+ }
|
|
|
+ if (primary == "HKEY_USERS")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_USERS;
|
|
|
+ }
|
|
|
+
|
|
|
+ HKEY hKey;
|
|
|
+ DWORD dwDummy;
|
|
|
+ if(RegCreateKeyEx(primaryKey,
|
|
|
+ second.c_str(),
|
|
|
+ 0,
|
|
|
+ "",
|
|
|
+ REG_OPTION_NON_VOLATILE,
|
|
|
+ KEY_WRITE,
|
|
|
+ NULL,
|
|
|
+ &hKey,
|
|
|
+ &dwDummy) != ERROR_SUCCESS)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(RegSetValueEx(hKey,
|
|
|
+ (LPTSTR)valuename.c_str(),
|
|
|
+ 0,
|
|
|
+ REG_SZ,
|
|
|
+ (CONST BYTE *)value,
|
|
|
+ (DWORD)(strlen(value) + 1)) == ERROR_SUCCESS)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+// Delete a registry value.
|
|
|
+// Example :
|
|
|
+// HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath
|
|
|
+// => will delete the data of the "default" value of the key
|
|
|
+// HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root
|
|
|
+// => will delete the data of the "Root" value of the key
|
|
|
+
|
|
|
+bool cmSystemTools::DeleteRegistryValue(const char *key)
|
|
|
+{
|
|
|
+#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
+
|
|
|
+ std::string primary = key;
|
|
|
+ std::string second;
|
|
|
+ std::string valuename;
|
|
|
+
|
|
|
+ size_t start = primary.find("\\");
|
|
|
+ if (start == std::string::npos)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ size_t valuenamepos = primary.find(";");
|
|
|
+ if (valuenamepos != std::string::npos)
|
|
|
+ {
|
|
|
+ valuename = primary.substr(valuenamepos+1);
|
|
|
+ }
|
|
|
+
|
|
|
+ second = primary.substr(start+1, valuenamepos-start-1);
|
|
|
+ primary = primary.substr(0, start);
|
|
|
+
|
|
|
+ HKEY primaryKey;
|
|
|
+ if (primary == "HKEY_CURRENT_USER")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_CURRENT_USER;
|
|
|
+ }
|
|
|
+ if (primary == "HKEY_CURRENT_CONFIG")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_CURRENT_CONFIG;
|
|
|
+ }
|
|
|
+ if (primary == "HKEY_CLASSES_ROOT")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_CLASSES_ROOT;
|
|
|
+ }
|
|
|
+ if (primary == "HKEY_LOCAL_MACHINE")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_LOCAL_MACHINE;
|
|
|
+ }
|
|
|
+ if (primary == "HKEY_USERS")
|
|
|
+ {
|
|
|
+ primaryKey = HKEY_USERS;
|
|
|
+ }
|
|
|
+
|
|
|
+ HKEY hKey;
|
|
|
+ if(RegOpenKeyEx(primaryKey,
|
|
|
+ second.c_str(),
|
|
|
+ 0,
|
|
|
+ KEY_WRITE,
|
|
|
+ &hKey) != ERROR_SUCCESS)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(RegDeleteValue(hKey,
|
|
|
+ (LPTSTR)valuename.c_str()) == ERROR_SUCCESS)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
#endif
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
// replace replace with with as many times as it shows up in source.
|
|
|
// write the result into source.
|
|
|
@@ -288,7 +455,7 @@ void cmSystemTools::ExpandRegistryValues(std::string& source)
|
|
|
// the arguments are the second match
|
|
|
std::string key = regEntry.match(1);
|
|
|
std::string val;
|
|
|
- if (ReadAValue(val,key.c_str()))
|
|
|
+ if (ReadRegistryValue(key.c_str(), val))
|
|
|
{
|
|
|
std::string reg = "[";
|
|
|
reg += key + "]";
|
|
|
@@ -305,8 +472,6 @@ void cmSystemTools::ExpandRegistryValues(std::string& source)
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
std::string cmSystemTools::EscapeQuotes(const char* str)
|
|
|
{
|
|
|
std::string result = "";
|