@@ -322,6 +322,79 @@ private void MainForm_Load(object sender, EventArgs e)
322322 textBoxPFXPassword . Text = "" ;
323323 }
324324
325+ // Load last used Trusted Signing options
326+ try
327+ {
328+ var savedAccount = iniFile . GetString ( "TrustedSigning" , "AccountName" , "" ) ;
329+ if ( ! string . IsNullOrWhiteSpace ( savedAccount ) )
330+ textBoxCodeSigningAccountName . Text = savedAccount ;
331+
332+ var savedProfile = iniFile . GetString ( "TrustedSigning" , "CertificateProfile" , "" ) ;
333+ if ( ! string . IsNullOrWhiteSpace ( savedProfile ) )
334+ textBoxCertificateProfileName . Text = savedProfile ;
335+ }
336+ catch ( Exception ex )
337+ {
338+ Message ( $ "Error loading Trusted Signing options: { ex . Message } ", EventType . Error , 3050 ) ;
339+ }
340+
341+ // Load last file list to sign
342+ try
343+ {
344+ var filesJson = iniFile . GetString ( "Files" , "ToSign" , "" ) ;
345+ if ( ! string . IsNullOrEmpty ( filesJson ) )
346+ {
347+ // Prefer robust parse to handle both JSON array and single string fallback
348+ List < string > files = null ;
349+ try
350+ {
351+ files = System . Text . Json . JsonSerializer . Deserialize < List < string > > ( filesJson ) ;
352+ }
353+ catch
354+ {
355+ // Try parse using JsonDocument in case of formatting issues
356+ using ( var doc = System . Text . Json . JsonDocument . Parse ( filesJson ) )
357+ {
358+ if ( doc . RootElement . ValueKind == System . Text . Json . JsonValueKind . Array )
359+ {
360+ files = new List < string > ( ) ;
361+ foreach ( var el in doc . RootElement . EnumerateArray ( ) )
362+ {
363+ if ( el . ValueKind == System . Text . Json . JsonValueKind . String )
364+ files . Add ( el . GetString ( ) ) ;
365+ }
366+ }
367+ }
368+ }
369+
370+ if ( files != null )
371+ {
372+ foreach ( var path in files )
373+ {
374+ try
375+ {
376+ var cleaned = System . Text . RegularExpressions . Regex . Replace ( path ?? string . Empty , @"\s*\[(Valid|Invalid)\]" , "" , System . Text . RegularExpressions . RegexOptions . IgnoreCase ) ;
377+ if ( ! string . IsNullOrWhiteSpace ( cleaned ) && File . Exists ( cleaned ) )
378+ {
379+ checkedListBoxFiles ? . Items . Add ( cleaned , true ) ;
380+ }
381+ }
382+ catch { /* ignore per-entry errors */ }
383+ }
384+
385+ if ( checkedListBoxFiles ? . Items != null && checkedListBoxFiles . Items . Count > 0 )
386+ {
387+ // Inform user via status bar
388+ statusLabel . Text = @"[INFO] " + checkedListBoxFiles . Items . Count + @" file(s) restored to File List" ;
389+ }
390+ }
391+ }
392+ }
393+ catch ( Exception ex )
394+ {
395+ Message ( $ "Error loading file list from configuration: { ex . Message } ", EventType . Error , 3051 ) ;
396+ }
397+
325398 // Initialize _previousSignToolPath with the current text box value or a default path
326399 _previousSignToolPath = textBoxSignToolPath . Text ;
327400 }
@@ -387,6 +460,41 @@ void SaveGeneralConfig(string encryptedPassword)
387460 // Save encrypted password (or empty if not saving)
388461 iniFile . WriteValue ( "Program" , "CertificatePassword" , encryptedPassword ?? "" ) ;
389462
463+ // Save last used Trusted Signing options
464+ try
465+ {
466+ iniFile . WriteValue ( "TrustedSigning" , "AccountName" , textBoxCodeSigningAccountName . Text ?? string . Empty ) ;
467+ iniFile . WriteValue ( "TrustedSigning" , "CertificateProfile" , textBoxCertificateProfileName . Text ?? string . Empty ) ;
468+ }
469+ catch ( Exception ex )
470+ {
471+ Message ( $ "Error saving Trusted Signing options: { ex . Message } ", EventType . Error , 3052 ) ;
472+ }
473+
474+ // Save file list to sign (as JSON array)
475+ try
476+ {
477+ var files = new List < string > ( ) ;
478+ if ( checkedListBoxFiles ? . Items != null )
479+ {
480+ foreach ( var item in checkedListBoxFiles . Items )
481+ {
482+ var s = item ? . ToString ( ) ?? string . Empty ;
483+ // Remove any [Valid]/[Invalid] tags before saving
484+ var cleaned = System . Text . RegularExpressions . Regex . Replace ( s , @"\s*\[(Valid|Invalid)\]" , "" , System . Text . RegularExpressions . RegexOptions . IgnoreCase ) ;
485+ if ( ! string . IsNullOrWhiteSpace ( cleaned ) )
486+ files . Add ( cleaned ) ;
487+ }
488+ }
489+
490+ var json = System . Text . Json . JsonSerializer . Serialize ( files ) ;
491+ iniFile . WriteValue ( "Files" , "ToSign" , json ) ;
492+ }
493+ catch ( Exception ex )
494+ {
495+ Message ( $ "Error saving file list to configuration: { ex . Message } ", EventType . Error , 3053 ) ;
496+ }
497+
390498 // Save timestamp and certificate type configuration
391499 try { SaveTimestampConfiguration ( ) ; } catch ( Exception ex ) { Message ( $ "Error saving timestamp configuration: { ex . Message } ", EventType . Error , 3013 ) ; }
392500 try { SaveCertificateTypeConfiguration ( ) ; } catch ( Exception ex ) { Message ( $ "Error saving certificate type configuration: { ex . Message } ", EventType . Error , 3030 ) ; }
@@ -1147,7 +1255,7 @@ private async Task SignWithPfxCertificateAsync()
11471255 {
11481256 if ( string . IsNullOrEmpty ( message ) ) return ;
11491257 // Filter out non-essential messages if the output checkbox is not checked.
1150- if ( ! checkBoxShowOutput . Checked && new [ ]
1258+ if ( ! checkBoxShowOutput . Checked && new [ ]
11511259 {
11521260 "Number of" , "Done Adding Additional Store" , "The following certificate was selected:" ,
11531261 "Signing file" , "hash:" , "Issued to:" , "Issued by:" , "Expires:" ,
@@ -1278,7 +1386,7 @@ private async Task SignWithTrustedSigningAsync()
12781386 {
12791387 if ( string . IsNullOrEmpty ( message ) ) return ;
12801388 // Filter out non-essential messages if the output checkbox is not checked.
1281- if ( ! checkBoxShowOutput . Checked && new [ ]
1389+ if ( ! checkBoxShowOutput . Checked && new [ ]
12821390 {
12831391 "Number of" , "Done Adding Additional Store" , "The following certificate was selected:" ,
12841392 "Signing file" , "hash:" , "Issued to:" , "Issued by:" , "Expires:" ,
@@ -1888,6 +1996,7 @@ private void ButtonShowSigningCertificate_Click(object sender, EventArgs e)
18881996 if ( radioButtonPFXCertificate . Checked )
18891997 {
18901998 // If the label for certificate information is not null, update it with the certificate info.
1999+ // If no certificate is selected, set the label to indicate that certificate info is not available.
18912000 if ( labelCertificateInformation != null )
18922001 labelCertificateInformation . Text = GetCertificateInfo ( GetCertificateFromPfx ( ) ) ;
18932002
0 commit comments