From 933b2a7a59948d3195aafc604d4d5711fa4a6345 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 7 Aug 2020 14:37:51 +0300 Subject: fix for rare crash on exit --- src/mir_app/src/database.cpp | 6 +- src/mir_app/src/meta_addto.cpp | 2 +- src/mir_app/src/meta_api.cpp | 24 +++--- src/mir_app/src/meta_edit.cpp | 2 +- src/mir_app/src/meta_menu.cpp | 20 ++--- src/mir_app/src/meta_services.cpp | 12 +-- src/mir_app/src/meta_utils.cpp | 10 +-- src/mir_app/src/miranda.h | 2 +- src/mir_app/src/newplugins.cpp | 2 +- src/mir_app/src/proto_chains.cpp | 10 +-- src/mir_core/src/db.cpp | 166 +++++++++++++++++++------------------- src/mir_core/src/mir_core.def | 1 + src/mir_core/src/mir_core64.def | 1 + src/mir_core/src/miranda.h | 1 - 14 files changed, 131 insertions(+), 128 deletions(-) (limited to 'src') 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 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; } diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp index 322402e22e..0b1d0c6096 100644 --- a/src/mir_core/src/db.cpp +++ b/src/mir_core/src/db.cpp @@ -24,30 +24,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -MDatabaseCommon *currDb = nullptr; +MIR_CORE_EXPORT MDatabaseCommon* g_pCurrDb = nullptr; ///////////////////////////////////////////////////////////////////////////////////////// // database functions MIR_CORE_DLL(void) db_set_safety_mode(BOOL bNewMode) { - if (currDb) - currDb->SetCacheSafetyMode(bNewMode != 0); + if (g_pCurrDb) + g_pCurrDb->SetCacheSafetyMode(bNewMode != 0); } MIR_CORE_DLL(int) db_get_contact_count(void) { - return (currDb) ? currDb->GetContactCount() : 0; + return (g_pCurrDb) ? g_pCurrDb->GetContactCount() : 0; } MIR_CORE_DLL(MDatabaseCommon*) db_get_current() { - return currDb; + return g_pCurrDb; } MIR_CORE_DLL(int) db_delete_module(MCONTACT hContact, const char *szModuleName) { - return (currDb) ? currDb->DeleteModule(hContact, szModuleName) : 0; + return (g_pCurrDb) ? g_pCurrDb->DeleteModule(hContact, szModuleName) : 0; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -55,7 +55,7 @@ MIR_CORE_DLL(int) db_delete_module(MCONTACT hContact, const char *szModuleName) MIR_CORE_DLL(MCONTACT) db_add_contact(void) { - MCONTACT hNew = (currDb) ? currDb->AddContact() : 0; + MCONTACT hNew = (g_pCurrDb) ? g_pCurrDb->AddContact() : 0; Netlib_Logf(nullptr, "New contact created: %d", hNew); return hNew; } @@ -67,12 +67,12 @@ MIR_CORE_DLL(int) db_delete_contact(MCONTACT hContact) DeleteFile(wszPhoto); Netlib_Logf(nullptr, "Contact deleted: %d", hContact); - return (currDb) ? currDb->DeleteContact(hContact) : 0; + return (g_pCurrDb) ? g_pCurrDb->DeleteContact(hContact) : 0; } MIR_CORE_DLL(int) db_is_contact(MCONTACT hContact) { - return (currDb) ? currDb->IsDbContact(hContact) : 0; + return (g_pCurrDb) ? g_pCurrDb->IsDbContact(hContact) : 0; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -80,17 +80,17 @@ MIR_CORE_DLL(int) db_is_contact(MCONTACT hContact) MIR_CORE_DLL(int) db_enum_modules(DBMODULEENUMPROC pFunc, void *param) { - return (currDb) ? currDb->EnumModuleNames(pFunc, param) : 0; + return (g_pCurrDb) ? g_pCurrDb->EnumModuleNames(pFunc, param) : 0; } MIR_CORE_DLL(int) db_enum_residents(DBMODULEENUMPROC pFunc, void *param) { - return (currDb) ? currDb->EnumResidentSettings(pFunc, param) : 0; + return (g_pCurrDb) ? g_pCurrDb->EnumResidentSettings(pFunc, param) : 0; } EXTERN_C MIR_CORE_DLL(int) db_enum_settings(MCONTACT hContact, DBSETTINGENUMPROC pFunc, const char *szModule, void *param) { - return (currDb) ? currDb->EnumContactSettings(hContact, pFunc, szModule, param) : 0; + return (g_pCurrDb) ? g_pCurrDb->EnumContactSettings(hContact, pFunc, szModule, param) : 0; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -98,16 +98,16 @@ EXTERN_C MIR_CORE_DLL(int) db_enum_settings(MCONTACT hContact, DBSETTINGENUMPROC MIR_CORE_DLL(int) db_get_b(MCONTACT hContact, const char *szModule, const char *szSetting, int errorValue) { - if (currDb != nullptr) { + if (g_pCurrDb != nullptr) { DBVARIANT dbv; - if (!currDb->GetContactSetting(hContact, szModule, szSetting, &dbv)) + if (!g_pCurrDb->GetContactSetting(hContact, szModule, szSetting, &dbv)) { switch(dbv.type) { case DBVT_BYTE: return dbv.bVal; case DBVT_WORD: return BYTE(dbv.wVal); case DBVT_DWORD: return BYTE(dbv.dVal); } - currDb->FreeVariant(&dbv); + g_pCurrDb->FreeVariant(&dbv); } } return errorValue; @@ -115,15 +115,15 @@ MIR_CORE_DLL(int) db_get_b(MCONTACT hContact, const char *szModule, const char * MIR_CORE_DLL(int) db_get_w(MCONTACT hContact, const char *szModule, const char *szSetting, int errorValue) { - if (currDb != nullptr) { + if (g_pCurrDb != nullptr) { DBVARIANT dbv; - if (!currDb->GetContactSetting(hContact, szModule, szSetting, &dbv)) { + if (!g_pCurrDb->GetContactSetting(hContact, szModule, szSetting, &dbv)) { switch(dbv.type) { case DBVT_BYTE: return dbv.bVal; case DBVT_WORD: return dbv.wVal; case DBVT_DWORD: return WORD(dbv.dVal); } - currDb->FreeVariant(&dbv); + g_pCurrDb->FreeVariant(&dbv); } } return errorValue; @@ -131,15 +131,15 @@ MIR_CORE_DLL(int) db_get_w(MCONTACT hContact, const char *szModule, const char * MIR_CORE_DLL(DWORD) db_get_dw(MCONTACT hContact, const char *szModule, const char *szSetting, DWORD errorValue) { - if (currDb != nullptr) { + if (g_pCurrDb != nullptr) { DBVARIANT dbv; - if (!currDb->GetContactSetting(hContact, szModule, szSetting, &dbv)) { + if (!g_pCurrDb->GetContactSetting(hContact, szModule, szSetting, &dbv)) { switch(dbv.type) { case DBVT_BYTE: return dbv.bVal; case DBVT_WORD: return dbv.wVal; case DBVT_DWORD: return dbv.dVal; } - currDb->FreeVariant(&dbv); + g_pCurrDb->FreeVariant(&dbv); } } @@ -148,26 +148,26 @@ MIR_CORE_DLL(DWORD) db_get_dw(MCONTACT hContact, const char *szModule, const cha MIR_CORE_DLL(INT_PTR) db_get(MCONTACT hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv) { - if (currDb == nullptr) + if (g_pCurrDb == nullptr) return 1; - return currDb->GetContactSetting(hContact, szModule, szSetting, dbv); + return g_pCurrDb->GetContactSetting(hContact, szModule, szSetting, dbv); } MIR_CORE_DLL(INT_PTR) db_get_s(MCONTACT hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv, const int nType) { - if (currDb == nullptr) + if (g_pCurrDb == nullptr) return 1; dbv->type = (BYTE)nType; - return currDb->GetContactSettingStr(hContact, szModule, szSetting, dbv); + return g_pCurrDb->GetContactSettingStr(hContact, szModule, szSetting, dbv); } MIR_CORE_DLL(char*) db_get_sa(MCONTACT hContact, const char *szModule, const char *szSetting, const char *szValue) { - if (currDb) { + if (g_pCurrDb) { DBVARIANT dbv = { DBVT_ASCIIZ }; - if (!currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) + if (!g_pCurrDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) return dbv.pszVal; } @@ -176,9 +176,9 @@ MIR_CORE_DLL(char*) db_get_sa(MCONTACT hContact, const char *szModule, const cha MIR_CORE_DLL(char*) db_get_utfa(MCONTACT hContact, const char *szModule, const char *szSetting, const char *szValue) { - if (currDb) { + if (g_pCurrDb) { DBVARIANT dbv = { DBVT_UTF8 }; - if (!currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) + if (!g_pCurrDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) return dbv.pszVal; } @@ -187,9 +187,9 @@ MIR_CORE_DLL(char*) db_get_utfa(MCONTACT hContact, const char *szModule, const c MIR_CORE_DLL(wchar_t*) db_get_wsa(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *szValue) { - if (currDb) { + if (g_pCurrDb) { DBVARIANT dbv = { DBVT_WCHAR }; - if (!currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) + if (!g_pCurrDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) return dbv.pwszVal; } @@ -198,11 +198,11 @@ MIR_CORE_DLL(wchar_t*) db_get_wsa(MCONTACT hContact, const char *szModule, const MIR_CORE_DLL(CMStringA) db_get_sm(MCONTACT hContact, LPCSTR szModule, LPCSTR szSetting, const char *szValue) { - if (currDb == nullptr) + if (g_pCurrDb == nullptr) return (szValue == nullptr) ? CMStringA() : CMStringA(szValue); DBVARIANT dbv = { DBVT_ASCIIZ }; - if (currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) + if (g_pCurrDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) return (szValue == nullptr) ? CMStringA() : CMStringA(szValue); return CMStringA(ptrA(dbv.pszVal)); @@ -210,11 +210,11 @@ MIR_CORE_DLL(CMStringA) db_get_sm(MCONTACT hContact, LPCSTR szModule, LPCSTR szS MIR_CORE_DLL(CMStringW) db_get_wsm(MCONTACT hContact, LPCSTR szModule, LPCSTR szSetting, const wchar_t *szValue) { - if (currDb == nullptr) + if (g_pCurrDb == nullptr) return (szValue == nullptr) ? CMStringW() : CMStringW(szValue); DBVARIANT dbv = { DBVT_WCHAR }; - if (currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) + if (g_pCurrDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) return (szValue == nullptr) ? CMStringW() : CMStringW(szValue); return CMStringW(ptrW(dbv.pwszVal)); @@ -225,38 +225,38 @@ MIR_CORE_DLL(CMStringW) db_get_wsm(MCONTACT hContact, LPCSTR szModule, LPCSTR sz MIR_CORE_DLL(int) db_get_static(MCONTACT hContact, const char *szModule, const char *szSetting, char *pDest, int cbDest) { - if (currDb == nullptr) + if (g_pCurrDb == nullptr) return 1; DBVARIANT dbv; dbv.type = DBVT_ASCIIZ; dbv.pszVal = pDest; dbv.cchVal = cbDest; - return currDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv); + return g_pCurrDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv); } MIR_CORE_DLL(int) db_get_static_utf(MCONTACT hContact, const char *szModule, const char *szSetting, char *pDest, int cbDest) { - if (currDb == nullptr) + if (g_pCurrDb == nullptr) return 1; DBVARIANT dbv; dbv.type = DBVT_UTF8; dbv.pszVal = pDest; dbv.cchVal = cbDest; - return currDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv); + return g_pCurrDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv); } MIR_CORE_DLL(int) db_get_wstatic(MCONTACT hContact, const char *szModule, const char *szSetting, wchar_t *pDest, int cbDest) { - if (currDb == nullptr) + if (g_pCurrDb == nullptr) return 1; DBVARIANT dbv; dbv.type = DBVT_WCHAR; dbv.pwszVal = pDest; dbv.cchVal = cbDest; - return currDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv); + return g_pCurrDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -264,90 +264,90 @@ MIR_CORE_DLL(int) db_get_wstatic(MCONTACT hContact, const char *szModule, const MIR_CORE_DLL(INT_PTR) db_set(MCONTACT hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv) { - if (currDb == nullptr) return 1; + if (g_pCurrDb == nullptr) return 1; DBCONTACTWRITESETTING cws; cws.szModule = szModule; cws.szSetting = szSetting; cws.value = *dbv; - return currDb->WriteContactSetting(hContact, &cws); + return g_pCurrDb->WriteContactSetting(hContact, &cws); } MIR_CORE_DLL(INT_PTR) db_set_b(MCONTACT hContact, const char *szModule, const char *szSetting, BYTE val) { - if (currDb == nullptr) return 1; + if (g_pCurrDb == nullptr) return 1; DBCONTACTWRITESETTING cws; cws.szModule = szModule; cws.szSetting = szSetting; cws.value.type = DBVT_BYTE; cws.value.bVal = val; - return currDb->WriteContactSetting(hContact, &cws); + return g_pCurrDb->WriteContactSetting(hContact, &cws); } MIR_CORE_DLL(INT_PTR) db_set_w(MCONTACT hContact, const char *szModule, const char *szSetting, WORD val) { - if (currDb == nullptr) return 1; + if (g_pCurrDb == nullptr) return 1; DBCONTACTWRITESETTING cws; cws.szModule = szModule; cws.szSetting = szSetting; cws.value.type = DBVT_WORD; cws.value.wVal = val; - return currDb->WriteContactSetting(hContact, &cws); + return g_pCurrDb->WriteContactSetting(hContact, &cws); } MIR_CORE_DLL(INT_PTR) db_set_dw(MCONTACT hContact, const char *szModule, const char *szSetting, DWORD val) { - if (currDb == nullptr) return 1; + if (g_pCurrDb == nullptr) return 1; DBCONTACTWRITESETTING cws; cws.szModule = szModule; cws.szSetting = szSetting; cws.value.type = DBVT_DWORD; cws.value.dVal = val; - return currDb->WriteContactSetting(hContact, &cws); + return g_pCurrDb->WriteContactSetting(hContact, &cws); } MIR_CORE_DLL(INT_PTR) db_set_s(MCONTACT hContact, const char *szModule, const char *szSetting, const char *val) { - if (currDb == nullptr) return 1; + if (g_pCurrDb == nullptr) return 1; DBCONTACTWRITESETTING cws; cws.szModule = szModule; cws.szSetting = szSetting; cws.value.type = DBVT_ASCIIZ; cws.value.pszVal = (char*)(val == nullptr ? "" : val); - return currDb->WriteContactSetting(hContact, &cws); + return g_pCurrDb->WriteContactSetting(hContact, &cws); } MIR_CORE_DLL(INT_PTR) db_set_ws(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *val) { - if (currDb == nullptr) return 1; + if (g_pCurrDb == nullptr) return 1; DBCONTACTWRITESETTING cws; cws.szModule = szModule; cws.szSetting = szSetting; cws.value.type = DBVT_WCHAR; cws.value.pwszVal = (wchar_t*)(val == nullptr ? L"" : val); - return currDb->WriteContactSetting(hContact, &cws); + return g_pCurrDb->WriteContactSetting(hContact, &cws); } MIR_CORE_DLL(INT_PTR) db_set_utf(MCONTACT hContact, const char *szModule, const char *szSetting, const char *val) { - if (currDb == nullptr) return 1; + if (g_pCurrDb == nullptr) return 1; DBCONTACTWRITESETTING cws; cws.szModule = szModule; cws.szSetting = szSetting; cws.value.type = DBVT_UTF8; cws.value.pszVal = (char*)(val == nullptr ? "" : val); - return currDb->WriteContactSetting(hContact, &cws); + return g_pCurrDb->WriteContactSetting(hContact, &cws); } MIR_CORE_DLL(INT_PTR) db_set_blob(MCONTACT hContact, const char *szModule, const char *szSetting, void *val, unsigned len) { - if (currDb == nullptr) return 1; + if (g_pCurrDb == nullptr) return 1; DBCONTACTWRITESETTING cws; cws.szModule = szModule; @@ -355,7 +355,7 @@ MIR_CORE_DLL(INT_PTR) db_set_blob(MCONTACT hContact, const char *szModule, const cws.value.type = DBVT_BLOB; cws.value.cpbVal = (WORD)len; cws.value.pbVal = (unsigned char*)val; - return currDb->WriteContactSetting(hContact, &cws); + return g_pCurrDb->WriteContactSetting(hContact, &cws); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -363,72 +363,72 @@ MIR_CORE_DLL(INT_PTR) db_set_blob(MCONTACT hContact, const char *szModule, const MIR_CORE_DLL(MEVENT) db_event_add(MCONTACT hContact, const DBEVENTINFO *dbei) { - return (currDb == nullptr) ? 0 : currDb->AddEvent(hContact, dbei); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->AddEvent(hContact, dbei); } MIR_CORE_DLL(int) db_event_count(MCONTACT hContact) { - return (currDb == nullptr) ? 0 : currDb->GetEventCount(hContact); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->GetEventCount(hContact); } MIR_CORE_DLL(int) db_event_delete(MEVENT hDbEvent) { - return (currDb == nullptr) ? 0 : currDb->DeleteEvent(hDbEvent); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->DeleteEvent(hDbEvent); } MIR_CORE_DLL(int) db_event_edit(MCONTACT hContact, MEVENT hDbEvent, const DBEVENTINFO *dbei) { - return (currDb == nullptr) ? 0 : currDb->EditEvent(hContact, hDbEvent, dbei); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->EditEvent(hContact, hDbEvent, dbei); } MIR_CORE_DLL(MEVENT) db_event_first(MCONTACT hContact) { - return (currDb == nullptr) ? 0 : currDb->FindFirstEvent(hContact); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->FindFirstEvent(hContact); } MIR_CORE_DLL(MEVENT) db_event_firstUnread(MCONTACT hContact) { - return (currDb == nullptr) ? 0 : currDb->FindFirstUnreadEvent(hContact); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->FindFirstUnreadEvent(hContact); } MIR_CORE_DLL(int) db_event_get(MEVENT hDbEvent, DBEVENTINFO *dbei) { - return (currDb == nullptr) ? 1 : currDb->GetEvent(hDbEvent, dbei); + return (g_pCurrDb == nullptr) ? 1 : g_pCurrDb->GetEvent(hDbEvent, dbei); } MIR_CORE_DLL(int) db_event_getBlobSize(MEVENT hDbEvent) { - return (currDb == nullptr) ? 0 : currDb->GetBlobSize(hDbEvent); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->GetBlobSize(hDbEvent); } MIR_CORE_DLL(MCONTACT) db_event_getContact(MEVENT hDbEvent) { - return (currDb == nullptr) ? 0 : currDb->GetEventContact(hDbEvent); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->GetEventContact(hDbEvent); } MIR_CORE_DLL(MEVENT) db_event_last(MCONTACT hContact) { - return (currDb == nullptr) ? 0 : currDb->FindLastEvent(hContact); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->FindLastEvent(hContact); } MIR_CORE_DLL(int) db_event_markRead(MCONTACT hContact, MEVENT hDbEvent) { - return (currDb == nullptr) ? 0 : currDb->MarkEventRead(hContact, hDbEvent); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->MarkEventRead(hContact, hDbEvent); } MIR_CORE_DLL(MEVENT) db_event_next(MCONTACT hContact, MEVENT hDbEvent) { - return (currDb == nullptr) ? 0 : currDb->FindNextEvent(hContact, hDbEvent); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->FindNextEvent(hContact, hDbEvent); } MIR_CORE_DLL(MEVENT) db_event_prev(MCONTACT hContact, MEVENT hDbEvent) { - return (currDb == nullptr) ? 0 : currDb->FindPrevEvent(hContact, hDbEvent); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->FindPrevEvent(hContact, hDbEvent); } MIR_CORE_DLL(MEVENT) db_event_getById(const char *szModule, const char *szId) { - return (currDb == nullptr) ? 0 : currDb->GetEventById(szModule, szId); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->GetEventById(szModule, szId); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -440,12 +440,12 @@ DB::EventCursor::~EventCursor() MIR_CORE_DLL(DB::EventCursor*) DB::Events(MCONTACT hContact, MEVENT iStartEvent) { - return (currDb == nullptr) ? 0 : currDb->EventCursor(hContact, iStartEvent); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->EventCursor(hContact, iStartEvent); } MIR_CORE_DLL(DB::EventCursor*) DB::EventsRev(MCONTACT hContact, MEVENT iStartEvent) { - return (currDb == nullptr) ? 0 : currDb->EventCursorRev(hContact, iStartEvent); + return (g_pCurrDb == nullptr) ? 0 : g_pCurrDb->EventCursorRev(hContact, iStartEvent); } DB::ECPTR::ECPTR(EventCursor *_pCursor) : @@ -482,36 +482,36 @@ MEVENT DB::ECPTR::FetchNext() MIR_CORE_DLL(INT_PTR) db_free(DBVARIANT *dbv) { - return (currDb == nullptr) ? 1 : currDb->FreeVariant(dbv); + return (g_pCurrDb == nullptr) ? 1 : g_pCurrDb->FreeVariant(dbv); } MIR_CORE_DLL(INT_PTR) db_unset(MCONTACT hContact, const char *szModule, const char *szSetting) { - if (currDb == nullptr) + if (g_pCurrDb == nullptr) return 1; - return currDb->DeleteContactSetting(hContact, szModule, szSetting); + return g_pCurrDb->DeleteContactSetting(hContact, szModule, szSetting); } MIR_CORE_DLL(DBCachedContact*) db_get_contact(MCONTACT hContact) { - return (currDb == nullptr) ? nullptr : currDb->getCache()->GetCachedContact(hContact); + return (g_pCurrDb == nullptr) ? nullptr : g_pCurrDb->getCache()->GetCachedContact(hContact); } MIR_CORE_DLL(MCONTACT) db_find_first(const char *szProto) { - return (currDb == nullptr) ? NULL : currDb->FindFirstContact(szProto); + return (g_pCurrDb == nullptr) ? NULL : g_pCurrDb->FindFirstContact(szProto); } MIR_CORE_DLL(MCONTACT) db_find_next(MCONTACT hContact, const char *szProto) { - return (currDb == nullptr) ? NULL : currDb->FindNextContact(hContact, szProto); + return (g_pCurrDb == nullptr) ? NULL : g_pCurrDb->FindNextContact(hContact, szProto); } MIR_CORE_DLL(void) db_setCurrent(MDatabaseCommon *_db) { - currDb = _db; - if (currDb == nullptr) + g_pCurrDb = _db; + if (g_pCurrDb == nullptr) return; // try to get the langpack's name from a profile @@ -524,10 +524,10 @@ MIR_CORE_DLL(void) db_setCurrent(MDatabaseCommon *_db) MIR_CORE_DLL(BOOL) db_set_resident(const char *szModule, const char *szService, BOOL bEnable) { - if (currDb == nullptr || szModule == nullptr || szService == nullptr) + if (g_pCurrDb == nullptr || szModule == nullptr || szService == nullptr) return FALSE; char str[MAXMODULELABELLENGTH * 2]; mir_snprintf(str, "%s/%s", szModule, szService); - return currDb->SetSettingResident(bEnable, str); + return g_pCurrDb->SetSettingResident(bEnable, str); } diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 829aeb94c4..1636bc0239 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1,6 +1,7 @@ LIBRARY mir_core.mir EXPORTS +?g_pCurrDb@@3PAVMDatabaseCommon@@A @1 NONAME CallFunctionAsync @5 CallPluginEventHook @7 CallService @8 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 41bebe9ac7..bb77e99aac 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1,6 +1,7 @@ LIBRARY mir_core.mir EXPORTS +?g_pCurrDb@@3PEAVMDatabaseCommon@@EA @1 NONAME CallFunctionAsync @5 CallPluginEventHook @7 CallService @8 diff --git a/src/mir_core/src/miranda.h b/src/mir_core/src/miranda.h index 8712b000d4..96cc91e089 100644 --- a/src/mir_core/src/miranda.h +++ b/src/mir_core/src/miranda.h @@ -35,7 +35,6 @@ extern HINSTANCE g_hInst; extern HWND hAPCWindow; extern HANDLE hThreadQueueEmpty; extern HCURSOR g_hCursorNS, g_hCursorWE; -extern MDatabaseCommon *currDb; ///////////////////////////////////////////////////////////////////////////////////////// // modules.cpp -- cgit v1.2.3