您的位置:首页 > 其它

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();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: