// TRY
{
// open target ini file.
if(! IniFile.Open(strIniPath, CFile::modeRead))
{
return strDefault;
}
// if the file is no data inside, return error.
if(IniFile.GetLength() == 0)
{
IniFile.Close();
return strDefault;
}
// read the string data for later use.
WCHAR *pBuf;
//the file is unicode, so data length must be twice size of that.
pBuf = new WCHAR[IniFile.GetLength() / 2 + 1];
if(pBuf == NULL)
{
IniFile.Close();
return strDefault;
}
if(IniFile.Read(pBuf, IniFile.GetLength()) != IniFile.GetLength())
{
delete[] pBuf;
IniFile.Close();
return strDefault;
}
pBuf[IniFile.GetLength() / 2] = NULL;
strCombine.GetBuffer(nSize); //create a big buffer.
strCombine = pBuf;
delete[] pBuf;
//see if the section, entry already exist.
int iIndex1, iIndex2, iIndex3, iIndexT;
iIndex1 = strCombine.Find(L"[" + strSection + L"]\r\n");
if(iIndex1 == -1) // not found section
{
IniFile.Close();
return strDefault;
}
iIndexT = iIndex1 + 4 + strSection.GetLength();
iIndex2 = strCombine.Find(strEntry + L"=", iIndexT);
if(iIndex2 == -1) // not found entry
{
IniFile.Close();
return strDefault;
}
else
{
//to find the entry key
iIndex3 = strCombine.Find(L"\r\n", iIndex2 + 1);
if(iIndex3 == -1)
{
IniFile.Close();
return strDefault;
}
// if find the entry key,
iIndexT = iIndex2 + 1 + strEntry.GetLength();
IniFile.Close();
//get the string between "enter key" and end of the string being searched before.
return strCombine.Mid(iIndexT, iIndex3 - iIndexT);
}
}
// CATCH(CFileException, e)
{
}
// END_CATCH //
// TRY
{
// open target ini file.
if(! IniFile.Open(strIniPath, CFile::modeRead))
{
return strDefault;
}
// if the file is no data inside, return error.
if(IniFile.GetLength() == 0)
{
IniFile.Close();
return strDefault;
}
// read the string data for later use.
WCHAR *pBuf;
//the file is unicode, so data length must be twice size of that.
pBuf = new WCHAR[IniFile.GetLength() / 2 + 1];
if(pBuf == NULL)
{
IniFile.Close();
return strDefault;
}
if(IniFile.Read(pBuf, IniFile.GetLength()) != IniFile.GetLength())
{
delete[] pBuf;
IniFile.Close();
return strDefault;
}
pBuf[IniFile.GetLength() / 2] = NULL;
strCombine.GetBuffer(nSize); //create a big buffer.
strCombine = pBuf;
delete[] pBuf;
//see if the section, entry already exist.
int iIndex1, iIndex2, iIndex3, iIndexT;
iIndex1 = strCombine.Find(L"[" + strSection + L"]\r\n");
if(iIndex1 == -1) // not found section
{
IniFile.Close();
return strDefault;
}
iIndexT = iIndex1 + 4 + strSection.GetLength();
iIndex2 = strCombine.Find(strEntry + L"=", iIndexT);
if(iIndex2 == -1) // not found entry
{
IniFile.Close();
return strDefault;
}
else
{
//to find the entry key
iIndex3 = strCombine.Find(L"\r\n", iIndex2 + 1);
if(iIndex3 == -1)
{
IniFile.Close();
return strDefault;
}
// if find the entry key,
iIndexT = iIndex2 + 1 + strEntry.GetLength();
IniFile.Close();
//get the string between "enter key" and end of the string being searched before.
return strCombine.Mid(iIndexT, iIndex3 - iIndexT);
}
}
// CATCH(CFileException, e)
{
}
// END_CATCH //