本文整理汇总了C++中CIniFile::FlushFile方法的典型用法代码示例。如果您正苦于以下问题:C++ CIniFile::FlushFile方法的具体用法?C++ CIniFile::FlushFile怎么用?C++ CIniFile::FlushFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIniFile
的用法示例。
在下文中一共展示了CIniFile::FlushFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpgradeLicq
/*-----------------------------------------------------------------------------
* UpgradeLicq
*
* Upgrades the config files to the current version.
*---------------------------------------------------------------------------*/
bool CLicq::UpgradeLicq(CIniFile &licqConf)
{
CIniFile ownerFile(INI_FxERROR);
string strBaseDir = BASE_DIR;
string strOwnerFile = strBaseDir + "/owner.uin";
if (!ownerFile.LoadFile(strOwnerFile.c_str()))
return false;
// Get the UIN
unsigned long nUin;
ownerFile.SetSection("user");
ownerFile.ReadNum("Uin", nUin, 0);
ownerFile.CloseFile();
// Set the new version number
licqConf.SetSection("licq");
licqConf.WriteNum("Version", (unsigned short)INT_VERSION);
// Create the owner section and fill it
licqConf.SetSection("owners");
licqConf.WriteNum("NumOfOwners", (unsigned short)1);
licqConf.WriteNum("Owner1.Id", nUin);
licqConf.WriteStr("Owner1.PPID", "Licq");
// Add the protocol plugins info
licqConf.SetSection("plugins");
licqConf.WriteNum("NumProtoPlugins", (unsigned short)0);
licqConf.FlushFile();
// Rename owner.uin to owner.Licq
string strNewOwnerFile = strBaseDir + "/owner.Licq";
if (rename(strOwnerFile.c_str(), strNewOwnerFile.c_str()))
return false;
// Update all the user files and update users.conf
struct dirent **UinFiles;
string strUserDir = strBaseDir + "/users";
string strUsersConf = strBaseDir + "/users.conf";
int n = scandir_alpha_r(strUserDir.c_str(), &UinFiles, SelectUserUtility);
if (n != 0)
{
CIniFile userConfFile(INI_FxERROR);
if (!userConfFile.LoadFile(strUsersConf.c_str()))
return false;
userConfFile.SetSection("users");
userConfFile.WriteNum("NumOfUsers", (unsigned short)n);
for (unsigned short i = 0; i < n; i++)
{
char szKey[20];
snprintf(szKey, sizeof(szKey), "User%d", i+1);
string strFileName = strUserDir + "/" + UinFiles[i]->d_name;
string strNewName = UinFiles[i]->d_name;
strNewName.replace(strNewName.find(".uin", 0), 4, ".Licq");
string strNewFile = strUserDir + "/" + strNewName;
if (rename(strFileName.c_str(), strNewFile.c_str()))
return false;
userConfFile.WriteStr(szKey, strNewName.c_str());
}
userConfFile.FlushFile();
}
// Rename the history files
struct dirent **HistoryFiles;
string strHistoryDir = strBaseDir + "/history";
int nNumHistory = scandir_alpha_r(strHistoryDir.c_str(), &HistoryFiles,
SelectHistoryUtility);
if (nNumHistory)
{
for (unsigned short i = 0; i < nNumHistory; i++)
{
string strFileName = strHistoryDir + "/" + HistoryFiles[i]->d_name;
string strNewFile = strHistoryDir + "/" + HistoryFiles[i]->d_name;
strNewFile.replace(strNewFile.find(".history", 0), 8, ".Licq.history");
if (rename(strFileName.c_str(), strNewFile.c_str()))
return false;
}
}
return true;
}