各位大神,,我这里每次热更新都会出现 调用是否需要检测更新后 明明不需要更新 但是之前更新完的本地目录被删掉了。。
/**
* 检测更新
* @private
*/
_beginCheckUpdate () {
if(this._am) {
this._localManifestDir = this._storagePath + “/project.manifest”;
cc.log(’_beginCheckUpdate find path ’ + this._localManifestDir);
// 自定义更新配置文件
let customManifest = JSON.stringify({
“packageUrl”: this._resBootUrl, // 更新服务器资源包根目录
“remoteManifestUrl”: this._resBootUrl + “/project.manifest”, // 更新服务器资源包project文件地址
“remoteVersionUrl”: this._resBootUrl + “/version.manifest”, // 更新服务器资源包version文件地址
“version”: “1.0.0.0”, // 本地主版本号
“assets”: {}, // 更新文件列表
“searchPaths”: [] // 搜索路径列表
});
// 设置检测更新监听 -- 检测版本是否需要更新
this._checkListener = new jsb.EventListenerAssetsManager(this._am, this._checkCb.bind(this));
cc.eventManager.addListener(this._checkListener, 1);
cc.log("_beginCheckUpdate ------ this._localManifestDir: " + this._localManifestDir);
// 创建目录
if(!jsb.fileUtils.isDirectoryExist(this._storagePath)) {
jsb.fileUtils.createDirectory(this._storagePath);
}
let manifestInfo = null;
//加载manifest
if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
if (jsb.fileUtils.isFileExist(this._localManifestDir)) {
console.log('更新过 加载本地Manifest');
manifestInfo = jsb.fileUtils.getStringFromFile(this._localManifestDir);
} else {
console.log('没更新过 在本地创建目录并用自定义Manifest');
manifestInfo = customManifest;
jsb.fileUtils.writeStringToFile(customManifest, this._localManifestDir);
}
}
if(manifestInfo) {
let manifest = new jsb.Manifest(manifestInfo, this._storagePath);
this._am.loadLocalManifest(manifest, this._storagePath);
this._am.checkUpdate();
this._updating = true;
cc.log("正在检查版本信息");
} else {
cc.log("-----------初始化更新数据失败。");
}
}
},
// 版本对比函数 以 1.0.0.0 形式对比 均为 int值
// Setup your own version compare handler, versionA and B is versions in string
// if the return value greater than 0, versionA is greater than B,
// if the return value equals 0, versionA equals to B,
// if the return value smaller than 0, versionA is smaller than B.
let versionCompareHandle = function (versionA, versionB) {
cc.log("JS Custom Version Compare: version A is " + versionA + ', version B is ' + versionB);
var vA = versionA.split('.');
var vB = versionB.split('.');
for (var i = 0; i < vA.length; ++i) {
var a = parseInt(vA[i]);
var b = parseInt(vB[i] || 0);
if (a === b) {
continue;
}
else {
cc.log("---------------- a - b: " + (a - b));
return a - b;
}
}
if (vB.length > vA.length) {
cc.log("---------------- -1 ");
return -1;
}
else {
cc.log("---------------- 0 ");
return 0;
}
};
这里是更新一次之后打印的log 更新一次之后
version A is 1.0.0.1, version B is 1.0.0.1
JS: ---------------- 0
看c++中 bool AssetsManagerEx::loadLocalManifest(Manifest* localManifest, const std::string& storagePath) 接口检测了
bool localNewer = _localManifest->versionGreater(cachedManifest, _versionCompareHandle);
返回的 localNewer 是大于>= 0 那 永远会执行
_fileUtils->removeDirectory(_storagePath);
_fileUtils->createDirectory(_storagePath);
CC_SAFE_RELEASE(cachedManifest);
这一句删除之前的本地文件,,
我看了下 c++ 中 _localManifest 和 cachedManifest 就是一个东西。。他俩在对比
这里给我干懵了,,我看代码发现这里检测明明就是同一个文件了啊,那每次检测完又把本地文件删除了,。。到底是咋回事,,求救了。。
c++ 版本 Cocos2d-x-lite v1.8.2
creator 版本 1.9.1