Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 8b28158

Browse files
committed
fix #3, preview final features
1 parent cfb93d2 commit 8b28158

File tree

6 files changed

+83
-43
lines changed

6 files changed

+83
-43
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
general.todo

index.js renamed to app.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
const {
33
app,
44
BrowserWindow,
5-
ipcMain
5+
ipcMain,
6+
dialog
67
} = require('electron')
78
const fs = require('fs')
89
const { spawn } = require('child_process');
910
const settings = require('electron-settings');
10-
1111
// Keep a global reference of the window object, if you don't, the window will
1212
// be closed automatically when the JavaScript object is garbage collected.
1313
let mainWindow
@@ -98,20 +98,22 @@ function sendClientAddonInfo() {
9898
ADDON_IDS.push([fixedArray[i].substr(0, 11).replace(/\s/g, '').toString()])
9999
}
100100

101-
console.log(ADDON_IDS)
102-
console.log('Sent to client!')
101+
if (fixedArray == "Couldn't initialize Steam!\r") {
102+
mainWindow.webContents.send('errorAlert', ADDON_IDS);
103+
}
103104
mainWindow.webContents.send('addonInfo', ADDON_IDS);
104105
});
105106
}
106107

107108
ipcMain.on('createJsonFile', (event, json, dir) => {
108109
console.log(json, dir)
109110
fs.writeFileSync(dir + "\\addon.json", json, 'utf8', (err) => {
110-
console.log("An error occured while writing JSON Object to File.\n", err);
111+
console.log("An error occured while writing JSON object to File.\n", err);
111112
mainWindow.webContents.send('error', "Error writing directory.");
112113
});
113114
});
114115

116+
// This is ran once the client requests to create an addon
115117
ipcMain.on('createGMAFile', (event, addonDir) => {
116118
console.log("Addon's Directory: " + addonDir.toString())
117119
const gmad = spawn(settings.get('gmodDirectory') + '\\bin\\gmad.exe', ['create', '-folder', addonDir]);
@@ -125,6 +127,7 @@ ipcMain.on('createGMAFile', (event, addonDir) => {
125127
});
126128
});
127129

130+
// This block will upload the GMA file to the Steam Workshop
128131
ipcMain.on('uploadToWorkshop', (event, gmaDir, iconDir, addonId) => {
129132
if (addonId != null) {
130133
const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['update', '-id', addonId, '-icon', iconDir, '-addon', gmaDir]);
@@ -133,26 +136,24 @@ ipcMain.on('uploadToWorkshop', (event, gmaDir, iconDir, addonId) => {
133136
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7);
134137
fixedArray = fixedArray[0].replace(/\D/, '');
135138
fixedArray = fixedArray.substr(5, fixedArray.length);
136-
console.log(fixedArray);
137139
mainWindow.webContents.send('currentAddonID', fixedArray);
138140
});
139141
} else {
142+
// Passes all the info needed to publish a Garry's Mod addon
140143
const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['create', '-icon', iconDir, '-addon', gmaDir]);
141144
gmpublish.stdout.on('data', (data) => {
142145
var arrayOfOutput = data.toString().split('\n');
143-
console.log(data.toString);
144-
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 8, arrayOfOutput.length - 7);
146+
console.log(arrayOfOutput)
147+
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 2, arrayOfOutput.length - 1);
145148
fixedArray = fixedArray[0].replace(/\D/, '');
146149
fixedArray = fixedArray.substr(5, fixedArray.length);
147-
console.log(fixedArray);
148-
mainWindow.webContents.send('currentAddonID', fixedArray);
150+
var stringArray = fixedArray.toString()
151+
var addonURLIndex = stringArray.indexOf("?id=")
152+
var addonURL = stringArray.slice(addonURLIndex + 4, addonURLIndex + 14)
153+
console.log(addonURL)
154+
mainWindow.webContents.send('currentAddonID', addonURL);
149155
});
150156
};
151-
152-
})
153-
154-
155-
156-
157+
});
157158

158159
// gmpublish.exe create -icon path/to/image512x512.jpg -addon path/to/gma.gma

