From e0377024f5048273f409b4844c2b44e3e7bb5d7d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 19 Jan 2021 15:50:20 +0300 Subject: fixes #2702 (Dbx_sqlite: missing "Compact" menu item) --- src/mir_app/src/database.cpp | 37 ++++++++++++++++++++++++++++++++++++- src/mir_app/src/profilemanager.cpp | 2 +- src/mir_app/src/profilemanager.h | 1 - 3 files changed, 37 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/database.cpp b/src/mir_app/src/database.cpp index 906358520d..d3ee8296e6 100644 --- a/src/mir_app/src/database.cpp +++ b/src/mir_app/src/database.cpp @@ -29,7 +29,7 @@ bool g_bDbCreated; wchar_t g_profileDir[MAX_PATH], g_profileName[MAX_PATH], g_shortProfileName[MAX_PATH]; wchar_t* g_defaultProfile; -bool fileExist(const wchar_t *fname) +static bool fileExist(const wchar_t *fname) { if (*fname == 0) return false; @@ -444,6 +444,38 @@ static BOOL CALLBACK EnumMirandaWindows(HWND hwnd, LPARAM lParam) return TRUE; } +///////////////////////////////////////////////////////////////////////////////////////// +// Default menu items + +static INT_PTR CompactMe(void* obj, WPARAM, LPARAM) +{ + auto *db = (MDatabaseCommon *)obj; + if (!db->Compact()) + MessageBox(0, TranslateT("Database was compacted successfully"), TranslateT("Database"), MB_OK | MB_ICONINFORMATION); + else + MessageBox(0, TranslateT("Database compaction failed"), TranslateT("Database"), MB_OK | MB_ICONERROR); + return 0; +} + +static int OnModulesLoaded(WPARAM, LPARAM) +{ + auto *pDb = db_get_current(); + if (pDb->GetDriver()->capabilities & MDB_CAPS_COMPACT) { + CMenuItem mi(&g_plugin); + mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000, 0); + + SET_UID(mi, 0x98c0caf3, 0xBfe5, 0x4e31, 0xac, 0xf0, 0xab, 0x95, 0xb2, 0x9b, 0x9f, 0x73); + mi.position++; + mi.hIcolibItem = g_plugin.getIconHandle(IDI_DATABASE); + mi.name.a = LPGEN("Compact"); + mi.pszService = "DB/UI/Compact"; + Menu_AddMainMenuItem(&mi); + + CreateServiceFunctionObj(mi.pszService, CompactMe, pDb); + } + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// static wchar_t tszNoDrivers[] = LPGENW("Miranda is unable to open '%s' because you do not have any profile plugins installed.\nYou need to install dbx_mdbx.dll"); @@ -510,5 +542,8 @@ int LoadDatabaseModule(void) } while (retry); + if (rc == 0) + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + return rc; } diff --git a/src/mir_app/src/profilemanager.cpp b/src/mir_app/src/profilemanager.cpp index 398bf6419c..628bc8856d 100644 --- a/src/mir_app/src/profilemanager.cpp +++ b/src/mir_app/src/profilemanager.cpp @@ -33,7 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define WM_INPUTCHANGED (WM_USER + 0x3000) #define WM_FOCUSTEXTBOX (WM_USER + 0x3001) -typedef BOOL (__cdecl *ENUMPROFILECALLBACK) (wchar_t *tszFullPath, wchar_t *profile, LPARAM lParam); +typedef BOOL (__cdecl *ENUMPROFILECALLBACK)(wchar_t *tszFullPath, wchar_t *profile, LPARAM lParam); ///////////////////////////////////////////////////////////////////////////////////////// // Profile creator diff --git a/src/mir_app/src/profilemanager.h b/src/mir_app/src/profilemanager.h index e4a5f89b62..a895474918 100644 --- a/src/mir_app/src/profilemanager.h +++ b/src/mir_app/src/profilemanager.h @@ -40,7 +40,6 @@ int touchDatabase(const wchar_t *tszProfile, DATABASELINK **pDblink); int getProfileManager(PROFILEMANAGERDATA *pd); int getProfilePath(wchar_t *buf, size_t cch); int isValidProfileName(const wchar_t *name); -bool fileExist(const wchar_t *fname); bool shouldAutoCreate(wchar_t *szProfile); extern wchar_t g_profileDir[MAX_PATH], g_profileName[MAX_PATH], g_shortProfileName[MAX_PATH]; -- cgit v1.2.3