123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #ifndef __Manifest__
- #define __Manifest__
- #include <string>
- #include <unordered_map>
- #include <vector>
- #include "extensions/ExtensionMacros.h"
- #include "extensions/ExtensionExport.h"
- #include "network/CCDownloader.h"
- #include "platform/CCFileUtils.h"
- #include "json/document-wrapper.h"
- NS_CC_EXT_BEGIN
- struct DownloadUnit
- {
- std::string srcUrl;
- std::string storagePath;
- std::string customId;
- float size;
- };
- struct ManifestAsset {
- std::string md5;
- std::string path;
- bool compressed;
- float size;
- int downloadState;
- };
- typedef std::unordered_map<std::string, DownloadUnit> DownloadUnits;
- class CC_EX_DLL Manifest : public Ref
- {
- public:
-
- friend class AssetsManagerEx;
-
-
- enum class DiffType {
- ADDED,
- DELETED,
- MODIFIED
- };
-
- enum DownloadState {
- UNSTARTED,
- DOWNLOADING,
- SUCCESSED,
- UNMARKED
- };
-
-
- typedef ManifestAsset Asset;
-
-
- struct AssetDiff {
- Asset asset;
- DiffType type;
- };
-
-
- bool isVersionLoaded() const;
-
-
- bool isLoaded() const;
-
-
- const std::string& getPackageUrl() const;
-
-
- const std::string& getManifestFileUrl() const;
-
-
- const std::string& getVersionFileUrl() const;
-
-
- const std::string& getVersion() const;
-
-
- std::vector<std::string> getSearchPaths() const;
-
- protected:
-
-
- Manifest(const std::string& manifestUrl = "");
-
-
- void loadJson(const std::string& url);
-
-
- void parseVersion(const std::string& versionUrl);
-
-
- void parse(const std::string& manifestUrl);
-
-
- bool versionEquals(const Manifest *b) const;
-
-
- bool versionGreater(const Manifest *b, const std::function<int(const std::string& versionA, const std::string& versionB)>& handle) const;
-
-
- std::unordered_map<std::string, AssetDiff> genDiff(const Manifest *b) const;
-
-
- void genResumeAssetsList(DownloadUnits *units) const;
-
-
- void prependSearchPaths();
-
- void loadVersion(const rapidjson::Document &json);
-
- void loadManifest(const rapidjson::Document &json);
-
- void saveToFile(const std::string &filepath);
-
- Asset parseAsset(const std::string &path, const rapidjson::Value &json);
-
- void clear();
-
-
- const std::vector<std::string>& getGroups() const;
-
-
- const std::unordered_map<std::string, std::string>& getGroupVerions() const;
-
-
- const std::string& getGroupVersion(const std::string &group) const;
-
-
- const std::unordered_map<std::string, Asset>& getAssets() const;
-
-
- void setAssetDownloadState(const std::string &key, const DownloadState &state);
-
- void setManifestRoot(const std::string &root) {_manifestRoot = root;};
-
- private:
-
-
- bool _versionLoaded;
-
-
- bool _loaded;
-
-
- FileUtils *_fileUtils;
-
-
- std::string _manifestRoot;
-
-
- std::string _packageUrl;
-
-
- std::string _remoteManifestUrl;
-
-
- std::string _remoteVersionUrl;
-
-
- std::string _version;
-
-
- std::vector<std::string> _groups;
-
-
- std::unordered_map<std::string, std::string> _groupVer;
-
-
- std::string _engineVer;
-
-
- std::unordered_map<std::string, Asset> _assets;
-
-
- std::vector<std::string> _searchPaths;
-
- rapidjson::Document _json;
- };
- NS_CC_EXT_END
- #endif
|