From 127ff7318528c45b33cfc3b622ed3ad62340408b Mon Sep 17 00:00:00 2001 From: neonew Date: Sun, 5 Nov 2017 17:20:37 +0100 Subject: [PATCH] decryptDatabaseCrypt7_8_12(): removed code duplications --- source/Platforms/Win32/GUI/MainWindow.cpp | 55 ++++------------------- source/Platforms/Win32/GUI/MainWindow.h | 1 + 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/source/Platforms/Win32/GUI/MainWindow.cpp b/source/Platforms/Win32/GUI/MainWindow.cpp index 2d7fff1..0086769 100644 --- a/source/Platforms/Win32/GUI/MainWindow.cpp +++ b/source/Platforms/Win32/GUI/MainWindow.cpp @@ -536,7 +536,7 @@ void MainWindow::decryptDatabaseCrypt5() } } -void MainWindow::decryptDatabaseCrypt7() +void MainWindow::decryptDatabaseCrypt7_8_12(void (*decryptWhatsappDatabase)(const std::string &filename, const std::string &filenameDecrypted, const std::string &keyFilename)) { OpenDatabaseStruct openDatabaseStruct = lastDatabaseOpened; DecryptDatabaseDialog7 dialog(MainWindow::dialog, openDatabaseStruct); @@ -545,7 +545,7 @@ void MainWindow::decryptDatabaseCrypt7() { try { - decryptWhatsappDatabase7(openDatabaseStruct.filename, openDatabaseStruct.decryptedFilename, openDatabaseStruct.keyFilename); + decryptWhatsappDatabase(openDatabaseStruct.filename, openDatabaseStruct.decryptedFilename, openDatabaseStruct.keyFilename); lastDatabaseOpened = openDatabaseStruct; settings.write("lastOpenedFile", lastDatabaseOpened.filename); @@ -562,56 +562,19 @@ void MainWindow::decryptDatabaseCrypt7() } } -void MainWindow::decryptDatabaseCrypt8() +void MainWindow::decryptDatabaseCrypt7() { - OpenDatabaseStruct openDatabaseStruct = lastDatabaseOpened; - DecryptDatabaseDialog7 dialog(MainWindow::dialog, openDatabaseStruct); - - if (dialog.openModal() == IDOK) - { - try - { - decryptWhatsappDatabase8(openDatabaseStruct.filename, openDatabaseStruct.decryptedFilename, openDatabaseStruct.keyFilename); - - lastDatabaseOpened = openDatabaseStruct; - settings.write("lastOpenedFile", lastDatabaseOpened.filename); - settings.write("lastOpenedKeyfile", lastDatabaseOpened.keyFilename); + decryptDatabaseCrypt7_8_12(decryptWhatsappDatabase7); +} - std::stringstream message; - message << "Database decrypted to file " << openDatabaseStruct.decryptedFilename; - MessageBox(MainWindow::dialog, strtowstr(message.str()).c_str(), L"Success", MB_OK | MB_ICONINFORMATION); - } - catch (Exception &exception) - { - displayException(MainWindow::dialog, exception); - } - } +void MainWindow::decryptDatabaseCrypt8() +{ + decryptDatabaseCrypt7_8_12(decryptWhatsappDatabase8); } void MainWindow::decryptDatabaseCrypt12() { - OpenDatabaseStruct openDatabaseStruct = lastDatabaseOpened; - DecryptDatabaseDialog7 dialog(MainWindow::dialog, openDatabaseStruct); - - if (dialog.openModal() == IDOK) - { - try - { - decryptWhatsappDatabase12(openDatabaseStruct.filename, openDatabaseStruct.decryptedFilename, openDatabaseStruct.keyFilename); - - lastDatabaseOpened = openDatabaseStruct; - settings.write("lastOpenedFile", lastDatabaseOpened.filename); - settings.write("lastOpenedKeyfile", lastDatabaseOpened.keyFilename); - - std::stringstream message; - message << "Database decrypted to file " << openDatabaseStruct.decryptedFilename; - MessageBox(MainWindow::dialog, strtowstr(message.str()).c_str(), L"Success", MB_OK | MB_ICONINFORMATION); - } - catch (Exception &exception) - { - displayException(MainWindow::dialog, exception); - } - } + decryptDatabaseCrypt7_8_12(decryptWhatsappDatabase12); } void MainWindow::displayException(HWND mainWindow, Exception &exception) diff --git a/source/Platforms/Win32/GUI/MainWindow.h b/source/Platforms/Win32/GUI/MainWindow.h index 56e0767..505f0b9 100644 --- a/source/Platforms/Win32/GUI/MainWindow.h +++ b/source/Platforms/Win32/GUI/MainWindow.h @@ -47,6 +47,7 @@ class MainWindow void decryptDatabaseCrypt7(); void decryptDatabaseCrypt8(); void decryptDatabaseCrypt12(); + void decryptDatabaseCrypt7_8_12(void (*decryptWhatsappDatabase)(const std::string &filename, const std::string &filenameDecrypted, const std::string &keyFilename)); void clearChats(); void clearChatList();