@@ -730,8 +730,8 @@ bool CBOINCBaseFrame::SaveState() {
730
730
wxString strConfigLocation;
731
731
wxString strPreviousLocation;
732
732
wxString strBuffer;
733
- int iIndex;
734
- int iItemCount ;
733
+ size_t iIndex;
734
+ wxArrayString existingComputers ;
735
735
736
736
737
737
// An odd case happens every once and awhile where wxWidgets looses
@@ -757,18 +757,43 @@ bool CBOINCBaseFrame::SaveState() {
757
757
758
758
pConfig->SetPath (strConfigLocation);
759
759
760
- iItemCount = (int )m_aSelectedComputerMRU.GetCount () - 1 ;
761
- for (iIndex = 0 ; iIndex <= iItemCount; iIndex++) {
762
- strBuffer.Printf (wxT (" %d" ), iIndex);
760
+
761
+ // Retrieve existing computers in the config because
762
+ // some computers may have been added by other BOINC manager windows.
763
+ iIndex = 0 ;
764
+ strBuffer.Printf (wxT (" %zu" ), iIndex);
765
+ while (pConfig->Exists (strBuffer)) {
766
+ wxString computer = pConfig->Read (strBuffer, wxEmptyString);
767
+ if (computer != wxEmptyString && existingComputers.Index (computer) == wxNOT_FOUND) {
768
+ existingComputers.Add (computer);
769
+ }
770
+ strBuffer.Printf (wxT (" %zu" ), ++iIndex);
771
+ }
772
+
773
+ for (iIndex = 0 ; iIndex < m_aSelectedComputerMRU.GetCount (); iIndex++) {
774
+ strBuffer.Printf (wxT (" %zu" ), iIndex);
763
775
pConfig->Write (
764
776
strBuffer,
765
777
m_aSelectedComputerMRU.Item (iIndex)
766
778
);
767
779
}
768
780
769
- pConfig->SetPath (strPreviousLocation);
781
+ // Write existing computers that are not in the MRU list into the config.
782
+ for (const wxString& computer : existingComputers) {
783
+ if (m_aSelectedComputerMRU.Index (computer) == wxNOT_FOUND) {
784
+ strBuffer.Printf (wxT (" %zu" ), iIndex++);
785
+ pConfig->Write (strBuffer, computer);
786
+ }
787
+ }
770
788
789
+ // Remove any remaining MRU computer entries in the config to avoid duplicates.
790
+ strBuffer.Printf (wxT (" %zu" ), iIndex);
791
+ while (pConfig->Exists (strBuffer)) {
792
+ pConfig->DeleteEntry (strBuffer);
793
+ strBuffer.Printf (wxT (" %zu" ), ++iIndex);
794
+ }
771
795
796
+ pConfig->SetPath (strPreviousLocation);
772
797
wxLogTrace (wxT (" Function Start/End" ), wxT (" CBOINCBaseFrame::SaveState - Function End" ));
773
798
return true ;
774
799
}
@@ -816,8 +841,10 @@ bool CBOINCBaseFrame::RestoreState() {
816
841
bKeepEnumerating = pConfig->GetFirstEntry (strBuffer, iIndex);
817
842
while (bKeepEnumerating) {
818
843
pConfig->Read (strBuffer, &strValue);
844
+ if (m_aSelectedComputerMRU.Index (strValue) == wxNOT_FOUND) {
845
+ m_aSelectedComputerMRU.Add (strValue);
846
+ }
819
847
820
- m_aSelectedComputerMRU.Add (strValue);
821
848
bKeepEnumerating = pConfig->GetNextEntry (strBuffer, iIndex);
822
849
}
823
850
0 commit comments