From 3846fa784456e71bbd13ddda691e209ce765cb06 Mon Sep 17 00:00:00 2001 From: JianMiau Date: Sun, 4 Sep 2022 12:01:59 +0800 Subject: [PATCH] =?UTF-8?q?[mod]=20=E7=86=B1=E6=9B=B4=E6=96=B0=E8=AA=BF?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 ++ assets/Script/Engine/Data/LocalStorageData.ts | 33 ------ assets/Script/HUD/HUDM.ts | 101 +++++++++++++++++- assets/Script/Manager.ts | 3 + .../BusinessTypeSetting.ts | 10 +- hotupdate.bat | 2 +- remote-assets/project.manifest | 2 +- remote-assets/version.manifest | 2 +- 8 files changed, 119 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 93f1a91..36a53bc 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,12 @@ Thumbs.db .idea/ +#////////////////////////// +# HotUpdate +#////////////////////////// + +remote-assets/ + #////////////////////////// # VS Code files #////////////////////////// diff --git a/assets/Script/Engine/Data/LocalStorageData.ts b/assets/Script/Engine/Data/LocalStorageData.ts index f390a3e..bc5fd9f 100644 --- a/assets/Script/Engine/Data/LocalStorageData.ts +++ b/assets/Script/Engine/Data/LocalStorageData.ts @@ -1,4 +1,3 @@ - export default class LocalStorageData { private static _instance: LocalStorageData = null; public static get Instance(): LocalStorageData { @@ -12,40 +11,8 @@ export default class LocalStorageData { // ======================================================================================= public get CompileVersion(): string { return cc.sys.localStorage.getItem("CompileVersion"); } public set CompileVersion(value: string) { cc.sys.localStorage.setItem("CompileVersion", value.toString()); } - public get RemoteVerList(): string { return cc.sys.localStorage.getItem("RemoteVerList"); } - public set RemoteVerList(value: string) { cc.sys.localStorage.setItem("RemoteVerList", value); } - public get LocalVerList(): string { return cc.sys.localStorage.getItem("LocalVerList"); } - public set LocalVerList(value: string) { cc.sys.localStorage.setItem("LocalVerList", value); } public get ComboDeviceID(): string { return cc.sys.localStorage.getItem("ComboDeviceID") || ""; } public set ComboDeviceID(value: string) { cc.sys.localStorage.setItem("ComboDeviceID", value); } public get BundleUrl(): string { return cc.sys.localStorage.getItem("BundleUrl"); } public set BundleUrl(value: string) { cc.sys.localStorage.setItem("BundleUrl", value); } - public get Language(): string { return cc.sys.localStorage.getItem("language"); } - public set Language(value: string) { cc.sys.localStorage.setItem("language", value); } - public get MusicType(): string { return cc.sys.localStorage.getItem("MusicType"); } - public set MusicType(value: string) { cc.sys.localStorage.setItem("MusicType", value); } - public get SoundType(): string { return cc.sys.localStorage.getItem("SoundType"); } - public set SoundType(value: string) { cc.sys.localStorage.setItem("SoundType", value); } - public get LvUpNotifyType(): boolean { return JSON.parse(cc.sys.localStorage.getItem("LvUpNotifyType")); } - public set LvUpNotifyType(value: boolean) { cc.sys.localStorage.setItem("LvUpNotifyType", JSON.stringify(value)); } - public get WinNotifyType(): boolean { return JSON.parse(cc.sys.localStorage.getItem("WinNotifyType")); } - public set WinNotifyType(value: boolean) { cc.sys.localStorage.setItem("WinNotifyType", JSON.stringify(value)); } - public get DownloadList_Preview(): string { return cc.sys.localStorage.getItem("DownloadList_Preview"); } - public set DownloadList_Preview(value: string) { cc.sys.localStorage.setItem("DownloadList_Preview", value); } - - /** - * key: id - * value: 是否開過卡 - */ - public get BingoCardInfo(): Map { return cc.sys.localStorage.getItem("BingoCardInfo") ? new Map(JSON.parse(cc.sys.localStorage.getItem("BingoCardInfo"))) : new Map(); } - public set BingoCardInfo(value: Map) { cc.sys.localStorage.setItem("BingoCardInfo", JSON.stringify(Array.from(value.entries()))); } - - /** - * key: id - * value: 是否開過卡 - */ - public get FiveCardInfo(): Map { return cc.sys.localStorage.getItem("FiveCardInfo") ? new Map(JSON.parse(cc.sys.localStorage.getItem("FiveCardInfo"))) : new Map(); } - public set FiveCardInfo(value: Map) { cc.sys.localStorage.setItem("FiveCardInfo", JSON.stringify(Array.from(value.entries()))); } - - // ======================================================================================= } diff --git a/assets/Script/HUD/HUDM.ts b/assets/Script/HUD/HUDM.ts index b277c81..eb879cd 100644 --- a/assets/Script/HUD/HUDM.ts +++ b/assets/Script/HUD/HUDM.ts @@ -1,4 +1,5 @@ import { CoroutineV2 } from "../Engine/CatanEngine/CoroutineV2/CoroutineV2"; +import LocalStorageData from "../Engine/Data/LocalStorageData"; import UpdatePanel from "../UpdatePanel"; import BusinessTypeSetting from "../_BusinessTypeSetting/BusinessTypeSetting"; import Enum_HUDM from "./Enum_HUDM"; @@ -45,17 +46,29 @@ export default class HUDM extends cc.Component { } HUDM._instance = this; this._updatePanel = params[0]; - let packageUrl: string = `https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/${BusinessTypeSetting.COMPILE_VERSION}`; + // let packageUrl: string = `https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/${BusinessTypeSetting.COMPILE_VERSION}`; + let packageUrl: string = BusinessTypeSetting.UsePatch; + + this.CheckCompileVersion(); + this.CheckChangePatchUrl(); this._customManifest = JSON.stringify({ "packageUrl": packageUrl, "remoteManifestUrl": `${packageUrl}/project.manifest`, "remoteVersionUrl": `${packageUrl}/version.json`, - "version": "0.0", + "version": "0.0.0", }); this._storagePath = `${(jsb.fileUtils ? jsb.fileUtils.getWritablePath() : "./")}${this._path}`; + // 本地熱更目錄下已存在project.manifest,則直接修改已存在的project.manifest + if (this._isChangeUrl) { + if (jsb.fileUtils.isFileExist(this._storagePath + "/project.manifest")) { + this._isChangeUrl = true; + this._modifyAppLoadUrlForManifestFile(this._storagePath, packageUrl); + } + } + this._versionCompareHandle = function (versionA: string, versionB: string): number { // console.log("Ver A " + versionA + "VerB " + versionB); let vA: string[] = versionA.split("."); @@ -120,6 +133,25 @@ export default class HUDM extends cc.Component { } } + private _modifyAppLoadUrlForManifestFile(filePath: string, newBundleUrl: string): void { + let allpath: string[] = [filePath, filePath + "_temp"]; + let manifestname: string[] = ["project.manifest", "project.manifest.temp"]; + for (var i: number = 0; i < allpath.length; ++i) { + let path: string = `${allpath[i]}/${manifestname[i]}`; + if (jsb.fileUtils.isFileExist(path)) { + // console.log(`[HUD] modifyAppLoadUrlForManifestFile: 有下載的manifest文件,直接修改熱更地址`); + // 修改project.manifest + let projectManifest: string = jsb.fileUtils.getStringFromFile(path); + let projectManifestObj: any = JSON.parse(projectManifest); + projectManifestObj.packageUrl = newBundleUrl; + projectManifestObj.remoteManifestUrl = newBundleUrl + "/project.manifest"; + projectManifestObj.remoteVersionUrl = newBundleUrl + "/version.json"; + let afterString: string = JSON.stringify(projectManifestObj); + jsb.fileUtils.writeStringToFile(afterString, path); + } + } + } + //#endregion public *CheckUpdate(): IterableIterator { @@ -148,6 +180,42 @@ export default class HUDM extends cc.Component { yield null; } + let newBundleUrl: string = BusinessTypeSetting.UsePatch; + this._modifyAppLoadUrlForManifestFile(this._storagePath, newBundleUrl); + this._initAssetManaget(); + + let manifest: jsb.Manifest = new jsb.Manifest(this._customManifest, this._storagePath); + this._am.loadLocalManifest(manifest, this._storagePath); + if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) { + // this.tipsLabel.string = "Failed to load local manifest ..."; + console.error("checkUpdate -> Failed to load local manifest ..."); + return; + } + + // 更新動態路徑後再跑一次 + this._am.setEventCallback(this.checkCb.bind(this)); + + this._needUpdateData = null; + this._am.checkUpdate(); + this._updating = true; + while (this._needUpdateData === null) { + yield null; + } + if (this._isChangeUrl && ((!this._needUpdateData.IsNeedUpdate && this._needUpdateData.TotalBytes !== "failed") || this._needUpdateData.TotalBytes === "0 B")) { + if (jsb.fileUtils.isFileExist(this._storagePath)) { + let isremoveDirectory: boolean = jsb.fileUtils.removeDirectory(this._storagePath); + let isremoveDirectory_temp: boolean = jsb.fileUtils.removeDirectory(this._storagePath + "_temp"); + if (isremoveDirectory_temp) { + console.log(`removeDirectory: ${this._storagePath}_temp`); + } + if (isremoveDirectory) { + console.log(`removeDirectory: ${this._storagePath}`); + this._needUpdateData = null; + this._initAssetManaget(); + this._needUpdateData = yield* this.CheckUpdate(); + } + } + } return this._needUpdateData; } @@ -184,7 +252,7 @@ export default class HUDM extends cc.Component { this._updating = false; if (failed) { - this._needUpdateData = new Enum_HUDM.NeedUpdateDataObj(false, null); + this._needUpdateData = new Enum_HUDM.NeedUpdateDataObj(false, "failed"); } } @@ -348,4 +416,31 @@ export default class HUDM extends cc.Component { this._updateListener = null; } } + + //#region 清除資料 + + /** 判斷更改編譯版號.清除BUNDLE記錄 */ + public CheckCompileVersion(): void { + let oldCompileVersion: string = LocalStorageData.Instance.CompileVersion; + let newCompileVersion: string = BusinessTypeSetting.COMPILE_VERSION; + if (oldCompileVersion && oldCompileVersion !== newCompileVersion) { + // this.ClearBundleData(); + console.warn(`change compile version. ${oldCompileVersion} -> ${newCompileVersion}`); + } + LocalStorageData.Instance.CompileVersion = BusinessTypeSetting.COMPILE_VERSION; + } + + /** 判斷更改PATCH環境.清除BUNDLE記錄 */ + public CheckChangePatchUrl(): void { + let oldBundleUrl: string = LocalStorageData.Instance.BundleUrl; + let newBundleUrl: string = BusinessTypeSetting.UsePatch; + if (oldBundleUrl && oldBundleUrl !== newBundleUrl) { + // this.ClearBundleData(); + console.warn(`change patch url. ${oldBundleUrl} -> ${newBundleUrl}`); + this._isChangeUrl = true; + } + LocalStorageData.Instance.BundleUrl = BusinessTypeSetting.UsePatch; + } + + //#endregion } diff --git a/assets/Script/Manager.ts b/assets/Script/Manager.ts index 23dc752..3fc6972 100644 --- a/assets/Script/Manager.ts +++ b/assets/Script/Manager.ts @@ -6,6 +6,7 @@ node version_generator.js -v 1.0.0 -u https://jianmiau.tk/Resources/App/JMKA/upd import { CoroutineV2 } from "./Engine/CatanEngine/CoroutineV2/CoroutineV2"; import { System_Eevent } from "./Engine/CatanEngine/CSharp/System/System_Eevent"; +import LocalStorageData from "./Engine/Data/LocalStorageData"; import { Enum_HUDM } from "./HUD/Enum_HUDM"; import HUDM from "./HUD/HUDM"; import NativeClass from "./NativeClass"; @@ -41,8 +42,10 @@ export default class Manager extends cc.Component { private *_init(): IterableIterator { console.log(`COMPILE VERSION: ${BusinessTypeSetting.COMPILE_VERSION}`); this.Version.string = `Ver ${BusinessTypeSetting.COMPILE_VERSION}`; + BusinessTypeSetting.UsePatch = `https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/${BusinessTypeSetting.NEXT_VERSION}`; cc.debug.setDisplayStats(false); + new LocalStorageData(); new NativeClass(this.webview); if (cc.sys.isNative) { new HUDM(this.UpdatePanel.getComponentInChildren(UpdatePanel)); diff --git a/assets/Script/_BusinessTypeSetting/BusinessTypeSetting.ts b/assets/Script/_BusinessTypeSetting/BusinessTypeSetting.ts index 4e3732d..a0d7f3a 100644 --- a/assets/Script/_BusinessTypeSetting/BusinessTypeSetting.ts +++ b/assets/Script/_BusinessTypeSetting/BusinessTypeSetting.ts @@ -1,4 +1,12 @@ export default class BusinessTypeSetting { + public static readonly MajorVersion: number = 3; + public static readonly MinorVersion: number = 0; + // public static readonly BuildVersion: number = 0; + public static readonly Revision: number = 0; /** 編譯版本 */ - public static readonly COMPILE_VERSION: string = "3.0"; + public static readonly COMPILE_VERSION: string = `${BusinessTypeSetting.MajorVersion}.${BusinessTypeSetting.MinorVersion}.${BusinessTypeSetting.Revision}`; + public static readonly NEXT_VERSION: string = `${BusinessTypeSetting.MajorVersion}.${BusinessTypeSetting.MinorVersion}.${BusinessTypeSetting.Revision + 1}`; + + /** 資源伺服器網址 */ + public static UsePatch: string = null; } \ No newline at end of file diff --git a/hotupdate.bat b/hotupdate.bat index 76e98fe..c5c3af2 100644 --- a/hotupdate.bat +++ b/hotupdate.bat @@ -1,6 +1,6 @@ @echo off -set Ver=3.0 +set Ver=3.0.1 set START1=%~dp0\build\jsb-default\remote-assets set START2=%~dp0\remote-assets set END=W:\web\MyWeb\Resources\App\JMKA\update\remote-assets\%Ver% diff --git a/remote-assets/project.manifest b/remote-assets/project.manifest index 1747619..f879930 100644 --- a/remote-assets/project.manifest +++ b/remote-assets/project.manifest @@ -1 +1 @@ -{"packageUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0/","remoteManifestUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0/project.manifest","remoteVersionUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0/version.manifest","version":"3.0","assets":{"src/assets/Plugins/responsivevoice.js":{"size":104943,"md5":"9f71d303fc7feda51261c2bf856ad4f1"},"src/assets/Script/Engine/Component/Animation/SkeletonExt.js":{"size":1161,"md5":"7e27cb40c535213460334d5f536e16b9"},"src/cocos2d-jsb.js":{"size":2995026,"md5":"8f7fa2615af9cf7f2121cf3077b97c0a"},"src/settings.js":{"size":500,"md5":"d989547c4773fe77c3dac0293e87e174"},"assets/main/config.json":{"size":1720,"md5":"4f2027d695a724c279c1f4faaea59ae9"},"assets/main/import/02/0254af710.json":{"size":281,"md5":"e859c04502eab6f53d55174bbd4f1d3d"},"assets/main/import/06/06cf73164.json":{"size":34830,"md5":"8288692b6f635b983ecf7ef2b804b03d"},"assets/main/index.js":{"size":436910,"md5":"5f1faf4ab0134b83b75ebd7a06539f25"},"assets/main/native/2d/2ddfe005-2129-41d8-aeec-2b1f51f02962.png":{"size":2290,"md5":"740ebade1729539882383360b2066d36"},"assets/main/native/34/3459ab36-782c-4c4e-8aef-7280aff8b272.png":{"size":18969,"md5":"96e39d211db65235f425ba3957b723b0"},"assets/main/native/70/700faa17-11a6-46cd-aeb5-d6900bc264f8.png":{"size":3765,"md5":"60ab4dfb6d3e8a147753b5665dcba27a"},"assets/main/native/71/71561142-4c83-4933-afca-cb7a17f67053.png":{"size":1050,"md5":"72c8f8527cdbe8246b8223a54f409ca3"},"assets/main/native/b4/b43ff3c2-02bb-4874-81f7-f2dea6970f18.png":{"size":1114,"md5":"49624805cb214b8d78d34a0c03dfbd00"},"assets/main/native/c3/c39ea496-96eb-4dc5-945a-e7c919b77c21.png":{"size":2548,"md5":"c3b93af99c4a65d85ad414e8e46dbfd5"},"assets/main/native/ca/caaaf9ff-5036-4232-a8a7-88b80b2e4c88.png":{"size":1829,"md5":"e3e1ef9049e7c82cbb696bc4e8cfa64b"},"assets/main/native/e5/e56254ca-0ee4-42ea-b69e-d2e57804a4f1.jpg":{"size":5809,"md5":"8fbe8a70e5b43c90bed44cf38e0e2a50"}},"searchPaths":[]} \ No newline at end of file +{"packageUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0.1/","remoteManifestUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0.1/project.manifest","remoteVersionUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0.1/version.manifest","version":"3.0.1","assets":{"src/assets/Plugins/responsivevoice.js":{"size":104943,"md5":"9f71d303fc7feda51261c2bf856ad4f1"},"src/assets/Script/Engine/Component/Animation/SkeletonExt.js":{"size":1161,"md5":"7e27cb40c535213460334d5f536e16b9"},"src/cocos2d-jsb.js":{"size":2995026,"md5":"8f7fa2615af9cf7f2121cf3077b97c0a"},"src/settings.js":{"size":500,"md5":"d989547c4773fe77c3dac0293e87e174"},"assets/main/config.json":{"size":1720,"md5":"4f2027d695a724c279c1f4faaea59ae9"},"assets/main/import/02/0254af710.json":{"size":281,"md5":"e859c04502eab6f53d55174bbd4f1d3d"},"assets/main/import/06/06cf73164.json":{"size":36298,"md5":"208e5254dfe5589ad716071ab641bfb5"},"assets/main/index.js":{"size":439011,"md5":"29d0658eb6fae91ff1254d061bdf5f5d"},"assets/main/native/2d/2ddfe005-2129-41d8-aeec-2b1f51f02962.png":{"size":2290,"md5":"740ebade1729539882383360b2066d36"},"assets/main/native/34/3459ab36-782c-4c4e-8aef-7280aff8b272.png":{"size":18969,"md5":"96e39d211db65235f425ba3957b723b0"},"assets/main/native/70/700faa17-11a6-46cd-aeb5-d6900bc264f8.png":{"size":3765,"md5":"60ab4dfb6d3e8a147753b5665dcba27a"},"assets/main/native/71/71561142-4c83-4933-afca-cb7a17f67053.png":{"size":1050,"md5":"72c8f8527cdbe8246b8223a54f409ca3"},"assets/main/native/b4/b43ff3c2-02bb-4874-81f7-f2dea6970f18.png":{"size":1114,"md5":"49624805cb214b8d78d34a0c03dfbd00"},"assets/main/native/c3/c39ea496-96eb-4dc5-945a-e7c919b77c21.png":{"size":2548,"md5":"c3b93af99c4a65d85ad414e8e46dbfd5"},"assets/main/native/ca/caaaf9ff-5036-4232-a8a7-88b80b2e4c88.png":{"size":1829,"md5":"e3e1ef9049e7c82cbb696bc4e8cfa64b"},"assets/main/native/e5/e56254ca-0ee4-42ea-b69e-d2e57804a4f1.jpg":{"size":5809,"md5":"8fbe8a70e5b43c90bed44cf38e0e2a50"}},"searchPaths":[]} \ No newline at end of file diff --git a/remote-assets/version.manifest b/remote-assets/version.manifest index 9cf212c..a5d28fa 100644 --- a/remote-assets/version.manifest +++ b/remote-assets/version.manifest @@ -1 +1 @@ -{"packageUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0/","remoteManifestUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0/project.manifest","remoteVersionUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0/version.manifest","version":"3.0"} \ No newline at end of file +{"packageUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0.1/","remoteManifestUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0.1/project.manifest","remoteVersionUrl":"https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/3.0.1/version.manifest","version":"3.0.1"} \ No newline at end of file