summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-05-20 20:30:37 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-05-20 20:30:37 +0300
commit497a8a92a3f4a9ab0c3c0a5a554d2af9ade87343 (patch)
tree48c474a1755e0fcd469a83c36da9c0e27dec002b
parentf679028cb4194b72efd4ebf27d5bb29341918957 (diff)
MsgExport: fix for replacing contact ids in file names
-rwxr-xr-xplugins/Msg_Export/src/options.cpp4
-rwxr-xr-xplugins/Msg_Export/src/utils.cpp87
-rw-r--r--plugins/Msg_Export/src/version.h2
3 files changed, 36 insertions, 57 deletions
diff --git a/plugins/Msg_Export/src/options.cpp b/plugins/Msg_Export/src/options.cpp
index 162929d257..2593fb0a98 100755
--- a/plugins/Msg_Export/src/options.cpp
+++ b/plugins/Msg_Export/src/options.cpp
@@ -244,11 +244,11 @@ public:
cmbDefaultFile.AddString(L"%UIN%.txt");
cmbDefaultFile.AddString(L"%group%.txt");
cmbDefaultFile.AddString(L"%e-mail%.txt");
- cmbDefaultFile.AddString(L"%identifier%.txt");
+ cmbDefaultFile.AddString(L"%id%.txt");
cmbDefaultFile.AddString(L"%year%-%month%-%day%.txt");
cmbDefaultFile.AddString(L"%group%\\%nick%.txt");
cmbDefaultFile.AddString(L"%group%\\%UIN%.txt");
- cmbDefaultFile.AddString(L"%group%\\%identifier%.txt");
+ cmbDefaultFile.AddString(L"%group%\\%id%.txt");
cmbDefaultFile.AddString(L"%protocol%\\%nick%.txt");
cmbDefaultFile.AddString(L"History.txt");
diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp
index 4e91949a22..d629ff16f1 100755
--- a/plugins/Msg_Export/src/utils.cpp
+++ b/plugins/Msg_Export/src/utils.cpp
@@ -446,69 +446,48 @@ void ReplaceAllNoColon(wstring &sSrc, const wchar_t *pszReplace, wstring &sNew)
// sTarget - String with either %user% or %UIN%, to replace in
// Returns : void
-void ReplaceDefines(MCONTACT hContact, wstring & sTarget)
+static wstring GetUniqueId(MCONTACT hContact, const char *szProto)
{
+ ptrW uniqueId(Contact_GetInfo(CNF_UNIQUEID, hContact, szProto));
+ return (uniqueId == nullptr) ? L"(null)" : uniqueId;
+}
+
+void ReplaceDefines(MCONTACT hContact, wstring &sTarget)
+{
+ const char *szProto = Proto_GetBaseAccountName(hContact);
+
if (sTarget.find(L"%nick%") != string::npos)
ReplaceAll(sTarget, L"%nick%", FileNickFromHandle(hContact));
- bool bUINUsed = sTarget.find(L"%UIN%") != string::npos;
- bool bEMailUsed = sTarget.find(L"%e-mail%") != string::npos;
- bool bProtoUsed = sTarget.find(L"%protocol%") != string::npos;
- bool bIdentifierUsed = sTarget.find(L"%identifier%") != string::npos;
-
- if (bUINUsed || bEMailUsed || bProtoUsed || bIdentifierUsed) {
- const char *szProto = Proto_GetBaseAccountName(hContact);
- if (bUINUsed || (bIdentifierUsed && !mir_strcmp(szProto, "ICQ"))) {
- DWORD dwUIN = db_get_dw(hContact, szProto, "UIN", 0);
- wstring sReplaceUin;
- if (dwUIN) {
- wchar_t sTmp[20];
- mir_snwprintf(sTmp, L"%d", dwUIN);
- sReplaceUin = sTmp;
- }
- else sReplaceUin = FileNickFromHandle(hContact);
-
- if (bUINUsed)
- ReplaceAll(sTarget, L"%UIN%", sReplaceUin);
- if (bIdentifierUsed && !mir_strcmp(szProto, "ICQ")) {
- bIdentifierUsed = false;
- ReplaceAll(sTarget, L"%identifier%", sReplaceUin);
- }
+ if (sTarget.find(L"%UIN%") != string::npos) {
+ DWORD dwUIN = db_get_dw(hContact, szProto, "UIN", 0);
+ wstring sReplaceUin;
+ if (dwUIN) {
+ wchar_t sTmp[20];
+ mir_snwprintf(sTmp, L"%d", dwUIN);
+ sReplaceUin = sTmp;
}
+ else sReplaceUin = GetUniqueId(hContact, szProto);
- if (bEMailUsed || (bIdentifierUsed && !mir_strcmp(szProto, "MSN"))) {
- wstring sEMail = _DBGetStringW(hContact, szProto, "e-mail", L"");
- if (sEMail.empty()) {
- sEMail = _DBGetStringW(hContact, "MSN", "e-mail", L"");
- if (sEMail.empty()) {
- // We can't find the E-mail address we will use the the nick
- sEMail = FileNickFromHandle(hContact);
- }
- }
- if (bEMailUsed)
- ReplaceAllNoColon(sTarget, L"%e-mail%", sEMail);
- if (bIdentifierUsed && !mir_strcmp(szProto, "MSN")) {
- bIdentifierUsed = false;
- ReplaceAllNoColon(sTarget, L"%identifier%", sEMail);
- }
- }
+ ReplaceAll(sTarget, L"%UIN%", sReplaceUin);
+ }
- if (bIdentifierUsed && !mir_strcmp(szProto, "Jabber")) {
- wstring sReplace = _DBGetStringW(hContact, "Jabber", "jid", L"");
- if (sReplace.empty()) {
- sReplace = FileNickFromHandle(hContact);
- }
- bIdentifierUsed = false;
- ReplaceAll(sTarget, L"%identifier%", sReplace);
- }
+ if (sTarget.find(L"%e-mail%") != string::npos) {
+ wstring sEMail = _DBGetStringW(hContact, szProto, "e-mail", L"");
+ if (sEMail.empty())
+ sEMail = FileNickFromHandle(hContact);
+ ReplaceAllNoColon(sTarget, L"%e-mail%", sEMail);
+ }
- if (bProtoUsed) {
- wstring tmp = _DBGetStringW(hContact, "Protocol", "p", L"");
- ReplaceAllNoColon(sTarget, L"%protocol%", tmp);
- }
+ if (sTarget.find(L"%identifier%") != string::npos)
+ ReplaceAll(sTarget, L"%identifier%", GetUniqueId(hContact, szProto));
+
+ if (sTarget.find(L"%id%") != string::npos)
+ ReplaceAll(sTarget, L"%id%", GetUniqueId(hContact, szProto));
- if (bIdentifierUsed) // It has still not been replaced we will just use nick
- ReplaceAll(sTarget, L"%nick%", FileNickFromHandle(hContact));
+ if (sTarget.find(L"%protocol%") != string::npos) {
+ wstring tmp = _DBGetStringW(hContact, "Protocol", "p", L"");
+ ReplaceAllNoColon(sTarget, L"%protocol%", tmp);
}
if (sTarget.find(L"%group%") != string::npos) {
diff --git a/plugins/Msg_Export/src/version.h b/plugins/Msg_Export/src/version.h
index 6cadfa7971..cb05903e6e 100644
--- a/plugins/Msg_Export/src/version.h
+++ b/plugins/Msg_Export/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 3
#define __MINOR_VERSION 1
#define __RELEASE_NUM 2
-#define __BUILD_NUM 6
+#define __BUILD_NUM 7
#include <stdver.h>