diff --git a/WhatsappTray/AppData.cpp b/WhatsappTray/AppData.cpp index 291e07f..6c5905d 100644 --- a/WhatsappTray/AppData.cpp +++ b/WhatsappTray/AppData.cpp @@ -24,7 +24,7 @@ #include "Logger.h" #include "Helper.h" -#include +//#include #include #include diff --git a/WhatsappTray/AppData.h b/WhatsappTray/AppData.h index 1ecd6a2..b9f7359 100644 --- a/WhatsappTray/AppData.h +++ b/WhatsappTray/AppData.h @@ -48,7 +48,7 @@ class SBool : public Serializeable public: SBool() : Value(false) { } SBool(bool value) : Value(value) { } - void operator=(const bool newValue) + void operator=(const SBool& newValue) { Value = newValue; valueChanged(); @@ -70,7 +70,7 @@ class SString : public Serializeable public: SString() : Value("") { } SString(std::string value) : Value(value) { } - void operator=(const std::string newValue) + void operator=(const SString& newValue) { Value = newValue; valueChanged(); @@ -126,7 +126,9 @@ class DataEntryS : public DataEntry std::function valueChangedHandler; void OnValueChanged() { - valueChangedHandler(*this); + if (valueChangedHandler) { + valueChangedHandler(*this); + } } }; diff --git a/WhatsappTray/WhatsAppApi.cpp b/WhatsappTray/WhatsAppApi.cpp index a1757d9..dc7189a 100644 --- a/WhatsappTray/WhatsAppApi.cpp +++ b/WhatsappTray/WhatsAppApi.cpp @@ -28,15 +28,39 @@ #include #include +#include +#include + +namespace fs = std::experimental::filesystem; #undef MODULE_NAME #define MODULE_NAME "WhatsAppApi::" -std::unique_ptr WhatsAppApi::dirWatcher(new DirectoryWatcher("C:\\Users\\Dakoon\\AppData\\Roaming\\WhatsApp\\IndexedDB\\file__0.indexeddb.leveldb", &WhatsAppApi::IndexedDbChanged)); +std::unique_ptr WhatsAppApi::dirWatcher = std::unique_ptr(nullptr); + std::function WhatsAppApi::receivedMessageEvent = NULL; std::function WhatsAppApi::receivedFullInitEvent = NULL; +void WhatsAppApi::Init() +{ + char appDataDirectory[MAX_PATH] = { 0 }; + if (SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataDirectory) != S_OK) { + Logger::Fatal(MODULE_NAME "Init() - Could not get the AppData-directory!"); + MessageBoxA(NULL, MODULE_NAME "Init() - Fatal: Could not get the AppData-directory!", "WhatsappTray", MB_OK | MB_ICONINFORMATION); + return; + } + std::string leveldbDirectory = std::string(appDataDirectory) + "\\WhatsApp\\IndexedDB\\file__0.indexeddb.leveldb"; + Logger::Info(MODULE_NAME "Init() - Using leveldb-directory:%s", leveldbDirectory.c_str()); + + if (fs::exists(fs::path(leveldbDirectory)) == false) { + Logger::Fatal(MODULE_NAME "Init() - Could not get the leveldb-directory!"); + MessageBoxA(NULL, MODULE_NAME "Init() - Fatal: Could not get the leveldb-directory!", "WhatsappTray", MB_OK | MB_ICONINFORMATION); + return; + } + WhatsAppApi::dirWatcher = std::unique_ptr(new DirectoryWatcher(leveldbDirectory, &WhatsAppApi::IndexedDbChanged)); +} + void WhatsAppApi::NotifyOnNewMessage(const std::function& receivedMessageHandler) { receivedMessageEvent = receivedMessageHandler; diff --git a/WhatsappTray/WhatsAppApi.h b/WhatsappTray/WhatsAppApi.h index ed404db..86921b0 100644 --- a/WhatsappTray/WhatsAppApi.h +++ b/WhatsappTray/WhatsAppApi.h @@ -30,6 +30,7 @@ class WhatsAppApi public: WhatsAppApi() { } ~WhatsAppApi() { } + static void WhatsAppApi::Init(); static void WhatsAppApi::NotifyOnNewMessage(const std::function& newMessageHandler); static void WhatsAppApi::NotifyOnFullInit(const std::function& newMessageHandler); private: diff --git a/WhatsappTray/WhatsappTray.cpp b/WhatsappTray/WhatsappTray.cpp index a5b34f7..16c3d10 100644 --- a/WhatsappTray/WhatsappTray.cpp +++ b/WhatsappTray/WhatsappTray.cpp @@ -36,7 +36,7 @@ #include #undef MODULE_NAME -#define MODULE_NAME "[WhatsappTray] " +#define MODULE_NAME "WhatsappTray" static HINSTANCE _hInstance; static HMODULE _hLib; @@ -61,6 +61,10 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ { Logger::Setup(); + Logger::Info(MODULE_NAME "::WinMain() - Starting WhatsappTray %s.", Helper::GetProductAndVersion().c_str()); + + WhatsAppApi::Init(); + Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; @@ -86,10 +90,10 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ } if (appData.StartMinimized.Get()) { - Logger::Info(MODULE_NAME "WinMain() - Prepare for starting minimized."); + Logger::Info(MODULE_NAME "::WinMain() - Prepare for starting minimized."); WhatsAppApi::NotifyOnFullInit([]() { - Logger::Info(MODULE_NAME "WinMain() - NotifyOnFullInit"); + Logger::Info(MODULE_NAME "::WinMain() - NotifyOnFullInit"); Sleep(500); PostMessageA(_hwndWhatsappTray, WM_ADDTRAY, 0, 0); // Remove event after the first execution @@ -259,7 +263,7 @@ void ExecuteMenu() { HMENU hMenu = CreatePopupMenu(); if (!hMenu) { - Logger::Error(MODULE_NAME "ExecuteMenu() - Error creating menu."); + Logger::Error(MODULE_NAME "::ExecuteMenu() - Error creating menu."); MessageBox(NULL, "Error creating menu.", "WhatsappTray", MB_OK | MB_ICONERROR); return; } @@ -305,7 +309,7 @@ void ExecuteMenu() LRESULT CALLBACK WhatsAppTrayWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - Logger::Info(MODULE_NAME "WhatsAppTrayWndProc() - Message Received msg='0x%X'", msg); + Logger::Info(MODULE_NAME "::WhatsAppTrayWndProc() - Message Received msg='0x%X'", msg); switch (msg) { case WM_COMMAND: @@ -331,7 +335,7 @@ LRESULT CALLBACK WhatsAppTrayWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM appData.StartMinimized.Set(!appData.StartMinimized.Get()); break; case IDM_RESTORE: - Logger::Info(MODULE_NAME "IDM_RESTORE"); + Logger::Info(MODULE_NAME "::WhatsAppTrayWndProc() - IDM_RESTORE"); trayManager->RestoreWindowFromTray(_hwndForMenu); break; case IDM_CLOSE: @@ -348,7 +352,7 @@ LRESULT CALLBACK WhatsAppTrayWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM setHook(); break; case WM_ADDTRAY: - Logger::Info(MODULE_NAME "WM_ADDTRAY"); + Logger::Info(MODULE_NAME "::WhatsAppTrayWndProc() - WM_ADDTRAY"); messagesSinceMinimize = 0; trayManager->MinimizeWindowToTray(_hwndWhatsapp); break; @@ -371,22 +375,22 @@ LRESULT CALLBACK WhatsAppTrayWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case WM_WHAHTSAPP_CLOSING: // If Whatsapp is closing we want to close WhatsappTray as well. - Logger::Info(MODULE_NAME "WM_WHAHTSAPP_CLOSING"); + Logger::Info(MODULE_NAME "::WhatsAppTrayWndProc() - WM_WHAHTSAPP_CLOSING"); DestroyWindow(_hwndWhatsappTray); break; case WM_DESTROY: - Logger::Info(MODULE_NAME "WM_DESTROY"); + Logger::Info(MODULE_NAME "::WhatsAppTrayWndProc() - WM_DESTROY"); trayManager->RestoreAllWindowsFromTray(); UnRegisterHook(); FreeLibrary(_hLib); PostQuitMessage(0); - Logger::Info(MODULE_NAME "QuitMessage posted."); + Logger::Info(MODULE_NAME "::WhatsAppTrayWndProc() - QuitMessage posted."); break; case WM_WHATSAPP_API_NEW_MESSAGE: - Logger::Info(MODULE_NAME "WM_WHATSAPP_API_NEW_MESSAGE"); + Logger::Info(MODULE_NAME "::WhatsAppTrayWndProc() - WM_WHATSAPP_API_NEW_MESSAGE"); messagesSinceMinimize++; char messagesSinceMinimizeBuffer[20] = { 0 }; snprintf(messagesSinceMinimizeBuffer, sizeof(messagesSinceMinimizeBuffer), "%d", messagesSinceMinimize); diff --git a/WhatsappTray/WhatsappTray.rc b/WhatsappTray/WhatsappTray.rc index a459ef4..c3740b6 100644 --- a/WhatsappTray/WhatsappTray.rc +++ b/WhatsappTray/WhatsappTray.rc @@ -101,7 +101,7 @@ IDI_WHATSAPPTRAY ICON "WhatsappTray.ico" VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,0 - PRODUCTVERSION 1,4,0,0 + PRODUCTVERSION 1,4,1,0 FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x1L @@ -119,10 +119,10 @@ BEGIN VALUE "FileDescription", "WhatsappTray" VALUE "FileVersion", "1.0.0.0" VALUE "InternalName", "WhatsappTray" - VALUE "LegalCopyright", "Copyright © 1998-2018 Sebastian Amann, Nikolay Redko, J.D. Purcell" + VALUE "LegalCopyright", "Copyright © 1998-2019 Sebastian Amann, Nikolay Redko, J.D. Purcell" VALUE "OriginalFilename", "WhatsappTray.exe" VALUE "ProductName", "WhatsappTray" - VALUE "ProductVersion", "1.4.0.0" + VALUE "ProductVersion", "1.4.1.0" END END BLOCK "VarFileInfo"