VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Main
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2016-01-24 02:02:48 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2016-01-24 02:41:49 +0100
commitc86697f51b0b71d327ba7f4b9211cacde0bbd2f0 (patch)
treeab5c41776a55270b3841a57a775c3fcc78f069df /src/Main
parent5a09d17c45696934ad76c5dc1c7b0207513bd98e (diff)
downloadVeraCrypt-c86697f51b0b71d327ba7f4b9211cacde0bbd2f0.tar.gz
VeraCrypt-c86697f51b0b71d327ba7f4b9211cacde0bbd2f0.zip
Linux/MacOSX: Support K/M/G/T suffixes for --size switch to indicate unit to use for size value (KiloByte, MegaByte, GigaByte and TeraByte respectively)
Diffstat (limited to 'src/Main')
-rw-r--r--src/Main/CommandLineInterface.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/Main/CommandLineInterface.cpp b/src/Main/CommandLineInterface.cpp
index 5a745696..c91976ed 100644
--- a/src/Main/CommandLineInterface.cpp
+++ b/src/Main/CommandLineInterface.cpp
@@ -528,9 +528,36 @@ namespace VeraCrypt
if (parser.Found (L"size", &str))
{
+ uint64 multiplier;
+ wxChar lastChar = str [str.Length () - 1];
+ if (lastChar >= wxT('0') && lastChar <= wxT('9'))
+ multiplier = 1;
+ else if (lastChar == wxT('K') || lastChar == wxT('k'))
+ multiplier = BYTES_PER_KB;
+ else if (lastChar == wxT('M') || lastChar == wxT('m'))
+ multiplier = BYTES_PER_MB;
+ else if (lastChar == wxT('G') || lastChar == wxT('g'))
+ multiplier = BYTES_PER_GB;
+ else if (lastChar == wxT('T') || lastChar == wxT('t'))
+ multiplier = BYTES_PER_TB;
+ else
+ throw_err (LangString["PARAMETER_INCORRECT"] + L": " + str);
+
+ // remove suffix if present
+ if (multiplier != 1)
+ str.RemoveLast ();
+ // check that we only have digits in the string
+ size_t index = str.find_first_not_of (wxT("0123456789"));
+ if (index != (size_t) wxNOT_FOUND)
+ {
+ // restore last characater for error display
+ if (multiplier != 1)
+ str += lastChar;
+ throw_err (LangString["PARAMETER_INCORRECT"] + L": " + str);
+ }
try
{
- ArgSize = StringConverter::ToUInt64 (wstring (str));
+ ArgSize = multiplier * StringConverter::ToUInt64 (wstring (str));
}
catch (...)
{