summaryrefslogtreecommitdiff
path: root/plugins/Msg_Export/src/utils.cpp
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2017-02-05 22:45:55 +0100
committerRobert Pösel <robyer@seznam.cz>2017-02-06 00:05:33 +0100
commit5a3ac5642a0e4bf770d399ae015dd9e65b34cf71 (patch)
tree44e4ab503452495db36671b9d8318676ee0fbff4 /plugins/Msg_Export/src/utils.cpp
parentd8142b3a62a0e0e5cb715f95f2e03d9bf808dff0 (diff)
Msg_Export: Optimize checking ignored contacts/protocols (addresses #609)
Makes export about 20% faster.
Diffstat (limited to 'plugins/Msg_Export/src/utils.cpp')
-rwxr-xr-xplugins/Msg_Export/src/utils.cpp67
1 files changed, 29 insertions, 38 deletions
diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp
index 89388048ac..6f0a26d065 100755
--- a/plugins/Msg_Export/src/utils.cpp
+++ b/plugins/Msg_Export/src/utils.cpp
@@ -1204,50 +1204,44 @@ HANDLE openCreateFile(tstring sFilePath)
return hFile;
}
-int nExportEvent(WPARAM hContact, LPARAM hDbEvent)
+bool bIsExportEnabled(MCONTACT hContact)
{
if (!db_get_b(hContact, MODULE, "EnableLog", 1))
- return 0;
+ return false;
- DBEVENTINFO dbei = {};
- int nSize = db_event_getBlobSize(hDbEvent);
- if (nSize > 0) {
- dbei.cbBlob = nSize;
- dbei.pBlob = (PBYTE)malloc(dbei.cbBlob + 2);
- dbei.pBlob[dbei.cbBlob] = 0;
- dbei.pBlob[dbei.cbBlob + 1] = 0;
- // Double null terminate, this shut pervent most errors
- // where the blob received has an invalid format
- }
+ const char *szProto = GetContactProto(hContact);
+ char szTemp[500];
+ mir_snprintf(szTemp, "DisableProt_%s", szProto);
+ if (!db_get_b(NULL, MODULE, szTemp, 1))
+ return false;
- if (!db_event_get(hDbEvent, &dbei)) {
- // Open/create file for writing
- tstring sFilePath = GetFilePathFromUser(hContact);
- HANDLE hFile = openCreateFile(sFilePath);
- if (hFile == INVALID_HANDLE_VALUE) {
- DisplayErrorDialog(LPGENW("Failed to open or create file :\n"), sFilePath, NULL);
- }
- else {
- // Write the event
- char szTemp[500];
- mir_snprintf(szTemp, "DisableProt_%s", dbei.szModule);
- if (db_get_b(NULL, MODULE, szTemp, 1))
- ExportDBEventInfo(hContact, hFile, sFilePath, dbei);
-
- // Close the file
- CloseHandle(hFile);
- }
+ return true;
+}
+
+int nExportEvent(WPARAM hContact, LPARAM hDbEvent)
+{
+ if (!bIsExportEnabled(hContact))
+ return 0;
+
+ // Open/create file for writing
+ tstring sFilePath = GetFilePathFromUser(hContact);
+ HANDLE hFile = openCreateFile(sFilePath);
+ if (hFile == INVALID_HANDLE_VALUE) {
+ DisplayErrorDialog(LPGENW("Failed to open or create file :\n"), sFilePath, NULL);
+ return 0;
}
- if (dbei.pBlob)
- free(dbei.pBlob);
+
+ // Write the event
+ bExportEvent((MCONTACT)hContact, (MEVENT)hDbEvent, hFile, sFilePath);
+
+ // Close the file
+ CloseHandle(hFile);
+
return 0;
}
bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, tstring sFilePath)
{
- if (!db_get_b(hContact, MODULE, "EnableLog", 1))
- return 0;
-
DBEVENTINFO dbei = {};
int nSize = db_event_getBlobSize(hDbEvent);
if (nSize > 0) {
@@ -1262,10 +1256,7 @@ bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, tstring sFil
bool result = true;
if (!db_event_get(hDbEvent, &dbei)) {
// Write the event
- char szTemp[500];
- mir_snprintf(szTemp, "DisableProt_%s", dbei.szModule);
- if (db_get_b(NULL, MODULE, szTemp, 1))
- result = ExportDBEventInfo(hContact, hFile, sFilePath, dbei);
+ result = ExportDBEventInfo(hContact, hFile, sFilePath, dbei);
}
if (dbei.pBlob)
free(dbei.pBlob);