static CString GetAppDirectory()
{
CString sPath;
GetModuleFileName(NULL,sPath.GetBuffer(MAX_PATH+1),MAX_PATH);
//GetCurrentDirectory(MAX_PATH,sPath.GetBuffer(MAX_PATH+1));
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('\\');
sPath=sPath.Left(nPos+1);
return sPath;
}
static CString IniFileGetValue(const CString& strFileName,const CString& strKeyPath,const CString& strDefault="")
{
CStringArray strKeys;
CString strValue;
int last_pos = 0;
int pos;
int new_pos;
CString strKey;
while (1)
{
pos = strKeyPath.Find("/",last_pos);
new_pos = pos;
if (pos==-1)
new_pos = strKeyPath.GetLength();
strKey = strKeyPath.Mid(last_pos,new_pos - last_pos);
last_pos = pos+1;
if (!strKey.IsEmpty())
strKeys.Add(strKey);
if (pos==-1)
break;
}
if (strKeys.GetSize()!=2)
return strDefault;
GetPrivateProfileString(strKeys[0],strKeys[1],0,strValue.GetBuffer(4096),4095,strFileName);
strValue.ReleaseBuffer();
if (strValue.IsEmpty())
return strDefault;
return strValue;
}
static BOOL IniFileSetValue(const CString& strFileName,const CString& strKeyPath,const CString& strValue)
{
CStringArray strKeys;
int last_pos = 0;
int pos;
int new_pos;
CString strKey;
while (1)
{
pos = strKeyPath.Find("/",last_pos);
new_pos = pos;
if (pos==-1)
new_pos = strKeyPath.GetLength();
strKey = strKeyPath.Mid(last_pos,new_pos - last_pos);
last_pos = pos+1;
if (!strKey.IsEmpty())
strKeys.Add(strKey);
if (pos==-1)
break;
}
if (strKeys.GetSize()!=2)
return FALSE;
return WritePrivateProfileString(strKeys[0],strKeys[1],strValue,strFileName);
}