diff options
-rw-r--r-- | src/app/browser.js | 16 | ||||
-rw-r--r-- | src/app/main.js | 10 | ||||
-rw-r--r-- | src/index.js | 2 | ||||
-rw-r--r-- | src/utils.js | 45 |
4 files changed, 60 insertions, 13 deletions
diff --git a/src/app/browser.js b/src/app/browser.js index 995a276..dee263b 100644 --- a/src/app/browser.js +++ b/src/app/browser.js @@ -363,13 +363,21 @@ function BrowserEl(properties) { <div class="text"> <div class="title">${properties.title}</div> <div class="description">${properties.description}</div> - <button class="install" onclick='installFromURL("${properties.download}", ${JSON.stringify(properties.dependencies)}, true)'>${installstr}</button> + <button class="install" onclick=''>${installstr}</button> <button class="info" onclick="Preview.set('${properties.url}')">${lang('gui.browser.view')}</button> <button class="visual">${properties.version}</button> <button class="visual">${lang("gui.browser.madeby")} ${properties.author}</button> </div> ` + entry.querySelector("button.install").addEventListener("click", () => { + installFromURL( + properties.download, + JSON.stringify(properties.dependencies), + true, properties.author + ) + }) + browserEntries.appendChild(entry); } @@ -451,7 +459,11 @@ ipcRenderer.on("installed-mod", (event, mod) => { }) if (installqueue.length != 0) { - installFromURL("https://thunderstore.io/package/download/" + installqueue[0]); + installFromURL( + "https://thunderstore.io/package/download/" + installqueue[0].pkg, + false, false, installqueue[0].author + ) + installqueue.shift(); } }) diff --git a/src/app/main.js b/src/app/main.js index 9d59cbc..50160d0 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -235,7 +235,7 @@ function installFromPath(path) { } // Tells the main process to install a mod from a URL -function installFromURL(url, dependencies, clearqueue) { +function installFromURL(url, dependencies, clearqueue, author) { if (clearqueue) {installqueue = []}; let prettydepends = []; @@ -248,7 +248,11 @@ function installFromURL(url, dependencies, clearqueue) { depend = dependencies[i].replaceAll("-", "/"); let pkg = depend.split("/"); if (! isModInstalled(pkg[1])) { - newdepends.push(depend); + newdepends.push({ + pkg: depend, + author: pkg[0] + }); + prettydepends.push(`${pkg[1]} v${pkg[2]} - ${lang("gui.browser.madeby")} ${pkg[0]}`); } } @@ -265,7 +269,7 @@ function installFromURL(url, dependencies, clearqueue) { } setButtons(false); - ipcRenderer.send("install-from-url", url, dependencies); + ipcRenderer.send("install-from-url", url, author); if (dependencies) { installqueue = dependencies; diff --git a/src/index.js b/src/index.js index b654f84..1f4cc87 100644 --- a/src/index.js +++ b/src/index.js @@ -81,7 +81,7 @@ function start() { // install calls ipcMain.on("install-from-path", (event, path) => {utils.mods.install(path)}); - ipcMain.on("install-from-url", (event, url) => {utils.mods.installFromURL(url)}); + ipcMain.on("install-from-url", (event, url, author) => {utils.mods.installFromURL(url, author)}); win.webContents.on("dom-ready", () => { send("mods", utils.mods.list()); diff --git a/src/utils.js b/src/utils.js index 890fc8c..514d8d2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -680,11 +680,12 @@ const mods = { // Either a zip or folder is supported, we'll also try to search // inside the zip or folder to see if buried in another folder or // not, as sometimes that's the case. - install: (mod, opts ) => { + install: (mod, opts) => { let modname = mod.replace(/^.*(\\|\/|\:)/, ""); opts = { forked: false, + author: false, destname: false, malformed: false, manifest_file: false, @@ -757,10 +758,30 @@ const mods = { copydest = path.join(modpath, opts.destname) } - copy(mod, copydest); - copy(opts.manifest_file, path.join(copydest, "manifest.json")); + copy(mod, copydest, (err, res) => { + if (err) { + ipcMain.emit("failed-mod"); + return; + } + + copy(opts.manifest_file, path.join(copydest, "manifest.json"), (err, res) => { + if (err) { + ipcMain.emit("failed-mod"); + return; + } + + if (opts.author) { + fs.writeFileSync( + path.join(copydest, "thunderstore_author.txt"), + opts.author + ) + } + + return installed(); + }); + }); - return installed(); + return; } else { mod_files = fs.readdirSync(mod); @@ -787,11 +808,13 @@ const mods = { let install = false; if (use_mod_name) { install = mods.install(path.join(mod, mod_files[i]), { + ...opts, forked: true, destname: mod_name, }) } else { install = mods.install(path.join(mod, mod_files[i]), { + ...opts, forked: true }) } @@ -825,6 +848,8 @@ const mods = { files = fs.readdirSync(path.join(cache, "mods")); if (fs.existsSync(path.join(cache, "mods/mod.json"))) { if (mods.install(path.join(cache, "mods"), { + ...opts, + forked: true, malformed: true, manifest_file: manifest, @@ -839,6 +864,7 @@ const mods = { if (fs.statSync(mod).isDirectory()) { setTimeout(() => { if (mods.install(mod, { + ...opts, forked: true, destname: false, manifest_file: manifest @@ -859,7 +885,10 @@ const mods = { return notamod(); } - if (mods.install(cache, { forked: true })) { + if (mods.install(cache, { + ...opts, + forked: true + })) { installed(); } else {return notamod()} }, 1000) @@ -875,7 +904,7 @@ const mods = { // // This'll simply download the file that the URL points to and then // install it with mods.install() - installFromURL: (url) => { + installFromURL: (url, author) => { https.get(url, (res) => { let tmp = path.join(app.getPath("cache"), "vipertmp"); let modlocation = path.join(tmp, "/mod.zip"); @@ -896,7 +925,9 @@ const mods = { stream.on("finish", () => { stream.close(); - mods.install(modlocation); + mods.install(modlocation, { + author: author + }) }) }) }, |