summaryrefslogtreecommitdiff
path: root/src/mir_core
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-02-09 17:40:09 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-02-09 17:40:09 +0300
commita43d5bcb1e0bdafb0193662168976aac989ed922 (patch)
treec4f154f05f36626678efc64ae7a1139b30b5f4fe /src/mir_core
parent760867149a99443036f53c73190d53bd87039def (diff)
db_is_module_empty & db_copy_module - new database helpers
Diffstat (limited to 'src/mir_core')
-rw-r--r--src/mir_core/src/db.cpp40
-rw-r--r--src/mir_core/src/mir_core.def2
-rw-r--r--src/mir_core/src/mir_core64.def2
3 files changed, 43 insertions, 1 deletions
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, &param);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// 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