1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 02:58:02 -06:00

Linux/MacOSX: code refactoring and cleanup.

This commit is contained in:
Mounir IDRASSI
2014-12-30 19:55:06 +01:00
parent c178e325b8
commit 7c050d681d
2 changed files with 25 additions and 28 deletions

View File

@@ -189,9 +189,8 @@ namespace VeraCrypt
volumeType, volumeType,
options->UseBackupHeaders options->UseBackupHeaders
); );
WaitDialog dlg(parent, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &routine);
dlg.Run(); ExecuteWaitThreadRoutine (parent, &routine);
volume = routine.m_pVolume; volume = routine.m_pVolume;
} }
catch (PasswordException &e) catch (PasswordException &e)
@@ -270,8 +269,8 @@ namespace VeraCrypt
// Re-encrypt volume header // Re-encrypt volume header
SecureBuffer newHeaderBuffer (normalVolume->GetLayout()->GetHeaderSize()); SecureBuffer newHeaderBuffer (normalVolume->GetLayout()->GetHeaderSize());
ReEncryptHeaderThreadRoutine routine(newHeaderBuffer, normalVolume->GetHeader(), normalVolumeMountOptions.Password, normalVolumeMountOptions.Keyfiles); ReEncryptHeaderThreadRoutine routine(newHeaderBuffer, normalVolume->GetHeader(), normalVolumeMountOptions.Password, normalVolumeMountOptions.Keyfiles);
WaitDialog dlg(parent, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &routine);
dlg.Run(); ExecuteWaitThreadRoutine (parent, &routine);
backupFile.Write (newHeaderBuffer); backupFile.Write (newHeaderBuffer);
@@ -279,8 +278,8 @@ namespace VeraCrypt
{ {
// Re-encrypt hidden volume header // Re-encrypt hidden volume header
ReEncryptHeaderThreadRoutine hiddenRoutine(newHeaderBuffer, hiddenVolume->GetHeader(), hiddenVolumeMountOptions.Password, hiddenVolumeMountOptions.Keyfiles); ReEncryptHeaderThreadRoutine hiddenRoutine(newHeaderBuffer, hiddenVolume->GetHeader(), hiddenVolumeMountOptions.Password, hiddenVolumeMountOptions.Keyfiles);
WaitDialog hiddenDlg(parent, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &hiddenRoutine);
hiddenDlg.Run(); ExecuteWaitThreadRoutine (parent, &hiddenRoutine);
} }
else else
{ {
@@ -1306,9 +1305,8 @@ namespace VeraCrypt
VolumeType::Unknown, VolumeType::Unknown,
true true
); );
WaitDialog dlg(parent, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &routine);
dlg.Run(); ExecuteWaitThreadRoutine (parent, &routine);
volume = routine.m_pVolume; volume = routine.m_pVolume;
} }
catch (PasswordException &e) catch (PasswordException &e)
@@ -1331,8 +1329,8 @@ namespace VeraCrypt
wxBusyCursor busy; wxBusyCursor busy;
SecureBuffer newHeaderBuffer (volume->GetLayout()->GetHeaderSize()); SecureBuffer newHeaderBuffer (volume->GetLayout()->GetHeaderSize());
ReEncryptHeaderThreadRoutine routine(newHeaderBuffer, volume->GetHeader(), options.Password, options.Keyfiles); ReEncryptHeaderThreadRoutine routine(newHeaderBuffer, volume->GetHeader(), options.Password, options.Keyfiles);
WaitDialog dlg(parent, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &routine);
dlg.Run(); ExecuteWaitThreadRoutine (parent, &routine);
// Write volume header // Write volume header
int headerOffset = volume->GetLayout()->GetHeaderOffset(); int headerOffset = volume->GetLayout()->GetHeaderOffset();
@@ -1420,9 +1418,9 @@ namespace VeraCrypt
EncryptionAlgorithmList encryptionAlgorithms = layout->GetSupportedEncryptionAlgorithms(); EncryptionAlgorithmList encryptionAlgorithms = layout->GetSupportedEncryptionAlgorithms();
EncryptionModeList encryptionModes = layout->GetSupportedEncryptionModes(); EncryptionModeList encryptionModes = layout->GetSupportedEncryptionModes();
DecryptThreadRoutine decryptRoutine(layout->GetHeader(), headerBuffer, *passwordKey, options.Kdf, options.TrueCryptMode, keyDerivationFunctions, encryptionAlgorithms, encryptionModes); DecryptThreadRoutine decryptRoutine(layout->GetHeader(), headerBuffer, *passwordKey, options.Kdf, options.TrueCryptMode, keyDerivationFunctions, encryptionAlgorithms, encryptionModes);
WaitDialog decryptDlg(parent, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &decryptRoutine);
decryptDlg.Run(); ExecuteWaitThreadRoutine (parent, &decryptRoutine);
if (decryptRoutine.m_bResult) if (decryptRoutine.m_bResult)
{ {
@@ -1450,8 +1448,8 @@ namespace VeraCrypt
wxBusyCursor busy; wxBusyCursor busy;
SecureBuffer newHeaderBuffer (decryptedLayout->GetHeaderSize()); SecureBuffer newHeaderBuffer (decryptedLayout->GetHeaderSize());
ReEncryptHeaderThreadRoutine routine(newHeaderBuffer, decryptedLayout->GetHeader(), options.Password, options.Keyfiles); ReEncryptHeaderThreadRoutine routine(newHeaderBuffer, decryptedLayout->GetHeader(), options.Password, options.Keyfiles);
WaitDialog dlg(parent, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &routine);
dlg.Run(); ExecuteWaitThreadRoutine (parent, &routine);
// Write volume header // Write volume header
int headerOffset = decryptedLayout->GetHeaderOffset(); int headerOffset = decryptedLayout->GetHeaderOffset();
@@ -1466,8 +1464,8 @@ namespace VeraCrypt
{ {
// Re-encrypt backup volume header // Re-encrypt backup volume header
ReEncryptHeaderThreadRoutine backupRoutine(newHeaderBuffer, decryptedLayout->GetHeader(), options.Password, options.Keyfiles); ReEncryptHeaderThreadRoutine backupRoutine(newHeaderBuffer, decryptedLayout->GetHeader(), options.Password, options.Keyfiles);
WaitDialog backupDlg(parent, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &backupRoutine);
backupDlg.Run(); ExecuteWaitThreadRoutine (parent, &backupRoutine);
// Write backup volume header // Write backup volume header
headerOffset = decryptedLayout->GetBackupHeaderOffset(); headerOffset = decryptedLayout->GetBackupHeaderOffset();
@@ -1818,21 +1816,20 @@ namespace VeraCrypt
#endif #endif
} }
WaitThreadUI* GraphicUserInterface::GetWaitThreadUI(WaitThreadRoutine *pRoutine) const
{
return new WaitDialog(GetTopWindow(), LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], pRoutine);
}
shared_ptr <VolumeInfo> GraphicUserInterface::MountVolumeThread (MountOptions &options) const shared_ptr <VolumeInfo> GraphicUserInterface::MountVolumeThread (MountOptions &options) const
{ {
MountThreadRoutine routine(options); MountThreadRoutine routine(options);
WaitDialog dlg(GetTopWindow(), LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], &routine);
ExecuteWaitThreadRoutine(GetTopWindow(), &routine);
return routine.m_pVolume;
}
void GraphicUserInterface::ExecuteWaitThreadRoutine (wxWindow *parent, WaitThreadRoutine *pRoutine) const
{
WaitDialog dlg(parent, LangString["IDT_STATIC_MODAL_WAIT_DLG_INFO"], pRoutine);
mWaitDialog = &dlg; mWaitDialog = &dlg;
finally_do_arg (WaitDialog**, &mWaitDialog, { *finally_arg = nullptr; }); finally_do_arg (WaitDialog**, &mWaitDialog, { *finally_arg = nullptr; });
dlg.Run(); dlg.Run();
return routine.m_pVolume;
} }
DEFINE_EVENT_TYPE (TC_EVENT_THREAD_EXITING); DEFINE_EVENT_TYPE (TC_EVENT_THREAD_EXITING);

