"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/VolumeHistory.cpp" (10 Oct 2018, 3374 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "VolumeHistory.cpp" see the Fossies "Dox" file reference documentation.

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