From d90d9f0c401a21c85a525aaca0b97df8f7955db8 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Thu, 25 Dec 2014 22:54:14 +0100 Subject: Linux/MacOSX: Implement waiting dialog for lengthy operations in order to have a better user experience. --- src/Core/Core.h | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) (limited to 'src/Core/Core.h') diff --git a/src/Core/Core.h b/src/Core/Core.h index 5f218775..1a7a1611 100644 --- a/src/Core/Core.h +++ b/src/Core/Core.h @@ -15,6 +15,138 @@ namespace VeraCrypt { extern auto_ptr Core; extern auto_ptr CoreDirect; + + class WaitThreadRoutine + { + public: + Exception* m_pException; + WaitThreadRoutine() : m_pException(NULL) {} + virtual ~WaitThreadRoutine() {if (m_pException) delete m_pException;} + bool HasException () { return m_pException != NULL;} + Exception* GetException () const { return m_pException;} + void Execute(void) + { + try + { + ExecutionCode(); + } + catch(Exception& ex) + { + m_pException = ex.CloneNew(); + } + catch(...) + { + m_pException = new UnknownException (SRC_POS); + } + } + virtual void ExecutionCode(void) = 0; + }; + + class MountThreadRoutine : public WaitThreadRoutine + { + public: + MountOptions& m_options; + shared_ptr m_pVolume; + MountThreadRoutine(MountOptions &options) : m_options(options) {} + virtual ~MountThreadRoutine() { } + virtual void ExecutionCode(void) { m_pVolume = Core->MountVolume(m_options); } + }; + + class VolumeCreatorThreadRoutine : public WaitThreadRoutine + { + public: + shared_ptr m_options; + shared_ptr m_pCreator; + VolumeCreatorThreadRoutine(shared_ptr options, shared_ptr pCreator) + : m_options(options), m_pCreator(pCreator) {} + virtual ~VolumeCreatorThreadRoutine() { } + virtual void ExecutionCode(void) { m_pCreator->CreateVolume (m_options); } + }; + + class ChangePasswordThreadRoutine : public WaitThreadRoutine + { + public: + shared_ptr m_volumePath; + bool m_preserveTimestamps; + shared_ptr m_password; + shared_ptr m_kdf; + shared_ptr m_keyfiles; + shared_ptr m_newPassword; + shared_ptr m_newKeyfiles; + shared_ptr m_newPkcs5Kdf; + int m_wipeCount; + ChangePasswordThreadRoutine(shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr kdf, shared_ptr keyfiles, shared_ptr newPassword, shared_ptr newKeyfiles, shared_ptr newPkcs5Kdf, int wipeCount) : m_volumePath(volumePath), m_preserveTimestamps(preserveTimestamps), m_password(password), m_kdf(kdf), m_keyfiles(keyfiles), m_newPassword(newPassword), m_newKeyfiles(newKeyfiles), m_newPkcs5Kdf(newPkcs5Kdf), m_wipeCount(wipeCount) {} + virtual ~ChangePasswordThreadRoutine() { } + virtual void ExecutionCode(void) { Core->ChangePassword(m_volumePath, m_preserveTimestamps, m_password, m_kdf, m_keyfiles, m_newPassword, m_newKeyfiles, m_newPkcs5Kdf, m_wipeCount); } + }; + + class OpenVolumeThreadRoutine : public WaitThreadRoutine + { + public: + shared_ptr m_volumePath; + bool m_preserveTimestamps; + shared_ptr m_password; + shared_ptr m_Kdf; + shared_ptr m_keyfiles; + VolumeProtection::Enum m_protection; + shared_ptr m_protectionPassword; + shared_ptr m_protectionKdf; + shared_ptr m_protectionKeyfiles; + bool m_sharedAccessAllowed; + VolumeType::Enum m_volumeType; + bool m_useBackupHeaders; + bool m_partitionInSystemEncryptionScope; + shared_ptr m_pVolume; + + OpenVolumeThreadRoutine(shared_ptr volumePath, bool preserveTimestamps, shared_ptr password, shared_ptr Kdf, shared_ptr keyfiles, VolumeProtection::Enum protection = VolumeProtection::None, shared_ptr protectionPassword = shared_ptr (), shared_ptr protectionKdf = shared_ptr (), shared_ptr protectionKeyfiles = shared_ptr (), bool sharedAccessAllowed = false, VolumeType::Enum volumeType = VolumeType::Unknown, bool useBackupHeaders = false, bool partitionInSystemEncryptionScope = false): + m_volumePath(volumePath), m_preserveTimestamps(preserveTimestamps), m_password(password), m_Kdf(Kdf), m_keyfiles(keyfiles), + m_protection(protection), m_protectionPassword(protectionPassword), m_protectionKdf(protectionKdf), m_protectionKeyfiles(protectionKeyfiles), m_sharedAccessAllowed(sharedAccessAllowed), m_volumeType(volumeType),m_useBackupHeaders(useBackupHeaders), + m_partitionInSystemEncryptionScope(partitionInSystemEncryptionScope) {} + + ~OpenVolumeThreadRoutine() {} + + virtual void ExecutionCode(void) { m_pVolume = Core->OpenVolume(m_volumePath,m_preserveTimestamps,m_password,m_Kdf,m_keyfiles, m_protection,m_protectionPassword,m_protectionKdf, m_protectionKeyfiles,m_sharedAccessAllowed,m_volumeType,m_useBackupHeaders, m_partitionInSystemEncryptionScope); } + + }; + + class ReEncryptHeaderThreadRoutine : public WaitThreadRoutine + { + public: + const BufferPtr &m_newHeaderBuffer; + shared_ptr m_header; + shared_ptr m_password; + shared_ptr m_keyfiles; + ReEncryptHeaderThreadRoutine(const BufferPtr &newHeaderBuffer, shared_ptr header, shared_ptr password, shared_ptr keyfiles) + : m_newHeaderBuffer(newHeaderBuffer), m_header(header), m_password(password), m_keyfiles(keyfiles) {} + virtual ~ReEncryptHeaderThreadRoutine() { } + virtual void ExecutionCode(void) { Core->ReEncryptVolumeHeaderWithNewSalt (m_newHeaderBuffer, m_header, m_password, m_keyfiles); } + }; + + class DecryptThreadRoutine : public WaitThreadRoutine + { + public: + shared_ptr m_pHeader; + const ConstBufferPtr &m_encryptedData; + const VolumePassword &m_password; + shared_ptr m_kdf; + const Pkcs5KdfList &m_keyDerivationFunctions; + const EncryptionAlgorithmList &m_encryptionAlgorithms; + const EncryptionModeList &m_encryptionModes; + bool m_bResult; + DecryptThreadRoutine(shared_ptr header, const ConstBufferPtr &encryptedData, const VolumePassword &password, shared_ptr kdf, const Pkcs5KdfList &keyDerivationFunctions, const EncryptionAlgorithmList &encryptionAlgorithms, const EncryptionModeList &encryptionModes) + : m_pHeader(header), m_encryptedData(encryptedData), m_password(password), m_kdf(kdf), m_keyDerivationFunctions(keyDerivationFunctions), m_encryptionAlgorithms(encryptionAlgorithms), m_encryptionModes(encryptionModes), m_bResult(false){} + virtual ~DecryptThreadRoutine() { } + virtual void ExecutionCode(void) { m_bResult = m_pHeader->Decrypt(m_encryptedData, m_password, m_kdf, m_keyDerivationFunctions, m_encryptionAlgorithms, m_encryptionModes); } + }; + + class WaitThreadUI + { + public: + WaitThreadUI(WaitThreadRoutine* pRoutine): m_pRoutine(pRoutine) {} + virtual ~WaitThreadUI() {} + virtual void Run(void) { m_pRoutine->ExecutionCode();} + WaitThreadRoutine* m_pRoutine; + }; } #endif // TC_HEADER_Core_Core -- cgit v1.2.3