diff options
author | Matthew Newhook <matthew@zeroc.com> | 2009-08-07 11:10:57 +0800 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2009-08-07 11:10:57 +0800 |
commit | e47e08887c823824bfc36f102c065075737394b1 (patch) | |
tree | dcbb175cb6ba3204ac55a06d61d28c488227ab4f /cpp/src/Ice/PropertiesI.cpp | |
parent | Revert "4171 - Global namespace pollution" (diff) | |
download | ice-e47e08887c823824bfc36f102c065075737394b1.tar.bz2 ice-e47e08887c823824bfc36f102c065075737394b1.tar.xz ice-e47e08887c823824bfc36f102c065075737394b1.zip |
Revert "Changes for bug 3962 and 4714"
This reverts commit d38ad95e45c0083d602a43e6d77e6c1599f324fe.
Diffstat (limited to 'cpp/src/Ice/PropertiesI.cpp')
-rw-r--r-- | cpp/src/Ice/PropertiesI.cpp | 126 |
1 files changed, 17 insertions, 109 deletions
diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp index 56f33473162..0939ee3eada 100644 --- a/cpp/src/Ice/PropertiesI.cpp +++ b/cpp/src/Ice/PropertiesI.cpp @@ -299,115 +299,40 @@ Ice::PropertiesI::load(const std::string& file) } HKEY iceKey; - if(RegOpenKeyExW(key, IceUtil::stringToWstring(file.substr(5)).c_str(), 0, KEY_QUERY_VALUE, &iceKey) != ERROR_SUCCESS) + 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 maxValueNameLen; - DWORD maxValueLen; DWORD numValues; - try + if(RegQueryInfoKey(iceKey, NULL, NULL, NULL, NULL, NULL, NULL, &numValues, NULL, NULL, NULL, NULL) == + ERROR_SUCCESS) { - if(RegQueryInfoKey(iceKey, NULL, NULL, NULL, NULL, NULL, NULL, &numValues, &maxValueNameLen, &maxValueLen, - NULL, NULL) == ERROR_SUCCESS && numValues > 0) + if(numValues > 0) { - auto_ptr<wchar_t> keyBuf(new wchar_t[maxValueNameLen + 1]); - auto_ptr<wchar_t> valueBuf(new wchar_t[maxValueLen + 1]); for(DWORD i = 0; i < numValues; ++i) { - DWORD keyBufSize = (maxValueNameLen + 1) * sizeof(wchar_t); - DWORD valueBufSize = (maxValueLen + 1) * sizeof(wchar_t) ; - unsigned int err = RegEnumValueW(iceKey, i, keyBuf.get(), &keyBufSize, NULL, NULL, NULL, NULL); - if(err != ERROR_SUCCESS) + char keyBuf[256]; + DWORD keyBufSize = sizeof(keyBuf); + if(RegEnumValue(iceKey, i, keyBuf, &keyBufSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { - getProcessLogger()->warning("Could not read Windows registry property name, key path: \"" + - file + "\""); - continue; - } - keyBuf.get()[keyBufSize] = L'\0'; - - DWORD keyType; - err = RegQueryValueExW(iceKey, keyBuf.get(), 0, &keyType, (BYTE*)valueBuf.get(), &valueBufSize); - if(err != ERROR_SUCCESS) - { - getProcessLogger()->warning("Could not read Windows registry property value, property name: `" + - IceUtil::wstringToString(wstring(keyBuf.get())) + "' key path: `" + - file + "'"); - continue; - } - valueBuf.get()[valueBufSize] = L'\0'; - - switch(keyType) - { - case REG_SZ: + char valueBuf[256]; + DWORD valueBufSize = sizeof(valueBuf); + DWORD keyType; + if(RegQueryValueEx(iceKey, keyBuf, 0, &keyType, (BYTE*)valueBuf, &valueBufSize) == + ERROR_SUCCESS) { - string name = IceUtil::wstringToString(wstring(keyBuf.get())); - string value = IceUtil::wstringToString(wstring(valueBuf.get())); - if(_converter) + if(keyType == REG_SZ) { - string tmp; - _converter->fromUTF8(reinterpret_cast<const Byte*>(name.data()), - reinterpret_cast<const Byte*>(name.data() + name.size()), tmp); - name.swap(tmp); - - _converter->fromUTF8(reinterpret_cast<const Byte*>(value.data()), - reinterpret_cast<const Byte*>(value.data() + value.size()), tmp); - value.swap(tmp); + setProperty(keyBuf, valueBuf); } - setProperty(name, value); - break; - } - case REG_EXPAND_SZ: - { - unsigned int sz = ExpandEnvironmentStringsW(valueBuf.get(), 0, 0); - auto_ptr<wchar_t> expandValue; - if(sz > 0) - { - valueBufSize = sz; - expandValue = auto_ptr<wchar_t>(new wchar_t[sz + 1]); - sz = ExpandEnvironmentStringsW(valueBuf.get(), expandValue.get(), sz); - } - - if(sz == 0 || sz > valueBufSize || expandValue.get() == 0) - { - getProcessLogger()->warning("Could not expand variables in property value: `" + - IceUtil::wstringToString(wstring(valueBuf.get())) + - "' key path: `" + file + "'"); - continue; - } - - string name = IceUtil::wstringToString(wstring(keyBuf.get())); - string value = IceUtil::wstringToString(wstring(expandValue.get())); - if(_converter) - { - string tmp; - _converter->fromUTF8(reinterpret_cast<const Byte*>(name.data()), - reinterpret_cast<const Byte*>(name.data() + name.size()), tmp); - name.swap(tmp); - - _converter->fromUTF8(reinterpret_cast<const Byte*>(value.data()), - reinterpret_cast<const Byte*>(value.data() + value.size()), tmp); - value.swap(tmp); - } - setProperty(name, value); - break; - } - default: - { - break; } } } } } - catch(...) - { - RegCloseKey(iceKey); - throw; - } RegCloseKey(iceKey); } else @@ -727,28 +652,11 @@ Ice::PropertiesI::loadConfig() if(value.empty() || value == "1") { - #ifdef _WIN32 - DWORD ret = GetEnvironmentVariableW(L"ICE_CONFIG", 0, 0); - if(ret > 0) + const char* s = getenv("ICE_CONFIG"); + if(s && *s != '\0') { - auto_ptr<wchar_t> v(new wchar_t[ret]); - ret = GetEnvironmentVariableW(L"ICE_CONFIG", v.get(), ret); - value = (ret > 0 && ret < sizeof(v.get()) / sizeof(wchar_t)) ? IceUtil::wstringToString(v.get()) : string(""); - if(_converter) - { - string tmp; - _converter->fromUTF8(reinterpret_cast<const Byte*>(value.data()), - reinterpret_cast<const Byte*>(value.data() + value.size()), tmp); - value.swap(tmp); - } + value = s; } -#else - const char* s = getenv("ICE_CONFIG"); - if(s && *s != '\0') - { - value = s; - } -#endif } if(!value.empty()) |