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); // Previous update is interrupted if (_fileUtils->isFileExist(_tempManifestPath)) { // Manifest parse failed, remove all temp files if (!_tempManifest->isLoaded()) { _fileUtils->removeDirectory(_tempStoragePath); CC_SAFE_RELEASE(_tempManifest); _tempManifest = nullptr; } } } 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_RELEASE(_localManifest); CC_SAFE_RELEASE(_tempManifest); CC_SAFE_RELEASE(_remoteManifest); _localManifest = nullptr; _tempManifest = nullptr; _remoteManifest = nullptr; } }
AssetsManager::AssetsManager(const std::string& manifestUrl, const std::string& storagePath) : _updateState(State::UNCHECKED) , _waitToUpdate(false) , _totalToDownload(0) , _totalWaitToDownload(0) , _percent(0) , _percentByFile(0) , _manifestUrl(manifestUrl) , _storagePath("") , _cacheVersionPath("") , _cacheManifestPath("") , _tempManifestPath("") , _assets(nullptr) , _localManifest(nullptr) , _tempManifest(nullptr) , _remoteManifest(nullptr) { // Init variables _eventDispatcher = Director::getInstance()->getEventDispatcher(); std::string pointer = StringUtils::format("%p", this); _eventName = EventListenerAssetsManager::LISTENER_ID + pointer; _fileUtils = FileUtils::getInstance(); _updateState = State::UNCHECKED; _downloader = std::make_shared<Downloader>(); _downloader->setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT); _downloader->_onError = std::bind(&AssetsManager::onError, this, std::placeholders::_1); _downloader->_onProgress = std::bind(&AssetsManager::onProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4); _downloader->_onSuccess = std::bind(&AssetsManager::onSuccess, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); setStoragePath(storagePath); _cacheVersionPath = _storagePath + VERSION_FILENAME; _cacheManifestPath = _storagePath + MANIFEST_FILENAME; _tempManifestPath = _storagePath + TEMP_MANIFEST_FILENAME; // Init and load local manifest _localManifest = new Manifest(); loadLocalManifest(manifestUrl); // Init and load temporary manifest _tempManifest = new Manifest(); _tempManifest->parse(_tempManifestPath); if (!_tempManifest->isLoaded()) _fileUtils->removeFile(_tempManifestPath); // Init remote manifest for future usage _remoteManifest = new Manifest(); }