From 011216b87696a0608b817f9992b8cbf1d3874dfd Mon Sep 17 00:00:00 2001 From: Ethan O'Brien <77750390+ethanaobrien@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:39:45 -0600 Subject: [PATCH] Attempt to fetch from emulatorjs cdn if core not found locally --- data/emulator.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/data/emulator.js b/data/emulator.js index de230c9..aec72c9 100644 --- a/data/emulator.js +++ b/data/emulator.js @@ -647,12 +647,26 @@ class EmulatorJS { let corePath = 'cores/'+filename; this.downloadFile(corePath, (res) => { if (res === -1) { - if (!this.supportsWebgl2) { - this.textElem.innerText = this.localization('Outdated graphics driver'); - } else { - this.textElem.innerText = this.localization('Network Error'); - } - this.textElem.style.color = "red"; + console.log("File not found, attemping to fetch from emulatorjs cdn"); + this.downloadFile("https://cdn.emulatorjs.org/stable/data/"+corePath, (res) => { + if (res === -1) { + if (!this.supportsWebgl2) { + this.textElem.innerText = this.localization('Outdated graphics driver'); + } else { + this.textElem.innerText = this.localization('Network Error'); + } + this.textElem.style.color = "red"; + return; + } + console.warn("File was not found locally, but was found on the emulatorjs cdn.\nIt is recommended to download the latest release from here: https://cdn.emulatorjs.org/releases/"); + gotCore(res.data); + this.storage.core.put(filename, { + version: this.version, + data: res.data + }); + }, (progress) => { + this.textElem.innerText = this.localization("Download Game Core") + progress; + }, true, {responseType: "arraybuffer", method: "GET"}) return; } gotCore(res.data);