From 5e547b127f25b0d4f526fdb4126b95c4ba03c4b2 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 21 Sep 2021 01:36:47 +0200 Subject: Linux/macOS: Add CLI switch (--size=max) and UI option to give a file container all available free space. This commit also makes --size switch accept KiB/MiB/GiB/TiB prefixes and adds TiB choice in UI. --- src/Main/Forms/Forms.cpp | 8 +++ src/Main/Forms/Forms.h | 2 + src/Main/Forms/TrueCrypt.fbp | 98 +++++++++++++++++++++++++++++++++ src/Main/Forms/VolumeSizeWizardPage.cpp | 58 +++++++++++++++---- src/Main/Forms/VolumeSizeWizardPage.h | 4 +- 5 files changed, 158 insertions(+), 12 deletions(-) (limited to 'src/Main/Forms') diff --git a/src/Main/Forms/Forms.cpp b/src/Main/Forms/Forms.cpp index 0af3e2a6..d281febc 100644 --- a/src/Main/Forms/Forms.cpp +++ b/src/Main/Forms/Forms.cpp @@ -3625,6 +3625,12 @@ VolumeSizeWizardPageBase::VolumeSizeWizardPageBase( wxWindow* parent, wxWindowID bSizer99->Add( 0, 0, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 ); + UseAllFreeSpaceCheckBox = new wxCheckBox( this, wxID_ANY, _("IDC_USE_ALL_FREE_SPACE"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer99->Add( UseAllFreeSpaceCheckBox, 0, wxALL|wxEXPAND, 5 ); + + + bSizer99->Add( 0, 0, 0, wxBOTTOM|wxEXPAND|wxTOP, 5 ); + FreeSpaceStaticText = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); FreeSpaceStaticText->Wrap( -1 ); @@ -3649,6 +3655,7 @@ VolumeSizeWizardPageBase::VolumeSizeWizardPageBase( wxWindow* parent, wxWindowID // Connect Events VolumeSizeTextCtrl->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumeSizeWizardPageBase::OnVolumeSizeTextChanged ), NULL, this ); VolumeSizePrefixChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( VolumeSizeWizardPageBase::OnVolumeSizePrefixSelected ), NULL, this ); + UseAllFreeSpaceCheckBox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumeSizeWizardPageBase::OnUseAllFreeSpaceCheckBoxClick ), NULL, this ); } VolumeSizeWizardPageBase::~VolumeSizeWizardPageBase() @@ -3656,6 +3663,7 @@ VolumeSizeWizardPageBase::~VolumeSizeWizardPageBase() // Disconnect Events VolumeSizeTextCtrl->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( VolumeSizeWizardPageBase::OnVolumeSizeTextChanged ), NULL, this ); VolumeSizePrefixChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( VolumeSizeWizardPageBase::OnVolumeSizePrefixSelected ), NULL, this ); + UseAllFreeSpaceCheckBox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( VolumeSizeWizardPageBase::OnUseAllFreeSpaceCheckBoxClick ), NULL, this ); } diff --git a/src/Main/Forms/Forms.h b/src/Main/Forms/Forms.h index 3ea89763..b1756876 100644 --- a/src/Main/Forms/Forms.h +++ b/src/Main/Forms/Forms.h @@ -1063,12 +1063,14 @@ namespace VeraCrypt protected: wxTextCtrl* VolumeSizeTextCtrl; wxChoice* VolumeSizePrefixChoice; + wxCheckBox* UseAllFreeSpaceCheckBox; wxStaticText* FreeSpaceStaticText; wxStaticText* InfoStaticText; // Virtual event handlers, overide them in your derived class virtual void OnVolumeSizeTextChanged( wxCommandEvent& event ) { event.Skip(); } virtual void OnVolumeSizePrefixSelected( wxCommandEvent& event ) { event.Skip(); } + virtual void OnUseAllFreeSpaceCheckBoxClick( wxCommandEvent& event ) { event.Skip(); } public: diff --git a/src/Main/Forms/TrueCrypt.fbp b/src/Main/Forms/TrueCrypt.fbp index 927a60b9..24689fcf 100644 --- a/src/Main/Forms/TrueCrypt.fbp +++ b/src/Main/Forms/TrueCrypt.fbp @@ -29550,6 +29550,104 @@ + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + IDC_USE_ALL_FREE_SPACE + + 0 + + + 0 + + 1 + UseAllFreeSpaceCheckBox + 1 + + + protected + 1 + + Resizable + 1 + + + ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + OnUseAllFreeSpaceCheckBoxClick + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxBOTTOM|wxEXPAND|wxTOP + 0 + + 0 + protected + 0 + + + 5 wxALL|wxEXPAND 0 diff --git a/src/Main/Forms/VolumeSizeWizardPage.cpp b/src/Main/Forms/VolumeSizeWizardPage.cpp index 47d73983..61427ea5 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 (1024)); - VolumeSizePrefixChoice->Append (LangString["MB"], reinterpret_cast (1024 * 1024)); - VolumeSizePrefixChoice->Append (LangString["GB"], reinterpret_cast (1024 * 1024 * 1024)); + VolumeSizePrefixChoice->Append (LangString["KB"], reinterpret_cast (1)); + VolumeSizePrefixChoice->Append (LangString["MB"], reinterpret_cast (2)); + VolumeSizePrefixChoice->Append (LangString["GB"], reinterpret_cast (3)); + VolumeSizePrefixChoice->Append (LangString["TB"], reinterpret_cast (4)); VolumeSizePrefixChoice->Select (Prefix::MB); wxLongLong diskSpace = 0; @@ -34,6 +35,7 @@ namespace VeraCrypt { VolumeSizeTextCtrl->Disable(); VolumeSizeTextCtrl->SetValue (L""); + UseAllFreeSpaceCheckBox->Disable(); } else { @@ -74,13 +76,25 @@ namespace VeraCrypt uint64 VolumeSizeWizardPage::GetVolumeSize () const { uint64 prefixMult = 1; - int selection = VolumeSizePrefixChoice->GetSelection(); - if (selection == wxNOT_FOUND) - return 0; - - prefixMult = reinterpret_cast (VolumeSizePrefixChoice->GetClientData (selection)); + uint64 val; + if (UseAllFreeSpaceCheckBox->IsChecked ()) + { + val = AvailableDiskSpace; + } + else + { + int selection = VolumeSizePrefixChoice->GetSelection(); + if (selection == wxNOT_FOUND) + return 0; - uint64 val = StringConverter::ToUInt64 (wstring (VolumeSizeTextCtrl->GetValue())); + uint64 counter = reinterpret_cast (VolumeSizePrefixChoice->GetClientData (selection)); + while (counter) + { + prefixMult *= 1024; + counter--; + } + val = StringConverter::ToUInt64 (wstring(VolumeSizeTextCtrl->GetValue())); + } if (val <= 0x7fffFFFFffffFFFFull / prefixMult) { val *= prefixMult; @@ -98,7 +112,7 @@ namespace VeraCrypt bool VolumeSizeWizardPage::IsValid () { - if (!VolumeSizeTextCtrl->GetValue().empty() && Validate()) + if ((!VolumeSizeTextCtrl->GetValue().empty() || UseAllFreeSpaceCheckBox->IsChecked ()) && Validate()) { try { @@ -126,7 +140,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 +163,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(); + } + } } diff --git a/src/Main/Forms/VolumeSizeWizardPage.h b/src/Main/Forms/VolumeSizeWizardPage.h index aac41f99..754bd691 100644 --- a/src/Main/Forms/VolumeSizeWizardPage.h +++ b/src/Main/Forms/VolumeSizeWizardPage.h @@ -37,13 +37,15 @@ namespace VeraCrypt { KB = 0, MB, - GB + GB, + TB }; }; void OnBrowseButtonClick (wxCommandEvent& event); void OnVolumeSizePrefixSelected (wxCommandEvent& event) { PageUpdatedEvent.Raise(); } void OnVolumeSizeTextChanged (wxCommandEvent& event) { PageUpdatedEvent.Raise(); } + void OnUseAllFreeSpaceCheckBoxClick( wxCommandEvent& event ); uint64 MaxVolumeSize; bool MaxVolumeSizeValid; -- cgit v1.2.3