mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-06-04 00:19:33 +08:00
修改project.manifest为js脚本。用于可以指定热更新路径
This commit is contained in:
@@ -8,7 +8,7 @@ const ErrCode = cc.Enum({
|
||||
downloadPackage: -10, //下载新包
|
||||
});
|
||||
|
||||
const MD5 = require("Uint8ArrayMD5");
|
||||
let hotupdateManifest = require('hotManifest');
|
||||
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
@@ -19,7 +19,7 @@ cc.Class({
|
||||
// type: cc.Asset,
|
||||
// default: null
|
||||
// },
|
||||
manifestUrl: cc.RawAsset,
|
||||
// manifestUrl: cc.RawAsset,
|
||||
_hotUpdateName: 'game-remote-asset',
|
||||
_nowVersion: ''
|
||||
},
|
||||
@@ -36,6 +36,8 @@ cc.Class({
|
||||
this.nextFn && nextFn(this._nowVersion);
|
||||
return;
|
||||
}
|
||||
//如果是重新进入游戏,清除cache
|
||||
this.clearHotupdateCacheTemp();
|
||||
let self = this;
|
||||
this._storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + this._hotUpdateName);
|
||||
this.versionCompareHandle = function (versionA, versionB) {
|
||||
@@ -73,23 +75,10 @@ cc.Class({
|
||||
|
||||
this._am.setVerifyCallback(function (path, asset) {
|
||||
var compressed = asset.compressed;
|
||||
/**
|
||||
* 计算md5
|
||||
* @param {*} filePath
|
||||
*/
|
||||
let calMD5OfFile = function (filePath) {
|
||||
return MD5(jsb.fileUtils.getDataFromFile(filePath));
|
||||
};
|
||||
|
||||
if (compressed) {
|
||||
return true;
|
||||
} else {
|
||||
var resMD5 = calMD5OfFile(path);
|
||||
if (asset.md5 == resMD5) {
|
||||
return true;
|
||||
}
|
||||
jsb.fileUtils.removeFile(path);
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -162,7 +151,9 @@ cc.Class({
|
||||
// url = cc.loader.md5Pipe.transformURL(url);
|
||||
// }
|
||||
// this._am.loadLocalManifest(url);
|
||||
this._am.loadLocalManifest(this.manifestUrl);
|
||||
// this._am.loadLocalManifest(this.manifestUrl);
|
||||
var manifest = new jsb.Manifest(JSON.stringify(hotupdateManifest), this._storagePath);
|
||||
this._am.loadLocalManifest(manifest, this._storagePath);
|
||||
}
|
||||
if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) {
|
||||
|
||||
@@ -317,12 +308,25 @@ cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
//清除热更新文件
|
||||
clearHotupdateCache() {
|
||||
if (cc.sys.isBrowser) {
|
||||
return;
|
||||
}
|
||||
let storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + this._hotUpdateName);
|
||||
jsb.fileUtils.removeDirectory(storagePath);
|
||||
},
|
||||
|
||||
//清除临时热更新文件
|
||||
clearHotupdateCacheTemp() {
|
||||
if (cc.sys.isBrowser) {
|
||||
return;
|
||||
}
|
||||
console.log('temp file clear');
|
||||
let storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + this._hotUpdateName + '_temp');
|
||||
jsb.fileUtils.removeDirectory(storagePath);
|
||||
},
|
||||
|
||||
// update (dt) {},
|
||||
|
||||
onDestroy() {
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
/**
|
||||
* 只接受Uint8Array数据的格式
|
||||
* from jsb_runtime_md5.js
|
||||
* @param {} data
|
||||
*/
|
||||
module.exports = function (data) {
|
||||
// for test/debug
|
||||
function fflog(msg) {
|
||||
try {
|
||||
console.log(msg);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// convert number to (unsigned) 32 bit hex, zero filled string
|
||||
function to_zerofilled_hex(n) {
|
||||
var t1 = (n >>> 24).toString(16);
|
||||
var t2 = (n & 0x00FFFFFF).toString(16);
|
||||
return "00".substr(0, 2 - t1.length) + t1 +
|
||||
"000000".substr(0, 6 - t2.length) + t2;
|
||||
}
|
||||
|
||||
// convert a 64 bit unsigned number to array of bytes. Little endian
|
||||
function int64_to_bytes(num) {
|
||||
var retval = [];
|
||||
for (var i = 0; i < 8; i++) {
|
||||
retval.push(num & 0xFF);
|
||||
num = num >>> 8;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
// 32 bit left-rotation
|
||||
function rol(num, places) {
|
||||
return ((num << places) & 0xFFFFFFFF) | (num >>> (32 - places));
|
||||
}
|
||||
|
||||
// The 4 MD5 functions
|
||||
function fF(b, c, d) {
|
||||
return (b & c) | (~b & d);
|
||||
}
|
||||
|
||||
function fG(b, c, d) {
|
||||
return (d & b) | (~d & c);
|
||||
}
|
||||
|
||||
function fH(b, c, d) {
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
|
||||
function fI(b, c, d) {
|
||||
return c ^ (b | ~d);
|
||||
}
|
||||
|
||||
// pick 4 bytes at specified offset. Little-endian is assumed
|
||||
function bytes_to_int32(arr, off) {
|
||||
return (arr[off + 3] << 24) | (arr[off + 2] << 16) | (arr[off + 1] << 8) | (arr[off]);
|
||||
}
|
||||
// convert the 4 32-bit buffers to a 128 bit hex string. (Little-endian is assumed)
|
||||
function int128le_to_hex(a, b, c, d) {
|
||||
var ra = "";
|
||||
var t = 0;
|
||||
var ta = 0;
|
||||
for (var i = 3; i >= 0; i--) {
|
||||
ta = arguments[i];
|
||||
t = (ta & 0xFF);
|
||||
ta = ta >>> 8;
|
||||
t = t << 8;
|
||||
t = t | (ta & 0xFF);
|
||||
ta = ta >>> 8;
|
||||
t = t << 8;
|
||||
t = t | (ta & 0xFF);
|
||||
ta = ta >>> 8;
|
||||
t = t << 8;
|
||||
t = t | ta;
|
||||
ra = ra + to_zerofilled_hex(t);
|
||||
}
|
||||
return ra;
|
||||
}
|
||||
|
||||
// check input data type and perform conversions if needed
|
||||
|
||||
if (!data instanceof Uint8Array) {
|
||||
fflog("input data type mismatch only support Uint8Array");
|
||||
return null;
|
||||
}
|
||||
var databytes = [];
|
||||
for (var i = 0; i < data.byteLength; i++) {
|
||||
databytes.push(data[i]);
|
||||
}
|
||||
|
||||
// save original length
|
||||
var org_len = databytes.length;
|
||||
|
||||
// first append the "1" + 7x "0"
|
||||
databytes.push(0x80);
|
||||
|
||||
// determine required amount of padding
|
||||
var tail = databytes.length % 64;
|
||||
// no room for msg length?
|
||||
if (tail > 56) {
|
||||
// pad to next 512 bit block
|
||||
for (var i = 0; i < (64 - tail); i++) {
|
||||
databytes.push(0x0);
|
||||
}
|
||||
tail = databytes.length % 64;
|
||||
}
|
||||
for (i = 0; i < (56 - tail); i++) {
|
||||
databytes.push(0x0);
|
||||
}
|
||||
// message length in bits mod 512 should now be 448
|
||||
// append 64 bit, little-endian original msg length (in *bits*!)
|
||||
databytes = databytes.concat(int64_to_bytes(org_len * 8));
|
||||
|
||||
// initialize 4x32 bit state
|
||||
var h0 = 0x67452301;
|
||||
var h1 = 0xEFCDAB89;
|
||||
var h2 = 0x98BADCFE;
|
||||
var h3 = 0x10325476;
|
||||
|
||||
// temp buffers
|
||||
var a = 0,
|
||||
b = 0,
|
||||
c = 0,
|
||||
d = 0;
|
||||
|
||||
|
||||
function _add(n1, n2) {
|
||||
return 0x0FFFFFFFF & (n1 + n2)
|
||||
}
|
||||
|
||||
// function update partial state for each run
|
||||
var updateRun = function (nf, sin32, dw32, b32) {
|
||||
var temp = d;
|
||||
d = c;
|
||||
c = b;
|
||||
//b = b + rol(a + (nf + (sin32 + dw32)), b32);
|
||||
b = _add(b,
|
||||
rol(
|
||||
_add(a,
|
||||
_add(nf, _add(sin32, dw32))
|
||||
), b32
|
||||
)
|
||||
);
|
||||
a = temp;
|
||||
};
|
||||
|
||||
|
||||
// Digest message
|
||||
for (i = 0; i < databytes.length / 64; i++) {
|
||||
// initialize run
|
||||
a = h0;
|
||||
b = h1;
|
||||
c = h2;
|
||||
d = h3;
|
||||
|
||||
var ptr = i * 64;
|
||||
|
||||
// do 64 runs
|
||||
updateRun(fF(b, c, d), 0xd76aa478, bytes_to_int32(databytes, ptr), 7);
|
||||
updateRun(fF(b, c, d), 0xe8c7b756, bytes_to_int32(databytes, ptr + 4), 12);
|
||||
updateRun(fF(b, c, d), 0x242070db, bytes_to_int32(databytes, ptr + 8), 17);
|
||||
updateRun(fF(b, c, d), 0xc1bdceee, bytes_to_int32(databytes, ptr + 12), 22);
|
||||
updateRun(fF(b, c, d), 0xf57c0faf, bytes_to_int32(databytes, ptr + 16), 7);
|
||||
updateRun(fF(b, c, d), 0x4787c62a, bytes_to_int32(databytes, ptr + 20), 12);
|
||||
updateRun(fF(b, c, d), 0xa8304613, bytes_to_int32(databytes, ptr + 24), 17);
|
||||
updateRun(fF(b, c, d), 0xfd469501, bytes_to_int32(databytes, ptr + 28), 22);
|
||||
updateRun(fF(b, c, d), 0x698098d8, bytes_to_int32(databytes, ptr + 32), 7);
|
||||
updateRun(fF(b, c, d), 0x8b44f7af, bytes_to_int32(databytes, ptr + 36), 12);
|
||||
updateRun(fF(b, c, d), 0xffff5bb1, bytes_to_int32(databytes, ptr + 40), 17);
|
||||
updateRun(fF(b, c, d), 0x895cd7be, bytes_to_int32(databytes, ptr + 44), 22);
|
||||
updateRun(fF(b, c, d), 0x6b901122, bytes_to_int32(databytes, ptr + 48), 7);
|
||||
updateRun(fF(b, c, d), 0xfd987193, bytes_to_int32(databytes, ptr + 52), 12);
|
||||
updateRun(fF(b, c, d), 0xa679438e, bytes_to_int32(databytes, ptr + 56), 17);
|
||||
updateRun(fF(b, c, d), 0x49b40821, bytes_to_int32(databytes, ptr + 60), 22);
|
||||
updateRun(fG(b, c, d), 0xf61e2562, bytes_to_int32(databytes, ptr + 4), 5);
|
||||
updateRun(fG(b, c, d), 0xc040b340, bytes_to_int32(databytes, ptr + 24), 9);
|
||||
updateRun(fG(b, c, d), 0x265e5a51, bytes_to_int32(databytes, ptr + 44), 14);
|
||||
updateRun(fG(b, c, d), 0xe9b6c7aa, bytes_to_int32(databytes, ptr), 20);
|
||||
updateRun(fG(b, c, d), 0xd62f105d, bytes_to_int32(databytes, ptr + 20), 5);
|
||||
updateRun(fG(b, c, d), 0x2441453, bytes_to_int32(databytes, ptr + 40), 9);
|
||||
updateRun(fG(b, c, d), 0xd8a1e681, bytes_to_int32(databytes, ptr + 60), 14);
|
||||
updateRun(fG(b, c, d), 0xe7d3fbc8, bytes_to_int32(databytes, ptr + 16), 20);
|
||||
updateRun(fG(b, c, d), 0x21e1cde6, bytes_to_int32(databytes, ptr + 36), 5);
|
||||
updateRun(fG(b, c, d), 0xc33707d6, bytes_to_int32(databytes, ptr + 56), 9);
|
||||
updateRun(fG(b, c, d), 0xf4d50d87, bytes_to_int32(databytes, ptr + 12), 14);
|
||||
updateRun(fG(b, c, d), 0x455a14ed, bytes_to_int32(databytes, ptr + 32), 20);
|
||||
updateRun(fG(b, c, d), 0xa9e3e905, bytes_to_int32(databytes, ptr + 52), 5);
|
||||
updateRun(fG(b, c, d), 0xfcefa3f8, bytes_to_int32(databytes, ptr + 8), 9);
|
||||
updateRun(fG(b, c, d), 0x676f02d9, bytes_to_int32(databytes, ptr + 28), 14);
|
||||
updateRun(fG(b, c, d), 0x8d2a4c8a, bytes_to_int32(databytes, ptr + 48), 20);
|
||||
updateRun(fH(b, c, d), 0xfffa3942, bytes_to_int32(databytes, ptr + 20), 4);
|
||||
updateRun(fH(b, c, d), 0x8771f681, bytes_to_int32(databytes, ptr + 32), 11);
|
||||
updateRun(fH(b, c, d), 0x6d9d6122, bytes_to_int32(databytes, ptr + 44), 16);
|
||||
updateRun(fH(b, c, d), 0xfde5380c, bytes_to_int32(databytes, ptr + 56), 23);
|
||||
updateRun(fH(b, c, d), 0xa4beea44, bytes_to_int32(databytes, ptr + 4), 4);
|
||||
updateRun(fH(b, c, d), 0x4bdecfa9, bytes_to_int32(databytes, ptr + 16), 11);
|
||||
updateRun(fH(b, c, d), 0xf6bb4b60, bytes_to_int32(databytes, ptr + 28), 16);
|
||||
updateRun(fH(b, c, d), 0xbebfbc70, bytes_to_int32(databytes, ptr + 40), 23);
|
||||
updateRun(fH(b, c, d), 0x289b7ec6, bytes_to_int32(databytes, ptr + 52), 4);
|
||||
updateRun(fH(b, c, d), 0xeaa127fa, bytes_to_int32(databytes, ptr), 11);
|
||||
updateRun(fH(b, c, d), 0xd4ef3085, bytes_to_int32(databytes, ptr + 12), 16);
|
||||
updateRun(fH(b, c, d), 0x4881d05, bytes_to_int32(databytes, ptr + 24), 23);
|
||||
updateRun(fH(b, c, d), 0xd9d4d039, bytes_to_int32(databytes, ptr + 36), 4);
|
||||
updateRun(fH(b, c, d), 0xe6db99e5, bytes_to_int32(databytes, ptr + 48), 11);
|
||||
updateRun(fH(b, c, d), 0x1fa27cf8, bytes_to_int32(databytes, ptr + 60), 16);
|
||||
updateRun(fH(b, c, d), 0xc4ac5665, bytes_to_int32(databytes, ptr + 8), 23);
|
||||
updateRun(fI(b, c, d), 0xf4292244, bytes_to_int32(databytes, ptr), 6);
|
||||
updateRun(fI(b, c, d), 0x432aff97, bytes_to_int32(databytes, ptr + 28), 10);
|
||||
updateRun(fI(b, c, d), 0xab9423a7, bytes_to_int32(databytes, ptr + 56), 15);
|
||||
updateRun(fI(b, c, d), 0xfc93a039, bytes_to_int32(databytes, ptr + 20), 21);
|
||||
updateRun(fI(b, c, d), 0x655b59c3, bytes_to_int32(databytes, ptr + 48), 6);
|
||||
updateRun(fI(b, c, d), 0x8f0ccc92, bytes_to_int32(databytes, ptr + 12), 10);
|
||||
updateRun(fI(b, c, d), 0xffeff47d, bytes_to_int32(databytes, ptr + 40), 15);
|
||||
updateRun(fI(b, c, d), 0x85845dd1, bytes_to_int32(databytes, ptr + 4), 21);
|
||||
updateRun(fI(b, c, d), 0x6fa87e4f, bytes_to_int32(databytes, ptr + 32), 6);
|
||||
updateRun(fI(b, c, d), 0xfe2ce6e0, bytes_to_int32(databytes, ptr + 60), 10);
|
||||
updateRun(fI(b, c, d), 0xa3014314, bytes_to_int32(databytes, ptr + 24), 15);
|
||||
updateRun(fI(b, c, d), 0x4e0811a1, bytes_to_int32(databytes, ptr + 52), 21);
|
||||
updateRun(fI(b, c, d), 0xf7537e82, bytes_to_int32(databytes, ptr + 16), 6);
|
||||
updateRun(fI(b, c, d), 0xbd3af235, bytes_to_int32(databytes, ptr + 44), 10);
|
||||
updateRun(fI(b, c, d), 0x2ad7d2bb, bytes_to_int32(databytes, ptr + 8), 15);
|
||||
updateRun(fI(b, c, d), 0xeb86d391, bytes_to_int32(databytes, ptr + 36), 21);
|
||||
|
||||
// update buffers
|
||||
h0 = _add(h0, a);
|
||||
h1 = _add(h1, b);
|
||||
h2 = _add(h2, c);
|
||||
h3 = _add(h3, d);
|
||||
}
|
||||
// Done! Convert buffers to 128 bit (LE)
|
||||
return int128le_to_hex(h3, h2, h1, h0).toLowerCase();
|
||||
};
|
||||
1
HotUpdateDemo/assets/hotManifest.js
Normal file
1
HotUpdateDemo/assets/hotManifest.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {"packageUrl":"http://localhost/hotUpdate/","remoteManifestUrl":"http://localhost/hotUpdate/project.manifest","remoteVersionUrl":"http://localhost/hotUpdate/version.manifest","version":"1.0.0","assets":{"src/jsb_polyfill.jsc":{"size":135144,"md5":"e08578cfca3384185849a0f3d25b289b"},"src/project.jsc":{"size":2752,"md5":"d1e51d4a8f7bf56feeda0fa7db99780f"},"src/settings.jsc":{"size":460,"md5":"1625325fab19c33dea59ed30b8cb6177"},"res/import/05/05dd1dc0e.json":{"size":2152,"md5":"d27a54680b96dbf0b88694bbd8a1e8e2"},"res/raw-assets/Texture/HelloWorld.png":{"size":37864,"md5":"55ea4e952bf080f300379ec26723598b"},"res/raw-assets/Texture/singleColor.png":{"size":17197,"md5":"e5136c625f53acd0366396e2b9d534ca"}},"searchPaths":[]}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "b723dc8e-07ac-4a35-b0d9-663f49b82e42",
|
||||
"uuid": "4e283479-e176-4eba-9617-6ba1cf51263a",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
@@ -1 +0,0 @@
|
||||
{"packageUrl":"http://localhost/hotUpdate/","remoteManifestUrl":"http://localhost/hotUpdate/project.manifest","remoteVersionUrl":"http://localhost/hotUpdate/version.manifest","version":"1.0.0","assets":{"src/jsb_polyfill.jsc":{"size":135144,"md5":"809df571102bcfda4ef8894516cf8f03"},"src/project.jsc":{"size":3792,"md5":"260475b293c07f1fe13ce362589f52e1"},"src/settings.jsc":{"size":460,"md5":"49f64cb5418c6c156ff11ac17ab4cca6"},"res/import/05/05dd1dc0e.json":{"size":2152,"md5":"d27a54680b96dbf0b88694bbd8a1e8e2"},"res/raw-assets/Texture/HelloWorld.png":{"size":37864,"md5":"55ea4e952bf080f300379ec26723598b"},"res/raw-assets/Texture/singleColor.png":{"size":17197,"md5":"e5136c625f53acd0366396e2b9d534ca"}},"searchPaths":[]}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "2857653b-09b5-4724-a067-615f6905fbc2",
|
||||
"subMetas": {}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
{"packageUrl":"http://localhost/hotUpdate/","remoteManifestUrl":"http://localhost/hotUpdate/project.manifest","remoteVersionUrl":"http://localhost/hotUpdate/version.manifest","version":"1.0.0"}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"ver": "1.0.0",
|
||||
"uuid": "5a4d5cda-d694-467c-9587-3653e9b41f0c",
|
||||
"subMetas": {}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ while (i < process.argv.length) {
|
||||
i += 2;
|
||||
break;
|
||||
default:
|
||||
i++;
|
||||
i += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -117,8 +117,6 @@ var mkdirSync = function (path) {
|
||||
readDir(path.join(src, 'src'), manifest.assets);
|
||||
readDir(path.join(src, 'res'), manifest.assets);
|
||||
|
||||
var destManifest = path.join(dest, 'project.manifest');
|
||||
var destVersion = path.join(dest, 'version.manifest');
|
||||
var hotManifest = path.join(hotDir, 'project.manifest');
|
||||
var hotVersion = path.join(hotDir, 'version.manifest');
|
||||
var tmp = path.join(packageRes, 'raw-assets');
|
||||
@@ -128,30 +126,24 @@ mkdirSync(dest);
|
||||
//生成热更新目录
|
||||
mkdirSync(hotDir);
|
||||
|
||||
//生成文件manifest到assets
|
||||
let isfailed = fs.writeFileSync(destManifest, JSON.stringify(manifest));
|
||||
|
||||
//生成文件manifest转成hotProject.js
|
||||
let hotProjectPath = path.join(dest, 'hotManifest.js');
|
||||
console.log('create hotProject', hotProjectPath);
|
||||
isfailed = fs.writeFileSync(hotProjectPath, 'module.exports = ' + JSON.stringify(manifest));
|
||||
if (!isfailed) {
|
||||
console.log('Manifest successfully generated');
|
||||
console.log('hotManifest successfully generated');
|
||||
}
|
||||
|
||||
//生成文件manifest到hotUpdate
|
||||
isfailed = fs.writeFileSync(hotManifest, JSON.stringify(manifest));
|
||||
if (!isfailed) {
|
||||
console.log('hotManifest successfully generated');
|
||||
}
|
||||
//把生成的maifest 同步到build\jsb-xxx\res\raw-assets 而不需要再次构建重新生成
|
||||
// fs.writeFile(packageMenifest, JSON.stringify(manifest), (err) => {
|
||||
// if (err) throw err;
|
||||
// console.log('packageMenifest successfully generated');
|
||||
// });
|
||||
|
||||
delete manifest.assets;
|
||||
delete manifest.searchPaths;
|
||||
|
||||
//生成版本manifest到assets
|
||||
isfailed = fs.writeFileSync(destVersion, JSON.stringify(manifest));
|
||||
if (!isfailed) {
|
||||
console.log('Version successfully generated');
|
||||
}
|
||||
//生成版本manifest到hotUpdate
|
||||
isfailed = fs.writeFileSync(hotVersion, JSON.stringify(manifest));
|
||||
if (isfailed) {
|
||||
|
||||
Reference in New Issue
Block a user