BigFile.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // BigFile.h
  3. // HelloLua
  4. //
  5. // Created by mac on 14-11-27.
  6. //
  7. //
  8. #ifndef __HelloLua__BigFile__
  9. #define __HelloLua__BigFile__
  10. #define HUNXIAO true
  11. #include <iostream>
  12. #include <map>
  13. #include <string>
  14. #include <mutex>
  15. #include <tuple>
  16. #include "cocos2d.h"
  17. using namespace std;
  18. #include "json11.hpp"
  19. using namespace json11;
  20. class BigFile :cocos2d::Ref
  21. {
  22. public:
  23. virtual ~BigFile(){};
  24. void targetFileNameFromDirAndFile(string& directory, string& filename);
  25. bool needDecode(string filepath);
  26. static bool inited;
  27. static BigFile* getInstance();
  28. void rc4_crypt(unsigned char *Data, ssize_t Len);
  29. void clearDataCache();
  30. void saveDataToCache(string path, unsigned char* buffer, ssize_t size);
  31. const unsigned char* getDataFromCache(string path, ssize_t *size);
  32. protected:
  33. bool b_IsHunXiao;
  34. string _assertDir;
  35. string _confFilePath;
  36. string _packname;
  37. bool b_configInited;
  38. Json _confFileRoot;
  39. Json _pathCfgRoot;
  40. Json _decCfgRoot;
  41. static BigFile* s_sharedBigFile;
  42. string _lastMusicFile;
  43. bool _useCache;
  44. map<string, tuple<unsigned char*,unsigned long>> _cachedDataDic;
  45. // 缓存锁,保证线程安全
  46. std::mutex _cachedDataDicMutex;
  47. BigFile(bool useCache = true);
  48. void setupPackName();
  49. void setupConfFileRoot();
  50. private:
  51. // 获取package name
  52. std::string _getAndroidPackageName();
  53. // 数字的app id
  54. std::string _getIOSAppId();
  55. };
  56. #endif /* defined(__HelloLua__BigFile__) */