From 52954e0d736c4f9c590f9caa734cd1c09e2cb8bb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 9 Mar 2024 12:08:11 +0300 Subject: Msg_Export: fix for export histories from options --- plugins/Msg_Export/src/options.cpp | 1 - plugins/Msg_Export/src/utils.cpp | 96 ++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 47 deletions(-) (limited to 'plugins/Msg_Export') diff --git a/plugins/Msg_Export/src/options.cpp b/plugins/Msg_Export/src/options.cpp index 1426854feb..fd0c981c5f 100644 --- a/plugins/Msg_Export/src/options.cpp +++ b/plugins/Msg_Export/src/options.cpp @@ -174,7 +174,6 @@ void __cdecl exportContactsMessages(struct ExportDialogData *data) if (g_bUseJson) { pJson = g_pDriver->Export(sFilePath.c_str()); - pJson->BeginExport(); hFile = pJson; } else { diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index fe3c467b6c..7fb311957f 100644 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -638,59 +638,65 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, const wstring &sF if (bAppendOnly) { bWriteUTF8Format = g_plugin.bUseUtf8InNewFiles; } - else if (!g_bUseJson) { - DWORD dwHighSize = 0; - DWORD dwLowSize = GetFileSize(hFile, &dwHighSize); - if (dwLowSize == INVALID_FILE_SIZE || dwLowSize != 0 || dwHighSize != 0) { - DWORD dwDataRead = 0; - uint8_t ucByteOrder[3]; - if (ReadFile(hFile, ucByteOrder, 3, &dwDataRead, nullptr)) - bWriteUTF8Format = bIsUtf8Header(ucByteOrder); - - DWORD dwPtr = SetFilePointer(hFile, 0, nullptr, FILE_END); - if (dwPtr == INVALID_SET_FILE_POINTER) - return false; + else { + if (g_bUseJson) { + if (!pJson->BeginExport()) + pJson->ExportContact(hContact); } else { - bWriteUTF8Format = g_plugin.bUseUtf8InNewFiles; - if (bWriteUTF8Format) - if (!bWriteToFile(hFile, szUtf8ByteOrderHeader, sizeof(szUtf8ByteOrderHeader) - 1)) + DWORD dwHighSize = 0; + DWORD dwLowSize = GetFileSize(hFile, &dwHighSize); + if (dwLowSize == INVALID_FILE_SIZE || dwLowSize != 0 || dwHighSize != 0) { + DWORD dwDataRead = 0; + uint8_t ucByteOrder[3]; + if (ReadFile(hFile, ucByteOrder, 3, &dwDataRead, nullptr)) + bWriteUTF8Format = bIsUtf8Header(ucByteOrder); + + DWORD dwPtr = SetFilePointer(hFile, 0, nullptr, FILE_END); + if (dwPtr == INVALID_SET_FILE_POINTER) return false; - - CMStringW output = L"------------------------------------------------\r\n"; - output.AppendFormat(L"%s\r\n", TranslateT(" History for")); - - // This is written this way because I expect this will become a string the user may set - // in the options dialog. - output.AppendFormat(L"%-10s: %s\r\n", TranslateT("User"), sRemoteUser.c_str()); - output.AppendFormat(L"%-10s: %S\r\n", TranslateT("Account"), szProto); - - ptrW id(Contact::GetInfo(CNF_UNIQUEID, hContact, szProto)); - if (id != NULL) - output.AppendFormat(L"%-10s: %s\r\n", TranslateT("User ID"), id.get()); - - szTemp[0] = (wchar_t)db_get_b(hContact, szProto, "Gender", 0); - if (szTemp[0]) { - szTemp[1] = 0; - output.AppendFormat(L"%-10s: %s\r\n", TranslateT("Gender"), szTemp); } + else { + bWriteUTF8Format = g_plugin.bUseUtf8InNewFiles; + if (bWriteUTF8Format) + if (!bWriteToFile(hFile, szUtf8ByteOrderHeader, sizeof(szUtf8ByteOrderHeader) - 1)) + return false; + + CMStringW output = L"------------------------------------------------\r\n"; + output.AppendFormat(L"%s\r\n", TranslateT(" History for")); + + // This is written this way because I expect this will become a string the user may set + // in the options dialog. + output.AppendFormat(L"%-10s: %s\r\n", TranslateT("User"), sRemoteUser.c_str()); + output.AppendFormat(L"%-10s: %S\r\n", TranslateT("Account"), szProto); + + ptrW id(Contact::GetInfo(CNF_UNIQUEID, hContact, szProto)); + if (id != NULL) + output.AppendFormat(L"%-10s: %s\r\n", TranslateT("User ID"), id.get()); + + szTemp[0] = (wchar_t)db_get_b(hContact, szProto, "Gender", 0); + if (szTemp[0]) { + szTemp[1] = 0; + output.AppendFormat(L"%-10s: %s\r\n", TranslateT("Gender"), szTemp); + } - int age = db_get_w(hContact, szProto, "Age", 0); - if (age != 0) - output.AppendFormat(L"%-10s: %d\r\n", TranslateT("Age"), age); + int age = db_get_w(hContact, szProto, "Age", 0); + if (age != 0) + output.AppendFormat(L"%-10s: %d\r\n", TranslateT("Age"), age); - for (auto &it : pSettings) { - wstring szValue = _DBGetStringW(hContact, szProto, it, L""); - if (!szValue.empty()) { - mir_snwprintf(szTemp, L"%-10s: %s\r\n", TranslateW(_A2T(it)), szValue.c_str()); - output += szTemp; + for (auto &it : pSettings) { + wstring szValue = _DBGetStringW(hContact, szProto, it, L""); + if (!szValue.empty()) { + mir_snwprintf(szTemp, L"%-10s: %s\r\n", TranslateW(_A2T(it)), szValue.c_str()); + output += szTemp; + } } - } - output += L"------------------------------------------------\r\n"; + output += L"------------------------------------------------\r\n"; - if (!bWriteTextToFile(hFile, output, bWriteUTF8Format, output.GetLength())) - return false; + if (!bWriteTextToFile(hFile, output, bWriteUTF8Format, output.GetLength())) + return false; + } } } @@ -885,8 +891,6 @@ int nExportEvent(WPARAM hContact, LPARAM hDbEvent) return 0; } - if (!pJson->BeginExport()) - pJson->ExportContact(hContact); hFile = pJson; } else { -- cgit v1.2.3