From 8ffc77be71507825a8f7585bcabff8ccc370206a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 8 Dec 2018 20:12:16 +0300 Subject: db_get_sa / db_get_wsa to receive the default value, massive code simplification --- src/mir_core/src/db.cpp | 26 +++++++++++++++----------- src/mir_core/src/openurl.cpp | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/mir_core') diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp index 87eb0ed80c..eef66081df 100644 --- a/src/mir_core/src/db.cpp +++ b/src/mir_core/src/db.cpp @@ -163,22 +163,26 @@ MIR_CORE_DLL(INT_PTR) db_get_s(MCONTACT hContact, const char *szModule, const ch return currDb->GetContactSettingStr(hContact, szModule, szSetting, dbv); } -MIR_CORE_DLL(char*) db_get_sa(MCONTACT hContact, const char *szModule, const char *szSetting) +MIR_CORE_DLL(char*) db_get_sa(MCONTACT hContact, const char *szModule, const char *szSetting, const char *szValue) { - if (currDb == nullptr) - return nullptr; + if (currDb) { + DBVARIANT dbv = { DBVT_ASCIIZ }; + if (!currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) + return dbv.pszVal; + } - DBVARIANT dbv = { DBVT_ASCIIZ }; - return currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv) ? nullptr : dbv.pszVal; + return (szValue == nullptr) ? nullptr : mir_strdup(szValue); } -MIR_CORE_DLL(wchar_t*) db_get_wsa(MCONTACT hContact, const char *szModule, const char *szSetting) +MIR_CORE_DLL(wchar_t*) db_get_wsa(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *szValue) { - if (currDb == nullptr) - return nullptr; + if (currDb) { + DBVARIANT dbv = { DBVT_WCHAR }; + if (!currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv)) + return dbv.pwszVal; + } - DBVARIANT dbv = { DBVT_WCHAR }; - return currDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv) ? nullptr : dbv.pwszVal; + return (szValue == nullptr) ? nullptr : mir_wstrdup(szValue); } MIR_CORE_DLL(CMStringA) db_get_sm(MCONTACT hContact, LPCSTR szModule, LPCSTR szSetting) @@ -459,7 +463,7 @@ MIR_CORE_DLL(void) db_setCurrent(MDatabaseCommon *_db) return; // try to get the langpack's name from a profile - ptrW langpack(db_get_wsa(NULL, "Langpack", "Current")); + ptrW langpack(db_get_wsa(0, "Langpack", "Current")); if (langpack && langpack[0] != '\0') LoadLangPack(langpack); else diff --git a/src/mir_core/src/openurl.cpp b/src/mir_core/src/openurl.cpp index 2fcd374dce..94fdabd3fd 100644 --- a/src/mir_core/src/openurl.cpp +++ b/src/mir_core/src/openurl.cpp @@ -54,7 +54,7 @@ static void __cdecl OpenURLThread(TOpenUrlInfo *hUrlInfo) } // check user defined browser for opening urls - ptrW tszBrowser(db_get_wsa(NULL, "Miranda", "OpenUrlBrowser")); + ptrW tszBrowser(db_get_wsa(0, "Miranda", "OpenUrlBrowser")); if (tszBrowser) ShellExecute(nullptr, L"open", tszBrowser, tszUrl, nullptr, (hUrlInfo->newWindow) ? SW_NORMAL : SW_SHOWDEFAULT); else -- cgit v1.2.3