100 lines
2.2 KiB
C++
100 lines
2.2 KiB
C++
// ---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#define _CFG_FILE_NAME_ "Config.ini";
|
|
|
|
#include "OperCfgFile.h"
|
|
// ---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
|
|
OperCfgFile::OperCfgFile() {
|
|
m_lpszCfgFileName = GetCfgFileName();
|
|
}
|
|
|
|
OperCfgFile::~OperCfgFile() {
|
|
}
|
|
|
|
String OperCfgFile::GetCfgFileName() {
|
|
|
|
String strExcPath = L"";
|
|
GetExcPath(strExcPath);
|
|
|
|
String strCfgFileName = strExcPath + _CFG_FILE_NAME_;
|
|
return strCfgFileName;
|
|
}
|
|
|
|
void OperCfgFile::SetCfgFileName(const AnsiString szCfgFileName) {
|
|
m_lpszCfgFileName = szCfgFileName;
|
|
}
|
|
|
|
UINT OperCfgFile::GetExcPath(String & strExcPath) {
|
|
// GetModuleFileName(Module: HMODULE; Buffer: PChar; BufLen: Integer): Integer;
|
|
wchar_t wszBuffer[MAX_PATH] = {0};
|
|
UINT uRet = -1;
|
|
uRet = ::GetModuleFileName(NULL, wszBuffer, MAX_PATH);
|
|
|
|
|
|
strExcPath = ExtractFilePath((WideString)wszBuffer);
|
|
return uRet;
|
|
}
|
|
|
|
UINT OperCfgFile::ReadSegKeyValue(const String strSegName,
|
|
const String strKeyName, String & strRetValue) {
|
|
|
|
wchar_t wszBuf[MAX_PATH] = {0};
|
|
::GetPrivateProfileString(strSegName.c_str(), strKeyName.c_str(), L"",
|
|
wszBuf, MAX_PATH, m_lpszCfgFileName.c_str());
|
|
|
|
strRetValue = (WideString)wszBuf;
|
|
|
|
return 0;
|
|
}
|
|
|
|
UINT OperCfgFile::SaveSegKeyValue(const String strSegName,
|
|
const String strKeyName, String strSaveValue) {
|
|
|
|
return ::WritePrivateProfileString(strSegName.c_str(), strKeyName.c_str(),
|
|
strSaveValue.c_str(), m_lpszCfgFileName.c_str()) ;
|
|
}
|
|
|
|
bool OperCfgFile::EncrytString(String & strEncryptData, bool bIsEncryptFlag) {
|
|
|
|
wchar_t * szBuf = new wchar_t[strEncryptData.Length()*2 + 1];
|
|
|
|
memcpy(szBuf,strEncryptData.c_str(),wcslen(strEncryptData.c_str()) + 1);
|
|
|
|
int iLen = wcslen(szBuf);
|
|
|
|
if(bIsEncryptFlag)
|
|
{
|
|
for(int i = 0; i < iLen; i++)
|
|
{
|
|
szBuf[i] -= 0x63;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for(int i =0 ; i < iLen ; i++)
|
|
{
|
|
szBuf[i] += 0x63;
|
|
}
|
|
}
|
|
|
|
strEncryptData = (WideString)szBuf;
|
|
#if 0
|
|
if (bIsEncryptFlag) {
|
|
for (int i = 0; i < strEncryptData.Length(); i++) {
|
|
strEncryptData[i] ^= 'H';
|
|
}
|
|
}
|
|
else {
|
|
for (int i = 0; i < strEncryptData.Length(); i++) {
|
|
strEncryptData[i] ^= 'H';
|
|
}
|
|
}
|
|
#endif
|
|
return true;
|
|
}
|
|
|