From 4a0246ea3f385396d2c596c9622d0d6716275e35 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 8 Aug 2023 14:04:26 +0300 Subject: =?UTF-8?q?fixes=20#3623=20(NewStory:=20=D1=8D=D0=BA=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20JSON=20=D0=B8=D0=BC=D0=B5=D0=B5=D1=82=20=D1=8E?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D1=81=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BE=D1=81=D1=8B=20=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/NewStory/src/history_dlg.cpp | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/plugins/NewStory/src/history_dlg.cpp b/plugins/NewStory/src/history_dlg.cpp index b138b8a924..26ab8cc06c 100644 --- a/plugins/NewStory/src/history_dlg.cpp +++ b/plugins/NewStory/src/history_dlg.cpp @@ -691,7 +691,7 @@ public: if (FirstTime) SubContactsList.Append(subid); else - SubContactsList.AppendFormat(L"\r\n%s", subid); + SubContactsList.AppendFormat(L"\r\n%s", subid.get()); FirstTime = false; } MessageText.AppendFormat(TranslateT("It is metacontact. For export use one of this subcontacts:\r\n%s"), SubContactsList.c_str()); @@ -721,18 +721,16 @@ public: if (!GetSaveFileName(&ofn)) return; - //create file + // create file + CreatePathToFileW(FileName); if (PathFileExistsW(FileName)) - DeleteFile(FileName); - HANDLE hFile = CreateFile(FileName, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - if (hFile == INVALID_HANDLE_VALUE) { - // this might be because the path isent created - // so we will try to create it - if (!CreatePathToFileW(FileName)) - hFile = CreateFile(FileName, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - } + DeleteFileW(FileName); + + FILE *out = _wfopen(FileName, L"wt"); + if (out == NULL) + return; - //export contact info + // export contact info JSONNode pRoot, pInfo, pHist(JSON_ARRAY); pInfo.set_name("info"); if (proto) @@ -754,10 +752,8 @@ public: pRoot.push_back(pHist); std::string output = pRoot.write_formatted(); - DWORD dwBytesWritten; - WriteFile(hFile, output.c_str(), (int)output.size(), &dwBytesWritten, nullptr); - - SetFilePointer(hFile, -3, nullptr, FILE_CURRENT); + fputs(output.c_str(), out); + fseek(out, -3, SEEK_CUR); // export events bool bAppendOnly = false; @@ -768,8 +764,8 @@ public: continue; if (bAppendOnly) { - SetFilePointer(hFile, -3, nullptr, FILE_END); - WriteFile(hFile, ",", 1, &dwBytesWritten, nullptr); + fseek(out, -3, SEEK_END); + fputs(",", out); } JSONNode pRoot2; @@ -797,13 +793,13 @@ public: output = pRoot2.write_formatted(); output += "\n]}"; + fputs(output.c_str(), out); - WriteFile(hFile, output.c_str(), (int)output.size(), &dwBytesWritten, nullptr); bAppendOnly = true; } // Close the file - CloseHandle(hFile); + fclose(out); MessageBox(m_hwnd, TranslateT("Complete"), TranslateT("History export"), MB_OK | MB_ICONINFORMATION); } -- cgit v1.2.3