66using System . Linq ;
77using System . Net ;
88using System . Runtime . InteropServices ;
9- using System . Text ;
109using System . Threading . Tasks ;
1110using System . Windows ;
12- using System . Windows . Controls ;
13- using System . Windows . Data ;
14- using System . Windows . Documents ;
15- using System . Windows . Input ;
1611using System . Windows . Interop ;
17- using System . Windows . Media ;
1812using System . Windows . Media . Imaging ;
19- using System . Windows . Navigation ;
20- using System . Windows . Shapes ;
2113
2214namespace CodeSwine_Solo_Public_Lobby
2315{
2416 public partial class MainWindow : Window
2517 {
2618 private IPTool iPTool = new IPTool ( ) ;
27- private DaWhitelist whiteList = new DaWhitelist ( ) ;
2819 private List < IPAddress > addresses = new List < IPAddress > ( ) ;
2920 private MWhitelist mWhitelist = new MWhitelist ( ) ;
3021
@@ -37,15 +28,16 @@ public MainWindow()
3728 Loaded += MainWindow_Loaded ;
3829 }
3930
40- private void MainWindow_Loaded ( object sender , RoutedEventArgs e )
31+ private async void MainWindow_Loaded ( object sender , RoutedEventArgs e )
4132 {
4233 FirewallRule . lblAdmin = lblAdmin ;
43- Init ( ) ;
34+ await InitAsync ( ) ;
4435 }
4536
46- void Init ( )
37+ private async Task InitAsync ( )
4738 {
48- lblYourIPAddress . Content += " " + iPTool . IpAddress + "." ;
39+ var ipAddress = await iPTool . GrabInternetAddressAsync ( ) ;
40+ lblYourIPAddress . Content += " " + ipAddress + "." ;
4941 addresses = DaWhitelist . ReadIPsFromJSON ( ) ;
5042 lsbAddresses . ItemsSource = addresses ;
5143 foreach ( IPAddress ip in addresses )
@@ -57,9 +49,9 @@ void Init()
5749
5850 private void btnAdd_Click ( object sender , RoutedEventArgs e )
5951 {
60- if ( IPTool . ValidateIP ( txbIpToAdd . Text ) )
52+ if ( IPTool . ValidateIP ( txbIpToAdd . Text ) )
6153 {
62- if ( ! addresses . Contains ( IPAddress . Parse ( txbIpToAdd . Text ) ) )
54+ if ( ! addresses . Contains ( IPAddress . Parse ( txbIpToAdd . Text ) ) )
6355 {
6456 addresses . Add ( IPAddress . Parse ( txbIpToAdd . Text ) ) ;
6557 lsbAddresses . Items . Refresh ( ) ;
@@ -75,7 +67,7 @@ private void btnAdd_Click(object sender, RoutedEventArgs e)
7567
7668 private void btnDelete_Click ( object sender , RoutedEventArgs e )
7769 {
78- if ( lsbAddresses . SelectedIndex != - 1 )
70+ if ( lsbAddresses . SelectedIndex != - 1 )
7971 {
8072 mWhitelist . Ips . Remove ( lsbAddresses . SelectedItem . ToString ( ) ) ;
8173 addresses . Remove ( IPAddress . Parse ( lsbAddresses . SelectedItem . ToString ( ) ) ) ;
@@ -98,7 +90,7 @@ private void btnEnableDisable_Click(object sender, RoutedEventArgs e)
9890 SetRules ( ) ;
9991 }
10092
101- void SetRules ( )
93+ private void SetRules ( )
10294 {
10395 string remoteAddresses = RangeCalculator . GetRemoteAddresses ( addresses ) ;
10496
@@ -124,7 +116,7 @@ void SetRules()
124116 }
125117
126118 // If they are active and set.
127- if ( active && set )
119+ if ( active && set )
128120 {
129121 FirewallRule . CreateInbound ( remoteAddresses , false , true ) ;
130122 FirewallRule . CreateOutbound ( remoteAddresses , false , true ) ;
@@ -133,22 +125,22 @@ void SetRules()
133125 }
134126 }
135127
136- void UpdateNotActive ( )
128+ private void UpdateNotActive ( )
137129 {
138130 btnEnableDisable . Background = ColorBrush . Red ;
139131 image4 . Source = new BitmapImage ( new Uri ( "/CodeSwine-Solo_Public_Lobby;component/ImageResources/unlocked.png" , UriKind . Relative ) ) ;
140132 lblLock . Content = "Rules not active." + Environment . NewLine + "Click to activate!" ;
141133 }
142134
143- void UpdateActive ( )
135+ private void UpdateActive ( )
144136 {
145137 btnEnableDisable . Background = ColorBrush . Green ;
146138 image4 . Source = new BitmapImage ( new Uri ( "/CodeSwine-Solo_Public_Lobby;component/ImageResources/locked.png" , UriKind . Relative ) ) ;
147139 lblLock . Content = "Rules active." + Environment . NewLine + "Click to deactivate!" ;
148140 }
149141
150142 [ DllImport ( "User32.dll" ) ]
151- private static extern bool RegisterHotKey (
143+ private static extern bool RegisterHotKey (
152144 [ In ] IntPtr hWnd ,
153145 [ In ] int id ,
154146 [ In ] uint fsModifiers ,
@@ -187,7 +179,6 @@ private void RegisterHotKey()
187179 const uint MOD_CTRL = 0x0002 ;
188180 if ( ! RegisterHotKey ( helper . Handle , HOTKEY_ID , MOD_CTRL , VK_F10 ) )
189181 {
190-
191182 }
192183 }
193184
@@ -221,4 +212,4 @@ private void OnHotKeyPressed()
221212 System . Media . SystemSounds . Hand . Play ( ) ;
222213 }
223214 }
224- }
215+ }
0 commit comments