123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- 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;
|