Skip to content

Commit

Permalink
Fix #25, add check for sudden change in gmod directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Leeous committed Jun 21, 2022
1 parent 3d441db commit 3e098b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
27 changes: 20 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
} = require('electron');
const fs = require('fs');
const { spawn } = require('cross-spawn');
const dialog = require('dialog');
const settings = require('electron-settings');
const homeDir = require('os').homedir();
// Keep a global reference of the window object, if you don't, the window will
Expand All @@ -34,6 +35,23 @@ console.log('\n');
//################//

function createWindow() {
// Called before anything else
if (settings.get('gmodDirectory')) {
fs.stat(settings.get('gmodDirectory') + "/bin/" + gmadFile, (err, stat) => {
if (err) {
dialog.err("It seems like your Garry's Mod directory has changed.\nResetting user settings so you can set your directory again.", "Gmad.exe not found", () => {
// Clear all settings
settings.deleteAll();

// Relaunch app so user can show where the directory has moved
setTimeout(() => {
app.relaunch(); app.exit();
}, 500);
});
}
});
}

app.allowRendererProcessReuse = true;

// Create the browser window.
Expand Down Expand Up @@ -115,6 +133,7 @@ if (isWin) {
}

function openSettings(callback) {

promptWindow = new BrowserWindow({
width: 250,
height: 275,
Expand Down Expand Up @@ -210,17 +229,11 @@ ipcMain.on('getAddonInfo', () => {

// We use this to get the addon IDs from gmpublish.exe
function sendClientAddonInfo() {
fs.stat(settings.get('gmodDirectory') + '/bin/gmad.exe', (err, stat) => {
if (err) {
mainWindow.webContents.send("wrongDirectory");
}
});

const bat = spawn(settings.get('gmodDirectory') + '/bin/' + gmpublishFile, ['list']);
bat.stdout.on('data', (data) => {
sendConsoleData(data.toString().split("\n"));
var arrayOfOutput = data.toString().split('\n');
// fixedArray are the lines where we get a
//fixedArray should be a list of addon IDs
var fixedArray = arrayOfOutput.slice(5, arrayOfOutput.length - 3);
if (data.includes("Couldn't initialize Steam!")) {
mainWindow.webContents.send('errorNote', "Steam doesn't seem to be open!", true, false);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"homepage": "https://leeous.com",
"dependencies": {
"cross-spawn": "^7.0.1",
"dialog": "^0.3.1",
"electron-settings": "^3.2.0",
"g": "^2.0.1",
"image-size": "^0.8.3",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,11 @@ detect-node@^2.0.4:
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.1.0.tgz#c9c70775a49c3d03bc2c06d9a73be550f978f8b1"
integrity sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==

dialog@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/dialog/-/dialog-0.3.1.tgz#8fd9b47fdb277bb9e82172bb6e26bc578aa61254"
integrity sha512-RYndSaXW/tYkfVbUKmyQzerHH080Pis7YabDxIHXRdYO6yo9/VqTIhPRB5RpoHwYlixeiUOvJCF7di+lmBaH6w==

dir-compare@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/dir-compare/-/dir-compare-2.4.0.tgz#785c41dc5f645b34343a4eafc50b79bac7f11631"
Expand Down

0 comments on commit 3e098b6

Please sign in to comment.