#include "stdafx.h" #include #include #include #include #include #include #include "tinyxml2.h" #include "Fish_IntermediateExchange.h" #include "FileEncrypt.h" std::auto_ptr Fish_IntermediateExchange::msSingleton(nullptr); int Fish_IntermediateExchange::GetCount() { return (int)mMapData.size(); } const Fish_IntermediateExchangeData* Fish_IntermediateExchange::GetData(int ID) { auto it = mMapData.find(ID); if (it != mMapData.end()) { return &it->second; } return NULL; } boost::unordered_map& Fish_IntermediateExchange::GetMapData() { return mMapData; } void Fish_IntermediateExchange::Reload() { mMapData.clear(); Load(); } void Fish_IntermediateExchange::Load(const std::string& path) { std::ifstream readStream(path, std::ios::binary); if (!readStream.is_open()) { assert(false); return; } readStream.seekg(0, std::ios::end); int fileSize = readStream.tellg(); boost::shared_array buffer(new char[fileSize+1]); buffer.get()[fileSize] = '\0'; readStream.seekg(0, std::ios::beg); readStream.read(buffer.get(), fileSize); readStream.close(); FileEncrypt::decryptBuffer( buffer, fileSize ); tinyxml2::XMLDocument xmlDoc; auto result = xmlDoc.Parse(buffer.get(), fileSize); if (result != tinyxml2::XML_SUCCESS) { assert(false); return; } auto root = xmlDoc.RootElement(); if (root == NULL) { assert(false); return; } auto element = root->FirstChildElement("Data"); while (element != NULL) { Fish_IntermediateExchangeData data; data.mID = element->IntAttribute("ID"); data.mname = element->Attribute("name"); { const char* itemId = element->Attribute("itemId"); std::vector vecitemId; boost::split(vecitemId, itemId, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecitemId.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecitemId[i].c_str(), &temp)) { data.mitemId.push_back(temp); } } } { const char* itemcount = element->Attribute("itemcount"); std::vector vecitemcount; boost::split(vecitemcount, itemcount, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecitemcount.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecitemcount[i].c_str(), &temp)) { data.mitemcount.push_back(temp); } } } { const char* fixedReward = element->Attribute("fixedReward"); std::vector vecfixedReward; boost::split(vecfixedReward, fixedReward, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecfixedReward.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecfixedReward[i].c_str(), &temp)) { data.mfixedReward.push_back(temp); } } } { const char* probabilityReward = element->Attribute("probabilityReward"); std::vector vecprobabilityReward; boost::split(vecprobabilityReward, probabilityReward, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecprobabilityReward.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecprobabilityReward[i].c_str(), &temp)) { data.mprobabilityReward.push_back(temp); } } } { const char* primaryFubao = element->Attribute("primaryFubao"); std::vector vecprimaryFubao; boost::split(vecprimaryFubao, primaryFubao, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecprimaryFubao.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecprimaryFubao[i].c_str(), &temp)) { data.mprimaryFubao.push_back(temp); } } } { const char* NewGiftIntegral = element->Attribute("NewGiftIntegral"); std::vector vecNewGiftIntegral; boost::split(vecNewGiftIntegral, NewGiftIntegral, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecNewGiftIntegral.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecNewGiftIntegral[i].c_str(), &temp)) { data.mNewGiftIntegral.push_back(temp); } } } { const char* NewIntegral = element->Attribute("NewIntegral"); std::vector vecNewIntegral; boost::split(vecNewIntegral, NewIntegral, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecNewIntegral.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecNewIntegral[i].c_str(), &temp)) { data.mNewIntegral.push_back(temp); } } } { const char* GiftIntegral = element->Attribute("GiftIntegral"); std::vector vecGiftIntegral; boost::split(vecGiftIntegral, GiftIntegral, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecGiftIntegral.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecGiftIntegral[i].c_str(), &temp)) { data.mGiftIntegral.push_back(temp); } } } { const char* ComIntegral = element->Attribute("ComIntegral"); std::vector vecComIntegral; boost::split(vecComIntegral, ComIntegral, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecComIntegral.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecComIntegral[i].c_str(), &temp)) { data.mComIntegral.push_back(temp); } } } { const char* NorIntegral = element->Attribute("NorIntegral"); std::vector vecNorIntegral; boost::split(vecNorIntegral, NorIntegral, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecNorIntegral.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecNorIntegral[i].c_str(), &temp)) { data.mNorIntegral.push_back(temp); } } } { const char* OnListWeight = element->Attribute("OnListWeight"); std::vector vecOnListWeight; boost::split(vecOnListWeight, OnListWeight, boost::is_any_of(",")); int temp; for (unsigned int i = 0; i < vecOnListWeight.size(); i++) { if (tinyxml2::XMLUtil::ToInt(vecOnListWeight[i].c_str(), &temp)) { data.mOnListWeight.push_back(temp); } } } if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl; assert(mMapData.find(data.mID) == mMapData.end()); mMapData.insert(std::make_pair(data.mID, data)); element = element->NextSiblingElement(); } } void Fish_IntermediateExchange::Load() { Load("../Config/Fish_IntermediateExchange.xml"); } Fish_IntermediateExchange* Fish_IntermediateExchange::GetSingleton() { if (msSingleton.get() == nullptr) { msSingleton.reset(new Fish_IntermediateExchange()); } return msSingleton.get(); }