From 972815e536f22c2e9dc0a49ec99b28acf8443df7 Mon Sep 17 00:00:00 2001 From: Cody Fields Date: Mon, 19 Oct 2020 11:46:52 -0400 Subject: [PATCH] Fix #15, major bug breaking big addon creations/uploads --- app.js | 33 ++++++++++++++++++++------------- index.html | 2 +- package.json | 2 +- src/js/script.js | 11 ++++++----- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app.js b/app.js index 1d51a68..bf68cf6 100644 --- a/app.js +++ b/app.js @@ -170,17 +170,21 @@ ipcMain.on('createJsonFile', (event, json, dir) => { // This is ran once the client requests to create an addon ipcMain.on('createGMAFile', (event, addonDir) => { console.log("Addon's Directory: " + addonDir.toString()); + sendConsoleData(["Addon's directory: " + addonDir.toString()]); const gmad = spawn(settings.get('gmodDirectory') + '/bin/' + gmadFile, ['create', '-folder', addonDir]); gmad.stdout.on('data', (data) => { var arrayOfOutput = data.toString().split('\n'); if (data.includes('File list verification failed')) { - mainWindow.webContents.send("errorNote", "File list verification failed - check your addon for unallowed files.", true); + mainWindow.webContents.send("errorNote", "File list verification failed - check your addon for unallowed files.", false, true); + } + if (data.includes("Successfully")) { + var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 2, arrayOfOutput.length - 1); + fixedArray = fixedArray[0].match(/(?:"[^"]*"|^[^"]*$)/)[0].replace(/"/g, ""); + var addonGMADir = fixedArray; + mainWindow.webContents.send('addonGMALocation', addonGMADir); + console.log("GMA location: " + addonGMADir); + sendConsoleData(arrayOfOutput); } - var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 2, arrayOfOutput.length - 1) - fixedArray = fixedArray[0].match(/(?:"[^"]*"|^[^"]*$)/)[0].replace(/"/g, "") - var addonGMADir = fixedArray; - console.log("GMA location: " + addonGMADir); - mainWindow.webContents.send('addonGMALocation', addonGMADir); }); }); @@ -202,19 +206,22 @@ ipcMain.on('uploadToWorkshop', (event, gmaDir, iconDir, addonId) => { } else { // Passes all the info needed to publish a Garry's Mod addon const gmpublish = spawn(settings.get('gmodDirectory') + '/bin/' + gmpublishFile, ['create', '-icon', iconDir, '-addon', gmaDir]); + console.log(gmpublishFile, gmaDir, iconDir) gmpublish.stdout.on('data', (data) => { var arrayOfOutput = data.toString().split('\n'); sendConsoleData(arrayOfOutput) if (data.includes('512x512')) { mainWindow.webContents.send("errorNote", "Image must be a 512x512 baseline jpeg! Trying exporting with Paint.", true); } - var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 2, arrayOfOutput.length - 1); - fixedArray = fixedArray[0].replace(/\D/, ''); - fixedArray = fixedArray.substr(5, fixedArray.length); - var stringArray = fixedArray.toString() - var addonURLIndex = stringArray.indexOf("?id=") - var addonURL = stringArray.slice(addonURLIndex + 4, addonURLIndex + 14) - mainWindow.webContents.send('currentAddonID', addonURL); + if (data.includes("Addon creation finished")) { + var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 2, arrayOfOutput.length - 1); + fixedArray = fixedArray[0].replace(/\D/, ''); + fixedArray = fixedArray.substr(5, fixedArray.length); + var stringArray = fixedArray.toString(); + var addonURLIndex = stringArray.indexOf("?id="); + var addonURL = stringArray.slice(addonURLIndex + 4, addonURLIndex + 14) + mainWindow.webContents.send('currentAddonID', addonURL); + } }); }; }); diff --git a/index.html b/index.html index 94c3a91..fc22789 100644 --- a/index.html +++ b/index.html @@ -200,7 +200,7 @@

Creating GMA...

-

Uploading to the workshop...

+

Uploading to the workshop...

diff --git a/package.json b/package.json index 2008938..a4f56b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gmod-addon-tool", - "version": "2.1.0", + "version": "2.2.0", "description": "A simple tool to update Garry's Mod workshop addons.", "main": "app.js", "homepage": "https://leeous.com", diff --git a/src/js/script.js b/src/js/script.js index 1bdf554..38d68fa 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -32,7 +32,7 @@ addonToCreateData = { "tags": [], "ignore": [] }; -currentAppVersion = "v2.1"; +currentAppVersion = "v2.2"; let defaultMenuTitle = "" let onlyCreate = null; // This tells us if the user is only wanting to create a GMA let consoleData = new Array; @@ -168,7 +168,6 @@ $(document).ready(() => { // Let user select a GMA to extract $("#gmaFileSelection").click(() => { dialog.showOpenDialog(win, fileDialogOptions).then(r => { - let addonGMA = r.filePaths[0]; addonPath = r.filePaths[0]; if (addonGMA != null) { ipcRenderer.send("checkIfDirectoryExists", addonGMA); @@ -200,9 +199,9 @@ $(document).ready(() => { if (!result.canceled) { currentNewAddon = result.filePaths[0]; if (currentNewAddon != null) { + currentNewAddon = currentNewAddon.replace(/\\/g, "/"); ipcRenderer.send("checkIfDirectoryExists", currentNewAddon); - var n = currentNewAddon.lastIndexOf("\\"); - console.log(n); + var n = currentNewAddon.lastIndexOf("/"); var result = currentNewAddon.substring(n + 1); $("#addonDir b").text(result); $("#addonDirCheck").css("background-color", "#56bd56"); @@ -219,6 +218,7 @@ $(document).ready(() => { $("#addon_icon").click(() => { dialog.showOpenDialog(win, imgDialogOptions).then(result => { addonIcon = result.filePaths[0]; + addonIcon = addonIcon.replace(/\\/g, "/"); if (addonIcon != null) { ipcRenderer.send("checkIfDirectoryExists", addonIcon); } @@ -567,7 +567,8 @@ $(document).ready(() => { function resetAddonCreation() { jsonCheckboxCount = 0; onlyCreate = null; - jsonExists =null + jsonExists = null; + addonPath = null; // Clear the old data we used to make addon.json addonToCreateData = {