Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

热更新。资源没有全部下载完全。

$
0
0

@1024359215 写道:

今天用模拟器进行更新,然后到更新目录查看,发现只下载了部分的远程端的资源,没有全部下载完毕。

这是生成manifest文件的脚本。

var fs = require('fs');
var path = require('path');
var crypto = require('crypto');

var manifest = {
packageUrl: 'http://localhost/tutorial-hot-update/remote-assets/',
remoteManifestUrl: 'http://localhost/tutorial-hot-update/remote-assets/project.manifest',
remoteVersionUrl: 'http://localhost/tutorial-hot-update/remote-assets/version.manifest',
version: '1.0.0',
assets: {},
searchPaths: []
};

var dest = './remote-assets/';
var src = './jsb/';

// Parse arguments
var i = 2;
while ( i < process.argv.length) {
var arg = process.argv[i];

switch (arg) {
case '--url' :
case '-u' :
    var url = process.argv[i+1];
    manifest.packageUrl = url;
    manifest.remoteManifestUrl = url + 'project.manifest';
    manifest.remoteVersionUrl = url + 'version.manifest';
    i += 2;
    break;
case '--version' :
case '-v' :
    manifest.version = process.argv[i+1];
    i += 2;
    break;
case '--src' :
case '-s' :
    src = process.argv[i+1];
    i += 2;
    break;
case '--dest' :
case '-d' :
    dest = process.argv[i+1];
    i += 2;
    break;
default :
    i++;
    break;
}

}

function readDir (dir, obj) {
var stat = fs.statSync(dir);
if (!stat.isDirectory()) {
return;
}
var subpaths = fs.readdirSync(dir), subpath, md5, relative;
for (var i = 0; i < subpaths.length; ++i) {
if (subpaths[i][0] === '.') {
continue;
}
subpath = path.join(dir, subpaths[i]);
stat = fs.statSync(subpath);
if (stat.isDirectory()) {
readDir(subpath, obj);
}
else if (stat.isFile()) {
md5 = crypto.createHash('md5').update(fs.readFileSync(subpath, 'utf8')).digest('hex');
relative = path.relative(src, subpath);
relative = relative.replace(/\/g, '/');
relative = encodeURI(relative);
obj[relative] = {'md5' : md5};
}
}
}

var mkdirSync = function (path) {
try {
fs.mkdirSync(path);
} catch(e) {
if ( e.code != 'EEXIST' ) throw e;
}
}

// Iterate res and src folder
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');

mkdirSync(dest);

fs.writeFile(destManifest, JSON.stringify(manifest), (err) => {
if (err) throw err;
console.log('Manifest successfully generated');
});

delete manifest.assets;
delete manifest.searchPaths;
fs.writeFile(destVersion, JSON.stringify(manifest), (err) => {
if (err) throw err;
console.log('Version successfully generated');
});

急求!!!!

帖子: 2

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>