diff --git a/extensions/AssetsManager/AssetsManager.cpp b/extensions/AssetsManager/AssetsManager.cpp index e4bc2e721d..f1ac337744 100644 --- a/extensions/AssetsManager/AssetsManager.cpp +++ b/extensions/AssetsManager/AssetsManager.cpp @@ -34,8 +34,10 @@ #include #include #include +#include #endif + #include "support/zip_support/unzip.h" using namespace cocos2d; @@ -644,4 +646,35 @@ AssetsManager* AssetsManager::create(const char* packageUrl, const char* version return manager; } +void AssetsManager::purgeStoragePath() +{ + // Delete recorded version codes. + deleteVersion(); + + // Remove downloaded files +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) + string command = "rm -r "; + // Path may include space. + command += "\"" + _storagePath + "\""; + system(command.c_str()); + DIR *pDir = NULL; + + pDir = opendir (_storagePath.c_str()); + if (! pDir) + { + mkdir(_storagePath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); + } +#else + string command = "rd /s /q "; + // Path may include space. + command += "\"" + _storagePath + "\""; + system(command.c_str()); + + if ((GetFileAttributesA(_storagePath.c_str())) == INVALID_FILE_ATTRIBUTES) + { + CreateDirectoryA(_storagePath.c_str(), 0); + } +#endif +} + NS_CC_EXT_END; diff --git a/extensions/AssetsManager/AssetsManager.h b/extensions/AssetsManager/AssetsManager.h index c9603f0188..e7dcb4a88d 100644 --- a/extensions/AssetsManager/AssetsManager.h +++ b/extensions/AssetsManager/AssetsManager.h @@ -146,6 +146,11 @@ public: /* downloadAndUncompress is the entry of a new thread */ friend int assetsManagerProgressFunc(void *, double, double, double, double); + + /** @brief Initialize storage path. + */ + void purgeStoragePath(); + protected: bool downLoad();