diff options
Diffstat (limited to 'src/Main/Forms/VolumeSizeWizardPage.cpp')
-rw-r--r-- | src/Main/Forms/VolumeSizeWizardPage.cpp | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/src/Main/Forms/VolumeSizeWizardPage.cpp b/src/Main/Forms/VolumeSizeWizardPage.cpp index 3781b05d..08aa7052 100644 --- a/src/Main/Forms/VolumeSizeWizardPage.cpp +++ b/src/Main/Forms/VolumeSizeWizardPage.cpp @@ -24,9 +24,10 @@ namespace VeraCrypt SectorSize (sectorSize), AvailableDiskSpace (0) { - VolumeSizePrefixChoice->Append (LangString["KB"], reinterpret_cast <void *> (1024)); - VolumeSizePrefixChoice->Append (LangString["MB"], reinterpret_cast <void *> (1024 * 1024)); - VolumeSizePrefixChoice->Append (LangString["GB"], reinterpret_cast <void *> (1024 * 1024 * 1024)); + VolumeSizePrefixChoice->Append (LangString["KB"], reinterpret_cast <void *> (1)); + VolumeSizePrefixChoice->Append (LangString["MB"], reinterpret_cast <void *> (2)); + VolumeSizePrefixChoice->Append (LangString["GB"], reinterpret_cast <void *> (3)); + VolumeSizePrefixChoice->Append (LangString["TB"], reinterpret_cast <void *> (4)); VolumeSizePrefixChoice->Select (Prefix::MB); wxLongLong diskSpace = 0; @@ -34,9 +35,16 @@ namespace VeraCrypt { VolumeSizeTextCtrl->Disable(); VolumeSizeTextCtrl->SetValue (L""); + UseAllFreeSpaceCheckBox->Disable(); } else { + if (!volumePath.IsDevice()) + { + wxULongLong containerSizeUnsigned = wxFileName (wstring (volumePath)).GetSize(); + if (containerSizeUnsigned != wxInvalidSize) + diskSpace += static_cast<wxLongLong_t>(containerSizeUnsigned.GetValue()); + } AvailableDiskSpace = (uint64) diskSpace.GetValue (); } @@ -52,35 +60,45 @@ namespace VeraCrypt wxString drive = wxFileName (wstring (volumePath)).GetVolume(); if (!drive.empty()) { - FreeSpaceStaticText->SetLabel (StringFormatter (_("Free space on drive {0}: is {1}."), + FreeSpaceStaticText->SetLabel (StringFormatter (LangString["LINUX_FREE_SPACE_ON_DRIVE"], drive, Gui->SizeToString (diskSpace.GetValue()))); } else #endif { - FreeSpaceStaticText->SetLabel (StringFormatter (_("Free space available: {0}"), + FreeSpaceStaticText->SetLabel (StringFormatter (LangString["DISK_FREE"], Gui->SizeToString (diskSpace.GetValue()))); } } VolumeSizeTextCtrl->SetMinSize (wxSize (Gui->GetCharWidth (VolumeSizeTextCtrl) * 20, -1)); - wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc. - const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" }; - validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr)); + wxTextValidator validator (wxFILTER_DIGITS); VolumeSizeTextCtrl->SetValidator (validator); } uint64 VolumeSizeWizardPage::GetVolumeSize () const { uint64 prefixMult = 1; - int selection = VolumeSizePrefixChoice->GetSelection(); - if (selection == wxNOT_FOUND) - return 0; - - prefixMult = reinterpret_cast <uint64> (VolumeSizePrefixChoice->GetClientData (selection)); + uint64 val; + if (UseAllFreeSpaceCheckBox->IsChecked ()) + { + val = MaxVolumeSizeValid ? MaxVolumeSize : AvailableDiskSpace; + } + else + { + int selection = VolumeSizePrefixChoice->GetSelection(); + if (selection == wxNOT_FOUND) + return 0; - uint64 val = StringConverter::ToUInt64 (wstring (VolumeSizeTextCtrl->GetValue())); + uint64 counter = reinterpret_cast <uint64> (VolumeSizePrefixChoice->GetClientData (selection)); + while (counter) + { + prefixMult *= 1024; + counter--; + } + val = StringConverter::ToUInt64 (wstring(VolumeSizeTextCtrl->GetValue())); + } if (val <= 0x7fffFFFFffffFFFFull / prefixMult) { val *= prefixMult; @@ -98,12 +116,12 @@ namespace VeraCrypt bool VolumeSizeWizardPage::IsValid () { - if (!VolumeSizeTextCtrl->GetValue().empty() && Validate()) + if ((!VolumeSizeTextCtrl->GetValue().empty() || UseAllFreeSpaceCheckBox->IsChecked ()) && Validate()) { try { uint64 uiVolumeSize = GetVolumeSize(); - if (uiVolumeSize >= MinVolumeSize && (!MaxVolumeSizeValid || uiVolumeSize <= MaxVolumeSize) && (CmdLine->ArgDisableFileSizeCheck || !AvailableDiskSpace || uiVolumeSize <= AvailableDiskSpace)) + if (uiVolumeSize >= MinVolumeSize && (!MaxVolumeSizeValid || uiVolumeSize <= MaxVolumeSize) && (MaxVolumeSizeValid || CmdLine->ArgDisableFileSizeCheck || !AvailableDiskSpace || uiVolumeSize <= AvailableDiskSpace)) return true; } catch (...) { } @@ -126,7 +144,12 @@ namespace VeraCrypt return; } - if (size % (1024 * 1024 * 1024) == 0) + if (size % (1024ULL * 1024ULL * 1024ULL * 1024ULL) == 0) + { + size /= 1024ULL * 1024ULL * 1024ULL * 1024ULL; + VolumeSizePrefixChoice->Select (Prefix::TB); + } + else if (size % (1024 * 1024 * 1024) == 0) { size /= 1024 * 1024 * 1024; VolumeSizePrefixChoice->Select (Prefix::GB); @@ -144,4 +167,21 @@ namespace VeraCrypt VolumeSizeTextCtrl->SetValue (StringConverter::FromNumber (size)); } + + void VolumeSizeWizardPage::OnUseAllFreeSpaceCheckBoxClick( wxCommandEvent& event ) + { + if (UseAllFreeSpaceCheckBox->IsChecked ()) + { + VolumeSizePrefixChoice->Select (Prefix::MB); + VolumeSizeTextCtrl->SetValue (L""); + VolumeSizePrefixChoice->Disable(); + VolumeSizeTextCtrl->Disable(); + } + else + { + VolumeSizePrefixChoice->Enable(); + VolumeSizeTextCtrl->SetValue (L""); + VolumeSizeTextCtrl->Enable(); + } + } } |