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;
return res;
}
return false;
}
//----------------------------------------------------------------------------
bool RegistryHelper::Close()
{
#ifdef WIN32
if ( m_RegistryType == Registry::RegistryType::WIN32)
{
int res;
res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS );
return res;
}
#else
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
int res = 0;
if ( !m_Changed )
{
@ -504,7 +510,9 @@ bool RegistryHelper::Close()
this->SetSubKey(0);
m_Empty = 1;
return res;
}
#endif
return false;
}
//----------------------------------------------------------------------------
@ -512,6 +520,8 @@ bool RegistryHelper::ReadValue(const char *skey, char *value)
{
#ifdef WIN32
if ( m_RegistryType == Registry::RegistryType::WIN32)
{
int res = 1;
DWORD dwType, dwSize;
dwType = REG_SZ;
@ -519,7 +529,10 @@ bool RegistryHelper::ReadValue(const char *skey, char *value)
res = ( RegQueryValueEx(this->HKey, key, NULL, &dwType,
(BYTE *)value, &dwSize) == ERROR_SUCCESS );
return res;
}
#else
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
int res = 0;
char *key = this->CreateKey( skey );
if ( !key )
@ -535,31 +548,45 @@ bool RegistryHelper::ReadValue(const char *skey, char *value)
}
delete [] key;
return res;
}
#endif
return false;
}
//----------------------------------------------------------------------------
bool RegistryHelper::DeleteKey(const char* key)
{
#ifdef WIN32
if ( m_RegistryType == Registry::RegistryType::WIN32)
{
int res = 1;
res = ( RegDeleteKey( this->HKey, key ) == ERROR_SUCCESS );
return res;
}
#else
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
(void)key;
int res = 0;
return res;
}
#endif
return false;
}
//----------------------------------------------------------------------------
bool RegistryHelper::DeleteValue(const char *skey)
{
#ifdef WIN32
if ( m_RegistryType == Registry::RegistryType::WIN32)
{
int res = 1;
res = ( RegDeleteValue( this->HKey, key ) == ERROR_SUCCESS );
return res;
}
#else
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
char *key = this->CreateKey( skey );
if ( !key )
{
@ -568,20 +595,27 @@ bool RegistryHelper::DeleteValue(const char *skey)
this->EntriesMap.erase(key);
delete [] key;
return 1;
}
#endif
return false;
}
//----------------------------------------------------------------------------
bool RegistryHelper::SetValue(const char *skey, const char *value)
{
#ifdef WIN32
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
if ( m_RegistryType == Registry::UNIX_REGISTRY )
{
char *key = this->CreateKey( skey );
if ( !key )
{
@ -590,14 +624,14 @@ bool RegistryHelper::SetValue(const char *skey, const char *value)
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)