@@ -8,65 +8,43 @@ namespace ForceBindIP_GUI
88{
99 public partial class frmMain : Form
1010 {
11- private Properties . Settings m_settings = Properties . Settings . Default ;
11+ private readonly string [ ] RequieredFiles = new string [ ] { "BindIP.dll" , "BindIP64.dll" , "ForceBindIP.exe" , "ForceBindIP64.exe" } ;
1212
1313 public frmMain ( )
1414 {
1515 InitializeComponent ( ) ;
1616
17- btnSelectFBIPath . Click += OnSelectFBIPathClicked ;
18- btnOpenTargetApplication . Click += OnOpenAppClicked ;
19- btnLaunch . Click += OnLaunchClicked ;
17+ CheckRequieredFiles ( ) ;
2018
21- ForceBindIPPath = AppSettings . FBIPath ;
22-
23- LoadAvailableNetworkAdapters ( ) ;
19+ btnOpenTargetApplication . Click += ( sender , e ) => OpenAppSelector ( ) ;
20+ btnLaunch . Click += ( sender , e ) => LaunchApp ( ) ;
21+ cmbNetworkAdapter . DropDown += ( sender , e ) => LoadAvailableNetworkAdapters ( ) ;
2422 }
2523
26- private Properties . Settings AppSettings => m_settings ;
24+ private string ForceBindIPPath => Environment . CurrentDirectory ;
25+
26+ private string ForceBindExe => chk64b . Checked ? "ForceBindIP64.exe" : "ForceBindIP.exe" ;
2727
28- public string ForceBindIPPath
28+ /// <summary>
29+ /// Check if all ForceBindIP files are in the directory
30+ /// </summary>
31+ private void CheckRequieredFiles ( )
2932 {
30- get { return txtFBIPath . Text ; }
31- set
33+ string curDir = Environment . CurrentDirectory ;
34+ foreach ( string s in RequieredFiles )
3235 {
33- if ( Directory . Exists ( value ) && txtFBIPath . Text != value )
36+ if ( ! File . Exists ( Path . Combine ( curDir , s ) ) )
3437 {
35- txtFBIPath . Text = value ;
36- if ( AppSettings . FBIPath != value )
37- {
38- AppSettings . FBIPath = value ;
39- AppSettings . Save ( ) ;
40- AppSettings . Reload ( ) ;
41- }
38+ MessageBox . Show ( "Couldn't find ForceBindIP files" , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
39+ Environment . Exit ( - 1 ) ;
4240 }
4341 }
4442 }
4543
46- public string ForceBindExe => chk64b . Checked ? "ForceBindIP64.exe" : "ForceBindIP.exe" ;
47-
48- private void OnSelectFBIPathClicked ( object sender , EventArgs e )
49- {
50- FolderBrowserDialog diag = new FolderBrowserDialog ( ) ;
51- if ( ! String . IsNullOrEmpty ( ForceBindIPPath ) && ForceBindIPPath . Length > 0 )
52- diag . SelectedPath = ForceBindIPPath ;
53- diag . Description = "Choose the ForceBindIP install path" ;
54- diag . ShowNewFolderButton = false ;
55- if ( diag . ShowDialog ( ) == DialogResult . OK )
56- ForceBindIPPath = diag . SelectedPath ;
57- }
58-
59- private void OnOpenAppClicked ( object sender , EventArgs e )
60- {
61- OpenFileDialog diag = new OpenFileDialog ( ) ;
62- diag . Filter = "Application (*.exe)|*.exe" ;
63- diag . Multiselect = false ;
64- diag . Title = "Select a application to open" ;
65- if ( diag . ShowDialog ( ) == DialogResult . OK )
66- txtTargetApp . Text = diag . FileName ;
67- }
68-
69- private void OnLaunchClicked ( object sender , EventArgs e )
44+ /// <summary>
45+ /// Launch the selected app on the given network adapter
46+ /// </summary>
47+ private void LaunchApp ( )
7048 {
7149 try
7250 {
@@ -78,17 +56,31 @@ private void OnLaunchClicked(object sender, EventArgs e)
7856 psi . WorkingDirectory = Path . GetDirectoryName ( txtTargetApp . Text ) ;
7957 Process . Start ( psi ) ;
8058 }
81- catch ( Exception ex )
59+ catch ( Exception ex )
8260 {
8361 MessageBox . Show ( ex . Message ) ;
8462 }
8563 }
8664
65+ /// <summary>
66+ /// Open the application selector
67+ /// </summary>
68+ private void OpenAppSelector ( )
69+ {
70+ OpenFileDialog diag = new OpenFileDialog ( ) ;
71+ diag . Filter = "Application (*.exe)|*.exe" ;
72+ diag . Multiselect = false ;
73+ diag . Title = "Select a application to open" ;
74+ if ( diag . ShowDialog ( ) == DialogResult . OK )
75+ txtTargetApp . Text = diag . FileName ;
76+ }
77+
8778 /// <summary>
8879 /// Get all available network adapters
8980 /// </summary>
9081 private void LoadAvailableNetworkAdapters ( )
9182 {
83+ cmbNetworkAdapter . Items . Clear ( ) ;
9284 foreach ( NetworkInterface ni in NetworkInterface . GetAllNetworkInterfaces ( ) )
9385 {
9486 if ( ni . NetworkInterfaceType == NetworkInterfaceType . Wireless80211 || ni . NetworkInterfaceType == NetworkInterfaceType . Ethernet )
@@ -102,5 +94,9 @@ private void LoadAvailableNetworkAdapters()
10294 }
10395 }
10496
97+ private void CmbNetworkAdapter_DropDown ( object sender , EventArgs e )
98+ {
99+ LoadAvailableNetworkAdapters ( ) ;
100+ }
105101 }
106102}
0 commit comments