Skip to content

Commit 3e098b6

Browse files
committedJun 21, 2022
Fix #25, add check for sudden change in gmod directory
1 parent 3d441db commit 3e098b6

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed
 

‎app.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
} = require('electron');
99
const fs = require('fs');
1010
const { spawn } = require('cross-spawn');
11+
const dialog = require('dialog');
1112
const settings = require('electron-settings');
1213
const homeDir = require('os').homedir();
1314
// Keep a global reference of the window object, if you don't, the window will
@@ -34,6 +35,23 @@ console.log('\n');
3435
//################//
3536

3637
function createWindow() {
38+
// Called before anything else
39+
if (settings.get('gmodDirectory')) {
40+
fs.stat(settings.get('gmodDirectory') + "/bin/" + gmadFile, (err, stat) => {
41+
if (err) {
42+
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", () => {
43+
// Clear all settings
44+
settings.deleteAll();
45+
46+
// Relaunch app so user can show where the directory has moved
47+
setTimeout(() => {
48+
app.relaunch(); app.exit();
49+
}, 500);
50+
});
51+
}
52+
});
53+
}
54+
3755
app.allowRendererProcessReuse = true;
3856

3957
// Create the browser window.
@@ -115,6 +133,7 @@ if (isWin) {
115133
}
116134

117135
function openSettings(callback) {
136+
118137
promptWindow = new BrowserWindow({
119138
width: 250,
120139
height: 275,
@@ -210,17 +229,11 @@ ipcMain.on('getAddonInfo', () => {
210229

211230
// We use this to get the addon IDs from gmpublish.exe
212231
function sendClientAddonInfo() {
213-
fs.stat(settings.get('gmodDirectory') + '/bin/gmad.exe', (err, stat) => {
214-
if (err) {
215-
mainWindow.webContents.send("wrongDirectory");
216-
}
217-
});
218-
219232
const bat = spawn(settings.get('gmodDirectory') + '/bin/' + gmpublishFile, ['list']);
220233
bat.stdout.on('data', (data) => {
221234
sendConsoleData(data.toString().split("\n"));
222235
var arrayOfOutput = data.toString().split('\n');
223-
// fixedArray are the lines where we get a
236+
//fixedArray should be a list of addon IDs
224237
var fixedArray = arrayOfOutput.slice(5, arrayOfOutput.length - 3);
225238
if (data.includes("Couldn't initialize Steam!")) {
226239
mainWindow.webContents.send('errorNote', "Steam doesn't seem to be open!", true, false);

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"homepage": "https://leeous.com",
77
"dependencies": {
88
"cross-spawn": "^7.0.1",
9+
"dialog": "^0.3.1",
910
"electron-settings": "^3.2.0",
1011
"g": "^2.0.1",
1112
"image-size": "^0.8.3",

‎yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,11 @@ detect-node@^2.0.4:
694694
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.1.0.tgz#c9c70775a49c3d03bc2c06d9a73be550f978f8b1"
695695
integrity sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==
696696

697+
dialog@^0.3.1:
698+
version "0.3.1"
699+
resolved "https://registry.yarnpkg.com/dialog/-/dialog-0.3.1.tgz#8fd9b47fdb277bb9e82172bb6e26bc578aa61254"
700+
integrity sha512-RYndSaXW/tYkfVbUKmyQzerHH080Pis7YabDxIHXRdYO6yo9/VqTIhPRB5RpoHwYlixeiUOvJCF7di+lmBaH6w==
701+
697702
dir-compare@^2.4.0:
698703
version "2.4.0"
699704
resolved "https://registry.yarnpkg.com/dir-compare/-/dir-compare-2.4.0.tgz#785c41dc5f645b34343a4eafc50b79bac7f11631"

0 commit comments

Comments
 (0)
Failed to load comments.