@@ -126,7 +126,7 @@ public void Shutdown(string parameter) {
126126 }
127127
128128 if ( MainProgram . testingAction ) {
129- successMessage = "Simulated shutdown" ;
129+ successMessage = "Simulated shutdown with parameters; " + shutdownParameters ;
130130 wasFatal = false ;
131131 } else {
132132 if ( shutdownParameters != "abort" ) {
@@ -298,7 +298,15 @@ public void Mute(string parameter) {
298298 }
299299 }
300300 public void SetVolume ( string parameter ) {
301- if ( double . TryParse ( parameter , out double volumeLevel ) ) {
301+ bool numberIsGood = double . TryParse ( parameter , out double volumeLevel ) ;
302+
303+ if ( ! numberIsGood ) {
304+ double newNum = new WordsToNumbers ( ) . EnglishGet ( parameter ) ;
305+ numberIsGood = ( newNum != - 1 ) ;
306+ volumeLevel = newNum ;
307+ }
308+
309+ if ( numberIsGood ) {
302310 if ( volumeLevel >= 0 && volumeLevel <= 100 ) {
303311 if ( ! MainProgram . testingAction ) {
304312 if ( Properties . Settings . Default . UnmuteOnVolumeChange ) {
@@ -384,26 +392,44 @@ public void Music(string parameter) {
384392 }
385393 public void Open ( string parameter ) {
386394 string location = ActionChecker . GetSecondaryParam ( parameter ) [ 0 ] , arguments = ( ActionChecker . GetSecondaryParam ( parameter ) . Length > 1 ? ActionChecker . GetSecondaryParam ( parameter ) [ 1 ] : null ) ;
387- string fileLocation = ( ! location . Contains ( @":\" ) || ! location . Contains ( @":/" ) ) ? Path . Combine ( MainProgram . shortcutLocation , location ) : location ;
395+ string fileLocation = ( ! location . Contains ( @":\" ) || ! location . Contains ( @":/" ) ) ? "" : location ;
396+ if ( fileLocation == "" ) {
397+ string combinedPath = "" ;
398+ try {
399+ combinedPath = Path . Combine ( MainProgram . shortcutLocation , location ) ;
400+ } catch {
401+ Error ( "Given path (" + location + ") is invalid (could not combine)" ) ;
402+ }
388403
389- if ( File . Exists ( fileLocation ) || Directory . Exists ( fileLocation ) || Uri . IsWellFormedUriString ( fileLocation , UriKind . Absolute ) ) {
390- if ( ! MainProgram . testingAction ) {
391- try {
392- Process p = new Process ( ) ;
393- p . StartInfo . FileName = fileLocation ;
394- if ( arguments != null )
395- p . StartInfo . Arguments = arguments ;
396- p . Start ( ) ;
397- successMessage = "OPEN: opened file/url; " + fileLocation ;
398- } catch ( Exception e ) {
399- MainProgram . DoDebug ( "Failed to open file; " + e . Message ) ;
400- Error ( "Failed to open file (" + fileLocation + ")" ) ;
404+ if ( combinedPath != "" ) {
405+ fileLocation = combinedPath ;
406+ }
407+ }
408+
409+ if ( fileLocation != "" ) {
410+ if ( MainProgram . IsValidPath ( location ) ) {
411+ if ( File . Exists ( fileLocation ) || Directory . Exists ( fileLocation ) || Uri . IsWellFormedUriString ( fileLocation , UriKind . Absolute ) ) {
412+ if ( ! MainProgram . testingAction ) {
413+ try {
414+ Process p = new Process ( ) ;
415+ p . StartInfo . FileName = fileLocation ;
416+ if ( arguments != null )
417+ p . StartInfo . Arguments = arguments ;
418+ p . Start ( ) ;
419+ successMessage = "OPEN: opened file/url; " + fileLocation ;
420+ } catch ( Exception e ) {
421+ MainProgram . DoDebug ( "Failed to open file; " + e . Message ) ;
422+ Error ( "Failed to open file (" + fileLocation + ")" ) ;
423+ }
424+ } else {
425+ successMessage = "OPEN: simulated opening file; " + fileLocation ;
426+ }
427+ } else {
428+ Error ( "File or directory doesn't exist (" + fileLocation + ")" ) ;
401429 }
402430 } else {
403- successMessage = "OPEN: simulated opening file; " + fileLocation ;
431+ Error ( "Given path is invalid" ) ;
404432 }
405- } else {
406- Error ( "File or directory doesn't exist (" + fileLocation + ")" ) ;
407433 }
408434 }
409435 public void OpenAll ( string parameter ) {
@@ -480,7 +506,7 @@ public void KeyShortcut(string parameter) {
480506 /*
481507 * Added by : Joshua Miller
482508 * How to use it :
483- * - To seperate keys please us '+' (to use '+' do {ADD})
509+ * - To seperate keys please use '+' (to use '+' do {ADD})
484510 * - Things like ctrl will be converted to control key
485511 */
486512
@@ -499,8 +525,7 @@ public void KeyShortcut(string parameter) {
499525 if ( command . Length == 1 ) {
500526 // Add to the out
501527 keyCombinationPress = keyCombinationPress + command . ToLower ( ) ;
502- }
503- else {
528+ } else {
504529 // If it is a command (probably)
505530 // Check if it is a possible command and needs to be changed
506531 bool foundYet = false ;
@@ -528,8 +553,7 @@ public void KeyShortcut(string parameter) {
528553 // Is it testing?
529554 if ( MainProgram . testingAction ) {
530555 successMessage = ( "Simulated sending the combination: " + keyCombinationPress ) ;
531- }
532- else {
556+ } else {
533557 // Try pressing keys
534558 bool keysPressedSuccess = true ;
535559 try {
@@ -728,7 +752,54 @@ public void DoMessageBox(string parameter) {
728752 }
729753 }
730754
755+ public void KillProcess ( string parameter ) {
756+ bool paramIsNum = int . TryParse ( parameter , out int pid ) ;
757+
758+ if ( paramIsNum ) {
759+ try {
760+ //Results in an exception if process doesn't exist
761+ Process theP = Process . GetProcessById ( pid ) ;
762+
763+ if ( ! MainProgram . testingAction ) {
764+ try {
765+ //theP.Close();
766+ theP . Kill ( ) ;
767+ successMessage = "Killed process with ID " + pid . ToString ( ) ;
768+ } catch ( Exception e ) {
769+ Error ( "Failed to kill process with ID " + pid . ToString ( ) + "; " + e . Message ) ;
770+ }
771+ } else {
772+ successMessage = "Successfully simulated killing process" ;
773+ }
774+ } catch {
775+ Error ( "A process with the ID " + pid . ToString ( ) + " doesn't exist" ) ;
776+ }
777+ } else {
778+ try {
779+ //Results in an exception if process doesn't exist
780+ Process [ ] thePs = Process . GetProcessesByName ( parameter ) ;
781+
782+ if ( ! MainProgram . testingAction ) {
783+ try {
784+ foreach ( Process p in thePs ) {
785+ p . Kill ( ) ;
786+ }
787+ successMessage = "Killed all processes with name " + parameter ;
788+ } catch ( Exception e ) {
789+ Error ( "Failed to kill processes with name " + parameter + "; " + e . Message ) ;
790+ }
791+ } else {
792+ successMessage = "Successfully simulated killing processes" ;
793+ }
794+ } catch {
795+ Error ( "A process with the name " + parameter + " doesn't exist" ) ;
796+ }
797+ }
798+ }
799+
731800 public void MoveSubject ( string parameter ) {
801+ /* Doesn't seem to be halfway finished ._. [TODO] */
802+
732803 string theSubject = ActionChecker . GetSecondaryParam ( parameter ) [ 0 ]
733804 , moveTo = ( ActionChecker . GetSecondaryParam ( parameter ) . Length > 1 ? ActionChecker . GetSecondaryParam ( parameter ) [ 1 ] : null ) ;
734805
0 commit comments