void AssetsManager::update() { if (!_localManifest->isLoaded()) { CCLOG("AssetsManager : No local manifest file found error.\n"); dispatchUpdateEvent(EventAssetsManager::EventCode::ERROR_NO_LOCAL_MANIFEST); return; } _waitToUpdate = true; switch (_updateState) { case State::UNCHECKED: { _updateState = State::PREDOWNLOAD_VERSION; } case State::PREDOWNLOAD_VERSION: { downloadVersion(); } break; case State::VERSION_LOADED: { parseVersion(); } break; case State::PREDOWNLOAD_MANIFEST: { downloadManifest(); } break; case State::MANIFEST_LOADED: { parseManifest(); } break; case State::FAIL_TO_UPDATE: case State::NEED_UPDATE: { // Manifest not loaded yet if (!_remoteManifest->isLoaded()) { _waitToUpdate = true; _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else { startUpdate(); } } break; case State::UP_TO_DATE: case State::UPDATING: _waitToUpdate = false; break; default: break; } }
void AssetsManager::parseVersion() { if (_updateState != State::VERSION_LOADED) return; _remoteManifest->parse(_cacheVersionPath); if (!_remoteManifest->isVersionLoaded()) { CCLOG("AssetsManager : Fail to parse version file, step skipped\n"); _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else { if (_localManifest->versionEquals(_remoteManifest)) { _updateState = State::UP_TO_DATE; dispatchUpdateEvent(EventAssetsManager::EventCode::ALREADY_UP_TO_DATE); } else { _updateState = State::NEED_UPDATE; dispatchUpdateEvent(EventAssetsManager::EventCode::NEW_VERSION_FOUND); // Wait to update so continue the process if (_waitToUpdate) { _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } } } }
void ModuleMgr::checkUpdate() { switch (_updateState) { case State::UNCHECKED: case State::PREDOWNLOAD_MANIFEST: { _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } break; case State::UP_TO_DATE: { dispatchUpdateEvent(ModuleMgrEvent::EventCode::ALREADY_UP_TO_DATE); } break; case State::FAIL_TO_UPDATE: case State::NEED_UPDATE: { dispatchUpdateEvent(ModuleMgrEvent::EventCode::NEW_VERSION_FOUND); } break; default: break; } }
void AssetsManager::onError(const Downloader::Error &error) { // Skip version error occured if (error.customId == VERSION_ID) { CCLOG("AssetsManager : Fail to download version file, step skipped\n"); _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else if (error.customId == MANIFEST_ID) { dispatchUpdateEvent(EventAssetsManager::EventCode::ERROR_DOWNLOAD_MANIFEST, error.customId, error.message, error.curle_code, error.curlm_code); } else { auto unitIt = _downloadUnits.find(error.customId); // Found unit and add it to failed units if (unitIt != _downloadUnits.end()) { Downloader::DownloadUnit unit = unitIt->second; _failedUnits.emplace(unit.customId, unit); } dispatchUpdateEvent(EventAssetsManager::EventCode::ERROR_UPDATING, error.customId, error.message, error.curle_code, error.curlm_code); } }
void ModuleMgr::update() { _waitToUpdate = true; switch (_updateState) { case State::UNCHECKED: { _updateState = State::PREDOWNLOAD_MANIFEST; } case State::PREDOWNLOAD_MANIFEST: { downloadManifest(); } break; case State::MANIFEST_LOADED: { parseManifest(); } break; case State::FAIL_TO_UPDATE: case State::NEED_UPDATE: { // Manifest not loaded yet if (!_remoteManifest->isLoaded()) { _waitToUpdate = true; _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else { startUpdate(); } } break; case State::UP_TO_DATE: case State::UPDATING: _waitToUpdate = false; break; default: break; } }
void AssetsManagerEx::parseVersion() { if (_updateState != State::VERSION_LOADED) return; _remoteManifest->parseVersion(_tempVersionPath); if (!_remoteManifest->isVersionLoaded()) { CCLOG("AssetsManagerEx : Fail to parse version file, step skipped\n"); _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else { if (_localManifest->versionGreater(_remoteManifest, _versionCompareHandle)) { _updateState = State::UP_TO_DATE; _fileUtils->removeDirectory(_tempStoragePath); dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ALREADY_UP_TO_DATE); } else { _updateState = State::NEED_UPDATE; // Wait to update so continue the process if (_updateEntry == UpdateEntry::DO_UPDATE) { // dispatch after checking update entry because event dispatching may modify the update entry dispatchUpdateEvent(EventAssetsManagerEx::EventCode::NEW_VERSION_FOUND); _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else { dispatchUpdateEvent(EventAssetsManagerEx::EventCode::NEW_VERSION_FOUND); } } } }
void AssetsManager::downloadVersion() { if (_updateState != State::PREDOWNLOAD_VERSION) return; std::string versionUrl = _localManifest->getVersionFileUrl(); if (versionUrl.size() > 0) { _updateState = State::DOWNLOADING_VERSION; // Download version file asynchronously _downloader->downloadAsync(versionUrl, _cacheVersionPath, VERSION_ID); } // No version file found else { CCLOG("AssetsManager : No version file found, step skipped\n"); _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } }
void AssetsManagerEx::onError(const network::DownloadTask& task, int errorCode, int errorCodeInternal, const std::string& errorStr) { // Skip version error occurred if (task.identifier == VERSION_ID) { CCLOG("AssetsManagerEx : Fail to download version file, step skipped\n"); _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else if (task.identifier == MANIFEST_ID) { dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST, task.identifier, errorStr, errorCode, errorCodeInternal); _updateState = State::FAIL_TO_UPDATE; } else { fileError(task.identifier, errorStr, errorCode, errorCodeInternal); } }
void AssetsManagerEx::update() { if (_updateEntry != UpdateEntry::NONE) { CCLOGERROR("AssetsManagerEx::update, updateEntry isn't NONE"); return; } if (!_inited){ CCLOG("AssetsManagerEx : Manifests uninited.\n"); dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST); return; } if (!_localManifest->isLoaded()) { CCLOG("AssetsManagerEx : No local manifest file found error.\n"); dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_NO_LOCAL_MANIFEST); return; } _updateEntry = UpdateEntry::DO_UPDATE; switch (_updateState) { case State::UNCHECKED: { _updateState = State::PREDOWNLOAD_VERSION; } case State::PREDOWNLOAD_VERSION: { downloadVersion(); } break; case State::VERSION_LOADED: { parseVersion(); } break; case State::PREDOWNLOAD_MANIFEST: { downloadManifest(); } break; case State::MANIFEST_LOADED: { parseManifest(); } break; case State::FAIL_TO_UPDATE: case State::NEED_UPDATE: { // Manifest not loaded yet if (!_remoteManifest->isLoaded()) { _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else { startUpdate(); } } break; case State::UP_TO_DATE: case State::UPDATING: case State::UNZIPPING: _updateEntry = UpdateEntry::NONE; break; default: break; } }