@@ -54,10 +54,10 @@ public void Shutdown(string parameter) {
54
54
if ( parameter == "abort" ) {
55
55
shutdownParameters = "abort" ;
56
56
} else {
57
- if ( parameter . Contains ( "/t" ) ) {
58
- shutdownParameters = ! parameter . Contains ( "/s" ) ? "/s " : "" + parameter ;
57
+ if ( parameter . Contains ( "/t" ) || parameter . Contains ( "-t" ) ) {
58
+ shutdownParameters = ! parameter . Contains ( "/s" ) && ! parameter . Contains ( "-s" ) ? "/s " : "" + parameter ;
59
59
} else {
60
- shutdownParameters = ! parameter . Contains ( "/s" ) ? "/s " : "" + parameter + " /t 0" ;
60
+ shutdownParameters = ! parameter . Contains ( "/s" ) && ! parameter . Contains ( "-s" ) ? "/s " : "" + parameter + " /t 0" ;
61
61
}
62
62
}
63
63
}
@@ -86,10 +86,10 @@ public void Restart(string parameter) {
86
86
if ( parameter == "abort" ) {
87
87
restartParameters = "abort" ;
88
88
} else {
89
- if ( parameter . Contains ( "/t" ) ) {
90
- restartParameters = ! parameter . Contains ( "/r" ) ? "/s " : "" + parameter ;
89
+ if ( parameter . Contains ( "/t" ) || parameter . Contains ( "-t" ) ) {
90
+ restartParameters = ! parameter . Contains ( "/r" ) && ! parameter . Contains ( "-r" ) ? "/r " : "" + parameter ;
91
91
} else {
92
- restartParameters = ! parameter . Contains ( "/r" ) ? "/s " : "" + parameter + " /t 0" ;
92
+ restartParameters = ! parameter . Contains ( "/r" ) && ! parameter . Contains ( "-r" ) ? "/r " : "" + parameter + " /t 0" ;
93
93
}
94
94
}
95
95
}
@@ -194,7 +194,7 @@ public void Lock(string parameter) {
194
194
successMessage = "Simulated PC lock" ;
195
195
} else {
196
196
MainProgram . DoDebug ( "Locking computer..." ) ;
197
- // wasFatal = true;
197
+ wasFatal = true ;
198
198
LockWorkStation ( ) ;
199
199
successMessage = "Locked pc" ;
200
200
}
@@ -204,7 +204,12 @@ public void Mute(string parameter) {
204
204
205
205
if ( parameter == null ) {
206
206
//No parameter - toggle
207
- doMute = ! AudioManager . GetMasterVolumeMute ( ) ;
207
+ try {
208
+ doMute = ! AudioManager . GetMasterVolumeMute ( ) ;
209
+ } catch {
210
+ MainProgram . DoDebug ( "No volume object (most likely)" ) ;
211
+ MainProgram . errorMessage = "Failed to mute; no volume object." ;
212
+ }
208
213
} else {
209
214
//Parameter set;
210
215
switch ( parameter ) {
@@ -247,15 +252,25 @@ public void SetVolume(string parameter) {
247
252
MainProgram . errorMessage = "Failed to unmute PC" ;
248
253
}
249
254
}
250
- AudioManager . SetMasterVolume ( ( float ) volumeLevel ) ;
255
+ try {
256
+ AudioManager . SetMasterVolume ( ( float ) volumeLevel ) ;
257
+ } catch {
258
+ //Might not have an audio device...
259
+ MainProgram . DoDebug ( "Failed to set PC volume. Exception caught." ) ;
260
+ MainProgram . errorMessage = "Failed to set PC volume" ;
261
+ }
251
262
}
252
263
if ( ! MainProgram . testingAction ) {
253
- if ( ( int ) AudioManager . GetMasterVolume ( ) != ( int ) volumeLevel ) {
254
- //Something went wrong... Audio not set to parameter-level
255
- MainProgram . DoDebug ( "ERROR: Volume was not set properly. Master volume is " + AudioManager . GetMasterVolume ( ) + ", not " + volumeLevel ) ;
256
- MainProgram . errorMessage = "Something went wrong when setting the volume" ;
257
- } else {
258
- successMessage = "Set volume to " + volumeLevel + "%" ;
264
+ try {
265
+ if ( ( int ) AudioManager . GetMasterVolume ( ) != ( int ) volumeLevel ) {
266
+ //Something went wrong... Audio not set to parameter-level
267
+ MainProgram . DoDebug ( "ERROR: Volume was not set properly. Master volume is " + AudioManager . GetMasterVolume ( ) + ", not " + volumeLevel ) ;
268
+ MainProgram . errorMessage = "Something went wrong when setting the volume" ;
269
+ } else {
270
+ successMessage = "Set volume to " + volumeLevel + "%" ;
271
+ }
272
+ } catch {
273
+ MainProgram . errorMessage = "Failed to check volume" ;
259
274
}
260
275
} else {
261
276
successMessage = "Simulated setting system volume to " + volumeLevel + "%" ;
@@ -313,16 +328,21 @@ public void Music(string parameter) {
313
328
}
314
329
public void Open ( string parameter ) {
315
330
string location = ActionChecker . GetSecondaryParam ( parameter ) [ 0 ] , arguments = ( ActionChecker . GetSecondaryParam ( parameter ) . Length > 1 ? ActionChecker . GetSecondaryParam ( parameter ) [ 1 ] : null ) ;
316
- string fileLocation = ( ! location . Contains ( @":\" ) ) ? Path . Combine ( MainProgram . shortcutLocation , location ) : location ;
331
+ string fileLocation = ( ! location . Contains ( @":\" ) || ! location . Contains ( @":/" ) ) ? Path . Combine ( MainProgram . shortcutLocation , location ) : location ;
317
332
318
333
if ( File . Exists ( fileLocation ) || Directory . Exists ( fileLocation ) || Uri . IsWellFormedUriString ( fileLocation , UriKind . Absolute ) ) {
319
334
if ( ! MainProgram . testingAction ) {
320
- Process p = new Process ( ) ;
321
- p . StartInfo . FileName = fileLocation ;
322
- if ( arguments != null )
323
- p . StartInfo . Arguments = arguments ;
324
- p . Start ( ) ;
325
- successMessage = "OPEN: opened file/url; " + fileLocation ;
335
+ try {
336
+ Process p = new Process ( ) ;
337
+ p . StartInfo . FileName = fileLocation ;
338
+ if ( arguments != null )
339
+ p . StartInfo . Arguments = arguments ;
340
+ p . Start ( ) ;
341
+ successMessage = "OPEN: opened file/url; " + fileLocation ;
342
+ } catch {
343
+ MainProgram . DoDebug ( "Failed to open file at " + fileLocation + "" ) ;
344
+ MainProgram . errorMessage = "Failed to open file (" + fileLocation + ")" ;
345
+ }
326
346
} else {
327
347
successMessage = "OPEN: simulated opening file; " + fileLocation ;
328
348
}
@@ -332,7 +352,7 @@ public void Open(string parameter) {
332
352
}
333
353
}
334
354
public void OpenAll ( string parameter ) {
335
- string fileLocation = ( ! parameter . Contains ( @":\" ) ) ? Path . Combine ( MainProgram . shortcutLocation , parameter ) : parameter ;
355
+ string fileLocation = ( ! parameter . Contains ( @":\" ) || ! parameter . Contains ( @":/" ) ) ? Path . Combine ( MainProgram . shortcutLocation , parameter ) : parameter ;
336
356
337
357
if ( Directory . Exists ( fileLocation ) || Uri . IsWellFormedUriString ( fileLocation , UriKind . Absolute ) ) {
338
358
DirectoryInfo d = new DirectoryInfo ( fileLocation ) ;
0 commit comments