Skip to content

Commit ba02641

Browse files
committedFeb 24, 2020
Fix not loading more than 13 addons (#5)
1 parent e16c6dd commit ba02641

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed
 

‎app.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function createWindow() {
4747
// This method will be called when Electron has finished
4848
// initialization and is ready to create browser windows.
4949
// Some APIs can only be used after this event occurs.
50-
app.on('ready', createWindow)
50+
app.on('ready', createWindow);
5151

5252
// Quit when all windows are closed.
5353
app.on('window-all-closed', function() {
@@ -68,7 +68,7 @@ app.on('activate', function() {
6868
// Checks to see if the directory the user chooses is writeable
6969
ipcMain.on('checkIfDirectoryExists', (event, file) => {
7070
fs.access(file, fs.constants.R_OK, (err) => {
71-
console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);
71+
// console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);
7272
});
7373
})
7474

@@ -87,24 +87,24 @@ function sendClientAddonInfo() {
8787
bat.stdout.on('data', (data) => {
8888
var arrayOfOutput = data.toString().split('\n')
8989
var fixedArray = arrayOfOutput.slice(5, arrayOfOutput.length - 3)
90-
console.log(fixedArray)
90+
// console.log(fixedArray)
9191
for (var i = 0; i < fixedArray.length; i++) {
9292
fixedArray[i] = fixedArray[i].replace('/r', '');
93-
console.log(fixedArray)
93+
// console.log(fixedArray)
9494
ADDON_IDS.push([fixedArray[i].substr(0, 11).replace(/\s/g, '').toString()])
9595
}
9696

9797
if (fixedArray == "Couldn't initialize Steam!\r") {
9898
mainWindow.webContents.send('errorAlert', ADDON_IDS);
9999
}
100-
console.log(ADDON_IDS);
100+
// console.log(ADDON_IDS);
101101
mainWindow.webContents.send('addonInfo', ADDON_IDS);
102102
});
103103
}
104104

105105
// This creates our addon.json
106106
ipcMain.on('createJsonFile', (event, json, dir) => {
107-
console.log(json, dir)
107+
// console.log(json, dir)
108108
fs.writeFileSync(dir + "\\addon.json", json, 'utf8', (err) => {
109109
console.log("An error occured while writing JSON object to File.\n", err);
110110
mainWindow.webContents.send('error', "Error writing directory.");
@@ -131,7 +131,7 @@ ipcMain.on('uploadToWorkshop', (event, gmaDir, iconDir, addonId) => {
131131
const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['update', '-id', addonId, '-icon', iconDir, '-addon', gmaDir]);
132132
gmpublish.stdout.on('data', (data) => {
133133
var arrayOfOutput = data.toString().split('\n');
134-
console.log(arrayOfOutput)
134+
// console.log(arrayOfOutput)
135135
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 2, arrayOfOutput.length - 1);
136136
fixedArray = fixedArray[0].replace(/\D/, '');
137137
fixedArray = fixedArray.substr(5, fixedArray.length);
@@ -142,22 +142,22 @@ ipcMain.on('uploadToWorkshop', (event, gmaDir, iconDir, addonId) => {
142142
const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['create', '-icon', iconDir, '-addon', gmaDir]);
143143
gmpublish.stdout.on('data', (data) => {
144144
var arrayOfOutput = data.toString().split('\n');
145-
console.log(arrayOfOutput)
145+
// console.log(arrayOfOutput)
146146
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 2, arrayOfOutput.length - 1);
147147
fixedArray = fixedArray[0].replace(/\D/, '');
148148
fixedArray = fixedArray.substr(5, fixedArray.length);
149149
var stringArray = fixedArray.toString()
150150
var addonURLIndex = stringArray.indexOf("?id=")
151151
var addonURL = stringArray.slice(addonURLIndex + 4, addonURLIndex + 14)
152-
console.log(addonURL)
152+
// console.log(addonURL)
153153
mainWindow.webContents.send('currentAddonID', addonURL);
154154
});
155155
};
156156
});
157157

158158
// This will extract a GMA file to GarrysMod/garrysmod/addons/[addon_name]
159159
ipcMain.on("extractAddon", (e, path) => {
160-
console.log(e, path);
160+
// console.log(e, path);
161161
const gmad = spawn(settings.get('gmodDirectory') + '\\bin\\gmad.exe', ['extract', '-file', path]);
162162
mainWindow.webContents.send("finishExtraction");
163163
});

‎index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<p>Garry's Mod Addon Tool <span style='font-size: 0.7em; font-weight: 300; -webkit-app-region: no-drag;'>by <a href='https://leeous.github.io' target='_blank' style='text-decoration: underline; color: inherit;'>Leeous</a></span></p>
1717
</div>
1818
<div class="main_buttons">
19+
<p id="coffeeApp" title="Buy me a coffee? :)"></p>
1920
<p id="minApp"></p>
2021
<p id="closeApp">X</p>
2122
</div>
@@ -66,11 +67,11 @@ <h3>Addon creation</h3>
6667
<p style="font-size: 0.8em">Must be a JPEG/JPG</p>
6768
<button id="addon_icon" class="button_normal">Choose Directory</button>
6869
<div class="next_prompt">
69-
<button id="addonIconCheck" class="transition_button" data-divtoshow="#addonjsonPrompt" data-divtohide="#addonIconPrompt" data-resize="500, 175" disabled>Next</button>
70+
<button id="addonIconCheck" class="transition_button" data-divtoshow="#addonjsonPrompt" data-divtohide="#addonIconPrompt" data-resize="500, 200" disabled>Next</button>
7071
</div>
7172
</div>
7273
<div id="addonjsonPrompt">
73-
<p>Do you already have an <i>addon.json</i> file?</p>
74+
<h3>Do you already have an <i>addon.json</i> file?</h3>
7475
<div>
7576
<button class="button_normal transition_button removeBackOption" data-divtoshow="#jsonCreator" data-divtohide="#addonjsonPrompt" data-resize="500, 350">No</button>
7677
<button class="button_normal transition_button removeBackOption" data-divtoshow="#gmaPrep" data-divtohide="#addonjsonPrompt" data-resize="500, 200">Yes</button>

‎src/js/script.js

+48-13
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ $(document).ready(() => {
9393
remote.getCurrentWindow().minimize();
9494
});
9595

96+
$("#coffeeApp").click(() => {
97+
shell.openExternal("https://www.buymeacoffee.com/Leeous");
98+
});
99+
96100
// Validate that we have read/write access to the users Garrysmod directory so we can use gmad & gmpublish
97101
$("#gmod_dir_folder").click(() => {
98102
dialog.showOpenDialog(win, dirDialogOptions).then(result => {
@@ -210,7 +214,7 @@ $(document).ready(() => {
210214

211215
$("#update_existing_addon_button").click(() => {
212216
if (okToProcessAddonList) {
213-
populateAddonList();
217+
populateAddonList(addon_data);
214218
$("#addon_management_prompt").fadeOut(() => {
215219
win.setBounds({height: 250})
216220
$("#update_existing_addon").fadeIn();
@@ -241,6 +245,10 @@ $(document).ready(() => {
241245
goBack(divToGoBack, divToShow, resizeInfo);
242246
});
243247

248+
$("#create_addon_button").click(() => {
249+
$("#create_new_addon .top h3").text("Addon creation");
250+
});
251+
244252
$("#jsonAddonValidate").click(() => {
245253
if ($(".typeCheckbox:checked").val() != null) {
246254
addonTags = $(".typeCheckbox:checked").map(function(){
@@ -303,7 +311,7 @@ $(document).ready(() => {
303311
$(checkboxes).prop('disabled', true);
304312
}
305313
}
306-
})
314+
});
307315

308316
// Dyamically change boolean based on whether or not string is empty
309317
$("#jsonTitle > input[name='addonTitle']").on("keyup", () => {
@@ -378,21 +386,31 @@ $(document).ready(() => {
378386
// Request JSON infomation on addons based on ID (this cannot read from private addons)
379387
function getAddonInfoFromSteam(message) {
380388
arrayOfAddonIds = message;
381-
382-
api_data["itemcount"] = arrayOfAddonIds.length;
383-
389+
arrayOfAddonIds = arrayOfAddonIds.chunk(13)
384390
for (let i = 0; i < arrayOfAddonIds.length; i++) {
391+
sendAPIRequest(arrayOfAddonIds[i], arrayOfAddonIds[i].length, arrayOfAddonIds.length);
392+
}
393+
}
394+
395+
function sendAPIRequest(array, length, amtOfArrays) {
396+
397+
let queuePosition = 0
398+
399+
for (let i = 0; i < array.length; i++) {
385400
// const element = arrayOfAddonIds[i];
386-
api_data["publishedfileids[" + i + "]"] = parseInt(arrayOfAddonIds[i]);
401+
api_data["publishedfileids[" + i + "]"] = parseInt(array[i]);
387402
}
403+
404+
api_data["itemcount"] = array.length;
405+
388406
$.ajax({
389407
type: "POST",
390408
url: "https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/",
391409
data: api_data,
392410
dataType: "json",
393411
}).done((data) => {
394412
var response = data.response;
395-
console.log(response)
413+
console.log(response);
396414
if (response.result == 1) {
397415
for (let i = 0; i < response.resultcount; i++) {
398416
if (response.publishedfiledetails[i].result == 1) {
@@ -401,16 +419,32 @@ $(document).ready(() => {
401419
"title": addon.title,
402420
"id": addon.publishedfileid
403421
}
422+
queuePosition++;
404423
addon_data.push(addonObject);
405424
}
406425
}
407426
}
408-
okToProcessAddonList = true;
427+
428+
if (queuePosition != amtOfArrays) {
429+
okToProcessAddonList = true;
430+
$("#update_existing_addon_button").text("Update existing addon");
431+
}
409432
// Change button text and allow user to view/update thier addons
410-
$("#update_existing_addon_button").text("Update existing addon");
411433
});
412434
}
413435

436+
Object.defineProperty(Array.prototype, 'chunk', {
437+
value: function(chunkSize){
438+
var temporal = [];
439+
440+
for (var i = 0; i < this.length; i+= chunkSize){
441+
temporal.push(this.slice(i,i+chunkSize));
442+
}
443+
444+
return temporal;
445+
}
446+
});
447+
414448
// General function for transitioning between div tags (with a shitty name)
415449
function goBack(divToFadeOut, divToFadeIn, resizeInfo) {
416450
$(divToFadeOut).fadeOut(() => {
@@ -425,11 +459,12 @@ $(document).ready(() => {
425459
}
426460

427461
// Get array of addon infomation and append their info to #yourAddons
428-
function populateAddonList() {
462+
function populateAddonList(array) {
463+
console.log(array)
429464
// This check is done to make sure this only gets executed once
430465
if (!donePopulatingAddonList) {
431-
for (let i = 0; i < addon_data.length; i++) {
432-
$("#yourAddons").append("<div class='addon_existing'><p class='title'>" + addon_data[i].title + "</p><p class='addon_link'><a href='steam://url/CommunityFilePage/" + addon_data[i].id + "'>View</a><a href='#' class='updateAddon' data-id='" + addon_data[i].id + "'>Update</a></p></div>");
466+
for (let i = 0; i < array.length; i++) {
467+
$("#yourAddons").append("<div class='addon_existing'><p class='title'>" + array[i].title + "</p><p class='addon_link'><a href='steam://url/CommunityFilePage/" + array[i].id + "'>View</a><a href='#' class='updateAddon' data-id='" + array[i].id + "'>Update</a></p></div>");
433468
donePopulatingAddonList = true;
434469
}
435470
// Make sure if nothing is returned to let the user know
@@ -452,7 +487,7 @@ $(document).ready(() => {
452487
});
453488

454489
if (0 == addon_data.length) {
455-
$("#yourAddons").append("<p style='background-color: #0f0f0f; padding: 15px 10px; margin: 10px 15px; border-radius: 5px;'><b>No addons found!</b><br/><br/>Either you don't have Steam open or haven't uploaded anything.</p>");
490+
$("#yourAddons").append("<p style='background-color: #0f0f0f; padding: 15px 10px; margin: 10px 15px; border-radius: 5px;'><b>No addons found!</b><br/><br/>Either you don't have Steam open or haven't uploaded anything public.</p>");
456491
donePopulatingAddonList = true;
457492
}
458493
}

0 commit comments

Comments
 (0)
Failed to load comments.