修改返回参数等问题

This commit is contained in:
nonameShijian 2024-03-31 22:29:48 +08:00
parent 6e09034db9
commit 21f1838537
2 changed files with 28 additions and 15 deletions

View File

@ -200,10 +200,14 @@ export async function cordovaReady() {
});
};
game.removeDir = (directory, successCallback, errorCallback) => {
new Promise((resolve, reject) => {
window.cordova.file
window.resolveLocalFileSystemURL(`${nonameInitialized}${directory}`, resolve, reject);
}).then((directoryEntry) => directoryEntry.removeRecursively(successCallback, errorCallback));
window.resolveLocalFileSystemURL(`${nonameInitialized}${directory}`, directoryEntry => {
directoryEntry.removeRecursively(() => {
if (typeof successCallback == 'function') successCallback();
});
}, e => {
if (typeof errorCallback == 'function') errorCallback(e);
else throw e;
});
};
if (ui.updateUpdate) {
ui.updateUpdate();

View File

@ -176,6 +176,7 @@ export function nodeReady() {
lib.node.fs.mkdir(lib.node.path.join(__dirname, directory), { recursive: true }, e => {
if (e) {
if (typeof errorCallback == 'function') errorCallback(e);
else throw e;
} else {
if (typeof successCallback == 'function') successCallback(e)
}
@ -184,17 +185,19 @@ export function nodeReady() {
const paths = directory.split('/').reverse();
let path = __dirname;
const redo = () => {
path += `/${paths.pop()}`;
return new Promise(resolve => lib.node.fs.exists(path, resolve)).then(exists => {
//不存在此目录
if (!exists) return new Promise(resolve => lib.node.fs.mkdir(path, resolve));
}).then(() => {
path = lib.node.path.join(path, paths.pop());
const exists = lib.node.fs.existsSync(path);
const callback = e => {
if (e) {
if (typeof errorCallback != 'function') throw e;
errorCallback(e);
return;
}
if (paths.length) return redo();
if (typeof successCallback == 'function') successCallback();
}).catch(reason => {
if (typeof errorCallback != 'function') return Promise.reject(reason);
errorCallback(reason);
});
};
if (!exists) lib.node.fs.mkdir(path, callback);
else callback();
};
redo();
}
@ -213,8 +216,9 @@ export function nodeReady() {
lib.node.fs.rmdir(target, { recursive: true }, e => {
if (e) {
if (typeof errorCallback == 'function') errorCallback(e);
else throw e;
} else {
if (typeof successCallback == 'function') successCallback(e)
if (typeof successCallback == 'function') successCallback()
}
});
} else {
@ -230,7 +234,12 @@ export function nodeReady() {
successCallback();
}
};
deleteFolderRecursive(target);
try {
deleteFolderRecursive(target);
} catch (e) {
if (typeof errorCallback == 'function') errorCallback(e);
else throw e;
}
}
};
if (ui.updateUpdate) {