|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.4 the full text of which is contained ! 5: in the file License.txt included in TrueCrypt binary and source code ! 6: distribution packages. ! 7: */ ! 8: ! 9: #include "System.h" ! 10: #include "Application.h" ! 11: #include "GraphicUserInterface.h" ! 12: #include "Xml.h" ! 13: #include "VolumeHistory.h" ! 14: ! 15: namespace TrueCrypt ! 16: { ! 17: VolumeHistory::VolumeHistory () ! 18: { ! 19: } ! 20: ! 21: VolumeHistory::~VolumeHistory () ! 22: { ! 23: } ! 24: ! 25: void VolumeHistory::Add (const VolumePath &newPath) ! 26: { ! 27: if (Gui->GetPreferences().SaveHistory) ! 28: { ! 29: ScopeLock lock (AccessMutex); ! 30: ! 31: VolumePathList::iterator iter = VolumePaths.begin(); ! 32: foreach (const VolumePath &path, VolumePaths) ! 33: { ! 34: if (newPath == path) ! 35: { ! 36: VolumePaths.erase (iter); ! 37: break; ! 38: } ! 39: iter++; ! 40: } ! 41: ! 42: VolumePaths.push_front (newPath); ! 43: if (VolumePaths.size() > MaxSize) ! 44: VolumePaths.pop_back(); ! 45: ! 46: foreach (wxComboBox *comboBox, ConnectedComboBoxes) ! 47: { ! 48: UpdateComboBox (comboBox); ! 49: } ! 50: } ! 51: } ! 52: ! 53: void VolumeHistory::Clear () ! 54: { ! 55: VolumePaths.clear(); ! 56: foreach (wxComboBox *comboBox, ConnectedComboBoxes) ! 57: { ! 58: UpdateComboBox (comboBox); ! 59: } ! 60: ! 61: Save(); ! 62: } ! 63: ! 64: void VolumeHistory::ConnectComboBox (wxComboBox *comboBox) ! 65: { ! 66: ScopeLock lock (AccessMutex); ! 67: ConnectedComboBoxes.push_back (comboBox); ! 68: ! 69: UpdateComboBox (comboBox); ! 70: } ! 71: ! 72: void VolumeHistory::DisconnectComboBox (wxComboBox *comboBox) ! 73: { ! 74: ScopeLock lock (AccessMutex); ! 75: ! 76: for (list<wxComboBox *>::iterator iter = ConnectedComboBoxes.begin(); iter != ConnectedComboBoxes.end(); ++iter) ! 77: { ! 78: if (comboBox == *iter) ! 79: { ! 80: ConnectedComboBoxes.erase (iter); ! 81: break; ! 82: } ! 83: } ! 84: } ! 85: ! 86: void VolumeHistory::Load () ! 87: { ! 88: ScopeLock lock (AccessMutex); ! 89: FilePath historyCfgPath = Application::GetConfigFilePath (GetFileName()); ! 90: ! 91: if (historyCfgPath.IsFile()) ! 92: { ! 93: if (!Gui->GetPreferences().SaveHistory) ! 94: { ! 95: historyCfgPath.Delete(); ! 96: } ! 97: else ! 98: { ! 99: foreach_reverse (const XmlNode &node, XmlParser (historyCfgPath).GetNodes (L"volume")) ! 100: { ! 101: Add (wstring (node.InnerText)); ! 102: } ! 103: } ! 104: } ! 105: } ! 106: ! 107: void VolumeHistory::Save () ! 108: { ! 109: ScopeLock lock (AccessMutex); ! 110: FilePath historyCfgPath = Application::GetConfigFilePath (GetFileName(), true); ! 111: ! 112: if (!Gui->GetPreferences().SaveHistory || VolumePaths.empty()) ! 113: { ! 114: if (historyCfgPath.IsFile()) ! 115: historyCfgPath.Delete(); ! 116: } ! 117: else ! 118: { ! 119: XmlNode historyXml (L"history"); ! 120: ! 121: foreach (const VolumePath &path, VolumePaths) ! 122: { ! 123: historyXml.InnerNodes.push_back (XmlNode (L"volume", wstring (path))); ! 124: } ! 125: ! 126: XmlWriter historyWriter (historyCfgPath); ! 127: historyWriter.WriteNode (historyXml); ! 128: historyWriter.Close(); ! 129: } ! 130: } ! 131: ! 132: void VolumeHistory::UpdateComboBox (wxComboBox *comboBox) ! 133: { ! 134: wxString curValue = comboBox->GetValue(); ! 135: ! 136: comboBox->Freeze(); ! 137: comboBox->Clear(); ! 138: ! 139: foreach (const VolumePath &path, VolumePaths) ! 140: { ! 141: comboBox->Append (wstring (path)); ! 142: } ! 143: ! 144: comboBox->SetValue (curValue); ! 145: comboBox->Thaw(); ! 146: } ! 147: ! 148: list <wxComboBox *> VolumeHistory::ConnectedComboBoxes; ! 149: VolumePathList VolumeHistory::VolumePaths; ! 150: Mutex VolumeHistory::AccessMutex; ! 151: ! 152: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.