94 lines
1.8 KiB
C
94 lines
1.8 KiB
C
|
|
#pragma once
|
|||
|
|
|
|||
|
|
class CIniHelper
|
|||
|
|
{
|
|||
|
|
private:
|
|||
|
|
std::string m_fileName;
|
|||
|
|
bool m_checked;
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
bool CheckFile()
|
|||
|
|
{
|
|||
|
|
if ( m_checked )
|
|||
|
|
return true;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
|||
|
|
if( GetFileAttributesA(m_fileName.c_str()) == INVALID_FILE_ATTRIBUTES)
|
|||
|
|
{
|
|||
|
|
FILE *fp = fopen(m_fileName.c_str(), "ab");
|
|||
|
|
if(fp)
|
|||
|
|
{
|
|||
|
|
m_checked = true;
|
|||
|
|
fclose(fp);
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
m_checked = true;
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
CIniHelper(const char* fileName = "")
|
|||
|
|
{
|
|||
|
|
SetFile(fileName);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SetFile(const char* fileName)
|
|||
|
|
{
|
|||
|
|
m_checked = false;
|
|||
|
|
m_fileName = fileName;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Ini <20><><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD> int <20><><EFBFBD><EFBFBD> <20>о<EFBFBD><D0BE>´<EFBFBD>.
|
|||
|
|
int Read(const char* app, const char* key, int defaultValue)
|
|||
|
|
{
|
|||
|
|
return GetPrivateProfileIntA(app, key, defaultValue, m_fileName.c_str());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Ini <20><><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD> <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>о<EFBFBD><D0BE>´<EFBFBD>.
|
|||
|
|
std::string Read(const char* app, const char* key, const char* defaultValue)
|
|||
|
|
{
|
|||
|
|
char buf[2048] = {0,} ;
|
|||
|
|
GetPrivateProfileStringA(app, key, defaultValue, buf, sizeof(buf), m_fileName.c_str());
|
|||
|
|
return std::string(buf);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Ini <20><><EFBFBD>Ͽ<EFBFBD> int <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
|||
|
|
bool Write(const char* app, const char* key, int v)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
if(!CheckFile())
|
|||
|
|
return false;
|
|||
|
|
|
|||
|
|
char buf[2048] = {0,} ;
|
|||
|
|
StringCbPrintfA(buf, sizeof(buf), "%d", v);
|
|||
|
|
return WritePrivateProfileStringA(app, key, buf, m_fileName.c_str()) ? true : false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Ini <20><><EFBFBD>Ͽ<EFBFBD> <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
|||
|
|
bool Write(const char* app, const char* key, const char* v)
|
|||
|
|
{
|
|||
|
|
if(!CheckFile())
|
|||
|
|
return false;
|
|||
|
|
|
|||
|
|
return WritePrivateProfileStringA(app, key, v, m_fileName.c_str()) ? true : false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Ini <20><><EFBFBD>Ͽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Ͽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20>ݵ<EFBFBD><DDB5><EFBFBD> ȣ<><C8A3><EFBFBD><EFBFBD> <20>ش<EFBFBD>.
|
|||
|
|
bool Flush()
|
|||
|
|
{
|
|||
|
|
if(!CheckFile())
|
|||
|
|
return false;
|
|||
|
|
|
|||
|
|
return WritePrivateProfileStringA(NULL, NULL, NULL, m_fileName.c_str()) ? true : false ;
|
|||
|
|
}
|
|||
|
|
};
|