From 6d9aee1e22a9c0674e70b38cdb85f599573312df Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Fri, 16 Sep 2005 09:15:52 -0400 Subject: ENH: Cleanups and expose unix registry on windows (for cygwin etc) --- Source/kwsys/Registry.cxx | 48 +++++++++++++++++++++----------------------- Source/kwsys/Registry.hxx.in | 4 ++-- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/Source/kwsys/Registry.cxx b/Source/kwsys/Registry.cxx index 1c3f1e6..39ab98d 100644 --- a/Source/kwsys/Registry.cxx +++ b/Source/kwsys/Registry.cxx @@ -25,16 +25,10 @@ #include // for isspace #include -#ifdef WIN32 +#ifdef _WIN32 # include #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 { @@ -79,7 +73,7 @@ protected: kwsys_stl::string m_TopLevel; bool m_GlobalScope; -#ifdef WIN32 +#ifdef _WIN32 HKEY HKey; #endif // Strip trailing and ending spaces. @@ -94,8 +88,13 @@ protected: bool m_SubKeySpecified; Registry::RegistryType m_RegistryType; + + + static const int BUFFER_SIZE; }; +//---------------------------------------------------------------------------- +const int RegistryHelper::BUFFER_SIZE = 8192; //---------------------------------------------------------------------------- Registry::Registry(Registry::RegistryType registryType) @@ -366,7 +365,7 @@ RegistryHelper::~RegistryHelper() bool RegistryHelper::Open(const char *toplevel, const char *subkey, int readonly) { -#ifdef WIN32 +#ifdef _WIN32 if ( m_RegistryType == Registry::WIN32_REGISTRY) { HKEY scope = HKEY_CURRENT_USER; @@ -412,7 +411,11 @@ bool RegistryHelper::Open(const char *toplevel, const char *subkey, 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 ) { return false; @@ -469,14 +472,14 @@ bool RegistryHelper::Open(const char *toplevel, const char *subkey, //---------------------------------------------------------------------------- bool RegistryHelper::Close() { -#ifdef WIN32 +#ifdef _WIN32 if ( m_RegistryType == Registry::WIN32_REGISTRY) { int res; res = ( RegCloseKey(this->HKey) == ERROR_SUCCESS ); return (res != 0); } -#else +#endif if ( m_RegistryType == Registry::UNIX_REGISTRY ) { int res = 0; @@ -533,7 +536,6 @@ bool RegistryHelper::Close() m_Empty = 1; return res; } -#endif return false; } @@ -541,7 +543,7 @@ bool RegistryHelper::Close() bool RegistryHelper::ReadValue(const char *skey, char *value) { -#ifdef WIN32 +#ifdef _WIN32 if ( m_RegistryType == Registry::WIN32_REGISTRY) { int res = 1; @@ -552,7 +554,7 @@ bool RegistryHelper::ReadValue(const char *skey, char *value) (BYTE *)value, &dwSize) == ERROR_SUCCESS ); return (res != 0); } -#else +#endif if ( m_RegistryType == Registry::UNIX_REGISTRY ) { int res = 0; @@ -571,42 +573,40 @@ bool RegistryHelper::ReadValue(const char *skey, char *value) delete [] key; return res; } -#endif return false; } //---------------------------------------------------------------------------- bool RegistryHelper::DeleteKey(const char* key) { -#ifdef WIN32 +#ifdef _WIN32 if ( m_RegistryType == Registry::WIN32_REGISTRY) { int res = 1; res = ( RegDeleteKey( this->HKey, key ) == ERROR_SUCCESS ); return (res != 0); } -#else +#endif if ( m_RegistryType == Registry::UNIX_REGISTRY ) { (void)key; int res = 0; return res; } -#endif return false; } //---------------------------------------------------------------------------- bool RegistryHelper::DeleteValue(const char *skey) { -#ifdef WIN32 +#ifdef _WIN32 if ( m_RegistryType == Registry::WIN32_REGISTRY) { int res = 1; res = ( RegDeleteValue( this->HKey, skey ) == ERROR_SUCCESS ); return (res != 0); } -#else +#endif if ( m_RegistryType == Registry::UNIX_REGISTRY ) { char *key = this->CreateKey( skey ); @@ -618,14 +618,13 @@ bool RegistryHelper::DeleteValue(const char *skey) delete [] key; return 1; } -#endif return false; } //---------------------------------------------------------------------------- bool RegistryHelper::SetValue(const char *skey, const char *value) { -#ifdef WIN32 +#ifdef _WIN32 if ( m_RegistryType == Registry::WIN32_REGISTRY) { int res = 1; @@ -635,7 +634,7 @@ bool RegistryHelper::SetValue(const char *skey, const char *value) len+1) == ERROR_SUCCESS ); return (res != 0); } -#else +#endif if ( m_RegistryType == Registry::UNIX_REGISTRY ) { char *key = this->CreateKey( skey ); @@ -647,7 +646,6 @@ bool RegistryHelper::SetValue(const char *skey, const char *value) delete [] key; return 1; } -#endif return false; } diff --git a/Source/kwsys/Registry.hxx.in b/Source/kwsys/Registry.hxx.in index cc6df58..e9ca1e5 100644 --- a/Source/kwsys/Registry.hxx.in +++ b/Source/kwsys/Registry.hxx.in @@ -36,13 +36,13 @@ class @KWSYS_NAMESPACE@_EXPORT Registry public: enum RegistryType { -#ifdef WIN32 +#ifdef _WIN32 WIN32_REGISTRY, #endif UNIX_REGISTRY }; -#ifdef WIN32 +#ifdef _WIN32 Registry(RegistryType registryType = WIN32_REGISTRY); #else Registry(RegistryType registryType = UNIX_REGISTRY); -- cgit v0.12