diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2009-05-29 13:10:56 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2009-05-29 13:10:56 -0230 |
commit | 98f6b988dbc9d3e61d1c87f2cba5c10efabafb3b (patch) | |
tree | 7d899ccb36b7c697d24eda2a456367d6a58d3bff /cpp/src/Ice/PropertiesI.cpp | |
parent | Fixed IceSSL Windows build (diff) | |
download | ice-98f6b988dbc9d3e61d1c87f2cba5c10efabafb3b.tar.bz2 ice-98f6b988dbc9d3e61d1c87f2cba5c10efabafb3b.tar.xz ice-98f6b988dbc9d3e61d1c87f2cba5c10efabafb3b.zip |
Bug 2754 - read properties from Windows registry
Diffstat (limited to 'cpp/src/Ice/PropertiesI.cpp')
-rw-r--r-- | cpp/src/Ice/PropertiesI.cpp | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp index 4424b8f4980..0939ee3eada 100644 --- a/cpp/src/Ice/PropertiesI.cpp +++ b/cpp/src/Ice/PropertiesI.cpp @@ -285,19 +285,73 @@ Ice::PropertiesI::parseIceCommandLineOptions(const StringSeq& options) void Ice::PropertiesI::load(const std::string& file) { - ifstream in(file.c_str()); - if(!in) +#ifdef _WIN32 + if(file.find("HKLM\\") == 0 || file.find("HKCU\\") == 0) { - FileException ex(__FILE__, __LINE__); - ex.path = file; - ex.error = getSystemErrno(); - throw ex; - } + HKEY key; + if(file.find("HKLM\\") == 0) + { + key = HKEY_LOCAL_MACHINE; + } + else + { + key = HKEY_CURRENT_USER; + } - string line; - while(getline(in, line)) + HKEY iceKey; + if(RegOpenKey(key, file.substr(5).c_str(), &iceKey) != ERROR_SUCCESS) + { + InitializationException ex(__FILE__, __LINE__); + ex.reason = "Could not open Windows registry key `" + file + "'"; + throw ex; + } + + DWORD numValues; + if(RegQueryInfoKey(iceKey, NULL, NULL, NULL, NULL, NULL, NULL, &numValues, NULL, NULL, NULL, NULL) == + ERROR_SUCCESS) + { + if(numValues > 0) + { + for(DWORD i = 0; i < numValues; ++i) + { + char keyBuf[256]; + DWORD keyBufSize = sizeof(keyBuf); + if(RegEnumValue(iceKey, i, keyBuf, &keyBufSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) + { + char valueBuf[256]; + DWORD valueBufSize = sizeof(valueBuf); + DWORD keyType; + if(RegQueryValueEx(iceKey, keyBuf, 0, &keyType, (BYTE*)valueBuf, &valueBufSize) == + ERROR_SUCCESS) + { + if(keyType == REG_SZ) + { + setProperty(keyBuf, valueBuf); + } + } + } + } + } + } + RegCloseKey(iceKey); + } + else +#endif { - parseLine(line, _converter); + ifstream in(file.c_str()); + if(!in) + { + FileException ex(__FILE__, __LINE__); + ex.path = file; + ex.error = getSystemErrno(); + throw ex; + } + + string line; + while(getline(in, line)) + { + parseLine(line, _converter); + } } } |