ENH: Cleanups and expose unix registry on windows (for cygwin etc)

This commit is contained in:
Andy Cedilnik 2005-09-16 09:15:52 -04:00
parent 30b67a8bfe
commit 6d9aee1e22
2 changed files with 25 additions and 27 deletions

View File

@ -25,16 +25,10 @@
#include <ctype.h> // for isspace #include <ctype.h> // for isspace
#include <stdio.h> #include <stdio.h>
#ifdef WIN32 #ifdef _WIN32
# include <windows.h> # include <windows.h>
#endif #endif
#ifdef KWSYS_IOS_USE_ANSI
# define VTK_IOS_NOCREATE
#else
# define VTK_IOS_NOCREATE | kwsys_ios::ios::nocreate
#endif
#define BUFFER_SIZE 8192
namespace KWSYS_NAMESPACE namespace KWSYS_NAMESPACE
{ {
@ -79,7 +73,7 @@ protected:
kwsys_stl::string m_TopLevel; kwsys_stl::string m_TopLevel;
bool m_GlobalScope; bool m_GlobalScope;
#ifdef WIN32 #ifdef _WIN32
HKEY HKey; HKEY HKey;
#endif #endif
// Strip trailing and ending spaces. // Strip trailing and ending spaces.
@ -94,8 +88,13 @@ protected:
bool m_SubKeySpecified; bool m_SubKeySpecified;
Registry::RegistryType m_RegistryType; Registry::RegistryType m_RegistryType;
static const int BUFFER_SIZE;
}; };
//----------------------------------------------------------------------------
const int RegistryHelper::BUFFER_SIZE = 8192;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
Registry::Registry(Registry::RegistryType registryType) Registry::Registry(Registry::RegistryType registryType)
@ -366,7 +365,7 @@ RegistryHelper::~RegistryHelper()
bool RegistryHelper::Open(const char *toplevel, const char *subkey, bool RegistryHelper::Open(const char *toplevel, const char *subkey,
int readonly) int readonly)
{ {
#ifdef WIN32 #ifdef _WIN32
if ( m_RegistryType == Registry::WIN32_REGISTRY) if ( m_RegistryType == Registry::WIN32_REGISTRY)
{ {
HKEY scope = HKEY_CURRENT_USER; HKEY scope = HKEY_CURRENT_USER;
@ -412,7 +411,11 @@ bool RegistryHelper::Open(const char *toplevel, const char *subkey,
ofs.close(); ofs.close();
} }
kwsys_ios::ifstream *ifs = new kwsys_ios::ifstream(str.str().c_str(), kwsys_ios::ios::in VTK_IOS_NOCREATE); kwsys_ios::ifstream *ifs = new kwsys_ios::ifstream(str.str().c_str(), kwsys_ios::ios::in
#ifndef KWSYS_IOS_USE_ANSI
| kwsys_ios::ios::nocreate
#endif
);
if ( !ifs ) if ( !ifs )
{ {
return false; return false;
@ -469,14 +472,14 @@ bool RegistryHelper::Open(const char *toplevel, const char *subkey,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool RegistryHelper::Close() bool RegistryHelper::Close()
{ {
#ifdef WIN32 #ifdef _WIN32
if ( m_RegistryType == Registry::WIN32_REGISTRY) if ( m_RegistryType == Registry::WIN32_REGISTRY)
{ {
int res; int res;
res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS ); res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS );
return (res != 0); return (res != 0);
} }
#else #endif
if ( m_RegistryType == Registry::UNIX_REGISTRY ) if ( m_RegistryType == Registry::UNIX_REGISTRY )
{ {
int res = 0; int res = 0;
@ -533,7 +536,6 @@ bool RegistryHelper::Close()
m_Empty = 1; m_Empty = 1;
return res; return res;
} }
#endif
return false; return false;
} }
@ -541,7 +543,7 @@ bool RegistryHelper::Close()
bool RegistryHelper::ReadValue(const char *skey, char *value) bool RegistryHelper::ReadValue(const char *skey, char *value)
{ {
#ifdef WIN32 #ifdef _WIN32
if ( m_RegistryType == Registry::WIN32_REGISTRY) if ( m_RegistryType == Registry::WIN32_REGISTRY)
{ {
int res = 1; int res = 1;
@ -552,7 +554,7 @@ bool RegistryHelper::ReadValue(const char *skey, char *value)
(BYTE *)value, &dwSize) == ERROR_SUCCESS ); (BYTE *)value, &dwSize) == ERROR_SUCCESS );
return (res != 0); return (res != 0);
} }
#else #endif
if ( m_RegistryType == Registry::UNIX_REGISTRY ) if ( m_RegistryType == Registry::UNIX_REGISTRY )
{ {
int res = 0; int res = 0;
@ -571,42 +573,40 @@ bool RegistryHelper::ReadValue(const char *skey, char *value)
delete [] key; delete [] key;
return res; return res;
} }
#endif
return false; return false;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool RegistryHelper::DeleteKey(const char* key) bool RegistryHelper::DeleteKey(const char* key)
{ {
#ifdef WIN32 #ifdef _WIN32
if ( m_RegistryType == Registry::WIN32_REGISTRY) if ( m_RegistryType == Registry::WIN32_REGISTRY)
{ {
int res = 1; int res = 1;
res = ( RegDeleteKey( this->HKey, key ) == ERROR_SUCCESS ); res = ( RegDeleteKey( this->HKey, key ) == ERROR_SUCCESS );
return (res != 0); return (res != 0);
} }
#else #endif
if ( m_RegistryType == Registry::UNIX_REGISTRY ) if ( m_RegistryType == Registry::UNIX_REGISTRY )
{ {
(void)key; (void)key;
int res = 0; int res = 0;
return res; return res;
} }
#endif
return false; return false;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool RegistryHelper::DeleteValue(const char *skey) bool RegistryHelper::DeleteValue(const char *skey)
{ {
#ifdef WIN32 #ifdef _WIN32
if ( m_RegistryType == Registry::WIN32_REGISTRY) if ( m_RegistryType == Registry::WIN32_REGISTRY)
{ {
int res = 1; int res = 1;
res = ( RegDeleteValue( this->HKey, skey ) == ERROR_SUCCESS ); res = ( RegDeleteValue( this->HKey, skey ) == ERROR_SUCCESS );
return (res != 0); return (res != 0);
} }
#else #endif
if ( m_RegistryType == Registry::UNIX_REGISTRY ) if ( m_RegistryType == Registry::UNIX_REGISTRY )
{ {
char *key = this->CreateKey( skey ); char *key = this->CreateKey( skey );
@ -618,14 +618,13 @@ bool RegistryHelper::DeleteValue(const char *skey)
delete [] key; delete [] key;
return 1; return 1;
} }
#endif
return false; 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::WIN32_REGISTRY) if ( m_RegistryType == Registry::WIN32_REGISTRY)
{ {
int res = 1; int res = 1;
@ -635,7 +634,7 @@ bool RegistryHelper::SetValue(const char *skey, const char *value)
len+1) == ERROR_SUCCESS ); len+1) == ERROR_SUCCESS );
return (res != 0); return (res != 0);
} }
#else #endif
if ( m_RegistryType == Registry::UNIX_REGISTRY ) if ( m_RegistryType == Registry::UNIX_REGISTRY )
{ {
char *key = this->CreateKey( skey ); char *key = this->CreateKey( skey );
@ -647,7 +646,6 @@ bool RegistryHelper::SetValue(const char *skey, const char *value)
delete [] key; delete [] key;
return 1; return 1;
} }
#endif
return false; return false;
} }

View File

@ -36,13 +36,13 @@ class @KWSYS_NAMESPACE@_EXPORT Registry
public: public:
enum RegistryType enum RegistryType
{ {
#ifdef WIN32 #ifdef _WIN32
WIN32_REGISTRY, WIN32_REGISTRY,
#endif #endif
UNIX_REGISTRY UNIX_REGISTRY
}; };
#ifdef WIN32 #ifdef _WIN32
Registry(RegistryType registryType = WIN32_REGISTRY); Registry(RegistryType registryType = WIN32_REGISTRY);
#else #else
Registry(RegistryType registryType = UNIX_REGISTRY); Registry(RegistryType registryType = UNIX_REGISTRY);