1- using NETworkManager . Views . Settings ;
2- using System ;
3- using System . Windows ;
1+ using System ;
42
53namespace NETworkManager . Models . Settings
64{
75 public static class CommandLineManager
86 {
97 public const string ParameterIdentifier = "--" ;
10- public const string ParameterHelp = "help" ;
11- public const string ParameterAutostart = "autostart" ;
12- public const string ParameterResetSettings = "reset-settings" ;
13- public const string ParameterRestartPid = "restart-pid:" ;
8+ public const char ParameterSplit = ':' ;
9+
10+ // Public + Help
11+ public const string ParameterHelp = ParameterIdentifier + "help" ;
12+ public const string ParameterResetSettings = ParameterIdentifier + "reset-settings" ;
13+
14+ // Internal use only
15+ public const string ParameterAutostart = ParameterIdentifier + "autostart" ;
16+ public const string ParameterRestartPid = ParameterIdentifier + "restart-pid" ;
1417
1518 public static CommandLineInfo Current { get ; set ; }
1619
@@ -22,46 +25,58 @@ public static void Parse()
2225 {
2326 Current = new CommandLineInfo ( ) ;
2427
25- // Get the command line args
28+ // Detect start parameters
2629 string [ ] parameters = Environment . GetCommandLineArgs ( ) ;
2730
28- char [ ] trimChars = ParameterIdentifier . ToCharArray ( ) ;
29-
30- // Detect start parameters
31- foreach ( string parameter in parameters )
31+ for ( int i = 0 ; i < parameters . Length ; i ++ )
3232 {
33- if ( parameter . StartsWith ( ParameterIdentifier ) )
33+ string [ ] param = parameters [ i ] . Split ( ParameterSplit ) ;
34+
35+ if ( param [ 0 ] . StartsWith ( ParameterIdentifier ) )
3436 {
35- string param = parameter . TrimStart ( trimChars ) ;
36- if ( param . Equals ( ParameterHelp , StringComparison . InvariantCultureIgnoreCase ) )
37+ if ( param [ 0 ] . Equals ( ParameterHelp , StringComparison . InvariantCultureIgnoreCase ) )
3738 {
3839 Current . Help = true ;
3940 } // Autostart
40- else if ( param . Equals ( ParameterAutostart , StringComparison . InvariantCultureIgnoreCase ) )
41+ else if ( param [ 0 ] . Equals ( ParameterAutostart , StringComparison . InvariantCultureIgnoreCase ) )
4142 {
4243 Current . Autostart = true ;
4344 } // Reset Settings
44- else if ( param . Equals ( ParameterResetSettings , StringComparison . InvariantCultureIgnoreCase ) )
45+ else if ( param [ 0 ] . Equals ( ParameterResetSettings , StringComparison . InvariantCultureIgnoreCase ) )
4546 {
4647 Current . ResetSettings = true ;
4748 } // Restart
48- else if ( param . StartsWith ( ParameterRestartPid , StringComparison . InvariantCultureIgnoreCase ) )
49+ else if ( param [ 0 ] . Equals ( ParameterRestartPid , StringComparison . InvariantCultureIgnoreCase ) )
4950 {
50- int . TryParse ( param . Split ( ':' ) [ 1 ] , out int restartPid ) ;
51+ int . TryParse ( param [ 1 ] , out int restartPid ) ;
5152
5253 Current . RestartPid = restartPid ;
5354 }
5455 else
5556 {
57+ AddToWrongParameter ( parameters [ i ] ) ;
58+
59+ Current . Help = true ;
60+ }
61+ }
62+ else
63+ {
64+ // Ignore the first parameter because it's the path of the .exe
65+ if ( i != 0 )
66+ {
67+ AddToWrongParameter ( parameters [ i ] ) ;
5668 Current . Help = true ;
5769 }
5870 }
5971 }
6072 }
6173
62- public static string GetCommandLineParameter ( string parameter )
74+ private static void AddToWrongParameter ( string parameter )
6375 {
64- return string . Format ( "{0}{1}" , ParameterIdentifier , parameter ) ;
76+ if ( ! string . IsNullOrEmpty ( Current . WrongParameter ) )
77+ Current . WrongParameter += Environment . NewLine ;
78+
79+ Current . WrongParameter += parameter ;
6580 }
6681 }
6782}
0 commit comments