VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Main/Forms/VolumeSizeWizardPage.cpp
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2021-09-21 01:36:47 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2021-09-21 01:41:25 +0200
commit5e547b127f25b0d4f526fdb4126b95c4ba03c4b2 (patch)
treed44d9d200f8c8040bab0a6424e78b68596bc935b /src/Main/Forms/VolumeSizeWizardPage.cpp
parent635213c8264c34e65b6711694e0b2cfd7fa6a078 (diff)
downloadVeraCrypt-5e547b127f25b0d4f526fdb4126b95c4ba03c4b2.tar.gz
VeraCrypt-5e547b127f25b0d4f526fdb4126b95c4ba03c4b2.zip
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.
Diffstat (limited to 'src/Main/Forms/VolumeSizeWizardPage.cpp')
-rw-r--r--src/Main/Forms/VolumeSizeWizardPage.cpp58
1 files changed, 47 insertions, 11 deletions
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 <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,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 <uint64> (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 <uint64> (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();
+ }
+ }
}