123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- #ifndef __AssetsManager__
- #define __AssetsManager__
- #include <string>
- #include <mutex>
- #include "2d/CCNode.h"
- #include "extensions/ExtensionMacros.h"
- #include "extensions/ExtensionExport.h"
- namespace cocos2d { namespace network {
- class Downloader;
- }}
- NS_CC_EXT_BEGIN
- class AssetsManagerDelegateProtocol;
- class CC_EX_DLL AssetsManager : public Node
- {
- public:
- enum class ErrorCode
- {
-
- CREATE_FILE,
-
- NETWORK,
-
- NO_NEW_VERSION,
-
- UNCOMPRESS,
- };
-
-
- AssetsManager(const char* packageUrl = NULL, const char* versionFileUrl = NULL, const char* storagePath = NULL);
-
- virtual ~AssetsManager();
-
- typedef std::function<void(int)> ErrorCallback;
- typedef std::function<void(int)> ProgressCallback;
- typedef std::function<void(void)> SuccessCallback;
-
- static AssetsManager* create(const char* packageUrl, const char* versionFileUrl, const char* storagePath, ErrorCallback errorCallback, ProgressCallback progressCallback, SuccessCallback successCallback );
-
- virtual bool checkUpdate();
-
- using Node::update;
-
- virtual void update();
-
-
- const char* getPackageUrl() const;
-
-
- void setPackageUrl(const char* packageUrl);
-
-
- const char* getVersionFileUrl() const;
-
-
- void setVersionFileUrl(const char* versionFileUrl);
-
-
- std::string getVersion();
-
-
- void deleteVersion();
-
-
- const char* getStoragePath() const;
-
-
- void setStoragePath(const char* storagePath);
-
-
- void setDelegate(AssetsManagerDelegateProtocol *delegate);
-
-
- AssetsManagerDelegateProtocol* getDelegate() const { return _delegate ;}
-
-
- void setConnectionTimeout(unsigned int timeout);
-
-
- unsigned int getConnectionTimeout();
- protected:
- void checkStoragePath();
- bool uncompress();
- void setSearchPath();
- void downloadAndUncompress();
- private:
-
- std::string _storagePath;
-
-
- std::string _version;
-
- std::string _packageUrl;
- std::string _versionFileUrl;
-
- std::string _downloadedVersion;
-
- cocos2d::network::Downloader* _downloader;
- unsigned int _connectionTimeout;
-
- AssetsManagerDelegateProtocol *_delegate;
-
- bool _isDownloading;
- bool _shouldDeleteDelegateWhenExit;
-
- std::string keyOfVersion() const;
- std::string keyOfDownloadedVersion() const;
- };
- class AssetsManagerDelegateProtocol
- {
- public:
- virtual ~AssetsManagerDelegateProtocol(){};
- public:
-
- virtual void onError(AssetsManager::ErrorCode errorCode) {};
-
- virtual void onProgress(int percent) {};
-
- virtual void onSuccess() {};
- };
- CC_DEPRECATED_ATTRIBUTE typedef AssetsManager CCAssetsManager;
- CC_DEPRECATED_ATTRIBUTE typedef AssetsManagerDelegateProtocol CCAssetsManagerDelegateProtocol;
- NS_CC_EXT_END;
- #endif
|