Skip to content

Commit

Permalink
Fix not loading more than 13 addons (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leeous committed Feb 24, 2020
1 parent e16c6dd commit ba02641
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 25 deletions.
20 changes: 10 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function createWindow() {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
app.on('ready', createWindow);

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

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

if (fixedArray == "Couldn't initialize Steam!\r") {
mainWindow.webContents.send('errorAlert', ADDON_IDS);
}
console.log(ADDON_IDS);
// console.log(ADDON_IDS);
mainWindow.webContents.send('addonInfo', ADDON_IDS);
});
}

// This creates our addon.json
ipcMain.on('createJsonFile', (event, json, dir) => {
console.log(json, dir)
// console.log(json, dir)
fs.writeFileSync(dir + "\\addon.json", json, 'utf8', (err) => {
console.log("An error occured while writing JSON object to File.\n", err);
mainWindow.webContents.send('error', "Error writing directory.");
Expand All @@ -131,7 +131,7 @@ ipcMain.on('uploadToWorkshop', (event, gmaDir, iconDir, addonId) => {
const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['update', '-id', addonId, '-icon', iconDir, '-addon', gmaDir]);
gmpublish.stdout.on('data', (data) => {
var arrayOfOutput = data.toString().split('\n');
console.log(arrayOfOutput)
// console.log(arrayOfOutput)
var fixedArray = arrayOfOutput.slice(arrayOfOutput.length - 2, arrayOfOutput.length - 1);
fixedArray = fixedArray[0].replace(/\D/, '');
fixedArray = fixedArray.substr(5, fixedArray.length);
Expand All @@ -142,22 +142,22 @@ ipcMain.on('uploadToWorkshop', (event, gmaDir, iconDir, addonId) => {
const gmpublish = spawn(settings.get('gmodDirectory') + '\\bin\\gmpublish.exe', ['create', '-icon', iconDir, '-addon', gmaDir]);
gmpublish.stdout.on('data', (data) => {
var arrayOfOutput = data.toString().split('\n');
console.log(arrayOfOutput)
// console.log(arrayOfOutput)
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)
console.log(addonURL)
// console.log(addonURL)
mainWindow.webContents.send('currentAddonID', addonURL);
});
};
});

// This will extract a GMA file to GarrysMod/garrysmod/addons/[addon_name]
ipcMain.on("extractAddon", (e, path) => {
console.log(e, path);
// console.log(e, path);
const gmad = spawn(settings.get('gmodDirectory') + '\\bin\\gmad.exe', ['extract', '-file', path]);
mainWindow.webContents.send("finishExtraction");
});
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<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>
</div>
<div class="main_buttons">
<p id="coffeeApp" title="Buy me a coffee? :)"></p>
<p id="minApp"></p>
<p id="closeApp">X</p>
</div>
Expand Down Expand Up @@ -66,11 +67,11 @@ <h3>Addon creation</h3>
<p style="font-size: 0.8em">Must be a JPEG/JPG</p>
<button id="addon_icon" class="button_normal">Choose Directory</button>
<div class="next_prompt">
<button id="addonIconCheck" class="transition_button" data-divtoshow="#addonjsonPrompt" data-divtohide="#addonIconPrompt" data-resize="500, 175" disabled>Next</button>
<button id="addonIconCheck" class="transition_button" data-divtoshow="#addonjsonPrompt" data-divtohide="#addonIconPrompt" data-resize="500, 200" disabled>Next</button>
</div>
</div>
<div id="addonjsonPrompt">
<p>Do you already have an <i>addon.json</i> file?</p>
<h3>Do you already have an <i>addon.json</i> file?</h3>
<div>
<button class="button_normal transition_button removeBackOption" data-divtoshow="#jsonCreator" data-divtohide="#addonjsonPrompt" data-resize="500, 350">No</button>
<button class="button_normal transition_button removeBackOption" data-divtoshow="#gmaPrep" data-divtohide="#addonjsonPrompt" data-resize="500, 200">Yes</button>
Expand Down
61 changes: 48 additions & 13 deletions src/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ $(document).ready(() => {
remote.getCurrentWindow().minimize();
});

$("#coffeeApp").click(() => {
shell.openExternal("https://www.buymeacoffee.com/Leeous");
});

// Validate that we have read/write access to the users Garrysmod directory so we can use gmad & gmpublish
$("#gmod_dir_folder").click(() => {
dialog.showOpenDialog(win, dirDialogOptions).then(result => {
Expand Down Expand Up @@ -210,7 +214,7 @@ $(document).ready(() => {

$("#update_existing_addon_button").click(() => {
if (okToProcessAddonList) {
populateAddonList();
populateAddonList(addon_data);
$("#addon_management_prompt").fadeOut(() => {
win.setBounds({height: 250})
$("#update_existing_addon").fadeIn();
Expand Down Expand Up @@ -241,6 +245,10 @@ $(document).ready(() => {
goBack(divToGoBack, divToShow, resizeInfo);
});

$("#create_addon_button").click(() => {
$("#create_new_addon .top h3").text("Addon creation");
});

$("#jsonAddonValidate").click(() => {
if ($(".typeCheckbox:checked").val() != null) {
addonTags = $(".typeCheckbox:checked").map(function(){
Expand Down Expand Up @@ -303,7 +311,7 @@ $(document).ready(() => {
$(checkboxes).prop('disabled', true);
}
}
})
});

// Dyamically change boolean based on whether or not string is empty
$("#jsonTitle > input[name='addonTitle']").on("keyup", () => {
Expand Down Expand Up @@ -378,21 +386,31 @@ $(document).ready(() => {
// Request JSON infomation on addons based on ID (this cannot read from private addons)
function getAddonInfoFromSteam(message) {
arrayOfAddonIds = message;

api_data["itemcount"] = arrayOfAddonIds.length;

arrayOfAddonIds = arrayOfAddonIds.chunk(13)
for (let i = 0; i < arrayOfAddonIds.length; i++) {
sendAPIRequest(arrayOfAddonIds[i], arrayOfAddonIds[i].length, arrayOfAddonIds.length);
}
}

function sendAPIRequest(array, length, amtOfArrays) {

let queuePosition = 0

for (let i = 0; i < array.length; i++) {
// const element = arrayOfAddonIds[i];
api_data["publishedfileids[" + i + "]"] = parseInt(arrayOfAddonIds[i]);
api_data["publishedfileids[" + i + "]"] = parseInt(array[i]);
}

api_data["itemcount"] = array.length;

$.ajax({
type: "POST",
url: "https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/",
data: api_data,
dataType: "json",
}).done((data) => {
var response = data.response;
console.log(response)
console.log(response);
if (response.result == 1) {
for (let i = 0; i < response.resultcount; i++) {
if (response.publishedfiledetails[i].result == 1) {
Expand All @@ -401,16 +419,32 @@ $(document).ready(() => {
"title": addon.title,
"id": addon.publishedfileid
}
queuePosition++;
addon_data.push(addonObject);
}
}
}
okToProcessAddonList = true;

if (queuePosition != amtOfArrays) {
okToProcessAddonList = true;
$("#update_existing_addon_button").text("Update existing addon");
}
// Change button text and allow user to view/update thier addons
$("#update_existing_addon_button").text("Update existing addon");
});
}

Object.defineProperty(Array.prototype, 'chunk', {
value: function(chunkSize){
var temporal = [];

for (var i = 0; i < this.length; i+= chunkSize){
temporal.push(this.slice(i,i+chunkSize));
}

return temporal;
}
});

// General function for transitioning between div tags (with a shitty name)
function goBack(divToFadeOut, divToFadeIn, resizeInfo) {
$(divToFadeOut).fadeOut(() => {
Expand All @@ -425,11 +459,12 @@ $(document).ready(() => {
}

// Get array of addon infomation and append their info to #yourAddons
function populateAddonList() {
function populateAddonList(array) {
console.log(array)
// This check is done to make sure this only gets executed once
if (!donePopulatingAddonList) {
for (let i = 0; i < addon_data.length; i++) {
$("#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>");
for (let i = 0; i < array.length; i++) {
$("#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>");
donePopulatingAddonList = true;
}
// Make sure if nothing is returned to let the user know
Expand All @@ -452,7 +487,7 @@ $(document).ready(() => {
});

if (0 == addon_data.length) {
$("#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>");
$("#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>");
donePopulatingAddonList = true;
}
}
Expand Down

0 comments on commit ba02641

Please sign in to comment.