MCPcopy Index your code
hub / github.com/EmulatorJS/EmulatorJS / loadExternalFiles

Method loadExternalFiles

data/src/GameManager.js:86–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84 this.writeFile("/home/web_user/retroarch/userdata/config/" + this.EJS.defaultCoreOpts.file, output);
85 }
86 loadExternalFiles() {
87 return new Promise(async (resolve, reject) => {
88 if (this.EJS.config.externalFiles && this.EJS.config.externalFiles.constructor.name === "Object") {
89 for (const key in this.EJS.config.externalFiles) {
90 await new Promise(done => {
91 this.EJS.downloadFile(this.EJS.config.externalFiles[key], null, true, { responseType: "arraybuffer", method: "GET" }).then(async (res) => {
92 if (res === -1) {
93 if (this.EJS.debug) console.warn("Failed to fetch file from '" + this.EJS.config.externalFiles[key] + "'. Make sure the file exists.");
94 return done();
95 }
96 let path = key;
97 if (key.trim().endsWith("/")) {
98 const invalidCharacters = /[#<$+%>!`&*'|{}/\\?"=@:^\r\n]/ig;
99 let name = this.EJS.config.externalFiles[key].split("/").pop().split("#")[0].split("?")[0].replace(invalidCharacters, "").trim();
100 if (!name) return done();
101 const files = await this.EJS.checkCompression(new Uint8Array(res.data), this.EJS.localization("Decompress Game Assets"));
102 if (files["!!notCompressedData"]) {
103 path += name;
104 } else {
105 for (const k in files) {
106 this.writeFile(path + k, files[k]);
107 }
108 return done();
109 }
110 }
111 try {
112 this.writeFile(path, res.data);
113 } catch(e) {
114 if (this.EJS.debug) console.warn("Failed to write file to '" + path + "'. Make sure there are no conflicting files.");
115 }
116 done();
117 });
118 })
119 }
120 }
121 resolve();
122 });
123 }
124 writeFile(path, data) {
125 const parts = path.split("/");
126 let current = "/";

Callers 1

downloadFilesMethod · 0.80

Calls 4

writeFileMethod · 0.95
downloadFileMethod · 0.80
checkCompressionMethod · 0.80
localizationMethod · 0.80

Tested by

no test coverage detected