index.html

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,30 @@ <h4 style="font-weight: 300; margin: 10px">Steam <b>must</b> be open!</h4>
3535
<div id="addon_management">
3636
<div id="addon_management_prompt">
3737
<h3>What would you like to do?</h3>
38-
<button id="create_new_addon_button" class="button_normal medium-text" style="margin: 10px;">Create a new addon</button>
39-
<button id="update_existing_addon_button" class="button_normal medium-text" style="margin: 10px;">Loading...</button>
38+
<div id="addon_mgt_btn_grid">
39+
<button id="create_new_addon_button" class="button_normal medium-text" style="margin: 10px;">Create a new addon</button>
40+
<button id="update_existing_addon_button" class="button_normal medium-text" style="margin: 10px;">Loading...</button>
41+
<button class="button_normal medium-text" style="margin: 10px;">Extract Addon</button>
42+
<button class="button_normal medium-text" style="margin: 10px;">Download Addon</button>
43+
</div>
4044
</div>
4145
<div id="update_existing_addon">
4246
<div class="top">
43-
<button id="back_button_existing_addon" class="back_button" data-backwards="#addon_management_prompt" data-forwards="#update_existing_addon" data-resize="500, 175">◀ Back</button>
47+
<button id="back_button_existing_addon" class="back_button" data-backwards="#addon_management_prompt" data-forwards="#update_existing_addon" data-resize="500, 200">◀ Back</button>
4448
<h3>Your addons</h3>
4549
</div>
4650
<div id="yourAddons"></div>
4751
</div>
4852
<div id="create_new_addon">
4953
<div class="top">
50-
<button id="back_button_addon_creation" class="back_button" data-backwards="#addon_management_prompt" data-forwards="#create_new_addon" data-resize="500, 175">◀ Back</button>
54+
<button id="back_button_addon_creation" class="back_button" data-backwards="#addon_management_prompt" data-forwards="#create_new_addon" data-resize="500, 200">◀ Back</button>
5155
<h3>Addon creation</h3>
5256
</div>
5357
<div id="addon_creation">
5458
<div id="addonDirPrompt">
5559
<p>Please select your addon's folder</p>
5660
<button class="button_normal fake_select" data-buttonclick="#addon_dir_folder">Choose Directory</button>
57-
<input id="addon_dir_folder" class="real_select" type="file" webkitdirectory />
61+
<input id="addon_dir_folder" class="real_select" type="button"/>
5862
<p id="addonDir"><b></b></p>
5963
<div class="next_prompt">
6064
<button id="addonDirCheck" class="transition_button" data-divtoshow="#addonIconPrompt" data-divtohide="#addonDirPrompt" data-resize="500, 250" disabled>Next</button>
@@ -160,7 +164,7 @@ <h3>Addon creation</h3>
160164
<div id="gmaPrep">
161165
<!-- <p>Created <span style="font-weight: 700">addon.json</span>!</p> -->
162166
<h3>Create GMA for uploading to the Workshop?</h3>
163-
<button style="width: 100px;" class="button_normal transition_button resetAddonCreation" data-divtohide="#create_new_addon" data-divtoshow="#addon_management_prompt" data-resize="500, 175">No</button>
167+
<button style="width: 100px;" class="button_normal transition_button resetAddonCreation" data-divtohide="#create_new_addon" data-divtoshow="#addon_management_prompt" data-resize="500, 200">No</button>
164168
<button style="width: 100px;" id="createGMAFile" class="button_normal transition_button">Yes</button>
165169
<!-- <img src="src/img/loading.gif" style="display: block; margin-left: auto; margin-right: auto; width: 64px;" alt=""> -->
166170
</div>
@@ -180,10 +184,15 @@ <h3>Upload to the Workshop?</h3>
180184
<div id="new_addon">
181185
<h3>Uploaded!</h3>
182186
<p><a id="new_addon_link" style="color: white;" href="#">View on Steam</a></p>
183-
<button class="button_normal transition_button resetAddonCreation" data-divtohide="#create_new_addon" data-divtoshow="#addon_management_prompt" data-resize="500, 175" style="width: 100px;">Done</button>
187+
<button class="button_normal transition_button resetAddonCreation" data-divtohide="#create_new_addon" data-divtoshow="#addon_management_prompt" data-resize="500, 200" style="width: 100px;">Done</button>
184188
</div>
185189
</div>
186190
</div>
191+
<div id="extract_addon">
192+
<div class="top">
193+
<h3>Addon Extraction</h3>
194+
</div>
195+
</div>
187196
</div>
188197
<div id="errorNote">
189198
<p>Error: <span id="error"></span></p>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gmod-addon-tool",
33
"version": "1.0.0",
44
"description": "A simple tool to update workshop addons.",
5-
"main": "index.js",
5+
"main": "app.js",
66
"dependencies": {
77
"cross-spawn": "^6.0.5",
88
"electron-settings": "^3.2.0",

src/css/style.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ header {
4040
}
4141

4242
/* IDs */
43+
#addon_mgt_btn_grid {
44+
display: grid;
45+
grid-row: 2;
46+
grid-template-columns: auto auto;
47+
}
4348

4449
#addon_management_prompt .button_normal {
4550
margin: 15px 0;
4651
box-shadow: 0 5px #797979;
4752
transition: none;
53+
display: inline-block;
4854
}
4955

5056
#addon_management_prompt .button_normal:active {
@@ -164,7 +170,12 @@ header {
164170
text-align: center;
165171
}
166172

