Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1:/tmp/cvs-serv12885 Modified Files: AnyEdit.cpp AnyEdit.dsp AssociationPref.cpp RegProfile.cpp RegProfile.h TemplatePref.cpp Removed Files: PRECOMP.H Log Message: Major cleanup of the AnyEdit registy interface. Rewrite of the CRegProfile class. Index: AnyEdit.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEdit.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** AnyEdit.cpp 21 Nov 2003 13:53:00 -0000 1.32 --- AnyEdit.cpp 22 Nov 2003 16:14:19 -0000 1.33 *************** *** 1039,1043 **** { langstr = SEC_LANG; ! langstr += SEC_SEP; langstr += m_reg.GetProfileString(SEC_LANG,msc.GetStringForInt(i),tempStr,""); langstr = m_reg.GetProfileString(langstr,"Extension",tempStr,""); --- 1039,1043 ---- { langstr = SEC_LANG; ! langstr += REG_SEP; langstr += m_reg.GetProfileString(SEC_LANG,msc.GetStringForInt(i),tempStr,""); langstr = m_reg.GetProfileString(langstr,"Extension",tempStr,""); *************** *** 1109,1113 **** tempstr = m_reg.GetProfileString(langstr,langpos,tempStr,""); ! langstr += SEC_SEP; langstr += tempstr; acmpstr = langstr; --- 1109,1113 ---- tempstr = m_reg.GetProfileString(langstr,langpos,tempStr,""); ! langstr += REG_SEP; langstr += tempstr; acmpstr = langstr; Index: AnyEdit.dsp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEdit.dsp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** AnyEdit.dsp 21 Nov 2003 13:53:00 -0000 1.24 --- AnyEdit.dsp 22 Nov 2003 16:14:19 -0000 1.25 *************** *** 591,598 **** # Begin Source File - SOURCE=.\Precomp.h - # End Source File - # Begin Source File - SOURCE=.\RegProfile.h # End Source File --- 591,594 ---- Index: AssociationPref.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AssociationPref.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssociationPref.cpp 8 May 2003 12:00:56 -0000 1.4 --- AssociationPref.cpp 22 Nov 2003 16:14:19 -0000 1.5 *************** *** 250,254 **** CString regRoot = SEC_ASSOC; m_reg.WriteProfileString(SEC_ASSOC,msc.GetStringForInt(extCnt),ext); ! regRoot+= SEC_SEP; regRoot+= ext; m_reg.WriteProfileString(regRoot,_T("Extension"),ext); --- 250,254 ---- CString regRoot = SEC_ASSOC; m_reg.WriteProfileString(SEC_ASSOC,msc.GetStringForInt(extCnt),ext); ! regRoot+= REG_SEP; regRoot+= ext; m_reg.WriteProfileString(regRoot,_T("Extension"),ext); *************** *** 263,267 **** int extCnt = m_reg.GetProfileInt(SEC_ASSOC,_T("Count"),0); CString regRoot = SEC_ASSOC; ! regRoot+= SEC_SEP; CString curRoot; TCHAR tempStr[1024]; --- 263,267 ---- int extCnt = m_reg.GetProfileInt(SEC_ASSOC,_T("Count"),0); CString regRoot = SEC_ASSOC; ! regRoot+= REG_SEP; CString curRoot; TCHAR tempStr[1024]; Index: RegProfile.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/RegProfile.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RegProfile.cpp 8 May 2003 12:00:56 -0000 1.3 --- RegProfile.cpp 22 Nov 2003 16:14:19 -0000 1.4 *************** *** 4,11 **** #include "stdafx.h" - #include "AnyEdit.h" #include "RegProfile.h" - #include "Precomp.h" - #include "Misc.h" #ifdef _DEBUG #undef THIS_FILE --- 4,8 ---- *************** *** 18,267 **** ////////////////////////////////////////////////////////////////////// ! CRegProfile::CRegProfile() ! { ! } ! CRegProfile::~CRegProfile() { } ! void CRegProfile::SaveProfile( HWND hWnd ) const ! { ! } ! ! void CRegProfile::LoadProfile( HWND hWnd ) { ! ! CMisc msc; ! TCHAR filName[_MAX_PATH]; ! GetModuleFileName(NULL,filName, _MAX_PATH); ! CString tempAppPath = msc.GetParentFolderForFile(filName); ! theApp.SetAppPath(tempAppPath); ! } ! //misc ! HKEY GetAppRegistryKey( LPCTSTR pszRegistryKey, LPCTSTR pszProfileName ) { - ASSERT( pszRegistryKey != NULL ); - ASSERT( pszProfileName != NULL ); - - HKEY hAppKey = NULL; HKEY hSoftKey = NULL; HKEY hCompanyKey = NULL; ! if ( RegOpenKeyEx( HKEY_CURRENT_USER, _T( "Software" ), 0, KEY_WRITE|KEY_READ, ! &hSoftKey ) == ERROR_SUCCESS ) { DWORD dw; ! if ( RegCreateKeyEx( hSoftKey, pszRegistryKey, 0, REG_NONE, ! REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, ! &hCompanyKey, &dw ) == ERROR_SUCCESS ) { ! RegCreateKeyEx( hCompanyKey, pszProfileName, 0, REG_NONE, ! REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, ! &hAppKey, &dw ); } } ! if ( hSoftKey != NULL ) ! RegCloseKey( hSoftKey ); ! if ( hCompanyKey != NULL ) ! RegCloseKey( hCompanyKey ); return hAppKey; } ! // returns key for: ! // HKEY_CURRENT_USER\"Software"\RegistryKey\AppName\pszSection ! // creating it if it doesn't exist. ! // responsibility of the caller to call RegCloseKey() on the returned HKEY ! HKEY GetSectionKey( LPCTSTR pszRegistryKey, LPCTSTR pszProfileName, LPCTSTR pszSection ) { ASSERT( pszSection != NULL ); HKEY hSectionKey = NULL; - HKEY hAppKey = GetAppRegistryKey( pszRegistryKey, pszProfileName ); - if ( hAppKey == NULL ) - return NULL; DWORD dw; ! RegCreateKeyEx( hAppKey, pszSection, 0, REG_NONE, ! REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, ! &hSectionKey, &dw ); ! RegCloseKey( hAppKey ); return hSectionKey; } ! UINT RegGetProfileInt( LPCTSTR pszRegistryKey, LPCTSTR pszProfileName, LPCTSTR pszSection, LPCTSTR pszEntry ! , int nDefault ) { ASSERT( pszSection != NULL ); ! ASSERT( pszEntry ! != NULL ); ! HKEY hSecKey = GetSectionKey( pszRegistryKey, pszProfileName, pszSection ); ! if ( hSecKey == NULL ) ! { ! return nDefault; ! } ! else { ! DWORD dwValue; ! DWORD dwType; ! DWORD dwCount = sizeof( DWORD ); ! LONG lResult = RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry ! , NULL, &dwType, ! ( LPBYTE )&dwValue, &dwCount ); ! RegCloseKey( hSecKey ); ! if ( lResult == ERROR_SUCCESS ) { ASSERT( dwType == REG_DWORD ); ASSERT( dwCount == sizeof( dwValue ) ); ! return ( UINT )dwValue; } } return nDefault; } ! // buffer pointed to by pszText must be 1024 bytes long. ! LPCTSTR RegGetProfileString( LPCTSTR pszRegistryKey, LPCTSTR pszProfileName, LPCTSTR pszSection, LPCTSTR pszEntry ! , LPTSTR pszValue, LPCTSTR pszDefault ) { ASSERT( pszSection != NULL ); ! ASSERT( pszEntry ! != NULL ); ! HKEY hSecKey = GetSectionKey( pszRegistryKey, pszProfileName, pszSection ); ! if ( hSecKey == NULL ) ! return pszDefault; ! DWORD dwType, dwCount; ! LONG lResult = RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry ! , NULL, &dwType, ! NULL, &dwCount ); ! if ( lResult == ERROR_SUCCESS ) ! { ! ASSERT( dwType == REG_SZ ); ! LPTSTR pszOut = new TCHAR[ dwCount + 1 ]; ! lResult = RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry ! , NULL, &dwType, ! ( LPBYTE )pszOut, &dwCount ); ! _tcsncpy( pszValue, pszOut, min( 1024, dwCount ) ); ! pszValue[ min( 1024, dwCount ) ] = _T( '\0' ); ! delete pszOut; ! } ! RegCloseKey( hSecKey ); ! if ( lResult == ERROR_SUCCESS ) ! { ! ASSERT( dwType == REG_SZ ); ! return pszValue; } return pszDefault; } ! BOOL RegGetProfileBinary( LPCTSTR pszRegistryKey, LPCTSTR pszProfileName, LPCTSTR pszSection, LPCTSTR pszEntry ! , BYTE** ppData, UINT* pBytes ) { ASSERT( pszSection != NULL ); ! ASSERT( pszEntry ! != NULL ); ASSERT( ppData != NULL ); ASSERT( pBytes != NULL ); *ppData = NULL; *pBytes = 0; ! HKEY hSecKey = GetSectionKey( pszRegistryKey, pszProfileName, pszSection ); ! if ( hSecKey == NULL ) ! return FALSE; ! DWORD dwType, dwCount; ! LONG lResult = RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry ! , NULL, &dwType, ! NULL, &dwCount ); ! *pBytes = dwCount; ! if ( lResult == ERROR_SUCCESS ) ! { ! ASSERT( dwType == REG_BINARY ); ! *ppData = new BYTE[*pBytes]; ! lResult = RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry ! , NULL, &dwType, ! *ppData, &dwCount ); ! } ! RegCloseKey( hSecKey ); ! if ( lResult == ERROR_SUCCESS ) ! { ! ASSERT( dwType == REG_BINARY ); ! return TRUE; ! } ! else ! { ! delete [] *ppData; ! *ppData = NULL; ! } ! return FALSE; } ! BOOL RegWriteProfileInt( LPCTSTR pszRegistryKey, LPCTSTR pszProfileName, LPCTSTR pszSection, LPCTSTR pszEntry ! , int nValue ) { ASSERT( pszSection != NULL ); ! ASSERT( pszEntry ! != NULL ); ! HKEY hSecKey = GetSectionKey( pszRegistryKey, pszProfileName, pszSection ); ! if ( hSecKey == NULL ) ! return FALSE; ! LONG lResult = RegSetValueEx( hSecKey, pszEntry ! , NULL, REG_DWORD, ! ( LPBYTE )&nValue, sizeof( nValue ) ); ! RegCloseKey( hSecKey ); ! return lResult == ERROR_SUCCESS; } ! BOOL RegWriteProfileString( LPCTSTR pszRegistryKey, LPCTSTR pszProfileName, LPCTSTR pszSection, LPCTSTR pszEntry ! , LPCTSTR pszValue ) { ASSERT( pszSection != NULL ); ! LONG lResult; ! if ( pszEntry ! == NULL ) //delete whole section ! { ! HKEY hAppKey = GetAppRegistryKey( pszRegistryKey, pszProfileName ); ! if ( hAppKey == NULL ) ! return FALSE; ! lResult = RegDeleteKey( hAppKey, pszSection ); ! RegCloseKey( hAppKey ); ! } ! else if ( pszValue == NULL ) ! { ! HKEY hSecKey = GetSectionKey( pszRegistryKey, pszProfileName, pszSection ); ! if ( hSecKey == NULL ) ! return FALSE; ! // necessary to cast away const below ! lResult = RegDeleteValue( hSecKey, ( LPTSTR )pszEntry ! ); RegCloseKey( hSecKey ); } ! else ! { ! HKEY hSecKey = GetSectionKey( pszRegistryKey, pszProfileName, pszSection ); ! if ( hSecKey == NULL ) ! return FALSE; ! lResult = RegSetValueEx( hSecKey, pszEntry ! , NULL, REG_SZ, ! ( LPBYTE )pszValue, ( lstrlen( pszValue )+1 )*sizeof( TCHAR ) ); RegCloseKey( hSecKey ); } ! return lResult == ERROR_SUCCESS; } ! BOOL RegWriteProfileBinary( LPCTSTR pszRegistryKey, LPCTSTR pszProfileName, LPCTSTR pszSection, LPCTSTR pszEntry ! , LPBYTE pData, UINT nBytes ) { ! ASSERT( pszSection != NULL ); ! LONG lResult; ! HKEY hSecKey = GetSectionKey( pszRegistryKey, pszProfileName, pszSection ); ! if ( hSecKey == NULL ) ! return FALSE; ! lResult = RegSetValueEx( hSecKey, pszEntry ! , NULL, REG_BINARY, ! pData, nBytes ); ! RegCloseKey( hSecKey ); ! return lResult == ERROR_SUCCESS; } --- 15,348 ---- ////////////////////////////////////////////////////////////////////// ! // In the constructer we open the Application registry key. We always ! // need this when we want to work with the registry. So we keep it open ! // the entire lifetime of the object. ! CRegProfile::CRegProfile() { + hAppKey = NULL; + // Open the the AnyEdit application key (HKEY_CURRENT_USER\Software\<COMPANY>\<APPNAME>) + hAppKey = GetAppRegistryKey(); } + // In the destructor we close the Application registry key. ! CRegProfile::~CRegProfile() { ! // If the hAppKey is opened, close it. ! if( NULL != hAppKey ) RegCloseKey( hAppKey ); } + // GetAppRegistryKey opens the main application registry key (HKEY_CURRENT_USER\Software\<COMPANY>\<APPNAME>) + // If the key is not available it will be created. ! HKEY CRegProfile::GetAppRegistryKey() { HKEY hSoftKey = NULL; HKEY hCompanyKey = NULL; ! if( RegOpenKeyEx( HKEY_CURRENT_USER, _T( "Software" ), 0, KEY_WRITE|KEY_READ, &hSoftKey ) == ERROR_SUCCESS ) { DWORD dw; ! if( RegCreateKeyEx( hSoftKey, COMPANY, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hCompanyKey, &dw ) == ERROR_SUCCESS ) { ! if( RegCreateKeyEx( hCompanyKey, APPNAME, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hAppKey, &dw ) != ERROR_SUCCESS ) ! { ! // Just to be sure the hAppKey is NULL when we can not create the key. ! hAppKey = NULL; ! } } } ! if ( hSoftKey != NULL ) RegCloseKey( hSoftKey ); ! if ( hCompanyKey != NULL ) RegCloseKey( hCompanyKey ); return hAppKey; } ! // GetSectionKey opens or creates the Section key under the application key ! // It returns the key for HKEY_CURRENT_USER\Software\<COMPANY>\<APPNAME>\<pszSection> ! // The caller is responsible for closing the returned HKEY. ! ! HKEY CRegProfile::GetSectionKey( LPCTSTR pszSection ) { ASSERT( pszSection != NULL ); HKEY hSectionKey = NULL; + // Check if we have the Application Registry key. + if( hAppKey == NULL ) GetAppRegistryKey(); + if( hAppKey == NULL ) return NULL; + + // Get or if non existent create the Section key. DWORD dw; ! if( ERROR_SUCCESS != RegCreateKeyEx( hAppKey, pszSection, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hSectionKey, &dw ) ) ! { ! hSectionKey = NULL; ! } ! return hSectionKey; } ! // GetProfileInt gets the integer value pointed to by Entry under Section. If the ! // key isn't found it returns the default value. ! ! const UINT CRegProfile::GetProfileInt( LPCTSTR pszSection, LPCTSTR pszEntry, int nDefault ) { ASSERT( pszSection != NULL ); ! ASSERT( pszEntry != NULL ); ! ! // First get the Section key. ! HKEY hSecKey = GetSectionKey( pszSection ); ! if( hSecKey != NULL ) { ! DWORD dwValue; ! DWORD dwType; ! DWORD dwCount = sizeof( DWORD ); ! ! // Let's get the value. ! if( ERROR_SUCCESS == RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry, NULL, &dwType, ( LPBYTE )&dwValue, &dwCount ) ) { ASSERT( dwType == REG_DWORD ); ASSERT( dwCount == sizeof( dwValue ) ); ! nDefault = (int)dwValue; } + + // Close the Section key we opened. + RegCloseKey( hSecKey ); } + return nDefault; } ! // GetProfileString copies the Entry under Section into Value. If the key doesn't ! // exist it returns the pointer to the default value. The Value buffer must be ! // at least 1024 bytes, can be longer, but the max number of characters returned ! // is 1024 including the terminating NULL character. ! ! LPCTSTR CRegProfile::GetProfileString( LPCTSTR pszSection, LPCTSTR pszEntry, LPTSTR pszValue, LPCTSTR pszDefault ) { ASSERT( pszSection != NULL ); ! ASSERT( pszEntry != NULL ); ! ASSERT( pszValue != NULL ); ! ! // First get the Section key ! HKEY hSecKey = GetSectionKey( pszSection ); ! if ( hSecKey != NULL ) ! { ! DWORD dwType; ! DWORD dwCount; ! ! // Ley's get the size of the string to be able to allocate exactly enough memory ! if( ERROR_SUCCESS == RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry, NULL, &dwType, NULL, &dwCount ) ) ! { ! ASSERT( dwType == REG_SZ ); ! ! // Allocate a buffer from the returned size + 1 ! LPTSTR pszOut = new TCHAR[ dwCount + 1 ]; ! ! // Read the string from the Registry ! if( ERROR_SUCCESS == RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry, NULL, &dwType, ( LPBYTE )pszOut, &dwCount ) ) ! { ! ASSERT( dwType == REG_SZ ); ! ! // Copy the string to the callers buffer ! _tcsncpy( pszValue, pszOut, min( 1023, dwCount ) ); ! pszValue[ min( 1023, dwCount ) ] = _T( '\0' ); ! pszDefault = pszValue; ! } ! ! // Delete the temporarily allocated memory ! delete pszOut; ! } ! ! // Close the Section key we opened. ! RegCloseKey( hSecKey ); } + return pszDefault; } ! // GetProfileBinary returns a pointer to an array of bytes from Entry under Section. ! // It's the responsibility of the caller to delete the allocated byte array! ! ! const BOOL CRegProfile::GetProfileBinary( LPCTSTR pszSection, LPCTSTR pszEntry, BYTE** ppData, UINT* pBytes ) { ASSERT( pszSection != NULL ); ! ASSERT( pszEntry != NULL ); ASSERT( ppData != NULL ); ASSERT( pBytes != NULL ); + *ppData = NULL; *pBytes = 0; ! ! BOOL bRetVal = FALSE; ! // First get the Section key. ! HKEY hSecKey = GetSectionKey( pszSection ); ! if ( hSecKey != NULL ) ! { ! DWORD dwType; ! DWORD dwCount; ! ! // Let's get the number of binary values to be able to allocate exactly enough memory ! if( ERROR_SUCCESS == RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry, NULL, &dwType, NULL, &dwCount ) ) ! { ! ASSERT( dwType == REG_BINARY ); ! ! // Allocate the needed memory ! *pBytes = dwCount; ! *ppData = new BYTE[*pBytes]; ! ! // Read the binary values from the registry ! if( ERROR_SUCCESS == RegQueryValueEx( hSecKey, ( LPTSTR )pszEntry, NULL, &dwType, *ppData, &dwCount ) ) ! { ! ASSERT( dwType == REG_BINARY ); ! bRetVal = TRUE; ! } ! else ! { ! // Delete the allocated memory if the reading failed. ! delete [] *ppData; ! *ppData = NULL; ! } ! } ! ! // Close the Section key we opened. ! RegCloseKey( hSecKey ); ! } ! ! return bRetVal; } ! // WriteProfileInt sets to Entry under Section to Value in the registry. ! ! BOOL CRegProfile::WriteProfileInt( LPCTSTR pszSection, LPCTSTR pszEntry, int nValue ) { ASSERT( pszSection != NULL ); ! ASSERT( pszEntry != NULL ); ! ! BOOL bRetVal = FALSE; ! ! // First get the Section Key ! HKEY hSecKey = GetSectionKey( pszSection ); ! if( hSecKey != NULL ) ! { ! // Write the value in the registry ! if( ERROR_SUCCESS == RegSetValueEx( hSecKey, pszEntry, NULL, REG_DWORD, ( LPBYTE )&nValue, sizeof( nValue ) ) ) ! { ! bRetVal = TRUE; ! } ! ! // Close the Section key we opened. ! RegCloseKey( hSecKey ); ! } ! ! return bRetVal; } ! ! // WriteProfileString writes the string Value to Entry under Section in the registry. ! ! BOOL CRegProfile::WriteProfileString( LPCTSTR pszSection, LPCTSTR pszEntry, LPCTSTR pszValue ) { ASSERT( pszSection != NULL ); ! ASSERT( pszEntry != NULL ); ! ASSERT( pszValue != NULL ); ! ! BOOL bRetVal = FALSE; ! ! // First get the Section Key ! HKEY hSecKey = GetSectionKey( pszSection ); ! if( hSecKey != NULL ) ! { ! // Writing the string to the registry. ! if( ERROR_SUCCESS == RegSetValueEx( hSecKey, pszEntry, NULL, REG_SZ, ( LPBYTE )pszValue, ( lstrlen( pszValue )+1 )*sizeof( TCHAR ) ) ) ! { ! bRetVal = TRUE; ! } ! ! // Close the Section key we opened. RegCloseKey( hSecKey ); } ! ! return bRetVal; ! } ! ! // WriteProfileBinary writes an array of binary values to Entry under Section in the registry. ! BOOL CRegProfile::WriteProfileBinary( LPCTSTR pszSection, LPCTSTR pszEntry, LPBYTE pData, UINT nBytes ) ! { ! ASSERT( pszSection != NULL ); ! ASSERT( pszEntry != NULL ); ! ASSERT( pData != NULL ); ! ! BOOL bRetVal = FALSE; ! ! // First get the Section Key ! HKEY hSecKey = GetSectionKey( pszSection ); ! if( hSecKey != NULL ) ! { ! // Write the byte data to the registry ! if( ERROR_SUCCESS != RegSetValueEx( hSecKey, pszEntry, NULL, REG_BINARY, pData, nBytes ) ) ! { ! bRetVal = TRUE; ! } ! ! // Close the Section key we openend. ! RegCloseKey( hSecKey ); ! } ! ! return bRetVal; ! } ! ! // DeleteProfileKey deletes key Entry under section in the registry. This function ! // fails if there are subkeys, so the key can only contain values. ! ! BOOL CRegProfile::DeleteProfileKey( LPCTSTR pszSection, LPCTSTR pszEntry ) ! { ! ASSERT( pszSection ); ! ASSERT( pszEntry ); ! ! BOOL bRetVal = FALSE; ! ! // First get the Section key ! HKEY hSecKey = GetSectionKey( pszSection ); ! if ( hSecKey != NULL ) ! { ! // Delete the desired Entry. ! if( ERROR_SUCCESS == RegDeleteKey( hSecKey, ( LPTSTR )pszEntry ) ) ! { ! bRetVal = TRUE; ! } ! ! // Close the Section key we opened. RegCloseKey( hSecKey ); } ! ! return bRetVal; } ! // DeleteProfileValue deletes value Entry under Section in the registry. ! ! BOOL CRegProfile::DeleteProfileValue( LPCTSTR pszSection, LPCTSTR pszEntry ) { ! ASSERT( pszSection ); ! ASSERT( pszEntry ); ! ! BOOL bRetVal = FALSE; ! ! // First get the Section key ! HKEY hSecKey = GetSectionKey( pszSection ); ! if ( hSecKey != NULL ) ! { ! ! // Delete the desired Entry. ! if( ERROR_SUCCESS == RegDeleteValue( hSecKey, ( LPTSTR )pszEntry ) ) ! { ! bRetVal = TRUE; ! } ! ! // Close the Section key we opened. ! RegCloseKey( hSecKey ); ! } ! ! return bRetVal; } Index: RegProfile.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/RegProfile.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RegProfile.h 8 May 2003 12:00:56 -0000 1.3 --- RegProfile.h 22 Nov 2003 16:14:19 -0000 1.4 *************** *** 3,11 **** ////////////////////////////////////////////////////////////////////// #if !defined(AFX_REGPROFILE_H__E90D4741_F35C_11D5_B413_8F804A43732E__INCLUDED_) #define AFX_REGPROFILE_H__E90D4741_F35C_11D5_B413_8F804A43732E__INCLUDED_ ! #define APPNAME _T("AnyEdit Editor") #define COMPANY _T("DeepSoft") #define CODE_SECTION _T("AECodeSection") #define SEC_ASSOC _T("Preferences\\Associations") --- 3,32 ---- ////////////////////////////////////////////////////////////////////// + /*-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + CRegProfile + + This class handles all access to the windows Registry. It provides eight + functions, three for reading from the Registry, three for writing to the + Registry and two functions for deleting keys and values. When keys don't + exist in the Registry when reading a value the key is created and set to + the default value, that is passed to the read function. It that case the + read function returnes the default value. + -=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ + #if !defined(AFX_REGPROFILE_H__E90D4741_F35C_11D5_B413_8F804A43732E__INCLUDED_) #define AFX_REGPROFILE_H__E90D4741_F35C_11D5_B413_8F804A43732E__INCLUDED_ ! #if _MSC_VER > 1000 ! #pragma once ! #endif // _MSC_VER > 1000 ! ! // These two values define the starting point for all AnyEdit's Registry ! // settings (HKEY_CURRENT_USER\Software\<COMPANY>\<APPNAME>) #define COMPANY _T("DeepSoft") + #define APPNAME _T("AnyEdit Editor") + + // The seperator used in registry keys + #define REG_SEP _T("\\"); + #define CODE_SECTION _T("AECodeSection") #define SEC_ASSOC _T("Preferences\\Associations") *************** *** 16,25 **** #define SEC_GREP _T("Preferences\\Grep") #define SEC_PREF _T("Preferences") - #define SEC_SEP _T("\\"); #define SEC_DEF _T("Preferences\\Defaults") ! //Registry keys ! ! //default editor prefs #define DEF_SYNTAXHIGHLIGHT _T("Syntax") #define DEF_VIEW_LINENO _T("LineNo") --- 37,43 ---- #define SEC_GREP _T("Preferences\\Grep") #define SEC_PREF _T("Preferences") #define SEC_DEF _T("Preferences\\Defaults") ! // Registry keys for default editor prefs #define DEF_SYNTAXHIGHLIGHT _T("Syntax") #define DEF_VIEW_LINENO _T("LineNo") *************** *** 60,116 **** #define KEY_NORMALIZECASE _T("NORMALIZECASE") #define KEY_SELBOUNDS _T("SELBOUNDS") - #define SEP _T("\\"); - - #if _MSC_VER > 1000 - #pragma once - #endif // _MSC_VER > 1000 - #include "Precomp.h" class CRegProfile { public: CRegProfile(); virtual ~CRegProfile(); - UINT CRegProfile::GetProfileInt( LPCTSTR pszSection, LPCTSTR pszEntry - , int nDefault ) const - { - return RegGetProfileInt( COMPANY, APPNAME, pszSection, pszEntry - , nDefault ); - } - LPCTSTR CRegProfile::GetProfileString( LPCTSTR pszSection, LPCTSTR pszEntry - , LPTSTR pszValue, LPCTSTR pszDefault ) const - { - return RegGetProfileString( COMPANY, APPNAME, pszSection, pszEntry - , pszValue, pszDefault ); - } - BOOL CRegProfile::GetProfileBinary( LPCTSTR pszSection, LPCTSTR pszEntry - , BYTE** ppData, UINT* pBytes ) const - { - return RegGetProfileBinary( COMPANY, APPNAME, pszSection, pszEntry - , ppData, pBytes ); - } - BOOL CRegProfile::WriteProfileInt( LPCTSTR pszSection, LPCTSTR pszEntry - , int nValue ) const - { - return RegWriteProfileInt( COMPANY, APPNAME, pszSection, pszEntry - , nValue ); - } - BOOL CRegProfile::WriteProfileString( LPCTSTR pszSection, LPCTSTR pszEntry - , LPCTSTR pszValue ) const - { - return RegWriteProfileString( COMPANY, APPNAME, pszSection, pszEntry - , pszValue ); - } - BOOL CRegProfile::WriteProfileBinary( LPCTSTR pszSection, LPCTSTR pszEntry - , LPBYTE pData, UINT nBytes ) const - { - return RegWriteProfileBinary( COMPANY, APPNAME, pszSection, pszEntry - , pData, nBytes ); - } - HFONT m_hFont; - public: - void SaveProfile( HWND hWnd ) const; - void LoadProfile( HWND hWnd ); }; --- 78,126 ---- #define KEY_NORMALIZECASE _T("NORMALIZECASE") #define KEY_SELBOUNDS _T("SELBOUNDS") class CRegProfile { + private: + // Variable to safe a reference to the AnyEdit Application key. + HKEY hAppKey; + + // GetAppRegistryKey opens the main AnyEdit Registry key + HKEY GetAppRegistryKey( /*LPCTSTR pszRegistryKey, LPCTSTR pszProfileName */ ); + + // GetSectionKey opens a Section key under the main AppKey + HKEY GetSectionKey( /*LPCTSTR pszRegistryKey, LPCTSTR pszProfileName,*/ LPCTSTR pszSection ); + public: + // The constructor, it opens the main AppKey. CRegProfile(); + + // The destructor, it closes the main AppKey. virtual ~CRegProfile(); + // GetProfileInt reads an unsigned integer value from an Entry under Section. If the + // key doesn't exist it creates it and returns the given default value. + const UINT GetProfileInt( LPCTSTR pszSection, LPCTSTR pszEntry, int nDefault ); + + // GetProfileString reads an LPCTSTR value from an Entry under Section. If + // the key doesn't exist it creates it and then returns the given default value. + LPCTSTR GetProfileString( LPCTSTR pszSection, LPCTSTR pszEntry, LPTSTR pszValue, LPCTSTR pszDefault ); + + // GetProfileBinary reads the number of Bytes in a byte Data Array from Entry under Section. + const BOOL GetProfileBinary( LPCTSTR pszSection, LPCTSTR pszEntry, BYTE** ppData, UINT* pBytes ); + + // WriteProfileInt writes the int Value into Entry under Section. + BOOL WriteProfileInt( LPCTSTR pszSection, LPCTSTR pszEntry, int nValue ); + + // WriteProfileString writes a LPCTSTR Value into Entry under Section. + BOOL WriteProfileString( LPCTSTR pszSection, LPCTSTR pszEntry, LPCTSTR pszValue ); + + // WriteProfileBinary writes a number of Bytes in an Entry under Section. + BOOL WriteProfileBinary( LPCTSTR pszSection, LPCTSTR pszEntry, LPBYTE pData, UINT nBytes ); + + // DeleteProfileKey delete a key Entry under Section and all it's values. + BOOL DeleteProfileKey( LPCTSTR pszSection, LPCTSTR pszEntry ); + + // DeleteProfileValue deletes the value Entry under Section and all it's values. + BOOL DeleteProfileValue( LPCTSTR pszSection, LPCTSTR pszEntry ); }; Index: TemplatePref.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/TemplatePref.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TemplatePref.cpp 8 May 2003 12:00:56 -0000 1.3 --- TemplatePref.cpp 22 Nov 2003 16:14:19 -0000 1.4 *************** *** 175,179 **** if(arr.GetSize()==0) { ! m_reg.WriteProfileString(regRoot,_T("Tools"),_T("")); return; } --- 175,179 ---- if(arr.GetSize()==0) { ! m_reg.DeleteProfileKey(regRoot,_T("Tools")); return; } --- PRECOMP.H DELETED --- |