summaryrefslogtreecommitdiff
path: root/src/mir_core
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-12-08 20:12:16 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-12-08 20:12:26 +0300
commit8ffc77be71507825a8f7585bcabff8ccc370206a (patch)
treeaa13a8070f31286db6ad22e17a577e547942f951 /src/mir_core
parent41b2fdfc654e3eec07c97ceba00cda13d988ffff (diff)
db_get_sa / db_get_wsa to receive the default value, massive code simplification
Diffstat (limited to 'src/mir_core')
-rw-r--r--src/mir_core/src/db.cpp26
-rw-r--r--src/mir_core/src/openurl.cpp2
2 files changed, 16 insertions, 12 deletions
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