291 lines
9.6 KiB
C++
291 lines
9.6 KiB
C++
// ConfigINI.cpp: implementation of the CConfigINI class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "ConfigINI.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
CConfigINI::CConfigINI()
|
|
{
|
|
m_sINIFileName = "";
|
|
}
|
|
|
|
CConfigINI::~CConfigINI()
|
|
{
|
|
}
|
|
|
|
BOOL CConfigINI::SetINIFile(CString sFileName)
|
|
{
|
|
if (sFileName != "")
|
|
{
|
|
m_sINIFileName = sFileName;
|
|
return TRUE;
|
|
}
|
|
else return FALSE;
|
|
}
|
|
|
|
/*
|
|
DWORD GetPrivateProfileString(
|
|
LPCTSTR lpAppName, // section name
|
|
LPCTSTR lpKeyName, // key name
|
|
LPCTSTR lpDefault, // default string
|
|
LPTSTR lpReturnedString, // destination buffer
|
|
DWORD nSize, // size of destination buffer
|
|
LPCTSTR lpFileName // initialization file name
|
|
);
|
|
*/
|
|
|
|
CString CConfigINI::GetSectionKeyData(CString sSectionName, CString sKeyName)
|
|
{
|
|
if ((sSectionName == "") && (sKeyName == "") && (m_sINIFileName == ""))
|
|
return "";
|
|
|
|
char lpBuffer[10240];
|
|
memset(lpBuffer, '\0', 10240);
|
|
CString sTmp = "ERROR";
|
|
int nError = GetPrivateProfileString( (LPCTSTR) sSectionName, // section name
|
|
(LPCTSTR) sKeyName, // key name
|
|
(LPCTSTR) sTmp, // default string
|
|
lpBuffer, // destination buffer
|
|
10240, // size of destination buffer
|
|
(LPCTSTR) m_sINIFileName // initialization file name
|
|
);
|
|
sTmp = "";
|
|
sTmp = lpBuffer;
|
|
if ((nError) && (sTmp != "ERROR"))
|
|
return sTmp;
|
|
else return "";
|
|
}
|
|
|
|
BOOL CConfigINI::PutSectionKeyData(CString sSectionName, CString sKeyName, CString sValue)
|
|
{
|
|
if ((sSectionName == "") && (sKeyName == "") && (sValue == "") && (m_sINIFileName == ""))
|
|
return FALSE;
|
|
|
|
BOOL bError = WritePrivateProfileString((LPCTSTR) sSectionName, // section name
|
|
(LPCTSTR) sKeyName, // key name
|
|
(LPCTSTR) sValue, // string to add
|
|
(LPCTSTR) m_sINIFileName // initialization file
|
|
);
|
|
if (bError)
|
|
return TRUE;
|
|
else return FALSE;
|
|
}
|
|
|
|
void CConfigINI::CreateConfigFile()
|
|
{
|
|
/*
|
|
if( m_sINIFileName == "" )
|
|
{
|
|
AfxMessageBox("config file name was not set!" );
|
|
return;
|
|
}
|
|
|
|
CStdioFile file;
|
|
if( !file.Open(m_sINIFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeText ) )
|
|
{
|
|
CString str;
|
|
str.Format("File Not Found : %s", m_sINIFileName);
|
|
AfxMessageBox(str);
|
|
return;
|
|
}
|
|
|
|
file.WriteString("[FUTURECHECK_SECTION]\n");
|
|
file.WriteString("LOCKUNLOCK_HOTKEY=191,3\n");
|
|
file.WriteString("USE_SOUNDEFFECT=1\n");
|
|
file.WriteString("MONEY=10000000\n");
|
|
file.WriteString("MESU_LEVEL=3\n");
|
|
|
|
file.Close();
|
|
*/
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
// Read from ini
|
|
void CConfigINI::ReadConfigEnvFromINI()
|
|
{
|
|
if( m_sINIFileName == "" )
|
|
{
|
|
AfxMessageBox("config file name was not set!" );
|
|
return;
|
|
}
|
|
|
|
CString strTemp;
|
|
CString str;
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "LockUnlockHotKey" );
|
|
AfxExtractSubString(strTemp, str, 0, ',');
|
|
if(strTemp != "")
|
|
g_AppEnv.LockUnlockHotKey.wVk = atoi( (LPSTR)(LPCTSTR)strTemp );
|
|
AfxExtractSubString(strTemp, str, 1, ',');
|
|
if(strTemp != "")
|
|
g_AppEnv.LockUnlockHotKey.wModifier = atoi( (LPSTR)(LPCTSTR)strTemp );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "UpConditionHotKey" );
|
|
AfxExtractSubString(strTemp, str, 0, ',');
|
|
if(strTemp != "")
|
|
g_AppEnv.UpConditionHotKey.wVk = atoi( (LPSTR)(LPCTSTR)strTemp );
|
|
AfxExtractSubString(strTemp, str, 1, ',');
|
|
if(strTemp != "")
|
|
g_AppEnv.UpConditionHotKey.wModifier = atoi( (LPSTR)(LPCTSTR)strTemp );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "DownConditionHotKey" );
|
|
AfxExtractSubString(strTemp, str, 0, ',');
|
|
if(strTemp != "")
|
|
g_AppEnv.DownConditionHotKey.wVk = atoi( (LPSTR)(LPCTSTR)strTemp );
|
|
AfxExtractSubString(strTemp, str, 1, ',');
|
|
if(strTemp != "")
|
|
g_AppEnv.DownConditionHotKey.wModifier = atoi( (LPSTR)(LPCTSTR)strTemp );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "nFAamountLimitTime" );
|
|
if( str != "" )
|
|
g_AppEnv.nFAamountLimitTime = atol( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "nFAmountLimitLine" );
|
|
if( str != "" )
|
|
g_AppEnv.nFAmountLimitLine = (short)atol( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "nFAmountRuleRadio" );
|
|
if( str != "" )
|
|
g_AppEnv.nFAmountRuleRadio = (short)atol( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "nFAmountUpCondition" );
|
|
if( str != "" )
|
|
g_AppEnv.nFAmountUpCondition = atol( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "nFAmountDownCondition" );
|
|
if( str != "" )
|
|
g_AppEnv.nFAmountDownCondition = atol( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "bFAmountApplyCheck" );
|
|
if( str != "" )
|
|
g_AppEnv.bFAmountApplyCheck = atoi( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "szFutureCode" );
|
|
if( str != "" )
|
|
strcpy( g_AppEnv.szFutureCode, (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "nFcurLimitTime" );
|
|
if( str != "" )
|
|
g_AppEnv.nFcurLimitTime = atol( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "nFcurLevelCheck" );
|
|
if( str != "" )
|
|
g_AppEnv.nFcurLevelCheck = (short)atol( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "bFcurApplyCheck" );
|
|
if( str != "" )
|
|
g_AppEnv.bFcurApplyCheck = atoi( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "bFApplyRuleRadio" );
|
|
if( str != "" )
|
|
g_AppEnv.bFApplyRuleRadio = (short)atol( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "nFApplyRuleRadioLimitTime" );
|
|
if( str != "" )
|
|
g_AppEnv.nFApplyRuleRadioLimitTime = atol( (LPSTR)(LPCTSTR)str );
|
|
|
|
str = GetSectionKeyData( "FUTURECHECK_SECTION", "bRunStatCheck" );
|
|
if( str != "" )
|
|
g_AppEnv.bRunStatCheck = atoi( (LPSTR)(LPCTSTR)str );
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
// Write to ini
|
|
void CConfigINI::WriteConfigEnvToINI()
|
|
{
|
|
if( m_sINIFileName == "" )
|
|
{
|
|
AfxMessageBox("config file name was not set!" );
|
|
return;
|
|
}
|
|
|
|
TCHAR szText1[MAX_PATH], szText2[MAX_PATH], szText3[MAX_PATH];
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.LockUnlockHotKey.wVk, szText1, 10 );
|
|
memset( szText2, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.LockUnlockHotKey.wModifier, szText2, 10 );
|
|
memset( szText3, NULL, MAX_PATH );
|
|
wsprintf( szText3, "%s,%s", szText1,szText2 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "LockUnlockHotKey", szText3 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.UpConditionHotKey.wVk, szText1, 10 );
|
|
memset( szText2, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.UpConditionHotKey.wModifier, szText2, 10 );
|
|
memset( szText3, NULL, MAX_PATH );
|
|
wsprintf( szText3, "%s,%s", szText1,szText2 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "UpConditionHotKey", szText3 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.DownConditionHotKey.wVk, szText1, 10 );
|
|
memset( szText2, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.DownConditionHotKey.wModifier, szText2, 10 );
|
|
memset( szText3, NULL, MAX_PATH );
|
|
wsprintf( szText3, "%s,%s", szText1,szText2 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "DownConditionHotKey", szText3 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.nFAamountLimitTime, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "nFAamountLimitTime", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.nFAmountLimitLine, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "nFAmountLimitLine", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.nFAmountRuleRadio, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "nFAmountRuleRadio", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.nFAmountUpCondition, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "nFAmountUpCondition", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.nFAmountDownCondition, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "nFAmountDownCondition", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.bFAmountApplyCheck, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "bFAmountApplyCheck", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
strcpy( szText1, g_AppEnv.szFutureCode );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "szFutureCode", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.nFcurLimitTime, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "nFcurLimitTime", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.nFcurLevelCheck, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "nFcurLevelCheck", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.bFcurApplyCheck, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "bFcurApplyCheck", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.bFApplyRuleRadio, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "bFApplyRuleRadio", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.nFApplyRuleRadioLimitTime, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "nFApplyRuleRadioLimitTime", szText1 );
|
|
|
|
memset( szText1, NULL, MAX_PATH );
|
|
_itoa( g_AppEnv.bRunStatCheck, szText1, 10 );
|
|
PutSectionKeyData( "FUTURECHECK_SECTION", "bRunStatCheck", szText1 );
|
|
}
|