完善热更新组件,添加验证函数。致此热更新已十分完善,可直接使用

This commit is contained in:
leo
2019-01-11 10:37:23 +08:00
parent 8a2329c657
commit 4fa8af43a1
2 changed files with 31 additions and 4 deletions

View File

@@ -1,7 +1,12 @@
/**
* 参考文章
* https://www.cnblogs.com/pixs-union/p/9435882.html
*/
const ErrCode = cc.Enum({
laodManifestFailed: 0, //下载manifest失败
updateFailed: 1, //更新失败,
});
const MD5 = require("Uint8ArrayMD5");
cc.Class({
extends: cc.Component,
@@ -56,11 +61,26 @@ cc.Class({
}
this._am.setVerifyCallback(function (path, asset) {
console.log('path', path, 'setVerifyCallback' + JSON.stringify(asset));
var compressed = asset.compressed;
/**
* 计算md5
* @param {*} filePath
*/
let calMD5OfFile = function (filePath) {
return MD5(jsb.fileUtils.getDataFromFile(filePath));
};
if (compressed) {
return true;
} else {
return true;
var resMD5 = calMD5OfFile(path);
console.log('resMD%=', resMD5, 'asset md5=', asset.md5);
if (asset.md5 == resMD5) {
return true;
}
jsb.fileUtils.removeFile(path);
return false;
}
});
@@ -134,7 +154,6 @@ cc.Class({
if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) {
this.onFailure(ErrCode.laodManifestFailed);
// this.panel.info.string = 'Failed to load local manifest ...';
return;
}
this._checkListener = new jsb.EventListenerAssetsManager(this._am, this.checkCb.bind(this));