22using System ;
33using System . Collections . Generic ;
44using System . Diagnostics ;
5- using System . Drawing ;
6- using System . IO ;
75using System . Linq ;
86using System . Text . RegularExpressions ;
97using System . Windows . Forms ;
@@ -21,62 +19,65 @@ public static void Main()
2119
2220 }
2321
24- private NotifyIcon trayIcon ;
25- private ContextMenu trayMenu ;
26- RegistryKey registryKey = Registry . CurrentUser . OpenSubKey ( "SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" , true ) ;
27- private string appName = "WinToLinux" ;
22+ private readonly NotifyIcon trayIcon ;
23+ private readonly ContextMenu trayMenu ;
24+ readonly RegistryKey registryKey = Registry . CurrentUser . OpenSubKey ( "SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" , true ) ;
25+ private readonly string appName = "WinToLinux" ;
2826
2927 List < string > uefi = new List < string > ( ) ;
3028 List < string > uuid = new List < string > ( ) ;
3129 string bootsequence ;
3230 string currentValue ;
3331 int shift ;
34-
35- Regex regexUUID = new Regex ( "^(\\ {){0,1}[0-9a-fA-F]{8}\\ -[0-9a-fA-F]{4}\\ -[0-9a-fA-F]{4}\\ -[0-9a-fA-F]{4}\\ -[0-9a-fA-F]{12}(\\ }){0,1}$" ) ;
32+ readonly Regex regexUUID = new Regex ( "^(\\ {){0,1}[0-9a-fA-F]{8}\\ -[0-9a-fA-F]{4}\\ -[0-9a-fA-F]{4}\\ -[0-9a-fA-F]{4}\\ -[0-9a-fA-F]{12}(\\ }){0,1}$" ) ;
3633
3734 public SysTrayApp ( )
3835 {
3936 bool isStart = registryKey . GetValue ( appName ) != null ;
40- getMenuItems ( ) ;
37+ GetMenuItems ( ) ;
4138
42- currentValue = bootsequence != null ? bootsequence : uuid . First ( ) ;
39+ currentValue = bootsequence ?? uuid . First ( ) ;
4340 shift = uuid . Count ( ) - uefi . Count ( ) ;
4441
4542 // Create a simple tray menu with only one item.
4643 trayMenu = new ContextMenu ( ) ;
4744 trayMenu . MenuItems . Add ( "Settings" ) . Enabled = false ;
4845 trayMenu . MenuItems . Add ( "-" ) ;
49- trayMenu . MenuItems . Add ( "Start with system" , onRegisterInStartup ) . Checked = isStart ;
46+ trayMenu . MenuItems . Add ( "Start with system" , OnRegisterInStartup ) . Checked = isStart ;
5047 trayMenu . MenuItems . Add ( "-" ) ;
5148 trayMenu . MenuItems . Add ( "Reboot to..." ) . Enabled = false ;
5249 trayMenu . MenuItems . Add ( "-" ) ;
5350
5451 foreach ( var pos in uefi . Select ( ( value , i ) => new { i , value } ) )
52+ {
53+ MenuItem item = new MenuItem
5554 {
56- MenuItem item = new MenuItem ( ) ;
57- item . Checked = uuid [ pos . i + shift ] == currentValue ;
58- item . Tag = uuid [ pos . i + shift ] ;
59- item . Text = pos . value ;
60- item . Click += onMenuClick ;
55+ Checked = uuid [ pos . i + shift ] == currentValue ,
56+ Tag = uuid [ pos . i + shift ] ,
57+ Text = pos . value
58+ } ;
59+ item . Click += OnMenuClick ;
6160 trayMenu . MenuItems . Add ( item ) ;
6261 }
6362
6463 trayMenu . MenuItems . Add ( "-" ) ;
65- trayMenu . MenuItems . Add ( "Reboot system" , onReboot ) ;
64+ trayMenu . MenuItems . Add ( "Reboot system" , OnReboot ) ;
6665 trayMenu . MenuItems . Add ( "-" ) ;
6766 trayMenu . MenuItems . Add ( "Exit" , OnExit ) ;
6867
6968 // Create a tray icon. In this example we use a
7069 // standard system icon for simplicity, but you
7170 // can of course use your own custom icon too.
7271
73- trayIcon = new NotifyIcon ( ) ;
74- trayIcon . Text = "Reboot to Linux" ;
75- trayIcon . Icon = WinToLinux . Properties . Resources . WtL ;
72+ trayIcon = new NotifyIcon
73+ {
74+ Text = "Reboot to Linux" ,
75+ Icon = WinToLinux . Properties . Resources . WtL ,
7676
77- // Add menu to tray icon and show it.
78- trayIcon . ContextMenu = trayMenu ;
79- trayIcon . Visible = true ;
77+ // Add menu to tray icon and show it.
78+ ContextMenu = trayMenu ,
79+ Visible = true
80+ } ;
8081 }
8182
8283
@@ -85,28 +86,28 @@ private void OnExit(object sender, EventArgs e)
8586 Application . Exit ( ) ;
8687 }
8788
88- private void onMenuClick ( object sender , EventArgs e )
89+ private void OnMenuClick ( object sender , EventArgs e )
8990 {
9091 string UUID = ( sender as MenuItem ) . Tag . ToString ( ) ;
9192 string command = "/C bcdedit.exe /set {fwbootmgr} bootsequence " + UUID + " /addfirst" ;
9293 Console . WriteLine ( command ) ;
9394
94- launchCMD ( command ) ;
95+ LaunchCMD ( command ) ;
9596
9697 uuid = new List < string > ( ) ;
9798 uefi = new List < string > ( ) ;
9899
99- launchCMD ( "/C bcdedit /enum firmware" ) ;
100-
101- currentValue = bootsequence != null ? bootsequence : uuid . First ( ) ;
100+ LaunchCMD ( "/C bcdedit /enum firmware" ) ;
101+
102+ currentValue = bootsequence ?? uuid . First ( ) ;
102103 shift = uuid . Count ( ) - uefi . Count ( ) ;
103104 foreach ( var pos in uefi . Select ( ( value , i ) => new { i , value } ) )
104105 {
105106 trayMenu . MenuItems [ pos . i + 6 ] . Checked = uuid [ pos . i + shift ] == currentValue ;
106107 }
107108 }
108109
109- private void onRegisterInStartup ( object sender , EventArgs e )
110+ private void OnRegisterInStartup ( object sender , EventArgs e )
110111 {
111112 bool isStartup = registryKey . GetValue ( appName ) == null ;
112113
@@ -122,17 +123,17 @@ private void onRegisterInStartup(object sender, EventArgs e)
122123 }
123124 }
124125
125- private void onReboot ( object sender , EventArgs e )
126+ private void OnReboot ( object sender , EventArgs e )
126127 {
127- launchCMD ( "/C shutdown /r /t 0" ) ;
128+ LaunchCMD ( "/C shutdown /r /t 0" ) ;
128129 }
129130
130- private void getMenuItems ( )
131+ private void GetMenuItems ( )
131132 {
132- launchCMD ( "/C bcdedit /enum firmware" ) ;
133+ LaunchCMD ( "/C bcdedit /enum firmware" ) ;
133134 }
134135
135- private void launchCMD ( string command )
136+ private void LaunchCMD ( string command )
136137 {
137138 Process build = new Process ( ) ;
138139 build . StartInfo . Arguments = command ;
@@ -142,16 +143,16 @@ private void launchCMD(string command)
142143 build . StartInfo . RedirectStandardOutput = true ;
143144 build . StartInfo . RedirectStandardError = true ;
144145 build . StartInfo . CreateNoWindow = true ;
145- build . ErrorDataReceived += build_ErrorAndDataReceived ;
146- build . OutputDataReceived += build_ErrorAndDataReceived ;
146+ build . ErrorDataReceived += Build_ErrorAndDataReceived ;
147+ build . OutputDataReceived += Build_ErrorAndDataReceived ;
147148 build . EnableRaisingEvents = true ;
148149 build . Start ( ) ;
149150 build . BeginOutputReadLine ( ) ;
150151 build . BeginErrorReadLine ( ) ;
151152 build . WaitForExit ( ) ;
152153 }
153154
154- void build_ErrorAndDataReceived ( object sender , DataReceivedEventArgs e )
155+ void Build_ErrorAndDataReceived ( object sender , DataReceivedEventArgs e )
155156 {
156157 if ( e . Data != null && e . Data != "" )
157158 {
@@ -163,7 +164,7 @@ void build_ErrorAndDataReceived(object sender, DataReceivedEventArgs e)
163164 if ( splited [ 0 ] == "description" )
164165 {
165166 splited = splited . Where ( w => w != splited [ 0 ] ) . ToArray ( ) ;
166- Console . WriteLine ( String . Join ( " " , splited ) ) ;
167+ Console . WriteLine ( String . Join ( " " , splited ) ) ;
167168 uefi . Add ( String . Join ( " " , splited ) ) ;
168169 }
169170
0 commit comments