|
|
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 "VolumeSizeWizardPage.h"
12:
13: namespace TrueCrypt
14: {
15: VolumeSizeWizardPage::VolumeSizeWizardPage (wxPanel* parent, const VolumePath &volumePath)
16: : VolumeSizeWizardPageBase (parent)
17: {
18: VolumeSizePrefixChoice->Append (LangString["KB"], reinterpret_cast <void *> (1024));
19: VolumeSizePrefixChoice->Append (LangString["MB"], reinterpret_cast <void *> (1024 * 1024));
20: VolumeSizePrefixChoice->Append (LangString["GB"], reinterpret_cast <void *> (1024 * 1024 * 1024));
21: VolumeSizePrefixChoice->Select (Prefix::MB);
22:
23: wxLongLong diskSpace = 0;
24: if (!wxGetDiskSpace (wxFileName (wstring (volumePath)).GetPath(), nullptr, &diskSpace))
25: {
26: VolumeSizeTextCtrl->Disable();
27: VolumeSizeTextCtrl->SetValue (L"");
28: }
29:
30: FreeSpaceStaticText->SetFont (Gui->GetDefaultBoldFont (this));
31:
32: #ifdef TC_WINDOWS
33: wxString drive = wxFileName (wstring (volumePath)).GetVolume();
34: if (!drive.empty())
35: {
36: FreeSpaceStaticText->SetLabel (StringFormatter (_("Free space on drive {0}: is {1}."),
37: drive, Gui->SizeToString (diskSpace.GetValue())));
38: }
39: else
40: #endif
41: {
42: FreeSpaceStaticText->SetLabel (StringFormatter (_("Free space available: {0}"),
43: Gui->SizeToString (diskSpace.GetValue())));
44: }
45:
46: VolumeSizeTextCtrl->SetMinSize (wxSize (Gui->GetCharWidth (VolumeSizeTextCtrl) * 20, -1));
47:
48: wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc.
49: const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" };
50: validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr));
51: VolumeSizeTextCtrl->SetValidator (validator);
52: }
53:
54: uint64 VolumeSizeWizardPage::GetVolumeSize () const
55: {
56: uint64 prefixMult = 1;
57: if (VolumeSizePrefixChoice->GetSelection() != wxNOT_FOUND)
58: prefixMult = reinterpret_cast <int> (VolumeSizePrefixChoice->GetClientData (VolumeSizePrefixChoice->GetSelection()));
59:
60: uint64 val = StringConverter::ToUInt64 (wstring (VolumeSizeTextCtrl->GetValue()));
61: if (val <= 0x7fffFFFFffffFFFFull / prefixMult)
62: return val * prefixMult;
63: else
64: return 0;
65: }
66:
67: bool VolumeSizeWizardPage::IsValid ()
68: {
69: if (!VolumeSizeTextCtrl->IsEmpty() && Validate())
70: {
71: try
72: {
73: if (GetVolumeSize() > 0)
74: return true;
75: }
76: catch (...) { }
77: }
78: return false;
79: }
80:
81: void VolumeSizeWizardPage::SetVolumeSize (uint64 size)
82: {
83: if (size == 0)
84: {
85: VolumeSizePrefixChoice->Select (Prefix::MB);
86: VolumeSizeTextCtrl->SetValue (L"");
87: return;
88: }
89:
90: if (size % (1024 * 1024 * 1024) == 0)
91: {
92: size /= 1024 * 1024 * 1024;
93: VolumeSizePrefixChoice->Select (Prefix::GB);
94: }
95: else if (size % (1024 * 1024) == 0)
96: {
97: size /= 1024 * 1024;
98: VolumeSizePrefixChoice->Select (Prefix::MB);
99: }
100: else
101: {
102: size /= 1024;
103: VolumeSizePrefixChoice->Select (Prefix::KB);
104: }
105:
106: VolumeSizeTextCtrl->SetValue (StringConverter::FromNumber (size));
107: }
108: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.