CString -> RString for files used in smpackage
This commit is contained in:
@@ -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<CString> &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<RString> &lst, const RString ®ex, bool bReturnPathToo )
|
||||
{
|
||||
HKEY hKey = OpenRegKey( sKey );
|
||||
if( hKey == NULL )
|
||||
@@ -124,7 +132,7 @@ bool RegistryAccess::GetRegSubKeys( const CString &sKey, vector<CString> &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<CString> &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.
|
||||
|
||||
@@ -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<RString> &lst, const RString ®ex = ".*", bool bReturnPathToo = true );
|
||||
|
||||
bool GetRegSubKeys( const CString &key, vector<CString> &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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "RegistryAccess.h"
|
||||
#include <shlobj.h>
|
||||
|
||||
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] = "";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef SpecialDirs_H
|
||||
#define SpecialDirs_H
|
||||
|
||||
CString GetMyDocumentsDir();
|
||||
CString GetApplicationDataDir();
|
||||
RString GetMyDocumentsDir();
|
||||
RString GetApplicationDataDir();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="ZipArchive"
|
||||
ProjectGUID="{F8FE2773-87CB-402F-8DC8-A80837C3E24C}"
|
||||
SccProjectName=""$/ZipArchive", LDAAAAAA"
|
||||
SccLocalPath="."
|
||||
Keyword="MFCProj">
|
||||
|
||||
Reference in New Issue
Block a user