@@ -5,21 +5,83 @@ internal static class Program
5
5
[ STAThread ]
6
6
private static void Main ( string [ ] args )
7
7
{
8
- if ( args . Length == 0 )
8
+ try
9
9
{
10
- Console . WriteLine ( Resx . Resource . Guidelines ) ;
11
- Thread . Sleep ( 5000 ) ;
12
- return ;
13
- }
10
+ // If no arguments are provided, display usage guidelines and exit
11
+ if ( args . Length == 0 )
12
+ {
13
+ ShowHelp ( ) ;
14
+ return ;
15
+ }
16
+
17
+ // Log all arguments for debugging purposes
18
+ foreach ( var arg in args )
19
+ {
20
+ Console . WriteLine ( arg ) ;
21
+ }
22
+
23
+ // Parse command based on first argument
24
+ switch ( args [ 0 ] . ToLowerInvariant ( ) )
25
+ {
26
+ case "rebootas" :
27
+ // Handle application restart
28
+ HandleRebootAsync ( ) ;
29
+ break ;
30
+
31
+ case "help" :
32
+ case "--help" :
33
+ case "-h" :
34
+ case "/?" :
35
+ // Display help information
36
+ ShowHelp ( ) ;
37
+ break ;
14
38
15
- var argData = Uri . UnescapeDataString ( string . Join ( " " , args ) ) ;
16
- if ( argData . Equals ( "rebootas" ) )
39
+ default :
40
+ // Default behavior: handle as upgrade data
41
+ // Maintain backward compatibility with existing usage pattern
42
+ var argData = Uri . UnescapeDataString ( string . Join ( " " , args ) ) ;
43
+ HandleUpgrade ( argData ) ;
44
+ break ;
45
+ }
46
+ }
47
+ catch ( Exception ex )
17
48
{
18
- Thread . Sleep ( 1000 ) ;
19
- Utils . StartV2RayN ( ) ;
20
- return ;
49
+ // Global exception handling
50
+ Console . WriteLine ( $ "An error occurred: { ex . Message } ") ;
51
+ Console . WriteLine ( "Press any key to exit..." ) ;
52
+ Console . ReadKey ( ) ;
21
53
}
54
+ }
22
55
23
- UpgradeApp . Upgrade ( argData ) ;
56
+ /// <summary>
57
+ /// Display help information and usage guidelines
58
+ /// </summary>
59
+ private static void ShowHelp ( )
60
+ {
61
+ Console . WriteLine ( Resx . Resource . Guidelines ) ;
62
+ Console . WriteLine ( "Available commands:" ) ;
63
+ Console . WriteLine ( " rebootas - Restart the application" ) ;
64
+ Console . WriteLine ( " help - Display this help information" ) ;
65
+ Thread . Sleep ( 5000 ) ;
66
+ }
67
+
68
+ /// <summary>
69
+ /// Handle application restart
70
+ /// </summary>
71
+ private static void HandleRebootAsync ( )
72
+ {
73
+ Console . WriteLine ( "Restarting application..." ) ;
74
+ Thread . Sleep ( 1000 ) ;
75
+ Utils . StartV2RayN ( ) ;
76
+ }
77
+
78
+ /// <summary>
79
+ /// Handle application upgrade with the provided data
80
+ /// </summary>
81
+ /// <param name="upgradeData">Data for the upgrade process</param>
82
+ private static void HandleUpgrade ( string upgradeData )
83
+ {
84
+ Console . WriteLine ( "Upgrading application..." ) ;
85
+ UpgradeApp . Upgrade ( upgradeData ) ;
24
86
}
25
87
}
0 commit comments