-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlFile.cpp
More file actions
88 lines (67 loc) · 1.84 KB
/
XmlFile.cpp
File metadata and controls
88 lines (67 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "XmlFile.h"
#include "tinyxml2.h"
#include <windows.h>
using namespace tinyxml2;
XmlFile* XmlFile::m_pInstance = 0;
XmlFile::XmlFile()
{
std::string filepath = GetExePath();
filepath += "\\ClientInfo.xml";
ParseFile(filepath.c_str());
}
void XmlFile::ParseFile(const char* file)
{
tinyxml2::XMLDocument doc;
if (doc.LoadFile(file) != XML_NO_ERROR)
{
const char* error = doc.GetErrorStr1();
printf("\n ********配置文件解析错误!!! %s \n", error);
return;
}
//parse attribute
XMLElement* kissElement = doc.FirstChildElement("server");
if (kissElement == NULL) {
return;
}
const char* netAttr = kissElement->Attribute("type");
if ((netAttr != NULL) && (strcmp(netAttr, "URL") == 0))
{
//当前模块为URL关系模块
}
// IPPort
XMLElement* IPElement = kissElement->FirstChildElement("IPPort");
if(IPElement)
{
const char* IP = IPElement->Attribute("IP");
const char* Port = IPElement->Attribute("Port");
m_strIP = IP;
m_strPort = Port;
}
// device
XMLElement* deviceElement = kissElement->FirstChildElement("device");
while (deviceElement != NULL)
{
const char* URLID = deviceElement->Attribute("URLID");
const char* realityURL = deviceElement->Attribute("realityURL");
if (URLID && realityURL)
{
//请不要改变顺序
vector<std::string> info;
info.push_back(realityURL);
m_FileIPMap.insert(make_pair(URLID, info));
}
deviceElement = deviceElement->NextSiblingElement("device");
}
}
string XmlFile::GetExePath()
{
char buffer[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, (LPSTR)buffer, MAX_PATH);
std::string file = buffer;
std::string path = ".\\";
size_t pos = file.rfind('\\');
if (pos < file.size()) {
path = file.substr(0, pos + 1);
}
return path;
}