From a43d5bcb1e0bdafb0193662168976aac989ed922 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 9 Feb 2022 17:40:09 +0300 Subject: db_is_module_empty & db_copy_module - new database helpers --- src/mir_app/src/db_ini.cpp | 12 ++---------- src/mir_core/src/db.cpp | 40 +++++++++++++++++++++++++++++++++++++++- src/mir_core/src/mir_core.def | 2 ++ src/mir_core/src/mir_core64.def | 2 ++ 4 files changed, 45 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/db_ini.cpp b/src/mir_app/src/db_ini.cpp index 978c802679..73ca514756 100644 --- a/src/mir_app/src/db_ini.cpp +++ b/src/mir_app/src/db_ini.cpp @@ -421,16 +421,8 @@ LBL_NewLine: case 'l': case 'L': case '-': - if (szValue[1] == '*') { - LIST arSettings(1); - ESFDParam param = { &arSettings, szName }; - db_enum_settings(0, EnumSettingsForDeletion, szSection, ¶m); - - for (auto &it : arSettings) { - db_unset(0, szSection, it); - mir_free(it); - } - } + if (szValue[1] == '*') + db_delete_module(0, szSection); db_unset(0, szSection, szName); break; case 'e': diff --git a/src/mir_core/src/db.cpp b/src/mir_core/src/db.cpp index ecd55c9be3..cb95ebb286 100644 --- a/src/mir_core/src/db.cpp +++ b/src/mir_core/src/db.cpp @@ -50,6 +50,44 @@ MIR_CORE_DLL(int) db_delete_module(MCONTACT hContact, const char *szModuleName) return (g_pCurrDb) ? g_pCurrDb->DeleteModule(hContact, szModuleName) : 0; } +///////////////////////////////////////////////////////////////////////////////////////// + +static int CheckIfModuleIsEmptyProc(const char *, void *) +{ + return 1; +} + +MIR_CORE_DLL(bool) db_is_module_empty(MCONTACT hContact, const char *szModule) +{ + return (g_pCurrDb) ? g_pCurrDb->EnumContactSettings(hContact, CheckIfModuleIsEmptyProc, szModule, 0) < 0 : true; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +struct EnumProcParam +{ + MCONTACT hContact; + LPCSTR szModule, szNewModule; +}; + +static int EnumProc(const char *szSetting, void *lParam) +{ + EnumProcParam *param = (EnumProcParam *)lParam; + + DBVARIANT dbv; + if (!db_get(param->hContact, param->szModule, szSetting, &dbv)) { + db_set(param->hContact, param->szNewModule, szSetting, &dbv); + db_free(&dbv); + } + return 0; +} + +MIR_CORE_DLL(int) db_copy_module(const char *szModule, const char *szNewModule, MCONTACT hContact) +{ + EnumProcParam param = { hContact, szModule, szNewModule }; + return db_enum_settings(hContact, EnumProc, szModule, ¶m); +} + ///////////////////////////////////////////////////////////////////////////////////////// // contact functions @@ -93,7 +131,7 @@ MIR_CORE_DLL(int) db_enum_residents(DBMODULEENUMPROC pFunc, void *param) 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) +MIR_CORE_DLL(int) db_enum_settings(MCONTACT hContact, DBSETTINGENUMPROC pFunc, const char *szModule, void *param) { return (g_pCurrDb) ? g_pCurrDb->EnumContactSettings(hContact, pFunc, szModule, param) : 0; } diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index b9c1d532ca..70f0dcd951 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1511,3 +1511,5 @@ TimeZone_GetSystemTime @1692 ?IsPrefixHex@XMLUtil@tinyxml2@@SA_NPBD@Z @1733 NONAME ?PrepareForNewNode@XMLPrinter@tinyxml2@@AAEX_N@Z @1734 NONAME ?QueryAttribute@XMLElement@tinyxml2@@QBE?AW4XMLError@2@PBDPAPBD@Z @1735 NONAME +db_copy_module @1736 +?db_is_module_empty@@YG_NIPBD@Z @1737 NONAME diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index a25eee9663..0fd20a620b 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1511,3 +1511,5 @@ TimeZone_GetSystemTime @1692 ?IsPrefixHex@XMLUtil@tinyxml2@@SA_NPEBD@Z @1733 NONAME ?PrepareForNewNode@XMLPrinter@tinyxml2@@AEAAX_N@Z @1734 NONAME ?QueryAttribute@XMLElement@tinyxml2@@QEBA?AW4XMLError@2@PEBDPEAPEBD@Z @1735 NONAME +db_copy_module @1736 +?db_is_module_empty@@YA_NIPEBD@Z @1737 NONAME -- cgit v1.2.3