bool StringMgr::Init() { bool result = false; XmlWrapper xmlWrapper; XmlDocument& doc = xmlWrapper.GetDoc(); m_FilterList.clear(); m_StringMap.clear(); do { if (!xmlWrapper.LoadFile("res/Data/String/StringList.xml")) break; XmlElement* rootNode = doc.FirstChildElement("StringList"); if (rootNode == NULL) break; bool hasError = false; for (XmlElement* fileNode = rootNode->FirstChildElement("String"); fileNode; fileNode = fileNode->NextSiblingElement("String")) { const char* fileName = fileNode->Attribute("File"); if (!LoadString(fileName)) { GameLog("LoadString error =%s", fileName ? fileName : ""); hasError = true; } } result = !hasError; } while (0); return result; }
bool StringMgr::LoadStringWithPath(const char* dpath, const char* fileName, bool isFilter) { if (!fileName) return false; bool result = false; XmlWrapper xmlWrapper; XmlDocument& doc = xmlWrapper.GetDoc(); do { char path[256] = {}; sprintf(path, "%s/%s", dpath, fileName); if (!xmlWrapper.LoadFile(path)) break; XmlElement* rootNode = doc.FirstChildElement("Strings"); if (rootNode == NULL) break; if (isFilter) { for (XmlElement* stringNode = rootNode->FirstChildElement("s"); stringNode; stringNode = stringNode->NextSiblingElement("s")) { const char* val = stringNode->Attribute("v"); m_FilterList.push_back(val); } } else { for (XmlElement* stringNode = rootNode->FirstChildElement("String"); stringNode; stringNode = stringNode->NextSiblingElement("String")) { const char* key = stringNode->Attribute("Key"); const char* value = stringNode->Attribute("Value"); if (key && value && strlen(key) > 0 && strlen(value) > 0) { if (m_StringMap.find(key) != m_StringMap.end()) { //Assert(false); GameLog("string key exist:%s file=%s", key, fileName); } m_StringMap[key] = value; } } } result = true; } while (0); return result; }
bool Load() { XmlDocument doc(_file.c_str()); if (!doc.LoadFile()) { return false; } XmlElement *root; XmlElement *psg; // parser servern node root = doc.RootElement()->FirstChildElement("notes"); if (root != NULL) { if (strcmp(root->Value(), "notes") == 0) { std::string event; int dia = -1, mes = -1, ano = -1; psg = root->FirstChildElement("event"); do { if (psg == NULL || strcmp(psg->Value(), "event") != 0) { break; } if (psg->Attribute("day") != NULL) { dia = atoi(psg->Attribute("day")); } if (psg->Attribute("month") != NULL) { mes = atoi(psg->Attribute("month")); } if (psg->Attribute("year") != NULL) { ano = atoi(psg->Attribute("year")); } event = psg->GetText(); if (dia != -1 && mes != -1 && ano != -1 && event != "") { struct agenda_t *t = new struct agenda_t; t->day = dia; t->month = mes; t->year = ano; t->event = event; events.push_back(t); } } while ((psg = psg->NextSiblingElement("event")) != NULL); } } return true; }