bool ClassName::isFullPath(CString cs)
{
if (cs.Find(_T(":")) != -1)
return true;
else
return false;
}
CString ClassName::getAppExePath()
{
CString path;
GetModuleFileName(NULL,
path.GetBufferSetLength(MAX_PATH + 1), MAX_PATH);
path.ReleaseBuffer();
int nPos = path.ReverseFind('\\');
return path.Left(nPos + 1);
}
bool ClassName::iniWrite_String(CString sectionName, CString keyName, CString keyValue, CString iniFileName)
{
CString iniFullFilePath;
if (isFullPath(iniFileName))
iniFullFilePath = iniFileName;
else
iniFullFilePath =
getAppExePath() + iniFileName;
int res = WritePrivateProfileString(sectionName, keyName, keyValue,
iniFullFilePath);
if (res == 0)
{
TRACE(_T("%s:%d,
WritePrivateProfileString fail:0x%x\n"), __FUNCTIONW__, __LINE__,
GetLastError());
return false;
}
else
{
return true;
}
}
bool ClassName::iniWrite_Int(CString sectionName, CString keyName, int keyValue, CString iniFileName)
{
CString csTemp;
csTemp.Format(_T("%d"), keyValue);
CString iniFullFilePath;
if (isFullPath(iniFileName))
iniFullFilePath = iniFileName;
else
iniFullFilePath =
getAppExePath() + iniFileName;
int res = WritePrivateProfileString(sectionName, keyName, csTemp,
iniFullFilePath);
if (res == 0)
{
TRACE(_T("%s:%d,
WritePrivateProfileString fail:0x%x\n"), __FUNCTIONW__, __LINE__,
GetLastError());
return false;
}
else
{
return true;
}
}
bool ClassName::iniWrite_Double(CString sectionName, CString keyName, double keyValue, CString iniFileName)
{
CString csTemp;
csTemp.Format(_T("%lf"), keyValue);
CString iniFullFilePath;
if (isFullPath(iniFileName))
iniFullFilePath = iniFileName;
else
iniFullFilePath =
getAppExePath() + iniFileName;
int res = WritePrivateProfileString(sectionName, keyName, csTemp,
iniFullFilePath);
if (res == 0)
{
TRACE(_T("%s:%d,
WritePrivateProfileString fail:0x%x\n"), __FUNCTIONW__, __LINE__,
GetLastError());
return false;
}
else
{
return true;
}
}
CString ClassName::iniRead_String(CString sectionName, CString keyName, CString iniFileName)
{
CString csTemp;
CString iniFullFilePath;
if (isFullPath(iniFileName))
iniFullFilePath = iniFileName;
else
iniFullFilePath =
getAppExePath() + iniFileName;
GetPrivateProfileString(sectionName, keyName, _T(""),
csTemp.GetBuffer(MAX_PATH), MAX_PATH, iniFullFilePath);
csTemp.ReleaseBuffer();
return csTemp;
}
int ClassName::iniRead_Int(CString sectionName, CString keyName, CString iniFileName)
{
CString iniFullFilePath;
if (isFullPath(iniFileName))
iniFullFilePath = iniFileName;
else
iniFullFilePath =
getAppExePath() + iniFileName;
return GetPrivateProfileInt(sectionName, keyName, 0,
iniFullFilePath);
}
bool ClassName::iniRead_Bool(CString sectionName, CString keyName, CString iniFileName)
{
CString iniFullFilePath;
if (isFullPath(iniFileName))
iniFullFilePath = iniFileName;
else
iniFullFilePath =
getAppExePath() + iniFileName;
return GetPrivateProfileInt(sectionName, keyName, 0,
iniFullFilePath) ? true : false;
}
double ClassName::iniRead_Double(CString sectionName, CString keyName, CString iniFileName)
{
CString csTemp;
csTemp.Format(_T("%lf"), 0.0);
CString iniFullFilePath;
if (isFullPath(iniFileName))
iniFullFilePath = iniFileName;
else
iniFullFilePath =
getAppExePath() + iniFileName;
GetPrivateProfileString(sectionName, keyName, csTemp,
csTemp.GetBuffer(MAX_PATH), MAX_PATH, iniFullFilePath);
csTemp.ReleaseBuffer();
return _ttof(csTemp);
}