2014-10-09 18:30:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
https://axys1.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
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:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
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>
|
|
|
|
|
2015-08-13 15:14:10 +08:00
|
|
|
#include "extensions/ExtensionMacros.h"
|
|
|
|
#include "extensions/ExtensionExport.h"
|
|
|
|
#include "network/CCDownloader.h"
|
2015-08-28 16:40:11 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2015-08-13 15:14:10 +08:00
|
|
|
|
2020-05-06 15:42:25 +08:00
|
|
|
#include "rapidjson/document-wrapper.h"
|
2014-10-09 18:30:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_EXT_BEGIN
|
2014-10-09 18:30:39 +08:00
|
|
|
|
2015-09-15 11:23:46 +08:00
|
|
|
struct DownloadUnit
|
|
|
|
{
|
|
|
|
std::string srcUrl;
|
|
|
|
std::string storagePath;
|
|
|
|
std::string customId;
|
2021-12-25 10:04:45 +08:00
|
|
|
float size;
|
2017-03-15 16:09:02 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
struct ManifestAsset
|
|
|
|
{
|
2017-03-15 16:09:02 +08:00
|
|
|
std::string md5;
|
|
|
|
std::string path;
|
|
|
|
bool compressed;
|
|
|
|
float size;
|
|
|
|
int downloadState;
|
2015-09-15 11:23:46 +08:00
|
|
|
};
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
typedef hlookup::string_map<DownloadUnit> DownloadUnits;
|
2014-10-09 18:30:39 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_EX_DLL Manifest : public Ref
|
2014-10-09 18:30:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
friend class AssetsManagerEx;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! The type of difference
|
2021-12-25 10:04:45 +08:00
|
|
|
enum class DiffType
|
|
|
|
{
|
2014-10-09 18:30:39 +08:00
|
|
|
ADDED,
|
|
|
|
DELETED,
|
|
|
|
MODIFIED
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
enum DownloadState
|
|
|
|
{
|
2014-10-09 18:30:39 +08:00
|
|
|
UNSTARTED,
|
|
|
|
DOWNLOADING,
|
2017-03-15 16:09:02 +08:00
|
|
|
SUCCESSED,
|
|
|
|
UNMARKED
|
2014-10-09 18:30:39 +08:00
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! Asset object
|
2017-03-15 16:09:02 +08:00
|
|
|
typedef ManifestAsset Asset;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! Object indicate the difference between two Assets
|
2021-12-25 10:04:45 +08:00
|
|
|
struct AssetDiff
|
|
|
|
{
|
2014-10-09 18:30:39 +08:00
|
|
|
Asset asset;
|
|
|
|
DiffType type;
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Check whether the version informations have been fully loaded
|
|
|
|
*/
|
|
|
|
bool isVersionLoaded() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Check whether the manifest have been fully loaded
|
|
|
|
*/
|
|
|
|
bool isLoaded() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Gets remote package url.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view getPackageUrl() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Gets remote manifest file url.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view getManifestFileUrl() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Gets remote version file url.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view getVersionFileUrl() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Gets manifest version.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view getVersion() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-12-28 11:55:31 +08:00
|
|
|
/** @brief Get the search paths list related to the Manifest.
|
|
|
|
*/
|
2014-12-30 10:09:56 +08:00
|
|
|
std::vector<std::string> getSearchPaths() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
protected:
|
|
|
|
/** @brief Constructor for Manifest class
|
2014-11-06 23:08:34 +08:00
|
|
|
* @param manifestUrl Url of the local manifest
|
2014-10-09 18:30:39 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
Manifest(std::string_view manifestUrl = "");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-06 23:08:34 +08:00
|
|
|
/** @brief Load the json file into local json object
|
|
|
|
* @param url Url of the json file
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void loadJson(std::string_view url);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-06 23:08:34 +08:00
|
|
|
/** @brief Parse the version file information into this manifest
|
|
|
|
* @param versionUrl Url of the local version file
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void parseVersion(std::string_view versionUrl);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Parse the manifest file information into this manifest
|
|
|
|
* @param manifestUrl Url of the local manifest
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void parse(std::string_view manifestUrl);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Check whether the version of this manifest equals to another.
|
|
|
|
* @param b The other manifest
|
2017-03-15 16:09:02 +08:00
|
|
|
* @return Equal or not
|
2014-10-09 18:30:39 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
bool versionEquals(const Manifest* b) const;
|
|
|
|
|
2017-03-15 16:09:02 +08:00
|
|
|
/** @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
|
|
|
|
*/
|
2021-12-28 11:00:34 +08:00
|
|
|
bool versionGreater(const Manifest* b,
|
|
|
|
const std::function<int(std::string_view versionA, std::string_view versionB)>& handle) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Generate difference between this Manifest and another.
|
|
|
|
* @param b The other manifest
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
hlookup::string_map<AssetDiff> genDiff(const Manifest* b) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Generate resuming download assets list
|
|
|
|
* @param units The download units reference to be modified by the generation result
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void genResumeAssetsList(DownloadUnits* units) const;
|
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Prepend all search paths to the FileUtils.
|
|
|
|
*/
|
|
|
|
void prependSearchPaths();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
void loadVersion(const rapidjson::Document& json);
|
|
|
|
|
|
|
|
void loadManifest(const rapidjson::Document& json);
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void saveToFile(std::string_view filepath);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
Asset parseAsset(std::string_view path, const rapidjson::Value& json);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
void clear();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Gets all groups.
|
|
|
|
*/
|
|
|
|
const std::vector<std::string>& getGroups() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Gets all groups version.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
const hlookup::string_map<std::string>& getGroupVerions() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @brief Gets version for the given group.
|
|
|
|
* @param group Key of the requested group
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view getGroupVersion(std::string_view group) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-30 15:47:47 +08:00
|
|
|
* @brief Gets assets.
|
|
|
|
* @lua NA
|
2014-11-13 10:53:38 +08:00
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
const hlookup::string_map<Asset>& getAssets() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
/** @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
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
void setAssetDownloadState(std::string_view key, const DownloadState& state);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void setManifestRoot(std::string_view root) { _manifestRoot = root; };
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
private:
|
|
|
|
//! Indicate whether the version informations have been fully loaded
|
|
|
|
bool _versionLoaded;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! Indicate whether the manifest have been fully loaded
|
|
|
|
bool _loaded;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! Reference to the global file utils
|
2021-12-25 10:04:45 +08:00
|
|
|
FileUtils* _fileUtils;
|
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! The local manifest root
|
|
|
|
std::string _manifestRoot;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! The remote package url
|
|
|
|
std::string _packageUrl;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! The remote path of manifest file
|
|
|
|
std::string _remoteManifestUrl;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! The remote path of version file [Optional]
|
|
|
|
std::string _remoteVersionUrl;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! The version of local manifest
|
|
|
|
std::string _version;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! All groups exist in manifest [Optional]
|
|
|
|
std::vector<std::string> _groups;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! The versions of all local group [Optional]
|
2021-12-26 23:26:34 +08:00
|
|
|
hlookup::string_map<std::string> _groupVer;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! The version of local engine
|
|
|
|
std::string _engineVer;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! Full assets list
|
2021-12-26 23:26:34 +08:00
|
|
|
hlookup::string_map<Asset> _assets;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
//! All search paths
|
|
|
|
std::vector<std::string> _searchPaths;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:30:39 +08:00
|
|
|
rapidjson::Document _json;
|
|
|
|
};
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_EXT_END
|
2014-10-09 18:30:39 +08:00
|
|
|
#endif /* defined(__Manifest__) */
|