[mod] 熱更新調整
This commit is contained in:
@@ -11,6 +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 BundleVersion(): string { return cc.sys.localStorage.getItem("BundleVersion"); }
|
||||
public set BundleVersion(value: string) { cc.sys.localStorage.setItem("BundleVersion", value.toString()); }
|
||||
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"); }
|
||||
|
@@ -30,6 +30,7 @@ export default class HUDM extends cc.Component {
|
||||
private _updating: boolean = false;
|
||||
private _canRetry: boolean = false;
|
||||
private _isChangeUrl: boolean = false;
|
||||
private _isNewBundle: boolean = false;
|
||||
private _path: string = "Bundle";
|
||||
private _customManifest: string = "";
|
||||
private _storagePath: string = "";
|
||||
@@ -46,6 +47,7 @@ export default class HUDM extends cc.Component {
|
||||
}
|
||||
HUDM._instance = this;
|
||||
this._updatePanel = params[0];
|
||||
this._isNewBundle = params[1];
|
||||
// let packageUrl: string = `https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/${BusinessTypeSetting.COMPILE_VERSION}`;
|
||||
let packageUrl: string = BusinessTypeSetting.UsePatch;
|
||||
|
||||
@@ -201,7 +203,7 @@ export default class HUDM extends cc.Component {
|
||||
while (this._needUpdateData === null) {
|
||||
yield null;
|
||||
}
|
||||
if (this._isChangeUrl && ((!this._needUpdateData.IsNeedUpdate && this._needUpdateData.TotalBytes !== "failed") || this._needUpdateData.TotalBytes === "0 B")) {
|
||||
if ((this._isChangeUrl || this._isNewBundle) && ((!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");
|
||||
|
@@ -40,15 +40,17 @@ export default class Manager extends cc.Component {
|
||||
}
|
||||
|
||||
private *_init(): IterableIterator<any> {
|
||||
new LocalStorageData();
|
||||
let isNewBundle: boolean = yield* this.CheckBundleVersion();
|
||||
console.log(`BUNDLE VERSION: ${LocalStorageData.Instance.BundleVersion}`);
|
||||
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}`;
|
||||
BusinessTypeSetting.UsePatch = `https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/${BusinessTypeSetting.MajorVersion}.${BusinessTypeSetting.MinorVersion}`;
|
||||
cc.debug.setDisplayStats(false);
|
||||
|
||||
new LocalStorageData();
|
||||
new NativeClass(this.webview);
|
||||
if (cc.sys.isNative) {
|
||||
new HUDM(this.UpdatePanel.getComponentInChildren(UpdatePanel));
|
||||
if (cc.sys.isNative && isNewBundle) {
|
||||
new HUDM(this.UpdatePanel.getComponentInChildren(UpdatePanel), isNewBundle);
|
||||
let needUpdateData: Enum_HUDM.NeedUpdateDataObj = yield* HUDM.Instance.CheckUpdate();
|
||||
if (needUpdateData.IsNeedUpdate) {
|
||||
this.UpdatePanel.active = true;
|
||||
@@ -181,5 +183,65 @@ export default class Manager extends cc.Component {
|
||||
}
|
||||
}
|
||||
|
||||
/** 判斷更改Bundle版號.清除BUNDLE記錄 */
|
||||
public *CheckBundleVersion(): IterableIterator<any> {
|
||||
let isNewBundle: boolean = false;
|
||||
let remote_version: string = "0";
|
||||
let versionLoadEnd: boolean = false;
|
||||
let fileName: string = "BundleVersion";
|
||||
let fileFormat: string = ".txt";
|
||||
let fileVersion: string = `?v=${Date.now()}`;
|
||||
let fileUrl: string = `https://jianmiau.tk/Resources/App/JMKA/update/remote-assets/${fileName}${fileFormat}${fileVersion}`;
|
||||
cc.assetManager.loadRemote(fileUrl, (err: Error, res: cc.TextAsset) => {
|
||||
if (!err) {
|
||||
remote_version = res.text;
|
||||
versionLoadEnd = true;
|
||||
console.log(`${fileName}.txt loaded`);
|
||||
} else {
|
||||
console.error(`[Error] ${fileName}載入失敗`);
|
||||
}
|
||||
});
|
||||
while (!versionLoadEnd) {
|
||||
yield null;
|
||||
}
|
||||
let oldBundleVersion: string = LocalStorageData.Instance.BundleVersion || "0.0.0";
|
||||
let newBundleVersion: string = remote_version;
|
||||
if (oldBundleVersion) {
|
||||
let IsUpdate: boolean = this.VersionCompareHandle(oldBundleVersion, newBundleVersion) < 0 ? true : false;
|
||||
if (IsUpdate) {
|
||||
console.warn(`change bundle version. ${oldBundleVersion} -> ${newBundleVersion}`);
|
||||
isNewBundle = true;
|
||||
}
|
||||
}
|
||||
LocalStorageData.Instance.BundleVersion = newBundleVersion;
|
||||
return isNewBundle;
|
||||
}
|
||||
|
||||
public VersionCompareHandle(versionA: string, versionB: string): number {
|
||||
// console.log("Ver A " + versionA + "VerB " + versionB);
|
||||
let vA: string[] = versionA.split(".");
|
||||
let vB: string[] = versionB.split(".");
|
||||
|
||||
// 長度不相等,則進行更新
|
||||
if (vA.length !== vB.length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (let i: number = 0; i < vA.length; ++i) {
|
||||
let a: number = +vA[i];
|
||||
let b: number = +vB[i] || 0;
|
||||
if (a === b) {
|
||||
// 數字相同,則跳過
|
||||
continue;
|
||||
} else {
|
||||
// 數字不同,則進行更新
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// 長度相等且數字相等,則不更新
|
||||
return 0;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ export default class BusinessTypeSetting {
|
||||
public static readonly Revision: number = 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;
|
||||
|
Reference in New Issue
Block a user