#include "cocos2d.h"#include <string>class FileManeger{public: static std::string getFilePath(const std::string &aPath, bool aIsNewVersion);#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID static bool exportOutData(const std::string &aPath);#endif};std::string FileManeger::getFilePath(const std::string &aPath, bool aIsNewVersion){#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID std::string fullPath = cocos2d::FileUtils::getInstance()->getWritablePath() + aPath; bool isExist = cocos2d::FileUtils::getInstance()->isFileExist(fullPath); if (!isExist || aIsNewVersion) { exportOutData(aPath); } return fullPath;#else return cocos2d::FileUtils::getInstance()->fullPathForFilename(aPath);#endif}#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROIDbool FileManeger::exportOutData(const std::string &aPath){ auto datas = cocos2d::FileUtils::getInstance()->getDataFromFile(aPath); if (!datas.isNull()) { std::string fullPath = cocos2d::FileUtils::getInstance()->getWritablePath() + aPath; std::string::size_type pos = fullPath.find_last_of("/"); std::string::size_type len = fullPath.length(); std::string folderPath = fullPath; if (std::string::npos != pos) { if ((len - 1) != pos) { folderPath = folderPath.substr(0, pos); } } else { assert(false); //file path error return false; } if (cocos2d::FileUtils::getInstance()->createDirectory(folderPath)) { FILE *fp = fopen(fullPath.c_str(), "w+"); if (fp) { if(1 == fwrite(datas.getBytes(), sizeof(char), datas.getSize(), fp)) { fclose(fp); return true; } fclose(fp); } } } return false;}#endif