VC使用tinyxml读写INI,cfg,XML配置文件
2014-06-10 16:10
681 查看
#define UPDATE_CONFIG "update.cfg" //客户端版本信息文件
//解析Update.cfg文件
TiXmlDocument UpdateCfgDoc(UPDATE_CONFIG);
if (!UpdateCfgDoc.LoadFile())
{
::MessageBox(NULL, "读取客户端版本文件失败!", NULL, MB_ICONERROR);
SwitchStateAsync(US_UpdateFailed);
return 0;
}
TiXmlElement* pConfigRoot = UpdateCfgDoc.RootElement()->FirstChildElement();
if (NULL == pConfigRoot)
{
return 0;
}
const char* szCurVer = pConfigRoot->Attribute("ClientVersion");
const char* szCurToolVer = pConfigRoot->Attribute("UpdateToolVersion");
//保存玩家当前选择服务器到配置文件
#define SERVER_CONFIG "LoginServer.cfg" //保存玩家选择的区
TiXmlDocument ServerConfigDoc(SERVER_CONFIG);
if (!ServerConfigDoc.LoadFile())
{
::MessageBox(NULL, "解析本地服务器选择配置文件失败!", NULL, MB_ICONERROR);
return;
}
CString strLoginServerName;
m_CurLoginServer.GetWindowText(strLoginServerName);
TiXmlElement* pHistoryServer = ServerConfigDoc.RootElement()->FirstChildElement();
if(pHistoryServer!=NULL)
{
if(strcmp(pHistoryServer->Value(), "server") == 0)
pHistoryServer->SetAttribute("name", strLoginServerName);
ServerConfigDoc.SaveFile();
}
else
{
TiXmlElement ele("server");
ele.SetAttribute("name",strLoginServerName);
ServerConfigDoc.RootElement()->LinkEndChild(&ele);
ServerConfigDoc.SaveFile();
}
//解析Update.cfg文件
TiXmlDocument UpdateCfgDoc(UPDATE_CONFIG);
if (!UpdateCfgDoc.LoadFile())
{
::MessageBox(NULL, "读取客户端版本文件失败!", NULL, MB_ICONERROR);
SwitchStateAsync(US_UpdateFailed);
return 0;
}
TiXmlElement* pConfigRoot = UpdateCfgDoc.RootElement()->FirstChildElement();
if (NULL == pConfigRoot)
{
return 0;
}
const char* szCurVer = pConfigRoot->Attribute("ClientVersion");
const char* szCurToolVer = pConfigRoot->Attribute("UpdateToolVersion");
//保存玩家当前选择服务器到配置文件
#define SERVER_CONFIG "LoginServer.cfg" //保存玩家选择的区
TiXmlDocument ServerConfigDoc(SERVER_CONFIG);
if (!ServerConfigDoc.LoadFile())
{
::MessageBox(NULL, "解析本地服务器选择配置文件失败!", NULL, MB_ICONERROR);
return;
}
CString strLoginServerName;
m_CurLoginServer.GetWindowText(strLoginServerName);
TiXmlElement* pHistoryServer = ServerConfigDoc.RootElement()->FirstChildElement();
if(pHistoryServer!=NULL)
{
if(strcmp(pHistoryServer->Value(), "server") == 0)
pHistoryServer->SetAttribute("name", strLoginServerName);
ServerConfigDoc.SaveFile();
}
else
{
TiXmlElement ele("server");
ele.SetAttribute("name",strLoginServerName);
ServerConfigDoc.RootElement()->LinkEndChild(&ele);
ServerConfigDoc.SaveFile();
}
相关文章推荐
- VC使用tinyxml读写INI,cfg,XML配置文件
- VC使用tinyxml读写INI,cfg,XML配置文件
- 使用win api 读写 ini配置文件
- 使用Xdoclet生成Hibernate配置文件(hibernate.cfg.xml)和Hibernate映射文件(*.hbm.xml)
- 使用XML读写删除功能来实现资源文件配置
- 使用IniEditor读写INI类型配置文件
- WinMoblie 利用EVC读写INI,XML配置文件
- VC配置文件ini的读写
- vc配置文件读写(ini与xml格式)
- 使用XML读写删除功能来实现资源文件配置
- 使用IniEditor读写INI类型配置文件
- VC++读写INI配置文件
- vc 将.ini配置文件里的内容进行读写
- QT 使用QSettings 读写ini配置文件
- QT 使用QSettings读写ini配置文件
- VC配置文件ini的读写(转载)
- Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
- VC INI文件读写 和 GetProfileString,WriteProfileString函数的使用
- VC配置文件ini的读写
- QT 使用QSettings读写ini配置文件