Skip to content

Commit 4eac0ef

Browse files
committed
add enable/disable checkboxes to native IP settings, to restore only selected items.
1 parent 7532cb6 commit 4eac0ef

3 files changed

Lines changed: 97 additions & 45 deletions

File tree

MainForm.Designer.cs

Lines changed: 54 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MainForm.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public MainForm()
4444
NetworkHelper.LoadAlterNativeSettings(textBoxGw4, textBoxGw6, textBoxDns4, textBoxDns6, checkBoxGw4, checkBoxGw6, checkBoxDns4, checkBoxDns6);
4545

4646
// Load native settings to UI
47-
NetworkHelper.LoadNativeSettingsToUI(textBoxNativeGw4, textBoxNativeGw6, textBoxNativeDns4, textBoxNativeDns6);
47+
NetworkHelper.LoadNativeSettingsToUI(textBoxNativeGw4, textBoxNativeGw6, textBoxNativeDns4, textBoxNativeDns6, checkBoxNativeGw4, checkBoxNativeGw6, checkBoxNativeDns4, checkBoxNativeDns6);
4848

4949
// Initialize auto-refresh settings
5050
checkBoxAutoRefresh.Checked = Settings.Default.AutoRefreshEnabled;
@@ -177,7 +177,7 @@ private void buttonSaveNative_Click(object sender, EventArgs e)
177177
{
178178
try
179179
{
180-
NetworkHelper.SaveNativeSettingsFromUI(textBoxNativeGw4, textBoxNativeGw6, textBoxNativeDns4, textBoxNativeDns6);
180+
NetworkHelper.SaveNativeSettingsFromUI(textBoxNativeGw4, textBoxNativeGw6, textBoxNativeDns4, textBoxNativeDns6, checkBoxNativeGw4, checkBoxNativeGw6, checkBoxNativeDns4, checkBoxNativeDns6);
181181
MessageBox.Show("Native network settings saved successfully!", "Settings Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
182182
}
183183
catch (Exception ex)
@@ -192,6 +192,13 @@ private void buttonLoadNative_Click(object sender, EventArgs e)
192192
{
193193
var currentInfo = NetworkHelper.GetCurrentNetworkInfo();
194194
NetworkHelper.PopulateNetworkInfoTextBoxes(currentInfo, textBoxNativeGw4, textBoxNativeGw6, textBoxNativeDns4, textBoxNativeDns6);
195+
196+
// Enable checkboxes for valid network settings
197+
checkBoxNativeGw4.Checked = currentInfo.Gateway4_enable;
198+
checkBoxNativeGw6.Checked = currentInfo.Gateway6_enable;
199+
checkBoxNativeDns4.Checked = currentInfo.Dns4_enable;
200+
checkBoxNativeDns6.Checked = currentInfo.Dns6_enable;
201+
195202
MessageBox.Show("Current network settings loaded into Native settings!", "Settings Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information);
196203
}
197204
catch (Exception ex)
@@ -205,6 +212,8 @@ protected override void OnShown(EventArgs e)
205212
base.OnShown(e);
206213
// Update AlterNative settings display
207214
AlterCheckBoxes_ReEnable();
215+
// Update Native settings display
216+
NativeCheckBoxes_ReEnable();
208217
DisplayCurrentMode(isSwitchedOn);
209218
TrackBar_Set(isSwitchedOn);
210219

@@ -473,6 +482,7 @@ private void CheckBox_CheckedChanged(object sender, EventArgs e)
473482
if (checkBox != null)
474483
{
475484
bool needSave = false;
485+
bool needNativeSave = false;
476486
switch (checkBox.Name)
477487
{
478488
case "checkBoxGw4":
@@ -484,6 +494,15 @@ private void CheckBox_CheckedChanged(object sender, EventArgs e)
484494
needSave = true;
485495
break;
486496
}
497+
case "checkBoxNativeGw4":
498+
case "checkBoxNativeGw6":
499+
case "checkBoxNativeDns4":
500+
case "checkBoxNativeDns6":
501+
{
502+
NativeCheckBoxes_ReEnable();
503+
needNativeSave = true;
504+
break;
505+
}
487506
case "checkBoxAutoRefresh":
488507
{
489508
if (!isLoadingSettings)
@@ -509,6 +528,10 @@ private void CheckBox_CheckedChanged(object sender, EventArgs e)
509528
{
510529
NetworkHelper.SaveAlterNativeSettings(textBoxGw4, textBoxGw6, textBoxDns4, textBoxDns6, checkBoxGw4, checkBoxGw6, checkBoxDns4, checkBoxDns6);
511530
}
531+
if (needNativeSave)
532+
{
533+
NetworkHelper.SaveNativeSettingsFromUI(textBoxNativeGw4, textBoxNativeGw6, textBoxNativeDns4, textBoxNativeDns6, checkBoxNativeGw4, checkBoxNativeGw6, checkBoxNativeDns4, checkBoxNativeDns6);
534+
}
512535
}
513536
}
514537
}
@@ -545,6 +568,13 @@ private void AlterCheckBoxes_ReEnable()
545568
textBoxDns4.Enabled = checkBoxDns4.Checked;
546569
textBoxDns6.Enabled = checkBoxDns6.Checked;
547570
}
571+
private void NativeCheckBoxes_ReEnable()
572+
{
573+
textBoxNativeGw4.Enabled = checkBoxNativeGw4.Checked;
574+
textBoxNativeGw6.Enabled = checkBoxNativeGw6.Checked;
575+
textBoxNativeDns4.Enabled = checkBoxNativeDns4.Checked;
576+
textBoxNativeDns6.Enabled = checkBoxNativeDns6.Checked;
577+
}
548578
private void TrackBarToggle_ValueChanged(object sender, EventArgs e)
549579
{
550580
if (!isLoadingSettings)

NetworkHelper.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,27 +251,32 @@ public static void SaveNativeSettings(NetworkInfo networkInfo)
251251
Settings.Default.Save();
252252
}
253253

254-
public static void SaveNativeSettingsFromUI(TextBox textBoxGw4, TextBox textBoxGw6, TextBox textBoxDns4, TextBox textBoxDns6)
254+
public static void SaveNativeSettingsFromUI(TextBox textBoxGw4, TextBox textBoxGw6, TextBox textBoxDns4, TextBox textBoxDns6, CheckBox checkBoxGw4, CheckBox checkBoxGw6, CheckBox checkBoxDns4, CheckBox checkBoxDns6)
255255
{
256256
Settings.Default.NativeGw4 = textBoxGw4.Text;
257257
Settings.Default.NativeGw6 = textBoxGw6.Text;
258258
Settings.Default.NativeDns4 = textBoxDns4.Text;
259259
Settings.Default.NativeDns6 = textBoxDns6.Text;
260260

261-
Settings.Default.NativeGw4Enabled = !string.IsNullOrEmpty(textBoxGw4.Text) && textBoxGw4.Text != "N/A";
262-
Settings.Default.NativeGw6Enabled = !string.IsNullOrEmpty(textBoxGw6.Text) && textBoxGw6.Text != "N/A";
263-
Settings.Default.NativeDns4Enabled = !string.IsNullOrEmpty(textBoxDns4.Text) && textBoxDns4.Text != "N/A";
264-
Settings.Default.NativeDns6Enabled = !string.IsNullOrEmpty(textBoxDns6.Text) && textBoxDns6.Text != "N/A";
261+
Settings.Default.NativeGw4Enabled = checkBoxGw4.Checked;
262+
Settings.Default.NativeGw6Enabled = checkBoxGw6.Checked;
263+
Settings.Default.NativeDns4Enabled = checkBoxDns4.Checked;
264+
Settings.Default.NativeDns6Enabled = checkBoxDns6.Checked;
265265

266266
Settings.Default.Save();
267267
}
268268

269-
public static void LoadNativeSettingsToUI(TextBox textBoxGw4, TextBox textBoxGw6, TextBox textBoxDns4, TextBox textBoxDns6)
269+
public static void LoadNativeSettingsToUI(TextBox textBoxGw4, TextBox textBoxGw6, TextBox textBoxDns4, TextBox textBoxDns6, CheckBox checkBoxGw4, CheckBox checkBoxGw6, CheckBox checkBoxDns4, CheckBox checkBoxDns6)
270270
{
271271
textBoxGw4.Text = Settings.Default.NativeGw4;
272272
textBoxGw6.Text = Settings.Default.NativeGw6;
273273
textBoxDns4.Text = Settings.Default.NativeDns4;
274274
textBoxDns6.Text = Settings.Default.NativeDns6;
275+
276+
checkBoxGw4.Checked = Settings.Default.NativeGw4Enabled;
277+
checkBoxGw6.Checked = Settings.Default.NativeGw6Enabled;
278+
checkBoxDns4.Checked = Settings.Default.NativeDns4Enabled;
279+
checkBoxDns6.Checked = Settings.Default.NativeDns6Enabled;
275280
}
276281

277282
public static NetworkInfo GetAlterNativeSettings()

0 commit comments

Comments
 (0)