View File

@@ -89,9 +89,9 @@ namespace VeraCrypt
virtual bool UpdateListCtrlItem (wxListCtrl *listCtrl, long itemIndex, const vector <wstring> &itemFields) const; virtual bool UpdateListCtrlItem (wxListCtrl *listCtrl, long itemIndex, const vector <wstring> &itemFields) const;
virtual void UserEnrichRandomPool (wxWindow *parent, shared_ptr <Hash> hash = shared_ptr <Hash>()) const; virtual void UserEnrichRandomPool (wxWindow *parent, shared_ptr <Hash> hash = shared_ptr <Hash>()) const;
virtual void Yield () const; virtual void Yield () const;
virtual WaitThreadUI* GetWaitThreadUI(WaitThreadRoutine *pRoutine) const;
virtual shared_ptr <VolumeInfo> MountVolumeThread (MountOptions &options) const; virtual shared_ptr <VolumeInfo> MountVolumeThread (MountOptions &options) const;
WaitDialog* GetWaitDialog () { return mWaitDialog; } WaitDialog* GetWaitDialog () { return mWaitDialog; }
void ExecuteWaitThreadRoutine (wxWindow *parent, WaitThreadRoutine *pRoutine) const;
#ifdef TC_MACOSX #ifdef TC_MACOSX
virtual void MacOpenFile (const wxString &fileName); virtual void MacOpenFile (const wxString &fileName);