#define _CCPERSIST_CPP_
#include "StdAfx.h"
#include ".\ccpersist.h"
LPCTSTR g_szCMDCMX_RegKey = TEXT("Software\\Harrington\\CMDCMX");
LPCTSTR g_szCMDCMXRun_RegKey = TEXT("Software\\Harrington\\CMDCMX\\Run Param History");
LPCTSTR g_szCMDCMXApplicationForDosBox_StringValue = TEXT("Application For Command Window");
LPCTSTR g_szCMDCMXShowRunOnFileMenuItem_DwordValue = TEXT("Show Run MenuItem");
LPCTSTR g_szCMDCMXShowRunOnFileMenuItem_StringValue = TEXT("Add Run MenuItem To");
LPCTSTR g_szCMDCMXShowOpenInCMDWNDMenuItem_DwordValue = TEXT("Show OpenInCMDWindow MenuItem");
LPCTSTR g_szCMDCMXShowCopyPathNameMenuItem_DwordValue = TEXT("Show CopyPathName MenuItem");
LPCTSTR g_szCMDCMXShowCopyShortPathNameMenuItem_DwordValue = TEXT("Show CopyShortPathName MenuItem");
CPersist::CPersist(void)
{
}
CPersist::~CPersist(void)
{
}
HRESULT CPersist::ShowMenuItem( int& nShow, LPCTSTR szKey )
{
HRESULT hRes;
DWORD dwDisp;
HKEY hKey = NULL;
// Open the key... create it if it doesn't already exist.
if( (hRes = ::RegCreateKeyEx( HKEY_LOCAL_MACHINE, g_szCMDCMX_RegKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hKey, &dwDisp)) == ERROR_SUCCESS )
{
DWORD dwType, dw = sizeof(int);
// default to true.
nShow = 1;
hRes = ::RegQueryValueEx( hKey, szKey, 0, &dwType, (UCHAR*)&nShow, &dw );
::RegCloseKey( hKey );
}
return hRes;
}
int CPersist::ReadFromRegistry_FileMenuItemsToAdd( bool& bShowRunOnFileMenuItem, bool& bShowOpenInDosMenuItem, bool& bShowCopyPathNameMenuItem, bool& bShowCopyShortPathNameMenuItem )
{
int nShow = 0;
int nShowCount = 0;
nShowCount = ReadFromRegistry_FolderMenuItemsToAdd(bShowOpenInDosMenuItem, bShowCopyPathNameMenuItem, bShowCopyShortPathNameMenuItem);
ShowMenuItem( nShow, g_szCMDCMXShowRunOnFileMenuItem_DwordValue );
if( nShow )
{
bShowRunOnFileMenuItem = true;
nShowCount++;
}
return nShowCount;
}
int CPersist::ReadFromRegistry_FolderMenuItemsToAdd( bool& bShowOpenInDosMenuItem, bool& bShowCopyPathNameMenuItem, bool& bShowCopyShortPathNameMenuItem )
{
int nShow = 0;
int nShowCount = 0;
ShowMenuItem( nShow, g_szCMDCMXShowOpenInCMDWNDMenuItem_DwordValue );
if( nShow )
{
bShowOpenInDosMenuItem = true;
nShowCount++;
}
ShowMenuItem( nShow, g_szCMDCMXShowCopyPathNameMenuItem_DwordValue );
if( nShow )
{
bShowCopyPathNameMenuItem = true;
nShowCount++;
}
ShowMenuItem( nShow, g_szCMDCMXShowCopyShortPathNameMenuItem_DwordValue );
if( nShow )
{
bShowCopyShortPathNameMenuItem = true;
nShowCount++;
}
return nShowCount;
}
int CPersist::ReadFromRegistry_FileTypesToAddRunMenuItemTo( LPTSTR pszTypes )
{
DWORD dwDisp;
HKEY hKey = NULL;
HRESULT hRes = E_FAIL;
// Open the key... create it if it doesn't already exist.
if( ::RegCreateKeyEx( HKEY_LOCAL_MACHINE, g_szCMDCMX_RegKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hKey, &dwDisp) == ERROR_SUCCESS )
{
DWORD dwType, dw = (2048*sizeof(TCHAR));
_tcscpy( pszTypes, TEXT("exe, com, bat") );
hRes = ::RegQueryValueEx( hKey, g_szCMDCMXShowRunOnFileMenuItem_StringValue, 0, &dwType, (UCHAR*)pszTypes, &dw );
::RegCloseKey( hKey );
}
if( SUCCEEDED(hRes) )
{
int i = 0;
while( pszTypes[i] != NULL )
{
pszTypes[i] = LOWORD(tolower(pszTypes[i]));
i++;
}
return 1;
}
return 0;
}
int CPersist::ReadFromRegistry_RunApplication( LPTSTR lptstrApplication )
{
DWORD dwDisp;
HKEY hKey = NULL;
HRESULT hRes = E_FAIL;
// Open the key... create it if it doesn't already exist.
if( (hRes = ::RegCreateKeyEx( HKEY_LOCAL_MACHINE, g_szCMDCMX_RegKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, NULL, &hKey, &dwDisp)) == ERROR_SUCCESS )
{
DWORD dwType = REG_SZ, dw = (MAX_PATH*sizeof(TCHAR));
DWORD dwVersion = ::GetVersion(); // Get major and minor version numbers of Windows
// Do the right thing for the OS - WinNT wants cmd.exe, Win95 wants command.com.
if (dwVersion < 0x80000000) // Windows NT
_tcscpy( lptstrApplication, TEXT("cmd.exe") );
else
_tcscpy( lptstrApplication, TEXT("command.com") );
hRes = ::RegQueryValueEx( hKey, g_szCMDCMXApplicationForDosBox_StringValue, 0, &dwType, (UCHAR*)lptstrApplication, &dw );
::RegCloseKey( hKey );
if( SUCCEEDED(hRes) )
return 1;
}
return 0;
}