@@ -54,10 +54,10 @@ public void Shutdown(string parameter) {
5454 if ( parameter == "abort" ) {
5555 shutdownParameters = "abort" ;
5656 } 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 ;
5959 } else {
60- shutdownParameters = ! parameter . Contains ( "/s" ) ? "/s " : "" + parameter + " /t 0" ;
60+ shutdownParameters = ! parameter . Contains ( "/s" ) && ! parameter . Contains ( "-s" ) ? "/s " : "" + parameter + " /t 0" ;
6161 }
6262 }
6363 }
@@ -86,10 +86,10 @@ public void Restart(string parameter) {
8686 if ( parameter == "abort" ) {
8787 restartParameters = "abort" ;
8888 } 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 ;
9191 } else {
92- restartParameters = ! parameter . Contains ( "/r" ) ? "/s " : "" + parameter + " /t 0" ;
92+ restartParameters = ! parameter . Contains ( "/r" ) && ! parameter . Contains ( "-r" ) ? "/r " : "" + parameter + " /t 0" ;
9393 }
9494 }
9595 }
@@ -194,7 +194,7 @@ public void Lock(string parameter) {
194194 successMessage = "Simulated PC lock" ;
195195 } else {
196196 MainProgram . DoDebug ( "Locking computer..." ) ;
197- // wasFatal = true;
197+ wasFatal = true ;
198198 LockWorkStation ( ) ;
199199 successMessage = "Locked pc" ;
200200 }
@@ -204,7 +204,12 @@ public void Mute(string parameter) {
204204
205205 if ( parameter == null ) {
206206 //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+ }
208213 } else {
209214 //Parameter set;
210215 switch ( parameter ) {
@@ -247,15 +252,25 @@ public void SetVolume(string parameter) {
247252 MainProgram . errorMessage = "Failed to unmute PC" ;
248253 }
249254 }
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+ }
251262 }
252263 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" ;
259274 }
260275 } else {
261276 successMessage = "Simulated setting system volume to " + volumeLevel + "%" ;
@@ -313,16 +328,21 @@ public void Music(string parameter) {
313328 }
314329 public void Open ( string parameter ) {
315330 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 ;
317332
318333 if ( File . Exists ( fileLocation ) || Directory . Exists ( fileLocation ) || Uri . IsWellFormedUriString ( fileLocation , UriKind . Absolute ) ) {
319334 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+ }
326346 } else {
327347 successMessage = "OPEN: simulated opening file; " + fileLocation ;
328348 }
@@ -332,7 +352,7 @@ public void Open(string parameter) {
332352 }
333353 }
334354 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 ;
336356
337357 if ( Directory . Exists ( fileLocation ) || Uri . IsWellFormedUriString ( fileLocation , UriKind . Absolute ) ) {
338358 DirectoryInfo d = new DirectoryInfo ( fileLocation ) ;
0 commit comments