mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Cleanup
This commit is contained in:
parent
0fc2c55971
commit
0682a46e28
2 changed files with 43 additions and 33 deletions
|
@ -50,31 +50,41 @@ class EJS_GameManager {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
loadExternalFiles() {
|
loadExternalFiles() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (this.EJS.config.externalFiles && this.EJS.config.externalFiles.constructor.name === 'Object') {
|
if (this.EJS.config.externalFiles && this.EJS.config.externalFiles.constructor.name === 'Object') {
|
||||||
for (const key in this.EJS.config.externalFiles) {
|
for (const key in this.EJS.config.externalFiles) {
|
||||||
let path = key;
|
await new Promise(done => {
|
||||||
if (key.trim().endsWith("/")) {
|
this.EJS.downloadFile(this.EJS.config.externalFiles[key], async (res) => {
|
||||||
const invalidCharacters = /[#<$+%>!`&*'|{}/\\?"=@:^\r\n]/ig;
|
if (res === -1) {
|
||||||
let name = this.EJS.config.externalFiles[key].split("/").pop().split("#")[0].split("?")[0].replace(invalidCharacters, "").trim();
|
if (this.EJS.debug) console.warn("Failed to fetch file from '" + this.EJS.config.externalFiles[key] + "'. Make sure the file exists.");
|
||||||
if (!name) continue;
|
return done();
|
||||||
path += name;
|
}
|
||||||
}
|
let path = key;
|
||||||
this.EJS.downloadFile(this.EJS.config.externalFiles[key], (res) => {
|
if (key.trim().endsWith("/")) {
|
||||||
if (res === -1) {
|
const invalidCharacters = /[#<$+%>!`&*'|{}/\\?"=@:^\r\n]/ig;
|
||||||
if (this.EJS.debug) console.warn("Failed to fetch file from '" + this.EJS.config.externalFiles[key] + "'. Make sure the file exists.");
|
let name = this.EJS.config.externalFiles[key].split("/").pop().split("#")[0].split("?")[0].replace(invalidCharacters, "").trim();
|
||||||
return resolve();
|
if (!name) return done();
|
||||||
}
|
const files = await this.EJS.checkCompression(new Uint8Array(res.data), this.EJS.localization("Decompress Game Assets"));
|
||||||
try {
|
if (files["!!notCompressedData"]) {
|
||||||
this.writeFile(path, this.EJS.config.externalFiles[key]);
|
path += name;
|
||||||
} catch(e) {
|
} else {
|
||||||
if (this.EJS.debug) console.warn("Failed to write file to '" + path + "'. Make sure there are no conflicting files.");
|
for (const k in files) {
|
||||||
}
|
this.writeFile(path+k, files[k]);
|
||||||
resolve();
|
}
|
||||||
}, null, true, {responseType: "text", method: "GET"});
|
return done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.writeFile(path, res.data);
|
||||||
|
} catch(e) {
|
||||||
|
if (this.EJS.debug) console.warn("Failed to write file to '" + path + "'. Make sure there are no conflicting files.");
|
||||||
|
}
|
||||||
|
done();
|
||||||
|
}, null, true, {responseType: "arraybuffer", method: "GET"});
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else resolve();
|
}
|
||||||
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
writeFile(path, data) {
|
writeFile(path, data) {
|
||||||
|
|
|
@ -494,21 +494,21 @@ class EmulatorJS {
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
isCompressed(data) { //https://www.garykessler.net/library/file_sigs.html
|
||||||
|
//todo. Use hex instead of numbers
|
||||||
|
if ((data[0] === 80 && data[1] === 75) && ((data[2] === 3 && data[3] === 4) || (data[2] === 5 && data[3] === 6) || (data[2] === 7 && data[3] === 8))) {
|
||||||
|
return 'zip';
|
||||||
|
} else if (data[0] === 55 && data[1] === 122 && data[2] === 188 && data[3] === 175 && data[4] === 39 && data[5] === 28) {
|
||||||
|
return '7z';
|
||||||
|
} else if ((data[0] === 82 && data[1] === 97 && data[2] === 114 && data[3] === 33 && data[4] === 26 && data[5] === 7) && ((data[6] === 0) || (data[6] === 1 && data[7] == 0))) {
|
||||||
|
return 'rar';
|
||||||
|
}
|
||||||
|
}
|
||||||
checkCompression(data, msg, fileCbFunc) {
|
checkCompression(data, msg, fileCbFunc) {
|
||||||
if (msg) {
|
if (msg) {
|
||||||
this.textElem.innerText = msg;
|
this.textElem.innerText = msg;
|
||||||
}
|
}
|
||||||
//to be put in another file
|
//to be put in another file
|
||||||
function isCompressed(data) { //https://www.garykessler.net/library/file_sigs.html
|
|
||||||
//todo. Use hex instead of numbers
|
|
||||||
if ((data[0] === 80 && data[1] === 75) && ((data[2] === 3 && data[3] === 4) || (data[2] === 5 && data[3] === 6) || (data[2] === 7 && data[3] === 8))) {
|
|
||||||
return 'zip';
|
|
||||||
} else if (data[0] === 55 && data[1] === 122 && data[2] === 188 && data[3] === 175 && data[4] === 39 && data[5] === 28) {
|
|
||||||
return '7z';
|
|
||||||
} else if ((data[0] === 82 && data[1] === 97 && data[2] === 114 && data[3] === 33 && data[4] === 26 && data[5] === 7) && ((data[6] === 0) || (data[6] === 1 && data[7] == 0))) {
|
|
||||||
return 'rar';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const createWorker = (path) => {
|
const createWorker = (path) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.downloadFile(path, (res) => {
|
this.downloadFile(path, (res) => {
|
||||||
|
@ -595,7 +595,7 @@ class EmulatorJS {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const compression = isCompressed(data.slice(0, 10));
|
const compression = this.isCompressed(data.slice(0, 10));
|
||||||
if (compression) {
|
if (compression) {
|
||||||
//Need to do zip and rar still
|
//Need to do zip and rar still
|
||||||
if (compression === "7z") {
|
if (compression === "7z") {
|
||||||
|
|
Loading…
Reference in a new issue