重构checkFileList写法

This commit is contained in:
nonameShijian 2024-04-14 01:38:38 +08:00
parent 18a546f2e0
commit 7c9e7ee412
1 changed files with 16 additions and 38 deletions

View File

@ -890,51 +890,29 @@ export class Game {
* @param { Function } proceed
*/
checkFileList(updates, proceed) {
if (!Array.isArray(updates) || !updates.length) proceed();
let n = updates.length;
if (!n) {
proceed(n);
}
for (let i = 0; i < updates.length; i++) {
if (lib.node && lib.node.fs) {
lib.node.fs.access(__dirname + '/' + updates[i], (function (entry) {
return function (err) {
if (!err) {
let stat = lib.node.fs.statSync(__dirname + '/' + entry);
if (stat.size == 0) {
// @ts-ignore
err = true;
}
}
if (err) {
n--;
if (n == 0) {
proceed();
}
}
else {
n--;
updates.remove(entry);
if (n == 0) {
proceed();
}
}
lib.node.fs.access(__dirname + '/' + updates[i], err => {
if (!err) {
let stat = lib.node.fs.statSync(__dirname + '/' + updates[i]);
// @ts-ignore
if (stat.size == 0) err = true;
}
}(updates[i])));
n--;
if (!err) updates.remove(updates[i]);
if (n == 0) proceed();
});
}
else {
window.resolveLocalFileSystemURL(nonameInitialized + updates[i], (function (name) {
return function (entry) {
n--;
updates.remove(name);
if (n == 0) {
proceed();
}
}
}(updates[i])), function () {
window.resolveLocalFileSystemURL(nonameInitialized + updates[i], () => {
n--;
if (n == 0) {
proceed();
}
updates.remove(updates[i]);
if (n == 0) proceed();
}, () => {
n--;
if (n == 0) proceed();
});
}
}