summaryrefslogtreecommitdiff
path: root/src/mir_app
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-08-07 14:37:51 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-08-07 14:37:51 +0300
commit933b2a7a59948d3195aafc604d4d5711fa4a6345 (patch)
tree8ee6f59f739b93e729f235c0f0bca47d784adb72 /src/mir_app
parentddc626f8e0cf30ca2e5fed59da4a3e1e5b36dd0e (diff)
fix for rare crash on exit
Diffstat (limited to 'src/mir_app')
-rw-r--r--src/mir_app/src/database.cpp6
-rw-r--r--src/mir_app/src/meta_addto.cpp2
-rw-r--r--src/mir_app/src/meta_api.cpp24
-rw-r--r--src/mir_app/src/meta_edit.cpp2
-rw-r--r--src/mir_app/src/meta_menu.cpp20
-rw-r--r--src/mir_app/src/meta_services.cpp12
-rw-r--r--src/mir_app/src/meta_utils.cpp10
-rw-r--r--src/mir_app/src/miranda.h2
-rw-r--r--src/mir_app/src/newplugins.cpp2
-rw-r--r--src/mir_app/src/proto_chains.cpp10
10 files changed, 46 insertions, 44 deletions
diff --git a/src/mir_app/src/database.cpp b/src/mir_app/src/database.cpp
index 3353b5af22..a3f288d15f 100644
--- a/src/mir_app/src/database.cpp
+++ b/src/mir_app/src/database.cpp
@@ -25,8 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
#include "profilemanager.h"
-MDatabaseCommon *currDb = nullptr;
-
bool g_bDbCreated;
wchar_t g_profileDir[MAX_PATH], g_profileName[MAX_PATH], g_shortProfileName[MAX_PATH];
wchar_t* g_defaultProfile;
@@ -404,7 +402,7 @@ int tryOpenDatabase(const wchar_t *tszProfile)
return EGROKPRF_CANTREAD;
fillProfileName(tszProfile);
- db_setCurrent(currDb = pDb);
+ db_setCurrent(pDb);
return 0;
}
@@ -425,7 +423,7 @@ static int tryCreateDatabase(const wchar_t *ptszProfile)
return EGROKPRF_CANTREAD;
fillProfileName(ptszProfile);
- db_setCurrent(currDb = pDb);
+ db_setCurrent(pDb);
return 0;
}
}
diff --git a/src/mir_app/src/meta_addto.cpp b/src/mir_app/src/meta_addto.cpp
index 0923078d85..5ad1c77f55 100644
--- a/src/mir_app/src/meta_addto.cpp
+++ b/src/mir_app/src/meta_addto.cpp
@@ -133,7 +133,7 @@ CMetaSelectDlg::CMetaSelectDlg(MCONTACT hContact)
bool CMetaSelectDlg::OnInitDialog()
{
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(m_hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(m_hContact);
if (cc == nullptr)
return false;
diff --git a/src/mir_app/src/meta_api.cpp b/src/mir_app/src/meta_api.cpp
index 27ba89c84e..3029377a65 100644
--- a/src/mir_app/src/meta_api.cpp
+++ b/src/mir_app/src/meta_api.cpp
@@ -38,17 +38,19 @@ MIR_APP_DLL(void) db_mc_enable(BOOL bEnabled)
MIR_APP_DLL(BOOL) db_mc_isMeta(MCONTACT hContact)
{
- if (currDb == nullptr || !g_bMetaEnabled) return FALSE;
+ if (g_pCurrDb == nullptr || !g_bMetaEnabled)
+ return FALSE;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hContact);
return (cc == nullptr) ? FALSE : cc->nSubs != -1;
}
MIR_APP_DLL(BOOL) db_mc_isSub(MCONTACT hContact)
{
- if (currDb == nullptr || !g_bMetaEnabled) return FALSE;
+ if (g_pCurrDb == nullptr || !g_bMetaEnabled)
+ return FALSE;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hContact);
return (cc == nullptr) ? FALSE : cc->parentID != 0;
}
@@ -79,18 +81,20 @@ MIR_APP_DLL(int) db_mc_getSubCount(MCONTACT hMetaContact)
// returns parent hContact for a subcontact or NULL if it's not a sub
MIR_APP_DLL(MCONTACT) db_mc_getMeta(MCONTACT hSubContact)
{
- if (currDb == nullptr) return NULL;
+ if (g_pCurrDb == nullptr)
+ return 0;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hSubContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hSubContact);
return (cc == nullptr) ? NULL : cc->parentID;
}
// returns parent hContact for a subcontact or hContact itself if it's not a sub
MIR_APP_DLL(MCONTACT) db_mc_tryMeta(MCONTACT hContact)
{
- if (currDb == nullptr) return hContact;
+ if (g_pCurrDb == nullptr)
+ return hContact;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hContact);
if (cc == nullptr) return hContact;
return (cc->IsSub()) ? cc->parentID : hContact;
@@ -153,7 +157,7 @@ MIR_APP_DLL(int) db_mc_setDefault(MCONTACT hMetaContact, MCONTACT hSub, BOOL bWr
if (cc->nDefault != contact_number) {
cc->nDefault = contact_number;
if (bWriteDb)
- currDb->MetaSetDefault(cc);
+ g_pCurrDb->MetaSetDefault(cc);
NotifyEventHooks(hEventDefaultChanged, hMetaContact, hSub);
}
@@ -172,7 +176,7 @@ MIR_APP_DLL(int) db_mc_setDefaultNum(MCONTACT hMetaContact, int iNum, BOOL bWrit
if (cc->nDefault != iNum) {
cc->nDefault = iNum;
if (bWriteDb)
- currDb->MetaSetDefault(cc);
+ g_pCurrDb->MetaSetDefault(cc);
NotifyEventHooks(hEventDefaultChanged, hMetaContact, Meta_GetContactHandle(cc, iNum));
}
diff --git a/src/mir_app/src/meta_edit.cpp b/src/mir_app/src/meta_edit.cpp
index bd879d9edb..1ba35d0eb1 100644
--- a/src/mir_app/src/meta_edit.cpp
+++ b/src/mir_app/src/meta_edit.cpp
@@ -215,7 +215,7 @@ static INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wPara
TranslateDialogDefault(hwndDlg);
Window_SetIcon_IcoLib(hwndDlg, Meta_GetIconHandle(I_EDIT));
{
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(lParam);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(lParam);
if (cc == nullptr) {
DestroyWindow(hwndDlg);
return FALSE;
diff --git a/src/mir_app/src/meta_menu.cpp b/src/mir_app/src/meta_menu.cpp
index 1bcc2b3e11..78afe31445 100644
--- a/src/mir_app/src/meta_menu.cpp
+++ b/src/mir_app/src/meta_menu.cpp
@@ -56,13 +56,13 @@ INT_PTR Meta_Convert(WPARAM wParam, LPARAM)
if (hMetaContact == 0)
return 0;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hMetaContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hMetaContact);
if (cc == nullptr)
return 0;
db_set_dw(hMetaContact, META_PROTO, "NumContacts", 0);
cc->nSubs = 0;
- currDb->MetaSetDefault(cc); // explicitly write default sub to a db
+ g_pCurrDb->MetaSetDefault(cc); // explicitly write default sub to a db
// Add the MetaContact protocol to the new meta contact
Proto_AddToContact(hMetaContact, META_PROTO);
@@ -93,7 +93,7 @@ void Meta_RemoveContactNumber(DBCachedContact *ccMeta, int number, bool bUpdateI
return;
// make sure this contact thinks it's part of this metacontact
- DBCachedContact *ccSub = currDb->getCache()->GetCachedContact(Meta_GetContactHandle(ccMeta, number));
+ DBCachedContact *ccSub = g_pCurrDb->getCache()->GetCachedContact(Meta_GetContactHandle(ccMeta, number));
if (ccSub != nullptr)
if (ccSub->parentID == ccMeta->contactID)
Contact_Hide(ccSub->contactID, false);
@@ -128,12 +128,12 @@ void Meta_RemoveContactNumber(DBCachedContact *ccMeta, int number, bool bUpdateI
db_unset(ccMeta->contactID, META_PROTO, buffer);
if (ccSub != nullptr) {
- currDb->MetaDetouchSub(ccMeta, ccMeta->nSubs - 1);
+ g_pCurrDb->MetaDetouchSub(ccMeta, ccMeta->nSubs - 1);
if (bDeleteSub)
- currDb->MetaRemoveSubHistory(ccSub);
+ g_pCurrDb->MetaRemoveSubHistory(ccSub);
else {
- currDb->MetaSplitHistory(ccMeta, ccSub);
+ g_pCurrDb->MetaSplitHistory(ccMeta, ccSub);
ccSub->parentID = 0;
}
}
@@ -181,7 +181,7 @@ void Meta_RemoveContactNumber(DBCachedContact *ccMeta, int number, bool bUpdateI
INT_PTR Meta_Delete(WPARAM hContact, LPARAM bSkipQuestion)
{
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hContact);
if (cc == nullptr)
return 1;
@@ -201,7 +201,7 @@ INT_PTR Meta_Delete(WPARAM hContact, LPARAM bSkipQuestion)
db_delete_contact(hContact);
}
else if (cc->IsSub()) {
- if ((cc = currDb->getCache()->GetCachedContact(cc->parentID)) == nullptr)
+ if ((cc = g_pCurrDb->getCache()->GetCachedContact(cc->parentID)) == nullptr)
return 2;
if (cc->nSubs == 1) {
@@ -227,7 +227,7 @@ INT_PTR Meta_Delete(WPARAM hContact, LPARAM bSkipQuestion)
INT_PTR Meta_Default(WPARAM hSub, LPARAM)
{
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(db_mc_getMeta(hSub));
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(db_mc_getMeta(hSub));
if (cc && cc->IsMeta())
db_mc_setDefault(cc->contactID, hSub, true);
return 0;
@@ -244,7 +244,7 @@ INT_PTR Meta_Default(WPARAM hSub, LPARAM)
int Meta_ModifyMenu(WPARAM hMeta, LPARAM)
{
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hMeta);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hMeta);
if (cc == nullptr)
return 0;
diff --git a/src/mir_app/src/meta_services.cpp b/src/mir_app/src/meta_services.cpp
index f8119452c3..f357903de7 100644
--- a/src/mir_app/src/meta_services.cpp
+++ b/src/mir_app/src/meta_services.cpp
@@ -126,7 +126,7 @@ static void Meta_SetSrmmSub(MCONTACT hMeta, MCONTACT hSub)
static INT_PTR MetaFilter_RecvMessage(WPARAM wParam, LPARAM lParam)
{
CCSDATA *ccs = (CCSDATA*)lParam;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(ccs->hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(ccs->hContact);
if (cc && cc->IsSub())
Meta_SetSrmmSub(cc->parentID, cc->contactID);
@@ -293,11 +293,11 @@ int Meta_SettingChanged(WPARAM hContact, LPARAM lParam)
if (hContact == 0)
return 0;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hContact);
if (cc == nullptr || !cc->IsSub())
return 0;
- DBCachedContact *ccMeta = currDb->getCache()->GetCachedContact(cc->parentID);
+ DBCachedContact *ccMeta = g_pCurrDb->getCache()->GetCachedContact(cc->parentID);
if (ccMeta == nullptr || !ccMeta->IsMeta())
return 0;
@@ -419,7 +419,7 @@ int Meta_SettingChanged(WPARAM hContact, LPARAM lParam)
int Meta_ContactDeleted(WPARAM hContact, LPARAM)
{
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hContact);
if (cc == nullptr)
return 0;
@@ -446,7 +446,7 @@ int Meta_ContactDeleted(WPARAM hContact, LPARAM)
// remove & restore all subcontacts
for (int i = 0; i < cc->nSubs; i++)
- currDb->MetaDetouchSub(cc, i);
+ g_pCurrDb->MetaDetouchSub(cc, i);
return 0;
}
@@ -500,7 +500,7 @@ static int Meta_MessageWindowEvent(WPARAM, LPARAM lParam)
{
MessageWindowEventData *mwed = (MessageWindowEventData*)lParam;
if (mwed->uType == MSG_WINDOW_EVT_OPEN) {
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(mwed->hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(mwed->hContact);
if (cc != nullptr) {
Srmm_SetIconFlags(cc->contactID, META_PROTO, 0, cc->IsMeta() ? 0 : MBF_HIDDEN);
if (cc->IsMeta()) {
diff --git a/src/mir_app/src/meta_utils.cpp b/src/mir_app/src/meta_utils.cpp
index 0924c1fad7..82ab92579c 100644
--- a/src/mir_app/src/meta_utils.cpp
+++ b/src/mir_app/src/meta_utils.cpp
@@ -60,7 +60,7 @@ int Meta_SetNick(char *szProto)
BOOL Meta_Assign(MCONTACT hSub, MCONTACT hMeta, bool set_as_default)
{
- DBCachedContact *ccDest = CheckMeta(hMeta), *ccSub = currDb->getCache()->GetCachedContact(hSub);
+ DBCachedContact *ccDest = CheckMeta(hMeta), *ccSub = g_pCurrDb->getCache()->GetCachedContact(hSub);
if (ccDest == nullptr || ccSub == nullptr)
return FALSE;
@@ -178,7 +178,7 @@ BOOL Meta_Assign(MCONTACT hSub, MCONTACT hMeta, bool set_as_default)
}
// merge sub's events to the meta-history
- currDb->MetaMergeHistory(ccDest, ccSub);
+ g_pCurrDb->MetaMergeHistory(ccDest, ccSub);
// hide sub finally
Contact_Hide(ccSub->contactID);
@@ -290,7 +290,7 @@ DBCachedContact* CheckMeta(MCONTACT hMeta)
if (!g_bMetaEnabled)
return nullptr;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hMeta);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hMeta);
return (cc == nullptr || cc->nSubs == -1) ? nullptr : cc;
}
@@ -324,7 +324,7 @@ int Meta_HideLinkedContacts(void)
char buffer[512];
for (auto &hContact : Contacts()) {
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hContact);
if (cc == nullptr || cc->parentID == 0)
continue;
@@ -383,7 +383,7 @@ int Meta_HideMetaContacts(bool bHide)
{
for (auto &hContact : Contacts()) {
bool bSet;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hContact);
if (cc->IsSub()) // show on hide, reverse flag
bSet = !bHide;
else if (cc->IsMeta())
diff --git a/src/mir_app/src/miranda.h b/src/mir_app/src/miranda.h
index dde8b65df3..fd2e62c307 100644
--- a/src/mir_app/src/miranda.h
+++ b/src/mir_app/src/miranda.h
@@ -50,7 +50,7 @@ extern pfnDwmIsCompositionEnabled dwmIsCompositionEnabled;
/**** database.cpp *********************************************************************/
-extern MDatabaseCommon *currDb;
+extern MIR_CORE_EXPORT MDatabaseCommon *g_pCurrDb;
extern LIST<DATABASELINK> arDbPlugins;
int InitIni(void);
diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp
index abb106b231..e4b9ab5e46 100644
--- a/src/mir_app/src/newplugins.cpp
+++ b/src/mir_app/src/newplugins.cpp
@@ -778,10 +778,10 @@ int LoadNewPluginsModuleInfos(void)
void UnloadDatabase(void)
{
+ auto *currDb = g_pCurrDb;
if (currDb != nullptr) {
db_setCurrent(nullptr);
delete currDb;
- currDb = nullptr;
}
UninitIni();
diff --git a/src/mir_app/src/proto_chains.cpp b/src/mir_app/src/proto_chains.cpp
index abc22753ab..ec1808363a 100644
--- a/src/mir_app/src/proto_chains.cpp
+++ b/src/mir_app/src/proto_chains.cpp
@@ -26,10 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static int GetProtocolP(MCONTACT hContact, char *szBuf, int cbLen)
{
- if (currDb == nullptr)
+ if (g_pCurrDb == nullptr)
return 1;
- DBCachedContact *cc = currDb->getCache()->GetCachedContact(hContact);
+ DBCachedContact *cc = g_pCurrDb->getCache()->GetCachedContact(hContact);
if (cc && cc->szProto != nullptr) {
strncpy(szBuf, cc->szProto, cbLen);
szBuf[cbLen - 1] = 0;
@@ -41,12 +41,12 @@ static int GetProtocolP(MCONTACT hContact, char *szBuf, int cbLen)
dbv.pszVal = szBuf;
dbv.cchVal = cbLen;
- int res = currDb->GetContactSettingStatic(hContact, "Protocol", "p", &dbv);
+ int res = g_pCurrDb->GetContactSettingStatic(hContact, "Protocol", "p", &dbv);
if (res == 0) {
if (cc == nullptr)
- cc = currDb->getCache()->AddContactToCache(hContact);
+ cc = g_pCurrDb->getCache()->AddContactToCache(hContact);
- cc->szProto = currDb->getCache()->GetCachedSetting(nullptr, szBuf, 0, mir_strlen(szBuf));
+ cc->szProto = g_pCurrDb->getCache()->GetCachedSetting(nullptr, szBuf, 0, mir_strlen(szBuf));
}
return res;
}