From 63a56b14c4c26f0ba80a7847ce7f28aca7c4535a Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 10 Dec 2005 08:24:45 +0000 Subject: [PATCH] CString -> RString for files used in smpackage --- .../src/archutils/Win32/RegistryAccess.cpp | 65 ++++++++++++++++--- .../src/archutils/Win32/RegistryAccess.h | 14 ++-- stepmania/src/archutils/Win32/SpecialDirs.cpp | 4 +- stepmania/src/archutils/Win32/SpecialDirs.h | 4 +- .../ZipArchive/ZipArchive-net2003.vcproj | 1 + 5 files changed, 68 insertions(+), 20 deletions(-) diff --git a/stepmania/src/archutils/Win32/RegistryAccess.cpp b/stepmania/src/archutils/Win32/RegistryAccess.cpp index 9a97aa25c4..173136bf98 100644 --- a/stepmania/src/archutils/Win32/RegistryAccess.cpp +++ b/stepmania/src/archutils/Win32/RegistryAccess.cpp @@ -5,7 +5,7 @@ /* Given "HKEY_LOCAL_MACHINE\hardware\foo", return "hardware\foo", and place * the HKEY_LOCAL_MACHINE constant in key. */ -static bool GetRegKeyType( const CString &sIn, CString &sOut, HKEY &key ) +static bool GetRegKeyType( const RString &sIn, RString &sOut, HKEY &key ) { size_t iBackslash = sIn.find( '\\' ); if( iBackslash == sIn.npos ) @@ -14,7 +14,7 @@ static bool GetRegKeyType( const CString &sIn, CString &sOut, HKEY &key ) return false; } - CString sType = sIn.substr( 0, iBackslash ); + RString sType = sIn.substr( 0, iBackslash ); if( !sType.CompareNoCase( "HKEY_CLASSES_ROOT" ) ) key = HKEY_CLASSES_ROOT; else if( !sType.CompareNoCase( "HKEY_CURRENT_CONFIG" ) ) key = HKEY_CURRENT_CONFIG; @@ -34,9 +34,9 @@ static bool GetRegKeyType( const CString &sIn, CString &sOut, HKEY &key ) /* Given a full key, eg. "HKEY_LOCAL_MACHINE\hardware\foo", open it and return it. * On error, return NULL. */ -static HKEY OpenRegKey( const CString &sKey ) +static HKEY OpenRegKey( const RString &sKey ) { - CString sSubkey; + RString sSubkey; HKEY hType; if( !GetRegKeyType(sKey, sSubkey, hType) ) return NULL; @@ -52,7 +52,7 @@ static HKEY OpenRegKey( const CString &sKey ) return hRetKey; } -bool RegistryAccess::GetRegValue( const CString &sKey, const CString &sName, CString &sVal ) +bool RegistryAccess::GetRegValue( const RString &sKey, const RString &sName, RString &sVal ) { HKEY hKey = OpenRegKey( sKey ); if( hKey == NULL ) @@ -74,11 +74,11 @@ bool RegistryAccess::GetRegValue( const CString &sKey, const CString &sName, CSt if( iSize && (iType == REG_SZ || iType == REG_MULTI_SZ || iType == REG_EXPAND_SZ) ) --iSize; /* remove nul terminator */ - sVal = CString( sBuffer, iSize ); + sVal = RString( sBuffer, iSize ); return true; } -bool RegistryAccess::GetRegValue( const CString &sKey, const CString &sName, int &iVal ) +bool RegistryAccess::GetRegValue( const RString &sKey, const RString &sName, int &iVal ) { HKEY hKey = OpenRegKey( sKey ); if( hKey == NULL ) @@ -99,7 +99,15 @@ bool RegistryAccess::GetRegValue( const CString &sKey, const CString &sName, int return true; } -bool RegistryAccess::GetRegSubKeys( const CString &sKey, vector &lst, const CString ®ex, bool bReturnPathToo ) +bool RegistryAccess::GetRegValue( const RString &sKey, const RString &sName, bool &bVal ) +{ + int iVal; + bool b = GetRegValue( sKey, sName, iVal ); + bVal = !!iVal; + return b; +} + +bool RegistryAccess::GetRegSubKeys( const RString &sKey, vector &lst, const RString ®ex, bool bReturnPathToo ) { HKEY hKey = OpenRegKey( sKey ); if( hKey == NULL ) @@ -124,7 +132,7 @@ bool RegistryAccess::GetRegSubKeys( const CString &sKey, vector &lst, c break; } - CString sStr( szBuffer, iSize ); + RString sStr( szBuffer, iSize ); if( re.Compare(sStr) ) { @@ -139,6 +147,45 @@ bool RegistryAccess::GetRegSubKeys( const CString &sKey, vector &lst, c return !bError; } +bool RegistryAccess::SetRegValue( const RString &sKey, const RString &sName, const RString &sVal ) +{ + HKEY hKey = OpenRegKey( sKey ); + if( hKey == NULL ) + return false; + + bool bSuccess = true; + TCHAR sz[255]; + + if (sVal.GetLength() > 254) return FALSE; + + strcpy( sz, sVal.c_str() ); + + if (::RegSetValueEx(hKey, LPCTSTR(sName), 0, + REG_SZ, (LPBYTE)sz, strlen(sz) + 1) + != ERROR_SUCCESS) + bSuccess = false; + + ::RegCloseKey(hKey); + return bSuccess; +} + +bool RegistryAccess::SetRegValue( const RString &sKey, const RString &sName, bool bVal ) +{ + HKEY hKey = OpenRegKey( sKey ); + if( hKey == NULL ) + return false; + + bool bSuccess = true; + + if (::RegSetValueEx(hKey, LPCTSTR(sName), 0, + REG_BINARY, (LPBYTE)&bVal, sizeof(bVal)) + != ERROR_SUCCESS) + bSuccess = false; + + ::RegCloseKey(hKey); + return bSuccess; +} + /* * (c) 2004 Glenn Maynard * All rights reserved. diff --git a/stepmania/src/archutils/Win32/RegistryAccess.h b/stepmania/src/archutils/Win32/RegistryAccess.h index 7672ceb67b..4a4553dc10 100644 --- a/stepmania/src/archutils/Win32/RegistryAccess.h +++ b/stepmania/src/archutils/Win32/RegistryAccess.h @@ -6,15 +6,15 @@ namespace RegistryAccess { - bool GetRegValue( const CString &key, const CString &sName, CString &val ); - bool GetRegValue( const CString &key, const CString &sName, int &val ); - bool GetRegValue( const CString &key, const CString &sName, bool &val ); + bool GetRegValue( const RString &key, const RString &sName, RString &val ); + bool GetRegValue( const RString &key, const RString &sName, int &val ); + bool GetRegValue( const RString &key, const RString &sName, bool &val ); - bool SetRegValue( const CString &key, const CString &sName, const CString &val ); - bool SetRegValue( const CString &key, const CString &sName, int val ); - bool SetRegValue( const CString &key, const CString &sName, bool val ); + bool GetRegSubKeys( const RString &key, vector &lst, const RString ®ex = ".*", bool bReturnPathToo = true ); - bool GetRegSubKeys( const CString &key, vector &lst, const CString ®ex = ".*", bool bReturnPathToo = true ); + bool SetRegValue( const RString &key, const RString &sName, const RString &val ); + bool SetRegValue( const RString &key, const RString &sName, int val ); + bool SetRegValue( const RString &key, const RString &sName, bool val ); } #endif diff --git a/stepmania/src/archutils/Win32/SpecialDirs.cpp b/stepmania/src/archutils/Win32/SpecialDirs.cpp index 1e8cebdc9d..c624e7e82b 100644 --- a/stepmania/src/archutils/Win32/SpecialDirs.cpp +++ b/stepmania/src/archutils/Win32/SpecialDirs.cpp @@ -3,7 +3,7 @@ #include "RegistryAccess.h" #include -CString GetMyDocumentsDir() +RString GetMyDocumentsDir() { CString sMyDocumentsDir; bool bSuccess = RegistryAccess::GetRegValue( "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Personal", sMyDocumentsDir ); @@ -13,7 +13,7 @@ CString GetMyDocumentsDir() return sMyDocumentsDir; } -CString GetApplicationDataDir() +RString GetApplicationDataDir() { CString sApplicationDataDir; TCHAR szDir[MAX_PATH] = ""; diff --git a/stepmania/src/archutils/Win32/SpecialDirs.h b/stepmania/src/archutils/Win32/SpecialDirs.h index acebc451e6..c52c368a09 100644 --- a/stepmania/src/archutils/Win32/SpecialDirs.h +++ b/stepmania/src/archutils/Win32/SpecialDirs.h @@ -1,8 +1,8 @@ #ifndef SpecialDirs_H #define SpecialDirs_H -CString GetMyDocumentsDir(); -CString GetApplicationDataDir(); +RString GetMyDocumentsDir(); +RString GetApplicationDataDir(); #endif diff --git a/stepmania/src/smpackage/ZipArchive/ZipArchive-net2003.vcproj b/stepmania/src/smpackage/ZipArchive/ZipArchive-net2003.vcproj index da56c1e06b..8ade4b618e 100644 --- a/stepmania/src/smpackage/ZipArchive/ZipArchive-net2003.vcproj +++ b/stepmania/src/smpackage/ZipArchive/ZipArchive-net2003.vcproj @@ -3,6 +3,7 @@ ProjectType="Visual C++" Version="7.10" Name="ZipArchive" + ProjectGUID="{F8FE2773-87CB-402F-8DC8-A80837C3E24C}" SccProjectName=""$/ZipArchive", LDAAAAAA" SccLocalPath="." Keyword="MFCProj">