diff options
Diffstat (limited to 'Source/kwsys/Registry.cxx')
-rw-r--r-- | Source/kwsys/Registry.cxx | 231 |
1 files changed, 132 insertions, 99 deletions
diff --git a/Source/kwsys/Registry.cxx b/Source/kwsys/Registry.cxx index 48f2053..b961760 100644 --- a/Source/kwsys/Registry.cxx +++ b/Source/kwsys/Registry.cxx @@ -441,70 +441,78 @@ bool RegistryHelper::Open(const char *toplevel, const char *subkey, delete ifs; return res; } + return false; } //---------------------------------------------------------------------------- bool RegistryHelper::Close() { #ifdef WIN32 - int res; - res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS ); - return res; -#else - int res = 0; - if ( !m_Changed ) - { - this->EntriesMap.erase( - this->EntriesMap.begin(), - this->EntriesMap.end()); - m_Empty = 1; - this->SetSubKey(0); - return 1; - } - - kwsys_ios::ostringstream str; - if ( !getenv("HOME") ) - { - return 0; - } - str << getenv("HOME") << "/." << this->GetTopLevel() << "rc"; - kwsys_ios::ofstream *ofs = new kwsys_ios::ofstream(str.str().c_str(), kwsys_ios::ios::out); - if ( !ofs ) + if ( m_RegistryType == Registry::RegistryType::WIN32) { - return 0; + int res; + res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS ); + return res; } - if ( ofs->fail()) +#else + if ( m_RegistryType == Registry::UNIX_REGISTRY ) { - delete ofs; - return 0; - } - *ofs << "# This file is automatically generated by the application" << kwsys_ios::endl - << "# If you change any lines or add new lines, note that all" << kwsys_ios::endl - << "# coments and empty lines will be deleted. Every line has" << kwsys_ios::endl - << "# to be in format: " << kwsys_ios::endl - << "# key = value" << kwsys_ios::endl - << "#" << kwsys_ios::endl; + int res = 0; + if ( !m_Changed ) + { + this->EntriesMap.erase( + this->EntriesMap.begin(), + this->EntriesMap.end()); + m_Empty = 1; + this->SetSubKey(0); + return 1; + } - if ( !this->EntriesMap.empty() ) - { - RegistryHelper::StringToStringMap::iterator it; - for ( it = this->EntriesMap.begin(); - it != this->EntriesMap.end(); - ++ it ) + kwsys_ios::ostringstream str; + if ( !getenv("HOME") ) { - *ofs << it->first.c_str() << " = " << it->second.c_str()<< kwsys_ios::endl; + return 0; + } + str << getenv("HOME") << "/." << this->GetTopLevel() << "rc"; + kwsys_ios::ofstream *ofs = new kwsys_ios::ofstream(str.str().c_str(), kwsys_ios::ios::out); + if ( !ofs ) + { + return 0; } + if ( ofs->fail()) + { + delete ofs; + return 0; + } + *ofs << "# This file is automatically generated by the application" << kwsys_ios::endl + << "# If you change any lines or add new lines, note that all" << kwsys_ios::endl + << "# coments and empty lines will be deleted. Every line has" << kwsys_ios::endl + << "# to be in format: " << kwsys_ios::endl + << "# key = value" << kwsys_ios::endl + << "#" << kwsys_ios::endl; + + if ( !this->EntriesMap.empty() ) + { + RegistryHelper::StringToStringMap::iterator it; + for ( it = this->EntriesMap.begin(); + it != this->EntriesMap.end(); + ++ it ) + { + *ofs << it->first.c_str() << " = " << it->second.c_str()<< kwsys_ios::endl; + } + } + this->EntriesMap.erase( + this->EntriesMap.begin(), + this->EntriesMap.end()); + ofs->close(); + delete ofs; + res = 1; + this->SetSubKey(0); + m_Empty = 1; + return res; } - this->EntriesMap.erase( - this->EntriesMap.begin(), - this->EntriesMap.end()); - ofs->close(); - delete ofs; - res = 1; - this->SetSubKey(0); - m_Empty = 1; - return res; #endif + return false; } //---------------------------------------------------------------------------- @@ -512,92 +520,118 @@ bool RegistryHelper::ReadValue(const char *skey, char *value) { #ifdef WIN32 - int res = 1; - DWORD dwType, dwSize; - dwType = REG_SZ; - dwSize = BUFFER_SIZE; - res = ( RegQueryValueEx(this->HKey, key, NULL, &dwType, - (BYTE *)value, &dwSize) == ERROR_SUCCESS ); - return res; -#else - int res = 0; - char *key = this->CreateKey( skey ); - if ( !key ) + if ( m_RegistryType == Registry::RegistryType::WIN32) { - return 0; + int res = 1; + DWORD dwType, dwSize; + dwType = REG_SZ; + dwSize = BUFFER_SIZE; + res = ( RegQueryValueEx(this->HKey, key, NULL, &dwType, + (BYTE *)value, &dwSize) == ERROR_SUCCESS ); + return res; } - RegistryHelper::StringToStringMap::iterator it - = this->EntriesMap.find(key); - if ( it != this->EntriesMap.end() ) +#else + if ( m_RegistryType == Registry::UNIX_REGISTRY ) { - strcpy(value, it->second.c_str()); - res = 1; + int res = 0; + char *key = this->CreateKey( skey ); + if ( !key ) + { + return 0; + } + RegistryHelper::StringToStringMap::iterator it + = this->EntriesMap.find(key); + if ( it != this->EntriesMap.end() ) + { + strcpy(value, it->second.c_str()); + res = 1; + } + delete [] key; + return res; } - delete [] key; - return res; #endif + return false; } //---------------------------------------------------------------------------- bool RegistryHelper::DeleteKey(const char* key) { #ifdef WIN32 - int res = 1; - res = ( RegDeleteKey( this->HKey, key ) == ERROR_SUCCESS ); - return res; + if ( m_RegistryType == Registry::RegistryType::WIN32) + { + int res = 1; + res = ( RegDeleteKey( this->HKey, key ) == ERROR_SUCCESS ); + return res; + } #else - (void)key; - int res = 0; - return res; + if ( m_RegistryType == Registry::UNIX_REGISTRY ) + { + (void)key; + int res = 0; + return res; + } #endif + return false; } //---------------------------------------------------------------------------- bool RegistryHelper::DeleteValue(const char *skey) { #ifdef WIN32 - int res = 1; - res = ( RegDeleteValue( this->HKey, key ) == ERROR_SUCCESS ); - return res; + if ( m_RegistryType == Registry::RegistryType::WIN32) + { + int res = 1; + res = ( RegDeleteValue( this->HKey, key ) == ERROR_SUCCESS ); + return res; + } #else - char *key = this->CreateKey( skey ); - if ( !key ) + if ( m_RegistryType == Registry::UNIX_REGISTRY ) { - return 0; + char *key = this->CreateKey( skey ); + if ( !key ) + { + return 0; + } + this->EntriesMap.erase(key); + delete [] key; + return 1; } - this->EntriesMap.erase(key); - delete [] key; - return 1; #endif + return false; } //---------------------------------------------------------------------------- bool RegistryHelper::SetValue(const char *skey, const char *value) { #ifdef WIN32 - int res = 1; - DWORD len = (DWORD)(value ? strlen(value) : 0); - res = ( RegSetValueEx(this->HKey, key, 0, REG_SZ, - (CONST BYTE *)(const char *)value, - len+1) == ERROR_SUCCESS ); - return res; + if ( m_RegistryType == Registry::RegistryType::WIN32) + { + int res = 1; + DWORD len = (DWORD)(value ? strlen(value) : 0); + res = ( RegSetValueEx(this->HKey, key, 0, REG_SZ, + (CONST BYTE *)(const char *)value, + len+1) == ERROR_SUCCESS ); + return res; + } #else - char *key = this->CreateKey( skey ); - if ( !key ) + if ( m_RegistryType == Registry::UNIX_REGISTRY ) { - return 0; + char *key = this->CreateKey( skey ); + if ( !key ) + { + return 0; + } + this->EntriesMap[key] = value; + delete [] key; + return 1; } - this->EntriesMap[key] = value; - delete [] key; - return 1; #endif + return false; } //---------------------------------------------------------------------------- char *RegistryHelper::CreateKey( const char *key ) { -#ifdef WIN32 -#else char *newkey; if ( !m_SubKeySpecified || m_SubKey.empty() || !key ) { @@ -607,7 +641,6 @@ char *RegistryHelper::CreateKey( const char *key ) newkey = new char[ len+1 ] ; ::sprintf(newkey, "%s\\%s", this->m_SubKey.c_str(), key); return newkey; -#endif } void RegistryHelper::SetSubKey(const char* sk) |