diff options
author | George Hazan <ghazan@miranda.im> | 2022-02-09 17:40:09 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-02-09 17:40:09 +0300 |
commit | a43d5bcb1e0bdafb0193662168976aac989ed922 (patch) | |
tree | c4f154f05f36626678efc64ae7a1139b30b5f4fe /src | |
parent | 760867149a99443036f53c73190d53bd87039def (diff) |
db_is_module_empty & db_copy_module - new database helpers
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/db_ini.cpp | 12 | ||||
-rw-r--r-- | src/mir_core/src/db.cpp | 40 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 2 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 2 |
4 files changed, 45 insertions, 11 deletions
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<char> 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 @@ -51,6 +51,44 @@ MIR_CORE_DLL(int) db_delete_module(MCONTACT hContact, const char *szModuleName) } ///////////////////////////////////////////////////////////////////////////////////////// + +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 MIR_CORE_DLL(MCONTACT) db_add_contact(void) @@ -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
|