Skip to content

Commit 073b25c

Browse files
authored
Merge pull request #6110 from ChihweiLHBird/zhiwei/merge-computer-mru-when-saving
Preserve Existing MRU Computers when Saving
2 parents 5c21d78 + a9d2077 commit 073b25c

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

clientgui/BOINCBaseFrame.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@ bool CBOINCBaseFrame::SaveState() {
730730
wxString strConfigLocation;
731731
wxString strPreviousLocation;
732732
wxString strBuffer;
733-
int iIndex;
734-
int iItemCount;
733+
size_t iIndex;
734+
wxArrayString existingComputers;
735735

736736

737737
// An odd case happens every once and awhile where wxWidgets looses
@@ -757,18 +757,43 @@ bool CBOINCBaseFrame::SaveState() {
757757

758758
pConfig->SetPath(strConfigLocation);
759759

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);
763775
pConfig->Write(
764776
strBuffer,
765777
m_aSelectedComputerMRU.Item(iIndex)
766778
);
767779
}
768780

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+
}
770788

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+
}
771795

796+
pConfig->SetPath(strPreviousLocation);
772797
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCBaseFrame::SaveState - Function End"));
773798
return true;
774799
}
@@ -816,8 +841,10 @@ bool CBOINCBaseFrame::RestoreState() {
816841
bKeepEnumerating = pConfig->GetFirstEntry(strBuffer, iIndex);
817842
while (bKeepEnumerating) {
818843
pConfig->Read(strBuffer, &strValue);
844+
if (m_aSelectedComputerMRU.Index(strValue) == wxNOT_FOUND) {
845+
m_aSelectedComputerMRU.Add(strValue);
846+
}
819847

820-
m_aSelectedComputerMRU.Add(strValue);
821848
bKeepEnumerating = pConfig->GetNextEntry(strBuffer, iIndex);
822849
}
823850

0 commit comments

Comments
 (0)