8
8
} = require ( 'electron' ) ;
9
9
const fs = require ( 'fs' ) ;
10
10
const { spawn } = require ( 'cross-spawn' ) ;
11
+ const dialog = require ( 'dialog' ) ;
11
12
const settings = require ( 'electron-settings' ) ;
12
13
const homeDir = require ( 'os' ) . homedir ( ) ;
13
14
// Keep a global reference of the window object, if you don't, the window will
@@ -34,6 +35,23 @@ console.log('\n');
34
35
//################//
35
36
36
37
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
+
37
55
app . allowRendererProcessReuse = true ;
38
56
39
57
// Create the browser window.
@@ -115,6 +133,7 @@ if (isWin) {
115
133
}
116
134
117
135
function openSettings ( callback ) {
136
+
118
137
promptWindow = new BrowserWindow ( {
119
138
width : 250 ,
120
139
height : 275 ,
@@ -210,17 +229,11 @@ ipcMain.on('getAddonInfo', () => {
210
229
211
230
// We use this to get the addon IDs from gmpublish.exe
212
231
function sendClientAddonInfo ( ) {
213
- fs . stat ( settings . get ( 'gmodDirectory' ) + '/bin/gmad.exe' , ( err , stat ) => {
214
- if ( err ) {
215
- mainWindow . webContents . send ( "wrongDirectory" ) ;
216
- }
217
- } ) ;
218
-
219
232
const bat = spawn ( settings . get ( 'gmodDirectory' ) + '/bin/' + gmpublishFile , [ 'list' ] ) ;
220
233
bat . stdout . on ( 'data' , ( data ) => {
221
234
sendConsoleData ( data . toString ( ) . split ( "\n" ) ) ;
222
235
var arrayOfOutput = data . toString ( ) . split ( '\n' ) ;
223
- // fixedArray are the lines where we get a
236
+ //fixedArray should be a list of addon IDs
224
237
var fixedArray = arrayOfOutput . slice ( 5 , arrayOfOutput . length - 3 ) ;
225
238
if ( data . includes ( "Couldn't initialize Steam!" ) ) {
226
239
mainWindow . webContents . send ( 'errorNote' , "Steam doesn't seem to be open!" , true , false ) ;
0 commit comments