M_StarLotteryEventCFG.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "stdafx.h"
  2. #include <cassert>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <iostream>
  6. #include <boost/smart_ptr.hpp>
  7. #include <boost/algorithm/string.hpp>
  8. #include "tinyxml2.h"
  9. #include "M_StarLotteryEventCFG.h"
  10. #include "FileEncrypt.h"
  11. std::auto_ptr<M_StarLotteryEventCFG> M_StarLotteryEventCFG::msSingleton(nullptr);
  12. int M_StarLotteryEventCFG::GetCount()
  13. {
  14. return (int)mMapData.size();
  15. }
  16. const M_StarLotteryEventCFGData* M_StarLotteryEventCFG::GetData(int Type)
  17. {
  18. auto it = mMapData.find(Type);
  19. if (it != mMapData.end())
  20. {
  21. return &it->second;
  22. }
  23. return NULL;
  24. }
  25. boost::unordered_map<int, M_StarLotteryEventCFGData>& M_StarLotteryEventCFG::GetMapData()
  26. {
  27. return mMapData;
  28. }
  29. void M_StarLotteryEventCFG::Reload()
  30. {
  31. mMapData.clear();
  32. Load();
  33. }
  34. void M_StarLotteryEventCFG::Load(const std::string& path)
  35. {
  36. std::ifstream readStream(path, std::ios::binary);
  37. if (!readStream.is_open())
  38. {
  39. assert(false);
  40. return;
  41. }
  42. readStream.seekg(0, std::ios::end);
  43. int fileSize = readStream.tellg();
  44. boost::shared_array<char> buffer(new char[fileSize+1]);
  45. buffer.get()[fileSize] = '\0';
  46. readStream.seekg(0, std::ios::beg);
  47. readStream.read(buffer.get(), fileSize);
  48. readStream.close();
  49. FileEncrypt::decryptBuffer( buffer, fileSize );
  50. tinyxml2::XMLDocument xmlDoc;
  51. auto result = xmlDoc.Parse(buffer.get(), fileSize);
  52. if (result != tinyxml2::XML_SUCCESS)
  53. {
  54. assert(false);
  55. return;
  56. }
  57. auto root = xmlDoc.RootElement();
  58. if (root == NULL)
  59. {
  60. assert(false);
  61. return;
  62. }
  63. auto element = root->FirstChildElement("Data");
  64. while (element != NULL)
  65. {
  66. M_StarLotteryEventCFGData data;
  67. data.mType = element->IntAttribute("Type");
  68. data.mDailyADD = element->IntAttribute("DailyADD");
  69. data.mTotalADD = element->IntAttribute("TotalADD");
  70. if (mMapData.find(data.mType) != mMapData.end())std::cout <<"data refind:" << data.mType << std::endl;
  71. assert(mMapData.find(data.mType) == mMapData.end());
  72. mMapData.insert(std::make_pair(data.mType, data));
  73. element = element->NextSiblingElement();
  74. }
  75. }
  76. void M_StarLotteryEventCFG::Load()
  77. {
  78. Load("../Config/M_StarLotteryEventCFG.xml");
  79. }
  80. M_StarLotteryEventCFG* M_StarLotteryEventCFG::GetSingleton()
  81. {
  82. if (msSingleton.get() == nullptr)
  83. {
  84. msSingleton.reset(new M_StarLotteryEventCFG());
  85. }
  86. return msSingleton.get();
  87. }