ENH: More handling of unix versus windows registry

This commit is contained in:
Andy Cedilnik 2005-09-16 08:38:12 -04:00
parent 0b30d23085
commit df4f999457
1 changed files with 136 additions and 103 deletions

View File

@ -441,16 +441,22 @@ bool RegistryHelper::Open(const char *toplevel, const char *subkey,
delete ifs; delete ifs;
return res; return res;
} }
return false;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool RegistryHelper::Close() bool RegistryHelper::Close()
{ {
#ifdef WIN32 #ifdef WIN32
if ( m_RegistryType == Registry::RegistryType::WIN32)
{
int res; int res;
res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS ); res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS );
return res; return res;
}
#else #else
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
int res = 0; int res = 0;
if ( !m_Changed ) if ( !m_Changed )
{ {
@ -504,7 +510,9 @@ bool RegistryHelper::Close()
this->SetSubKey(0); this->SetSubKey(0);
m_Empty = 1; m_Empty = 1;
return res; return res;
}
#endif #endif
return false;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -512,6 +520,8 @@ bool RegistryHelper::ReadValue(const char *skey, char *value)
{ {
#ifdef WIN32 #ifdef WIN32
if ( m_RegistryType == Registry::RegistryType::WIN32)
{
int res = 1; int res = 1;
DWORD dwType, dwSize; DWORD dwType, dwSize;
dwType = REG_SZ; dwType = REG_SZ;
@ -519,7 +529,10 @@ bool RegistryHelper::ReadValue(const char *skey, char *value)
res = ( RegQueryValueEx(this->HKey, key, NULL, &dwType, res = ( RegQueryValueEx(this->HKey, key, NULL, &dwType,
(BYTE *)value, &dwSize) == ERROR_SUCCESS ); (BYTE *)value, &dwSize) == ERROR_SUCCESS );
return res; return res;
}
#else #else
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
int res = 0; int res = 0;
char *key = this->CreateKey( skey ); char *key = this->CreateKey( skey );
if ( !key ) if ( !key )
@ -535,31 +548,45 @@ bool RegistryHelper::ReadValue(const char *skey, char *value)
} }
delete [] key; delete [] key;
return res; return res;
}
#endif #endif
return false;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool RegistryHelper::DeleteKey(const char* key) bool RegistryHelper::DeleteKey(const char* key)
{ {
#ifdef WIN32 #ifdef WIN32
if ( m_RegistryType == Registry::RegistryType::WIN32)
{
int res = 1; int res = 1;
res = ( RegDeleteKey( this->HKey, key ) == ERROR_SUCCESS ); res = ( RegDeleteKey( this->HKey, key ) == ERROR_SUCCESS );
return res; return res;
}
#else #else
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
(void)key; (void)key;
int res = 0; int res = 0;
return res; return res;
}
#endif #endif
return false;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool RegistryHelper::DeleteValue(const char *skey) bool RegistryHelper::DeleteValue(const char *skey)
{ {
#ifdef WIN32 #ifdef WIN32
if ( m_RegistryType == Registry::RegistryType::WIN32)
{
int res = 1; int res = 1;
res = ( RegDeleteValue( this->HKey, key ) == ERROR_SUCCESS ); res = ( RegDeleteValue( this->HKey, key ) == ERROR_SUCCESS );
return res; return res;
}
#else #else
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
char *key = this->CreateKey( skey ); char *key = this->CreateKey( skey );
if ( !key ) if ( !key )
{ {
@ -568,20 +595,27 @@ bool RegistryHelper::DeleteValue(const char *skey)
this->EntriesMap.erase(key); this->EntriesMap.erase(key);
delete [] key; delete [] key;
return 1; return 1;
}
#endif #endif
return false;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool RegistryHelper::SetValue(const char *skey, const char *value) bool RegistryHelper::SetValue(const char *skey, const char *value)
{ {
#ifdef WIN32 #ifdef WIN32
if ( m_RegistryType == Registry::RegistryType::WIN32)
{
int res = 1; int res = 1;
DWORD len = (DWORD)(value ? strlen(value) : 0); DWORD len = (DWORD)(value ? strlen(value) : 0);
res = ( RegSetValueEx(this->HKey, key, 0, REG_SZ, res = ( RegSetValueEx(this->HKey, key, 0, REG_SZ,
(CONST BYTE *)(const char *)value, (CONST BYTE *)(const char *)value,
len+1) == ERROR_SUCCESS ); len+1) == ERROR_SUCCESS );
return res; return res;
}
#else #else
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
char *key = this->CreateKey( skey ); char *key = this->CreateKey( skey );
if ( !key ) if ( !key )
{ {
@ -590,14 +624,14 @@ bool RegistryHelper::SetValue(const char *skey, const char *value)
this->EntriesMap[key] = value; this->EntriesMap[key] = value;
delete [] key; delete [] key;
return 1; return 1;
}
#endif #endif
return false;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
char *RegistryHelper::CreateKey( const char *key ) char *RegistryHelper::CreateKey( const char *key )
{ {
#ifdef WIN32
#else
char *newkey; char *newkey;
if ( !m_SubKeySpecified || m_SubKey.empty() || !key ) if ( !m_SubKeySpecified || m_SubKey.empty() || !key )
{ {
@ -607,7 +641,6 @@ char *RegistryHelper::CreateKey( const char *key )
newkey = new char[ len+1 ] ; newkey = new char[ len+1 ] ;
::sprintf(newkey, "%s\\%s", this->m_SubKey.c_str(), key); ::sprintf(newkey, "%s\\%s", this->m_SubKey.c_str(), key);
return newkey; return newkey;
#endif
} }
void RegistryHelper::SetSubKey(const char* sk) void RegistryHelper::SetSubKey(const char* sk)