summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-04-12 20:55:18 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-04-12 20:55:18 +0300
commitcdf4c110510a39c162b469ecbd6f69571019cf69 (patch)
treef7e47d684c94d877a141fc64ade0ca471aa1fce1 /src
parent376f5d4859ba96bff4a3c4d7c9622664b9e578d7 (diff)
initial version of profile compactor for MDBX
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/MDatabaseCommon.cpp5
-rw-r--r--src/mir_app/src/mir_app.def1
-rw-r--r--src/mir_app/src/mir_app64.def1
-rw-r--r--src/mir_app/src/profilemanager.cpp76
4 files changed, 56 insertions, 27 deletions
diff --git a/src/mir_app/src/MDatabaseCommon.cpp b/src/mir_app/src/MDatabaseCommon.cpp
index dd3034a00e..74f33688dc 100644
--- a/src/mir_app/src/MDatabaseCommon.cpp
+++ b/src/mir_app/src/MDatabaseCommon.cpp
@@ -82,6 +82,11 @@ BOOL MDatabaseCommon::DeleteModule(MCONTACT hContact, LPCSTR szModule)
return 0;
}
+BOOL MDatabaseCommon::Compact(void)
+{
+ return ERROR_NOT_SUPPORTED;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// Contacts
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index d8c739b539..b449c2a281 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -580,3 +580,4 @@ Clist_GetRealStatus @599
Clist_GetGeneralizedStatus @600
Proto_GetStatus @601
?getCache@MDatabaseCommon@@QBEPAUMIDatabaseCache@@XZ @602 NONAME
+?Compact@MDatabaseCommon@@UAGHXZ @603 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 9e8b034edc..bd05a3184e 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -580,3 +580,4 @@ Clist_GetRealStatus @599
Clist_GetGeneralizedStatus @600
Proto_GetStatus @601
?getCache@MDatabaseCommon@@QEBAPEAUMIDatabaseCache@@XZ @602 NONAME
+?Compact@MDatabaseCommon@@UEAAHXZ @603 NONAME
diff --git a/src/mir_app/src/profilemanager.cpp b/src/mir_app/src/profilemanager.cpp
index de4e2b2628..a39fee2bb0 100644
--- a/src/mir_app/src/profilemanager.cpp
+++ b/src/mir_app/src/profilemanager.cpp
@@ -255,7 +255,7 @@ class CChooseProfileDlg : public CDlgBase
if (p != nullptr) *p = 0;
LVITEM item = { 0 };
- item.mask = LVIF_TEXT | LVIF_IMAGE;
+ item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
item.pszText = profile;
item.iItem = 0;
@@ -286,6 +286,8 @@ class CChooseProfileDlg : public CDlgBase
item.iImage = 3;
}
+ item.lParam = (LPARAM)dblink;
+
int iItem = list.InsertItem(&item);
if (mir_wstrcmpi(ped->szProfile, tszFullPath) == 0)
list.SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
@@ -303,35 +305,34 @@ class CChooseProfileDlg : public CDlgBase
return TRUE;
}
- void DeleteProfile(int iItem)
+ void DeleteProfile(const LVITEM &item)
{
- if (iItem < 0)
- return;
-
- wchar_t profile[MAX_PATH], profilef[MAX_PATH * 2];
-
- LVITEM item = { 0 };
- item.mask = LVIF_TEXT;
- item.iItem = iItem;
- item.pszText = profile;
- item.cchTextMax = _countof(profile);
- if (!m_profileList.GetItem(&item))
- return;
-
- mir_snwprintf(profilef, TranslateT("Are you sure you want to remove profile \"%s\"?"), profile);
- if (IDYES != MessageBox(nullptr, profilef, L"Miranda NG", MB_YESNO | MB_TASKMODAL | MB_ICONWARNING))
+ CMStringW wszMessage(FORMAT, TranslateT("Are you sure you want to remove profile \"%s\"?"), item.pszText);
+ if (IDYES != MessageBox(nullptr, wszMessage, L"Miranda NG", MB_YESNO | MB_TASKMODAL | MB_ICONWARNING))
return;
- mir_snwprintf(profilef, L"%s\\%s%c", m_pd->ptszProfileDir, profile, 0);
+ wszMessage.Format(L"%s\\%s%c", m_pd->ptszProfileDir, item.pszText, 0);
SHFILEOPSTRUCT sf = {};
sf.wFunc = FO_DELETE;
- sf.pFrom = profilef;
+ sf.pFrom = wszMessage;
sf.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_ALLOWUNDO;
SHFileOperation(&sf);
+
m_profileList.DeleteItem(item.iItem);
}
+ void CompactProfile(DATABASELINK *dblink, const wchar_t *profile)
+ {
+ CMStringW wszFullName(FORMAT, L"%s\\%s\\%s.dat", m_pd->ptszProfileDir, profile, profile);
+
+ MDatabaseCommon *db = dblink->Load(wszFullName, false);
+ if (db != nullptr) {
+ db->Compact();
+ delete db;
+ }
+ }
+
void CheckRun()
{
m_btnOk.Enable(m_profileList.GetSelectedCount() == 1);
@@ -383,21 +384,30 @@ class CChooseProfileDlg : public CDlgBase
if (lvht.iItem == -1)
return;
- LVITEM tvi = { 0 };
- tvi.mask = LVIF_IMAGE;
- tvi.iItem = lvht.iItem;
- if (!m_profileList.GetItem(&tvi))
+ wchar_t profile[MAX_PATH];
+ LVITEM item = { 0 };
+ item.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT;
+ item.iItem = lvht.iItem;
+ item.pszText = profile;
+ item.cchTextMax = _countof(profile);
+ if (!m_profileList.GetItem(&item))
return;
lvht.pt.x = GET_X_LPARAM(lParam);
lvht.pt.y = GET_Y_LPARAM(lParam);
HMENU hMenu = CreatePopupMenu();
- if (tvi.iImage < 2) {
+ if (item.iImage < 2) {
AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run"));
AppendMenu(hMenu, MF_SEPARATOR, 0, nullptr);
}
+ DATABASELINK *dblink = (DATABASELINK*)item.lParam;
+ if (dblink != nullptr && dblink->capabilities & MDB_CAPS_COMPACT) {
+ AppendMenu(hMenu, MF_STRING, 3, TranslateT("Compact"));
+ AppendMenu(hMenu, MF_SEPARATOR, 0, nullptr);
+ }
+
AppendMenu(hMenu, MF_STRING, 2, TranslateT("Delete"));
int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, m_hwnd, nullptr);
switch (index) {
@@ -406,7 +416,11 @@ class CChooseProfileDlg : public CDlgBase
break;
case 2:
- DeleteProfile(lvht.iItem);
+ DeleteProfile(item);
+ break;
+
+ case 3:
+ CompactProfile(dblink, profile);
break;
}
DestroyMenu(hMenu);
@@ -478,8 +492,16 @@ public:
void list_OnKeyDown(CCtrlListView::TEventInfo *evt)
{
- if (evt->nmlvkey->wVKey == VK_DELETE)
- DeleteProfile(m_profileList.GetNextItem(-1, LVNI_SELECTED | LVNI_ALL));
+ if (evt->nmlvkey->wVKey == VK_DELETE) {
+ wchar_t profile[MAX_PATH];
+ LVITEM item = { 0 };
+ item.mask = LVIF_TEXT;
+ item.iItem = m_profileList.GetNextItem(-1, LVNI_SELECTED | LVNI_ALL);
+ item.pszText = profile;
+ item.cchTextMax = _countof(profile);
+ if (m_profileList.GetItem(&item))
+ DeleteProfile(item);
+ }
}
void list_OnGetTip(CCtrlListView::TEventInfo *evt)