"Fossies" - the Fresh Open Source Software Archive

Member "src/Main/Forms/VolumeCreationProgressWizardPage.cpp" (10 Oct 2018, 5511 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 "VolumeCreationProgressWizardPage.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 "Main/GraphicUserInterface.h"
   15 #include "VolumeCreationProgressWizardPage.h"
   16 
   17 namespace VeraCrypt
   18 {
   19     VolumeCreationProgressWizardPage::VolumeCreationProgressWizardPage (wxPanel* parent, bool displayKeyInfo)
   20         : VolumeCreationProgressWizardPageBase (parent),
   21         PreviousGaugeValue (0),
   22         ProgressBarRange (1),
   23         RealProgressBarRange (1),
   24         VolumeCreatorRunning (false),
   25         MouseEventsCounter (0)
   26     {
   27         DisplayKeysCheckBox->SetValue (displayKeyInfo);
   28 #ifdef TC_WINDOWS
   29         DisplayKeysCheckBox->SetLabel (L"");
   30 #endif
   31 
   32 #ifdef TC_MACOSX
   33         ProgressGauge->SetMinSize (wxSize (-1, 12)); // OS X apparently supports only up to 12px thick progress bars
   34         KeySamplesUpperSizer->Remove (KeySamplesUpperInnerSizer);
   35 #else
   36         ProgressGauge->SetMinSize (wxSize (-1, Gui->GetCharHeight (this) * 2));
   37 #endif
   38 
   39         CollectedEntropy->SetRange (RNG_POOL_SIZE * 8);
   40 
   41         if (DisplayKeysCheckBox->IsChecked())
   42             ShowBytes (RandomPoolSampleStaticText, RandomNumberGenerator::PeekPool(), true);
   43         else
   44             ShowAsterisks (RandomPoolSampleStaticText);
   45 
   46         class Timer : public wxTimer
   47         {
   48         public:
   49             Timer (VolumeCreationProgressWizardPage *page) : Page (page) { }
   50 
   51             void Notify()
   52             {
   53                 Page->OnRandomPoolTimer();
   54             }
   55 
   56             VolumeCreationProgressWizardPage *Page;
   57         };
   58 
   59         RandomPoolTimer.reset (dynamic_cast <wxTimer *> (new Timer (this)));
   60         RandomPoolTimer->Start (30);
   61 
   62         AbortButton->Disable();
   63         ProgressGauge->SetValue (0);
   64 
   65     }
   66 
   67     void VolumeCreationProgressWizardPage::OnAbortButtonClick (wxCommandEvent& event)
   68     {
   69         AbortEvent.Raise();
   70     }
   71 
   72     void VolumeCreationProgressWizardPage::OnDisplayKeysCheckBoxClick (wxCommandEvent& event)
   73     {
   74         if (!event.IsChecked())
   75         {
   76             ShowAsterisks (RandomPoolSampleStaticText);
   77             ShowAsterisks (HeaderKeySampleStaticText);
   78             ShowAsterisks (MasterKeySampleStaticText);
   79         }
   80         else
   81         {
   82             RandomPoolSampleStaticText->SetLabel (L"");
   83             HeaderKeySampleStaticText->SetLabel (L"");
   84             MasterKeySampleStaticText->SetLabel (L"");
   85         }
   86     }
   87 
   88     void VolumeCreationProgressWizardPage::OnRandomPoolTimer ()
   89     {
   90         if (!VolumeCreatorRunning && DisplayKeysCheckBox->IsChecked())
   91             ShowBytes (RandomPoolSampleStaticText, RandomNumberGenerator::PeekPool(), true);
   92     }
   93 
   94     void VolumeCreationProgressWizardPage::SetKeyInfo (const VolumeCreator::KeyInfo &keyInfo)
   95     {
   96         if (DisplayKeysCheckBox->IsChecked())
   97         {
   98             ShowBytes (RandomPoolSampleStaticText, RandomNumberGenerator::PeekPool(), true);
   99             ShowBytes (HeaderKeySampleStaticText, keyInfo.HeaderKey);
  100             ShowBytes (MasterKeySampleStaticText, keyInfo.MasterKey);
  101         }
  102     }
  103 
  104     void VolumeCreationProgressWizardPage::ShowAsterisks (wxStaticText *textCtrl)
  105     {
  106         wxString str;
  107         for (size_t i = 0; i < MaxDisplayedKeyBytes + 1; ++i)
  108         {
  109             str += L"**";
  110         }
  111 
  112         textCtrl->SetLabel (str.c_str());
  113     }
  114 
  115     void VolumeCreationProgressWizardPage::ShowBytes (wxStaticText *textCtrl, const ConstBufferPtr &buffer, bool appendDots)
  116     {
  117         wxString str;
  118 
  119         for (size_t i = 0; i < MaxDisplayedKeyBytes && i < buffer.Size(); ++i)
  120         {
  121             str += wxString::Format (L"%02X", buffer[i]);
  122         }
  123 
  124         if (appendDots)
  125             str += L"..";
  126 
  127         textCtrl->SetLabel (str.c_str());
  128 
  129         for (size_t i = 0; i < str.size(); ++i)
  130         {
  131             str[i] = L'X';
  132         }
  133     }
  134 
  135     void VolumeCreationProgressWizardPage::SetProgressValue (uint64 value)
  136     {
  137         int gaugeValue = static_cast <int> (value * RealProgressBarRange / ProgressBarRange);
  138 
  139         if (value == ProgressBarRange)
  140             gaugeValue = RealProgressBarRange; // Prevent round-off error
  141 
  142         if (gaugeValue != PreviousGaugeValue)
  143         {
  144             ProgressGauge->SetValue (gaugeValue);
  145             PreviousGaugeValue = gaugeValue;
  146         }
  147 
  148         if (value != 0)
  149         {
  150             SizeDoneStaticText->SetLabel (wxString::Format (L"%7.3f%%", 100.0 - double (ProgressBarRange - value) / (double (ProgressBarRange) / 100.0)));
  151 
  152             wxLongLong timeDiff = wxGetLocalTimeMillis() - StartTime;
  153             if (timeDiff.GetValue() > 0)
  154             {
  155                 uint64 speed = value * 1000 / timeDiff.GetValue();
  156 
  157                 if (ProgressBarRange != value)
  158                     SpeedStaticText->SetLabel (Gui->SpeedToString (speed));
  159 
  160                 TimeLeftStaticText->SetLabel (speed > 0 ? Gui->TimeSpanToString ((ProgressBarRange - value) / speed) : L"");
  161             }
  162         }
  163         else
  164         {
  165             SizeDoneStaticText->SetLabel (L"");
  166             SpeedStaticText->SetLabel (L"");
  167             TimeLeftStaticText->SetLabel (L"");
  168         }
  169     }
  170 
  171     void VolumeCreationProgressWizardPage::SetMaxStaticTextWidth (int width)
  172     {
  173         InfoStaticText->Wrap (width);
  174     }
  175 
  176     void VolumeCreationProgressWizardPage::SetProgressState (bool volumeCreatorRunning)
  177     {
  178         if (volumeCreatorRunning)
  179             StartTime = wxGetLocalTimeMillis();
  180 
  181         VolumeCreatorRunning = volumeCreatorRunning;
  182     }
  183 
  184     void VolumeCreationProgressWizardPage::SetProgressRange (uint64 progressBarRange)
  185     {
  186         ProgressBarRange = progressBarRange;
  187         RealProgressBarRange = ProgressGauge->GetSize().GetWidth();
  188         ProgressGauge->SetRange (RealProgressBarRange);
  189     }
  190 
  191     void VolumeCreationProgressWizardPage::IncrementEntropyProgress ()
  192     {
  193         ScopeLock lock (AccessMutex);
  194         if (MouseEventsCounter < (RNG_POOL_SIZE * 8))
  195             CollectedEntropy->SetValue (++MouseEventsCounter);
  196     }
  197 }