summaryrefslogtreecommitdiff
path: root/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp')
-rw-r--r--plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp317
1 files changed, 139 insertions, 178 deletions
diff --git a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp
index 390af4034f..196daf6230 100644
--- a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp
+++ b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp
@@ -79,43 +79,40 @@ INT_PTR CALLBACK DlgProc_DataHistory(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
* exporting stuff
***********************************************************************************************************/
-/**
- * name: Export
- * desc: globally accessible function which does the whole export stuff.
- * params: hContact - handle to the contact who is to export
- * pszFileName - full qualified path to the xml file which is destination for the export process
- * return: 0 on success, 1 otherwise
- **/
+ /**
+ * name: Export
+ * desc: globally accessible function which does the whole export stuff.
+ * params: hContact - handle to the contact who is to export
+ * pszFileName - full qualified path to the xml file which is destination for the export process
+ * return: 0 on success, 1 otherwise
+ **/
int CFileXml::Export(lpExImParam ExImContact, LPCSTR pszFileName)
{
DB::CEnumList Modules;
- DWORD result = (DWORD) DialogBox(g_plugin.getInst(),
- MAKEINTRESOURCE(IDD_EXPORT_DATAHISTORY),
- nullptr, DlgProc_DataHistory);
- if (LOWORD(result) != IDOK)
- {
+ DWORD result = (DWORD)DialogBox(g_plugin.getInst(),
+ MAKEINTRESOURCE(IDD_EXPORT_DATAHISTORY),
+ nullptr, DlgProc_DataHistory);
+ if (LOWORD(result) != IDOK) {
return 0;
}
_wExport = HIWORD(result);
// show dialog to enable user to select modules for export
if (!(_wExport & EXPORT_DATA) ||
- !DlgExImModules_SelectModulesToExport(ExImContact, &Modules, nullptr))
- {
+ !DlgExImModules_SelectModulesToExport(ExImContact, &Modules, nullptr)) {
FILE *xmlfile = fopen(pszFileName, "wt");
- if (!xmlfile)
- {
+ if (!xmlfile) {
MsgErr(nullptr, LPGENW("Can't create xml file!\n%S"), pszFileName);
return 1;
}
-
+
SYSTEMTIME now;
GetLocalTime(&now);
// write xml header raw as it is without using the tinyxml api
- fprintf(xmlfile,
+ fprintf(xmlfile,
"%c%c%c<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
"<XMLCard ver=\"" XMLCARD_VERSION "\" ref=\"%04d-%02d-%02d %02d:%02d:%02d\">\n",
0xefU, 0xbbU, 0xbfU, now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond
@@ -126,7 +123,7 @@ int CFileXml::Export(lpExImParam ExImContact, LPCSTR pszFileName)
CExImContactXML vContact(this);
// write data
- if ( ExImContact->Typ == EXIM_CONTACT) {
+ if (ExImContact->Typ == EXIM_CONTACT) {
// export single contact
_hContactToWorkOn = ExImContact->hContact;
if (vContact.fromDB(ExImContact->hContact)) {
@@ -136,57 +133,45 @@ int CFileXml::Export(lpExImParam ExImContact, LPCSTR pszFileName)
else {
// other export mode
_hContactToWorkOn = INVALID_CONTACT_ID;
-#ifdef _DEBUG
- LARGE_INTEGER freq, t1, t2;
- QueryPerformanceFrequency(&freq);
- QueryPerformanceCounter(&t1);
-#endif
// export owner contact
if (ExImContact->Typ == EXIM_ALL && vContact.fromDB(NULL)) {
vContact.Export(xmlfile, &Modules);
}
// loop for all other contact
- for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact))
- {
- switch (ExImContact->Typ)
- {
- case EXIM_ALL:
- case EXIM_GROUP:
- // dont export meta subcontacts by default
- if (!db_mc_isSub(hContact)) {
- if (vContact.fromDB(hContact)) {
- vContact.Export(xmlfile, &Modules);
- }
+ for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) {
+ switch (ExImContact->Typ) {
+ case EXIM_ALL:
+ case EXIM_GROUP:
+ // dont export meta subcontacts by default
+ if (!db_mc_isSub(hContact)) {
+ if (vContact.fromDB(hContact)) {
+ vContact.Export(xmlfile, &Modules);
}
- break;
- case EXIM_SUBGROUP:
- // dont export meta subcontacts by default and
- // export only contact with selectet group name
- if (!db_mc_isSub(hContact) &&
- mir_wstrncmp(ExImContact->ptszName, DB::Setting::GetTString(hContact, "CList", "Group"), mir_wstrlen(ExImContact->ptszName))== 0)
- {
- if (vContact.fromDB(hContact)) {
- vContact.Export(xmlfile, &Modules);
- }
+ }
+ break;
+ case EXIM_SUBGROUP:
+ // dont export meta subcontacts by default and
+ // export only contact with selectet group name
+ if (!db_mc_isSub(hContact) &&
+ mir_wstrncmp(ExImContact->ptszName, DB::Setting::GetTString(hContact, "CList", "Group"), mir_wstrlen(ExImContact->ptszName)) == 0) {
+ if (vContact.fromDB(hContact)) {
+ vContact.Export(xmlfile, &Modules);
}
- break;
- case EXIM_ACCOUNT:
- // export only contact with selectet account name
- if (!mir_strncmp(ExImContact->pszName, Proto_GetBaseAccountName(hContact), mir_strlen(ExImContact->pszName))) {
- if (vContact.fromDB(hContact)) {
- vContact.Export(xmlfile, &Modules);
- }
+ }
+ break;
+ case EXIM_ACCOUNT:
+ // export only contact with selectet account name
+ if (!mir_strncmp(ExImContact->pszName, Proto_GetBaseAccountName(hContact), mir_strlen(ExImContact->pszName))) {
+ if (vContact.fromDB(hContact)) {
+ vContact.Export(xmlfile, &Modules);
}
- break;
+ }
+ break;
}
} // *end for
-#ifdef _DEBUG
- QueryPerformanceCounter(&t2);
- MsgErr(nullptr, LPGENW("Export took %f ms"),
- (long double)(t2.QuadPart - t1.QuadPart) / freq.QuadPart * 1000.);
-#endif
- }// *end other export mode
+ }
+ // *end other export mode
// nothing exported?
if (cbHeader == ftell(xmlfile)) {
@@ -207,15 +192,15 @@ int CFileXml::Export(lpExImParam ExImContact, LPCSTR pszFileName)
CFileXml::CFileXml()
{
- _numContactsTodo = 0;
- _numContactsDone = 0;
- _numSettingsTodo = 0;
- _numSettingsDone = 0;
- _numEventsTodo = 0;
- _numEventsDone = 0;
- _numEventsDuplicated = 0;
- _hContactToWorkOn = INVALID_CONTACT_ID;
- _wExport = 0;
+ _numContactsTodo = 0;
+ _numContactsDone = 0;
+ _numSettingsTodo = 0;
+ _numSettingsDone = 0;
+ _numEventsTodo = 0;
+ _numEventsDone = 0;
+ _numEventsDuplicated = 0;
+ _hContactToWorkOn = INVALID_CONTACT_ID;
+ _wExport = 0;
}
/**
@@ -258,33 +243,23 @@ int CFileXml::ImportContacts(TiXmlElement* xmlParent)
if (_progress.UpdateContact(LPGENW("Contact: %s (%S)"), pszNick, xContact->Attribute("proto"))) {
int result = vContact.LoadXmlElemnt(xContact);
switch (result) {
- case ERROR_OK:
- // init contact class and import if matches the user desires
- if (_hContactToWorkOn == INVALID_CONTACT_ID || vContact.handle() == _hContactToWorkOn) {
- result = vContact.Import(_hContactToWorkOn != INVALID_CONTACT_ID);
- switch (result) {
- case ERROR_OK:
- _numContactsDone++;
- break;
- case ERROR_ABORTED:
- if (pszNick) mir_free(pszNick);
- return ERROR_ABORTED;
-#ifdef _DEBUG
- default:
- MsgErr(nullptr, LPGENW("Importing %s caused error %d"), pszNick, result);
- break;
-#endif
- }
+ case ERROR_OK:
+ // init contact class and import if matches the user desires
+ if (_hContactToWorkOn == INVALID_CONTACT_ID || vContact.handle() == _hContactToWorkOn) {
+ result = vContact.Import(_hContactToWorkOn != INVALID_CONTACT_ID);
+ switch (result) {
+ case ERROR_OK:
+ _numContactsDone++;
+ break;
+ case ERROR_ABORTED:
+ if (pszNick) mir_free(pszNick);
+ return ERROR_ABORTED;
}
- break;
- case ERROR_ABORTED:
- if (pszNick) mir_free(pszNick);
- return ERROR_ABORTED;
-#ifdef _DEBUG
- default:
- MsgErr(nullptr, LPGENW("Loading contact %s from xml failed with error %d"), pszNick, result);
- break;
-#endif
+ }
+ break;
+ case ERROR_ABORTED:
+ if (pszNick) mir_free(pszNick);
+ return ERROR_ABORTED;
}
}
if (pszNick) mir_free(pszNick);
@@ -293,15 +268,11 @@ int CFileXml::ImportContacts(TiXmlElement* xmlParent)
else if (_hContactToWorkOn == INVALID_CONTACT_ID && !mir_strcmpi(xContact->Value(), XKEY_OWNER) && (vContact = xContact)) {
int result = vContact.Import();
switch (result) {
- case ERROR_OK:
- _numContactsDone++;
- break;
- case ERROR_ABORTED:
- return ERROR_ABORTED;
-#ifdef _DEBUG
- default:
- MsgErr(nullptr, LPGENW("Importing Owner caused error %d"), result);
-#endif
+ case ERROR_OK:
+ _numContactsDone++;
+ break;
+ case ERROR_ABORTED:
+ return ERROR_ABORTED;
}
}
}
@@ -316,18 +287,13 @@ int CFileXml::ImportContacts(TiXmlElement* xmlParent)
**/
DWORD CFileXml::CountContacts(TiXmlElement* xmlParent)
{
- try {
- DWORD dwCount = 0;
- // count contacts in file for progress bar
- for (TiXmlNode *xContact = xmlParent->FirstChild(); xContact != nullptr; xContact = xContact->NextSibling())
- if (!mir_strcmpi(xContact->Value(), XKEY_CONTACT) || !mir_strcmpi(xContact->Value(), XKEY_OWNER))
- dwCount += CountContacts(xContact->ToElement()) + 1;
+ DWORD dwCount = 0;
+ // count contacts in file for progress bar
+ for (TiXmlNode *xContact = xmlParent->FirstChild(); xContact != nullptr; xContact = xContact->NextSibling())
+ if (!mir_strcmpi(xContact->Value(), XKEY_CONTACT) || !mir_strcmpi(xContact->Value(), XKEY_OWNER))
+ dwCount += CountContacts(xContact->ToElement()) + 1;
- return dwCount;
- }
- catch(...) {
- return 0;
- }
+ return dwCount;
}
/**
@@ -340,77 +306,72 @@ DWORD CFileXml::CountContacts(TiXmlElement* xmlParent)
**/
int CFileXml::Import(MCONTACT hContact, LPCSTR pszFileName)
{
- try {
- _hContactToWorkOn = hContact;
- // load xml file
- TiXmlDocument doc;
- if (!doc.LoadFile(pszFileName)) {
- MsgErr(nullptr, LPGENW("Parser is unable to load XMLCard \"%s\"\nError: %d\nDescription: %s"),
- pszFileName, doc.ErrorID(), doc.Error());
- return 1;
- }
- // is xmlfile a XMLCard ?
- TiXmlElement *xmlCard = doc.FirstChildElement("XMLCard");
- if (xmlCard == nullptr) {
- MsgErr(nullptr, LPGENW("The selected file is no valid XMLCard"));
- return 1;
+ _hContactToWorkOn = hContact;
+ // load xml file
+ TiXmlDocument doc;
+ if (!doc.LoadFile(pszFileName)) {
+ MsgErr(nullptr, LPGENW("Parser is unable to load XMLCard \"%s\"\nError: %d\nDescription: %s"),
+ pszFileName, doc.ErrorID(), doc.Error());
+ return 1;
+ }
+ // is xmlfile a XMLCard ?
+ TiXmlElement *xmlCard = doc.FirstChildElement("XMLCard");
+ if (xmlCard == nullptr) {
+ MsgErr(nullptr, LPGENW("The selected file is no valid XMLCard"));
+ return 1;
+ }
+ // check version
+ if (mir_strcmp(xmlCard->Attribute("ver"), XMLCARD_VERSION)) {
+ MsgErr(nullptr, LPGENW("The version of the XMLCard is not supported by UserInfoEx"));
+ return 1;
+ }
+
+ // is owner contact to import ?
+ if (_hContactToWorkOn == NULL) {
+ int ret;
+
+ // disable database safty mode to speed up the operation
+ db_set_safety_mode(0);
+ // import owner contact
+ ret = ImportOwner(xmlCard->FirstChildElement(XKEY_OWNER));
+ // as soon as possible enable safty mode again!
+ db_set_safety_mode(1);
+
+ if (!ret) {
+ MsgBox(nullptr, MB_ICONINFORMATION,
+ LPGENW("Complete"),
+ LPGENW("Import complete"),
+ LPGENW("Owner contact successfully imported."));
+ return 0;
}
- // check version
- if (mir_strcmp(xmlCard->Attribute("ver"), XMLCARD_VERSION)) {
- MsgErr(nullptr, LPGENW("The version of the XMLCard is not supported by UserInfoEx"));
+ else {
+ MsgErr(nullptr, LPGENW("Selected XMLCard does not contain an owner contact!"));
return 1;
}
-
- // is owner contact to import ?
- if (_hContactToWorkOn == NULL) {
- int ret;
-
+ }
+ else {
+ // count contacts in file for progress bar
+ _numContactsTodo = CountContacts(xmlCard);
+ if (_numContactsTodo > 0) {
+ _progress.SetContactCount(_numContactsTodo);
// disable database safty mode to speed up the operation
db_set_safety_mode(0);
- // import owner contact
- ret = ImportOwner(xmlCard->FirstChildElement(XKEY_OWNER));
+ // import the contacts
+ ImportContacts(xmlCard);
// as soon as possible enable safty mode again!
db_set_safety_mode(1);
-
- if (!ret) {
- MsgBox(nullptr, MB_ICONINFORMATION,
- LPGENW("Complete"),
- LPGENW("Import complete"),
- LPGENW("Owner contact successfully imported."));
- return 0;
- } else {
- MsgErr(nullptr, LPGENW("Selected XMLCard does not contain an owner contact!"));
- return 1;
- }
- }
- else {
- // count contacts in file for progress bar
- _numContactsTodo = CountContacts(xmlCard);
- if (_numContactsTodo > 0) {
- _progress.SetContactCount(_numContactsTodo);
- // disable database safty mode to speed up the operation
- db_set_safety_mode(0);
- // import the contacts
- ImportContacts(xmlCard);
- // as soon as possible enable safty mode again!
- db_set_safety_mode(1);
- }
- // finally hide the progress dialog
- _progress.Hide();
-
- // show results
- MsgBox(nullptr, MB_ICONINFORMATION, LPGENW("Import complete"), LPGENW("Some basic statistics"),
- LPGENW("added contacts: %u / %u\nadded settings: %u / %u\nadded events %u / %u\nduplicated events: %u"),
- _numContactsDone, _numContactsTodo,
- _numSettingsDone, _numSettingsTodo,
- _numEventsDone, _numEventsTodo,
- _numEventsDuplicated);
-
}
- return 0;
- }
- catch(...) {
- MsgErr(nullptr, LPGENW("FATAL: An exception was thrown while importing contacts from xmlCard!"));
- return 1;
+ // finally hide the progress dialog
+ _progress.Hide();
+
+ // show results
+ MsgBox(nullptr, MB_ICONINFORMATION, LPGENW("Import complete"), LPGENW("Some basic statistics"),
+ LPGENW("added contacts: %u / %u\nadded settings: %u / %u\nadded events %u / %u\nduplicated events: %u"),
+ _numContactsDone, _numContactsTodo,
+ _numSettingsDone, _numSettingsTodo,
+ _numEventsDone, _numEventsTodo,
+ _numEventsDuplicated);
+
}
+ return 0;
}