mirror of https://github.com/axmolengine/axmol.git
#9061: Add check for instantiation
This commit is contained in:
parent
f4e61f5620
commit
ef76724f19
|
@ -64,6 +64,7 @@ AssetsManagerEx::AssetsManagerEx(const std::string& manifestUrl, const std::stri
|
||||||
, _percentByFile(0)
|
, _percentByFile(0)
|
||||||
, _totalToDownload(0)
|
, _totalToDownload(0)
|
||||||
, _totalWaitToDownload(0)
|
, _totalWaitToDownload(0)
|
||||||
|
, _inited(false)
|
||||||
{
|
{
|
||||||
// Init variables
|
// Init variables
|
||||||
_eventDispatcher = Director::getInstance()->getEventDispatcher();
|
_eventDispatcher = Director::getInstance()->getEventDispatcher();
|
||||||
|
@ -87,18 +88,7 @@ AssetsManagerEx::AssetsManagerEx(const std::string& manifestUrl, const std::stri
|
||||||
_cacheManifestPath = _storagePath + MANIFEST_FILENAME;
|
_cacheManifestPath = _storagePath + MANIFEST_FILENAME;
|
||||||
_tempManifestPath = _storagePath + TEMP_MANIFEST_FILENAME;
|
_tempManifestPath = _storagePath + TEMP_MANIFEST_FILENAME;
|
||||||
|
|
||||||
// Init and load local manifest
|
initManifests(manifestUrl);
|
||||||
_localManifest = new (std::nothrow) Manifest();
|
|
||||||
loadLocalManifest(manifestUrl);
|
|
||||||
|
|
||||||
// Init and load temporary manifest
|
|
||||||
_tempManifest = new (std::nothrow) Manifest();
|
|
||||||
_tempManifest->parse(_tempManifestPath);
|
|
||||||
if (!_tempManifest->isLoaded())
|
|
||||||
_fileUtils->removeFile(_tempManifestPath);
|
|
||||||
|
|
||||||
// Init remote manifest for future usage
|
|
||||||
_remoteManifest = new (std::nothrow) Manifest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetsManagerEx::~AssetsManagerEx()
|
AssetsManagerEx::~AssetsManagerEx()
|
||||||
|
@ -115,7 +105,7 @@ AssetsManagerEx::~AssetsManagerEx()
|
||||||
|
|
||||||
AssetsManagerEx* AssetsManagerEx::create(const std::string& manifestUrl, const std::string& storagePath)
|
AssetsManagerEx* AssetsManagerEx::create(const std::string& manifestUrl, const std::string& storagePath)
|
||||||
{
|
{
|
||||||
AssetsManagerEx* ret = new AssetsManagerEx(manifestUrl, storagePath);
|
AssetsManagerEx* ret = new (std::nothrow) AssetsManagerEx(manifestUrl, storagePath);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
ret->autorelease();
|
ret->autorelease();
|
||||||
|
@ -127,6 +117,48 @@ AssetsManagerEx* AssetsManagerEx::create(const std::string& manifestUrl, const s
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssetsManagerEx::initManifests(const std::string& manifestUrl)
|
||||||
|
{
|
||||||
|
_inited = true;
|
||||||
|
// Init and load local manifest
|
||||||
|
_localManifest = new (std::nothrow) Manifest();
|
||||||
|
if (_localManifest)
|
||||||
|
{
|
||||||
|
loadLocalManifest(manifestUrl);
|
||||||
|
|
||||||
|
// Init and load temporary manifest
|
||||||
|
_tempManifest = new (std::nothrow) Manifest();
|
||||||
|
if (_tempManifest)
|
||||||
|
{
|
||||||
|
_tempManifest->parse(_tempManifestPath);
|
||||||
|
if (!_tempManifest->isLoaded())
|
||||||
|
_fileUtils->removeFile(_tempManifestPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_inited = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init remote manifest for future usage
|
||||||
|
_remoteManifest = new (std::nothrow) Manifest();
|
||||||
|
if (!_remoteManifest)
|
||||||
|
{
|
||||||
|
_inited = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_inited = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_inited)
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE(_localManifest);
|
||||||
|
CC_SAFE_DELETE(_tempManifest);
|
||||||
|
CC_SAFE_DELETE(_remoteManifest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AssetsManagerEx::prepareLocalManifest()
|
void AssetsManagerEx::prepareLocalManifest()
|
||||||
{
|
{
|
||||||
// An alias to assets
|
// An alias to assets
|
||||||
|
@ -143,12 +175,14 @@ void AssetsManagerEx::loadLocalManifest(const std::string& manifestUrl)
|
||||||
if (_fileUtils->isFileExist(_cacheManifestPath))
|
if (_fileUtils->isFileExist(_cacheManifestPath))
|
||||||
{
|
{
|
||||||
cachedManifest = new (std::nothrow) Manifest();
|
cachedManifest = new (std::nothrow) Manifest();
|
||||||
cachedManifest->parse(_cacheManifestPath);
|
if (cachedManifest) {
|
||||||
if (!cachedManifest->isLoaded())
|
cachedManifest->parse(_cacheManifestPath);
|
||||||
{
|
if (!cachedManifest->isLoaded())
|
||||||
_fileUtils->removeFile(_cacheManifestPath);
|
{
|
||||||
CC_SAFE_RELEASE(cachedManifest);
|
_fileUtils->removeFile(_cacheManifestPath);
|
||||||
cachedManifest = nullptr;
|
CC_SAFE_RELEASE(cachedManifest);
|
||||||
|
cachedManifest = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,6 +647,11 @@ void AssetsManagerEx::updateSucceed()
|
||||||
|
|
||||||
void AssetsManagerEx::checkUpdate()
|
void AssetsManagerEx::checkUpdate()
|
||||||
{
|
{
|
||||||
|
if (!_inited){
|
||||||
|
CCLOG("AssetsManagerEx : Manifests uninited.\n");
|
||||||
|
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!_localManifest->isLoaded())
|
if (!_localManifest->isLoaded())
|
||||||
{
|
{
|
||||||
CCLOG("AssetsManagerEx : No local manifest file found error.\n");
|
CCLOG("AssetsManagerEx : No local manifest file found error.\n");
|
||||||
|
@ -645,6 +684,11 @@ void AssetsManagerEx::checkUpdate()
|
||||||
|
|
||||||
void AssetsManagerEx::update()
|
void AssetsManagerEx::update()
|
||||||
{
|
{
|
||||||
|
if (!_inited){
|
||||||
|
CCLOG("AssetsManagerEx : Manifests uninited.\n");
|
||||||
|
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!_localManifest->isLoaded())
|
if (!_localManifest->isLoaded())
|
||||||
{
|
{
|
||||||
CCLOG("AssetsManagerEx : No local manifest file found error.\n");
|
CCLOG("AssetsManagerEx : No local manifest file found error.\n");
|
||||||
|
@ -706,6 +750,12 @@ void AssetsManagerEx::update()
|
||||||
|
|
||||||
void AssetsManagerEx::updateAssets(const Downloader::DownloadUnits& assets)
|
void AssetsManagerEx::updateAssets(const Downloader::DownloadUnits& assets)
|
||||||
{
|
{
|
||||||
|
if (!_inited){
|
||||||
|
CCLOG("AssetsManagerEx : Manifests uninited.\n");
|
||||||
|
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_updateState != State::UPDATING && _localManifest->isLoaded() && _remoteManifest->isLoaded())
|
if (_updateState != State::UPDATING && _localManifest->isLoaded() && _remoteManifest->isLoaded())
|
||||||
{
|
{
|
||||||
int size = (int)(assets.size());
|
int size = (int)(assets.size());
|
||||||
|
|
|
@ -120,6 +120,8 @@ protected:
|
||||||
|
|
||||||
std::string get(const std::string& key) const;
|
std::string get(const std::string& key) const;
|
||||||
|
|
||||||
|
void initManifests(const std::string& manifestUrl);
|
||||||
|
|
||||||
void loadLocalManifest(const std::string& manifestUrl);
|
void loadLocalManifest(const std::string& manifestUrl);
|
||||||
|
|
||||||
void prepareLocalManifest();
|
void prepareLocalManifest();
|
||||||
|
@ -259,6 +261,9 @@ private:
|
||||||
int _totalToDownload;
|
int _totalToDownload;
|
||||||
//! Total number of assets still waiting to be downloaded
|
//! Total number of assets still waiting to be downloaded
|
||||||
int _totalWaitToDownload;
|
int _totalWaitToDownload;
|
||||||
|
|
||||||
|
//! Marker for whether the assets manager is inited
|
||||||
|
bool _inited;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_EXT_END
|
NS_CC_EXT_END
|
||||||
|
|
Loading…
Reference in New Issue