/*----------------------------------------------------------------------------- * 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; }