var t = require; var e = module; var i = exports; var e = (this && this.__decorate) || function (t, e, i, s) { var o, a = arguments.length, n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s); else for (var r = t.length - 1; 0 <= r; r--) (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n); return 3 < a && n && Object.defineProperty(e, i, n), n; }, s = (this && this.__awaiter) || function (t, n, r, l) { return new (r = r || Promise)(function (i, e) { function s(t) { try { a(l.next(t)); } catch (t) { e(t); } } function o(t) { try { a(l.throw(t)); } catch (t) { e(t); } } function a(t) { var e; t.done ? i(t.value) : ((e = t.value) instanceof r ? e : new r(function (t) { t(e); }) ).then(s, o); } a((l = l.apply(t, n || [])).next()); }); }; Object.defineProperty(i, "__esModule", {value: !0}); t("ViewConst"); const n = t("TipView"), r = t("App"), l = t("GameText"), {ccclass: o} = cc._decorator; e = e( [o], (e = class extends cc.Component { constructor() { super(...arguments), (this._updating = !1), (this._canRetry = !1), (this._storagePath = ""), (this._updateListener = !1), (this._am = null), (this._failCount = 0), (this.checkPromise = null), (this.checkResolve = null), (this.isCheck = !1), (this.porgressFunc = null); } log(t, ...e) { Log.trace("HotUpdateLog:", t, ...e); } versionCompareHandle(t, e) { return ( this.log( "JS Custom Version Compare: version A is " + t + ", version B is " + e, 0 < parseInt(t) - parseInt(e) ), parseInt(t) - parseInt(e) ); } checkCb(t) { let e = !1; switch ((this.log("Code: " + t.getEventCode()), (this.isCheck = !0), t.getEventCode())) { case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST: this.log("No local manifest file found, hot update skipped."); break; case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST: case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST: this.log("Fail to download manifest file, hot update skipped."); break; case jsb.EventAssetsManager.ALREADY_UP_TO_DATE: this.log("Already up to date with the latest remote version."); break; case jsb.EventAssetsManager.NEW_VERSION_FOUND: (e = !0), this.log("New version found, please try to update."); break; default: return; } this._am.setEventCallback(null), (this._updating = !1), e ? this.hotUpdate() : this.checkResolve && (this.checkResolve(!1), (this.checkResolve = this.checkPromise = null)); } updateCb(a) { return s(this, void 0, void 0, function* () { var t, e, i = !1, s = !1; switch ((Log.trace("updateCb:", a.getEventCode()), a.getEventCode())) { case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST: this.log("No local manifest file found, hot update skipped."), (s = !0); break; case jsb.EventAssetsManager.UPDATE_PROGRESSION: this.log(a.getDownloadedFiles() + " / " + a.getTotalFiles()), this.log(a.getDownloadedBytes() + " / " + a.getTotalBytes()), this.log(a.getPercent()), this.porgressFunc && this.porgressFunc(a.getPercent(), a.getDownloadedBytes(), a.getTotalBytes()); var o = a.getMessage(); o && this.log("Updated file: " + o); break; case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST: case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST: this.log("Fail to download manifest file, hot update skipped."), (s = !0); break; case jsb.EventAssetsManager.ALREADY_UP_TO_DATE: this.log("Already up to date with the latest remote version."), (s = !0); break; case jsb.EventAssetsManager.UPDATE_FINISHED: this.log("Update finished. " + a.getMessage()), (i = !0); break; case jsb.EventAssetsManager.UPDATE_FAILED: this.log("Update failed. " + a.getMessage()), (this._updating = !1), (this._canRetry = !0), r.default.ViewManager.open(13, { curState: n.TIPSTATE.SURE, leftFunc: () => { cc.audioEngine.stopAll(), cc.game.restart(); }, leftThisObj: this, tipsStr: l.GameText.getText(lang.hotupdate_failed_tip) }); break; case jsb.EventAssetsManager.ERROR_UPDATING: Log.error("Asset update error: " + a.getAssetId() + ", " + a.getMessage()); break; case jsb.EventAssetsManager.ERROR_DECOMPRESS: this.log(a.getMessage()); } s && (this._am.setEventCallback(null), (this._updating = !1), this._canRetry ? this.retry() : (this.checkResolve(!1), (this.checkResolve = this.checkPromise = null))), i && (this._am.setEventCallback(null), (this._updateListener = null), (t = jsb.fileUtils.getSearchPaths()), (e = this._am.getLocalManifest().getSearchPaths()), this.log(JSON.stringify(e)), Array.prototype.unshift.apply(t, e), cc.sys.localStorage.setItem("HotUpdateSearchPaths", JSON.stringify(t)), jsb.fileUtils.setSearchPaths(t), cc.sys.localStorage.removeItem("isUPdateing"), cc.audioEngine.stopAll(), cc.game.restart()); }); } loadCustomManifest() {} retry() { !this._updating && this._canRetry && ((this._canRetry = !1), this.log("Retry failed Assets..."), this._am.downloadFailedAssets()); } timeOut(e) { return new Promise(t => { r.default.TimerManager.setTimeOut( e, () => { this.isCheck || t(!1); }, this ); }); } showUpdatePackTip() { return new Promise(t => { r.default.ViewManager.open(13, { curState: n.TIPSTATE.SURE_CANCEL, leftBtnText: "确定", leftFunc: () => { t(); }, rightFunc: () => { t(); }, rightThisObj: this, rightBtnText: "取消", leftThisObj: this, tipsStr: "检测到新的版本,是否下载更新!" }); }); } checkUpdate(t) { return cc.sys.isNative ? this.checkPromise || ((this.porgressFunc = t), (this.checkPromise = Promise.race([ new Promise(t => { if ( ((this.checkResolve = t), this._am.getState() === jsb.AssetsManager.State.UNINITED && (cc.sys.os === cc.sys.OS_ANDROID ? this._am.loadLocalManifest("@assets/project.manifest") : this._am.loadLocalManifest( jsb.fileUtils.fullPathForFilename("project.manifest") )), !this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) ) return this.log("Failed to load local manifest ..."), void t(!1); this._am.setEventCallback(this.checkCb.bind(this)), this._am.checkUpdate(), (this._updating = !0); }), this.timeOut(1e4) ])), this.checkPromise) : Promise.resolve(!1); } hotUpdate() { this._am && !this._updating && (this._am.setEventCallback(this.updateCb.bind(this)), cc.sys.localStorage.setItem("isUPdateing", "true"), (this._failCount = 0), this._am.update(), (this._updating = !0)); } show() {} onLoad() { cc.sys.isNative && ((this._storagePath = (jsb.fileUtils ? jsb.fileUtils.getWritablePath() : "/") + "blackjack-remote-asset"), this.log("this._storagePath:", this._storagePath), (this._am = new jsb.AssetsManager("", this._storagePath, this.versionCompareHandle.bind(this))), this._am.setVerifyCallback((t, e) => { var i = e.compressed, s = e.md5, o = e.path; return e.size, !!i || (this.log("Verification passed : " + o + " (" + s + ")"), !0); }), this.log("Hot update is ready, please check or directly update."), cc.sys.os === cc.sys.OS_ANDROID && this.log("Max concurrent tasks count have been limited to 2")); } onDestroy() { this._updateListener && (this._am.setEventCallback(null), (this._updateListener = null)); } }) ); i.default = e;