123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /****************************************************************************
- Copyright (c) 2013 cocos2d-x.org
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos2d-x.org
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- #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;
- typedef std::map<std::string, DownloadUnit> DownloadUnits;
- class CC_EX_DLL Manifest : public Ref
- {
- public:
-
- friend class AssetsManagerEx;
-
- //! The type of difference
- enum class DiffType {
- ADDED,
- DELETED,
- MODIFIED
- };
-
- enum DownloadState {
- UNSTARTED,
- DOWNLOADING,
- SUCCESSED,
- UNMARKED
- };
- enum DownloadType
- {
- PURE_MD5,
- MIXTURE_MD5
- };
-
- //! Asset object
- typedef ManifestAsset Asset;
-
- //! Object indicate the difference between two Assets
- struct AssetDiff {
- Asset asset;
- DiffType type;
- };
-
- /** @brief Check whether the version informations have been fully loaded
- */
- bool isVersionLoaded() const;
-
- /** @brief Check whether the manifest have been fully loaded
- */
- bool isLoaded() const;
-
- /** @brief Gets remote package url.
- */
- const std::string& getPackageUrl() const;
-
- /** @brief Gets remote manifest file url.
- */
- const std::string& getManifestFileUrl() const;
-
- /** @brief Gets remote version file url.
- */
- const std::string& getVersionFileUrl() const;
-
- /** @brief Gets manifest version.
- */
- const std::string& getVersion() const;
-
- /** @brief Get the search paths list related to the Manifest.
- */
- std::vector<std::string> getSearchPaths() const;
- void setCustomDownloadType(Manifest::DownloadType bCustomDownloadType);
- Manifest::DownloadType getCustomDownloadType();
- bool is_force_download() { return _is_force; };
- int get_pop_size() { return _pop_size; };
- std::string replace_string(std::string s1) const;
- bool is_download_half(const Manifest *b);
-
- protected:
-
- /** @brief Constructor for Manifest class
- * @param manifestUrl Url of the local manifest
- */
- Manifest(const std::string& manifestUrl = "");
-
- /** @brief Load the json file into local json object
- * @param url Url of the json file
- */
- void loadJson(const std::string& url);
-
- /** @brief Parse the version file information into this manifest
- * @param versionUrl Url of the local version file
- */
- void parseVersion(const std::string& versionUrl);
-
- /** @brief Parse the manifest file information into this manifest
- * @param manifestUrl Url of the local manifest
- */
- void parse(const std::string& manifestUrl);
-
- /** @brief Check whether the version of this manifest equals to another.
- * @param b The other manifest
- * @return Equal or not
- */
- bool versionEquals(const Manifest *b) const;
-
- /** @brief Check whether the version of this manifest is greater than another.
- * @param b The other manifest
- * @param [handle] Customized comparasion handle function
- * @return Greater or not
- */
- bool versionGreater(const Manifest *b, const std::function<int(const std::string& versionA, const std::string& versionB)>& handle) const;
-
- /** @brief Generate difference between this Manifest and another.
- * @param b The other manifest
- */
- std::unordered_map<std::string, AssetDiff> genDiff(const Manifest *b, bool is_all = false) const;
-
- /** @brief Generate resuming download assets list
- * @param units The download units reference to be modified by the generation result
- */
- void genResumeAssetsList(DownloadUnits *units) const;
-
- /** @brief Prepend all search paths to the FileUtils.
- */
- 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();
-
- /** @brief Gets all groups.
- */
- const std::vector<std::string>& getGroups() const;
-
- /** @brief Gets all groups version.
- */
- const std::unordered_map<std::string, std::string>& getGroupVerions() const;
-
- /** @brief Gets version for the given group.
- * @param group Key of the requested group
- */
- const std::string& getGroupVersion(const std::string &group) const;
-
- /**
- * @brief Gets assets.
- * @lua NA
- */
- const std::unordered_map<std::string, Asset>& getAssets() const;
-
- /** @brief Set the download state for an asset
- * @param key Key of the asset to set
- * @param state The current download state of the asset
- */
- void setAssetDownloadState(const std::string &key, const DownloadState &state);
-
- void setManifestRoot(const std::string &root) {_manifestRoot = root;};
- const std::string& getPlatFormUrl() const;
- const std::string& getResourceUrl() const;
-
- void setAppVersion(const std::string & appVersion) {_appVersion = appVersion;}
- private:
-
- //! Indicate whether the version informations have been fully loaded
- bool _versionLoaded;
-
- //! Indicate whether the manifest have been fully loaded
- bool _loaded;
- bool _is_force;
-
- //! Reference to the global file utils
- FileUtils *_fileUtils;
-
- //! The local manifest root
- std::string _manifestRoot;
-
- //! The remote package url
- std::string _packageUrl;
-
- //! The remote path of manifest file
- std::string _remoteManifestUrl;
-
- //! The remote path of version file [Optional]
- std::string _remoteVersionUrl;
-
- //! The version of local manifest
- std::string _version;
-
- //! All groups exist in manifest [Optional]
- std::vector<std::string> _groups;
-
- //! The versions of all local group [Optional]
- std::unordered_map<std::string, std::string> _groupVer;
-
- //! The version of local engine
- std::string _engineVer;
-
- //! Full assets list
- std::unordered_map<std::string, Asset> _assets;
-
- //! All search paths
- std::vector<std::string> _searchPaths;
- //ios:ipa android:apk
- std::string platform_full_url;
- //��Դ��ַ
- std::string resource_full_url;
-
- rapidjson::Document _json;
-
- std::string _appVersion;
- //是否自定义下载地址标识
- Manifest::DownloadType _nCustomDownloadType;
- int _pop_size;
- };
- NS_CC_EXT_END
- #endif /* defined(__Manifest__) */
|