@@ -397,6 +397,73 @@ private static void CheckAction(string theLine, string theFile) {
397397 }
398398 }
399399
400+ private static string GetPathFolder ( string winEnvPathVar )
401+ /* Get windows environment path as string */
402+ {
403+ string folderPath = "" ;
404+ switch ( winEnvPathVar )
405+ {
406+ case "%USERPROFILE%" :
407+ return Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
408+
409+ case "%DESKTOP%" :
410+ return Environment . GetFolderPath ( Environment . SpecialFolder . Desktop ) ;
411+
412+ case "%PROGRAMS%" :
413+ return Environment . GetFolderPath ( Environment . SpecialFolder . Programs ) ;
414+
415+ case "%DOCUMENTS%" :
416+ return Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) ;
417+
418+ case "%MUSIC%" :
419+ return Environment . GetFolderPath ( Environment . SpecialFolder . MyMusic ) ;
420+
421+ case "%VIDEOS%" :
422+ return Environment . GetFolderPath ( Environment . SpecialFolder . MyVideos ) ;
423+
424+ case "%IMAGES%" :
425+ return Environment . GetFolderPath ( Environment . SpecialFolder . MyPictures ) ;
426+
427+ case "%COMPUTER%" :
428+ return Environment . GetFolderPath ( Environment . SpecialFolder . MyComputer ) ;
429+
430+ case "%FAVORITES%" :
431+ return Environment . GetFolderPath ( Environment . SpecialFolder . Favorites ) ;
432+
433+ case "%COOKIES%" :
434+ return Environment . GetFolderPath ( Environment . SpecialFolder . Cookies ) ;
435+
436+ case "%FONTS%" :
437+ return Environment . GetFolderPath ( Environment . SpecialFolder . Fonts ) ;
438+
439+ case "%HISTORY%" :
440+ return Environment . GetFolderPath ( Environment . SpecialFolder . History ) ;
441+
442+ case "%PERSONAL%" :
443+ return Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ;
444+
445+ case "%VIRTUALNETWORK%" :
446+ return Environment . GetFolderPath ( Environment . SpecialFolder . NetworkShortcuts ) ;
447+
448+ case "%VIRTUALPRINT%" :
449+ return Environment . GetFolderPath ( Environment . SpecialFolder . PrinterShortcuts ) ;
450+
451+ case "%APPDATA%" :
452+ return Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ;
453+
454+ case "%PROGRAMFILES%" :
455+ return Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) ;
456+
457+ case "%DIRSYSTEM%" :
458+ return Environment . GetFolderPath ( Environment . SpecialFolder . System ) ;
459+
460+ case "%WINDOWS%" :
461+ return Environment . GetFolderPath ( Environment . SpecialFolder . Windows ) ;
462+
463+ }
464+ return folderPath ;
465+ }
466+
400467 public static string [ ] GetSecondaryParam ( string param ) {
401468 if ( param . Contains ( "{" ) && param . Contains ( "}" ) ) {
402469 string [ ] toReturn = param . Split ( '{' ) ;
@@ -407,6 +474,24 @@ public static string[] GetSecondaryParam(string param) {
407474 }
408475 return toReturn ;
409476 }
477+ // check for any environment variables that starts with %
478+ if ( param . StartsWith ( "%" ) )
479+ {
480+ // environment variables between two characters (e.g. %ENV%)
481+ if ( Regex . Matches ( param , "%" ) . Count == 2 )
482+ {
483+ // a subfolder or file was specified
484+ if ( ! param . EndsWith ( "%" ) )
485+ {
486+ var rawPath = param . Split ( Convert . ToChar ( "%" ) ) ;
487+ var finalPath = GetPathFolder ( "%" + rawPath [ 1 ] + "%" ) + rawPath [ 2 ] . Replace ( "/" , "\\ " ) ;
488+ return new [ ] { finalPath } ;
489+ }
490+ // else, translate only %ENV%
491+ return new [ ] { GetPathFolder ( param ) } ;
492+ }
493+ }
494+
410495 return new string [ 1 ] { param } ;
411496 }
412497
0 commit comments