// Encodes a selection from the CSelectDrivesDlg into a string which can be routed as a pseudo // document "path" through MFC and finally arrives in OnOpenDocument(). // CString CDirstatDoc::EncodeSelection(RADIO radio, CString folder, const CStringArray& drives) { CString ret; switch (radio) { case RADIO_ALLLOCALDRIVES: case RADIO_SOMEDRIVES: { for(int i = 0; i < drives.GetSize(); i++) { if(i > 0) { ret += CString(GetEncodingSeparator()); } ret += drives[i]; } } break; case RADIO_AFOLDER: { ret = folder; } break; } return ret; }
// The inverse of EncodeSelection // void CDirstatDoc::DecodeSelection(CString s, CString& folder, CStringArray& drives) { folder.Empty(); drives.RemoveAll(); // s is either something like "C:\programme" // or something like "C:|D:|E:". CStringArray sa; int i=0; while (i < s.GetLength()) { CString token; while (i < s.GetLength() && s[i] != GetEncodingSeparator()) token+= s[i++]; token.TrimLeft(); token.TrimRight(); ASSERT(!token.IsEmpty()); sa.Add(token); if (i < s.GetLength()) i++; } ASSERT(sa.GetSize() > 0); if (sa.GetSize() > 1) { for (int i=0; i < sa.GetSize(); i++) { CString d= sa[i]; ASSERT(d.GetLength() == 2); ASSERT(d[1] == _T(':')); drives.Add(d + _T("\\")); } } else { CString f= sa[0]; if (f.GetLength() == 2 && f[1] == _T(':')) { drives.Add(f + _T("\\")); } else { // Remove trailing backslash, if any and not drive-root. if (f.GetLength() > 0 && f.Right(1) == _T("\\") && (f.GetLength() != 3 || f[1] != _T(':'))) { f= f.Left(f.GetLength() - 1); } folder= f; } } }