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