167-
#update_existing_addon, #directory_selection, #create_new_addon, #jsonCreator, #gmaPrep, #addonjsonPrompt, #addon_management_prompt, #createGMA, #uploadToWorkshopPrompt, #addonIconPrompt, #uploading, #new_addon, #errorNote {
173+
#addon_management {
174+
display: none;
175+
text-align: center;
176+
}
177+
178+
#update_existing_addon, #directory_selection, #create_new_addon, #jsonCreator, #gmaPrep, #addonjsonPrompt, #addon_management_prompt, #createGMA, #uploadToWorkshopPrompt, #addonIconPrompt, #uploading, #new_addon, #errorNote, #extract_addon {
168179
display: none;
169180
}
170181

src/js/script.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const {
77
const settings = require("electron-settings");
88
const shell = require("electron").shell;
99
const imageSize = require("image-size");
10+
const { dialog } = require('electron').remote
1011
let win = remote.getCurrentWindow();
11-
1212
addon_data = [];
1313
api_data = {
1414
"itemcount": "0",
@@ -31,9 +31,16 @@ addonToCreateData = {
3131
"tags": [],
3232
"ignore": []
3333
}
34-
currentAppVersion = "v1.2";
35-
36-
34+
currentAppVersion = "v1.3";
35+
36+
let dirDialogOptions = {
37+
title : "Select your addon's folder",
38+
buttonLabel : "Select Folder",
39+
filters :[
40+
{name: 'All Folders', extensions: ['*']}
41+
],
42+
properties: ['openDirectory']
43+
}
3744

3845
// Make links open in enternal browser
3946
$(document).on("click", "a[href^='http']", function(event) {
@@ -48,6 +55,11 @@ $(document).ready(() => {
4855
getAddonInfoFromSteam(message)
4956
});
5057

58+
// Sends an alert if Steam doesn't initialize
59+
ipcRenderer.on("errorAlert", (event, message) => {
60+
alert("Steam doesn't seem open!\nOpen Steam and restart. ")
61+
});
62+
5163
// Check current version, let user know if it differs
5264
$.ajax({
5365
type: "GET",
@@ -65,8 +77,7 @@ $(document).ready(() => {
6577
function getAddonInfoFromSteam(message) {
6678
arrayOfAddonIds = message;
6779

68-
api_data['itemcount'] = arrayOfAddonIds.length;
69-
80+
api_data['itemcount'] = arrayOfAddonIds.length;
7081

7182
for (let i = 0; i < arrayOfAddonIds.length; i++) {
7283
// const element = arrayOfAddonIds[i];
@@ -102,7 +113,7 @@ $(document).ready(() => {
102113
$('#addon_management').fadeIn();
103114
$('#addon_management_prompt').fadeIn();
104115
win.setBounds({
105-
height: 175
116+
height: 200
106117
})
107118
ipcRenderer.send('getAddonInfo');
108119
} else {
@@ -151,16 +162,22 @@ $(document).ready(() => {
151162
})
152163

153164
// If directory exists (and is writable/readable) allow user to procede
154-
$('#addon_dir_folder').change(() => {
155-
currentNewAddon = document.getElementById("addon_dir_folder").files[0].path;
156-
ipcRenderer.send('checkIfDirectoryExists', currentNewAddon);
157-
var n = currentNewAddon.lastIndexOf('\\');
158-
var result = currentNewAddon.substring(n + 1);
159-
$('#addonDir b').text(result);
160-
$('#addonDirCheck').css('background-color', '#56bd56');
161-
$('#addonDirCheck').prop('disabled', false);
162-
$('#addonDirCheck').css('cursor', 'pointer');
163-
})
165+
$('#addon_dir_folder').click(() => {
166+
dialog.showOpenDialog(win, dirDialogOptions).then(result => {
167+
if (!result.canceled) {
168+
currentNewAddon = result.filePaths[0];
169+
ipcRenderer.send('checkIfDirectoryExists', currentNewAddon);
170+
var n = currentNewAddon.lastIndexOf('\\');
171+
var result = currentNewAddon.substring(n + 1);
172+
$('#addonDir b').text(result);
173+
$('#addonDirCheck').css('background-color', '#56bd56');
174+
$('#addonDirCheck').prop('disabled', false);
175+
$('#addonDirCheck').css('cursor', 'pointer');
176+
}
177+
}).catch(err => {
178+
console.log("dialog error")
179+
});
180+
});
164181

165182
$('#addon_icon').change(() => {
166183
addonIcon = document.getElementById("addon_icon").files[0].path;
@@ -190,7 +207,7 @@ $(document).ready(() => {
190207
$('#addon_management').fadeIn();
191208
$('#addon_management_prompt').fadeIn();
192209
win.setBounds({
193-
height: 175,
210+
height: 200,
194211
})
195212
});
196213
})
@@ -418,6 +435,7 @@ $(document).ready(() => {
418435
$('#gmaPrep').fadeOut(() => {
419436
win.setBounds({height: 250});
420437
$('#createGMA').fadeIn();
438+
console.log(currentNewAddon)
421439
ipcRenderer.send('createGMAFile', currentNewAddon);
422440
});
423441
});

0 commit comments

Comments
 (0)