@@ -19,6 +19,7 @@ public class MainForm : Form
1919 private Button reloadButton ;
2020 private Button checkUpdatesButton ;
2121 private Button accessibilityButton ;
22+ private CheckBox safeApplyCheckBox ;
2223 private Label statusLabel ;
2324 private Config currentConfig ;
2425 private GpdDevice device ;
@@ -60,9 +61,15 @@ public MainForm()
6061 resetButton . AutoSize = true ;
6162 resetButton . Click += new EventHandler ( ResetButton_Click ) ;
6263
64+ safeApplyCheckBox = new CheckBox ( ) ;
65+ safeApplyCheckBox . Text = "Safe Apply Verify" ;
66+ safeApplyCheckBox . AutoSize = true ;
67+ safeApplyCheckBox . Checked = true ;
68+
6369 buttonPanel . Controls . Add ( reloadButton ) ;
6470 buttonPanel . Controls . Add ( applyButton ) ;
6571 buttonPanel . Controls . Add ( resetButton ) ;
72+ buttonPanel . Controls . Add ( safeApplyCheckBox ) ;
6673 mainLayout . Controls . Add ( buttonPanel , 0 , 0 ) ;
6774
6875 // Content Tabs
@@ -1290,6 +1297,53 @@ private void CaptureKey_Click(object sender, EventArgs e)
12901297 }
12911298 }
12921299
1300+ private bool VerifyAppliedConfiguration ( Config expectedConfig , out string report )
1301+ {
1302+ report = string . Empty ;
1303+ try
1304+ {
1305+ byte [ ] verifyRaw = device . ReadConfig ( ) ;
1306+ Config actualConfig = new Config ( verifyRaw ) ;
1307+
1308+ List < string > mismatches = new List < string > ( ) ;
1309+ foreach ( Config . FieldDef def in Config . Fields )
1310+ {
1311+ string expected = expectedConfig . GetValue ( def ) ;
1312+ string actual = actualConfig . GetValue ( def ) ;
1313+ if ( ! string . Equals ( expected , actual , StringComparison . OrdinalIgnoreCase ) )
1314+ {
1315+ mismatches . Add ( string . Format ( "{0}: expected {1}, actual {2}" , def . Name , expected , actual ) ) ;
1316+ }
1317+ }
1318+
1319+ if ( mismatches . Count == 0 )
1320+ {
1321+ currentConfig = actualConfig ;
1322+ RefreshList ( ) ;
1323+ return true ;
1324+ }
1325+
1326+ StringWriter sw = new StringWriter ( ) ;
1327+ sw . WriteLine ( "Verification failed. Mismatched fields: " + mismatches . Count ) ;
1328+ int limit = Math . Min ( 30 , mismatches . Count ) ;
1329+ for ( int i = 0 ; i < limit ; i ++ )
1330+ {
1331+ sw . WriteLine ( mismatches [ i ] ) ;
1332+ }
1333+ if ( mismatches . Count > limit )
1334+ {
1335+ sw . WriteLine ( "...and " + ( mismatches . Count - limit ) + " more" ) ;
1336+ }
1337+ report = sw . ToString ( ) ;
1338+ return false ;
1339+ }
1340+ catch ( Exception ex )
1341+ {
1342+ report = "Verification read-back failed: " + ex . Message ;
1343+ return false ;
1344+ }
1345+ }
1346+
12931347 private void ApplyButton_Click ( object sender , EventArgs e )
12941348 {
12951349 if ( ! EnsureConnectedAndLoaded ( ) ) return ;
@@ -1304,6 +1358,22 @@ private void ApplyButton_Click(object sender, EventArgs e)
13041358 statusLabel . Text = "Writing to device..." ;
13051359 Application . DoEvents ( ) ;
13061360 device . WriteConfig ( currentConfig . Raw ) ;
1361+
1362+ if ( safeApplyCheckBox != null && safeApplyCheckBox . Checked )
1363+ {
1364+ statusLabel . Text = "Verifying write..." ;
1365+ Application . DoEvents ( ) ;
1366+ string verifyReport ;
1367+ if ( ! VerifyAppliedConfiguration ( currentConfig , out verifyReport ) )
1368+ {
1369+ statusLabel . Text = "Verification failed." ;
1370+ GuiLogger . Log ( "Safe apply verification failed. " + verifyReport . Replace ( Environment . NewLine , " | " ) ) ;
1371+ MessageBox . Show ( verifyReport , "Safe Apply Verification Failed" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
1372+ return ;
1373+ }
1374+ GuiLogger . Log ( "Safe apply verification passed." ) ;
1375+ }
1376+
13071377 statusLabel . Text = "Saved successfully." ;
13081378 GuiLogger . Log ( "Configuration written to device." ) ;
13091379 ShowInfo ( "Configuration saved to device!" , "Configuration saved." ) ;
0 commit comments