[Libreoffice-commits] core.git: desktop/source include/desktop

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 1 16:32:04 UTC 2021


 desktop/source/app/crashreport.cxx          |   12 ++++++++++++
 desktop/source/minidump/minidump.cxx        |   15 +++++++++++++++
 desktop/source/minidump/minidump_upload.cxx |   15 +++++++++++++++
 include/desktop/minidump.hxx                |    2 +-
 4 files changed, 43 insertions(+), 1 deletion(-)

New commits:
commit 51092f2baafab6153fead06f5e22575ef3b9fe95
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Mon Dec 28 19:18:50 2020 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri Jan 1 17:31:25 2021 +0100

    Use Unicode paths on Windows for minidumps
    
    Change-Id: I6c409a297116ffaefb8d1c1fb82286964d85e8cf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108479
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/desktop/source/app/crashreport.cxx b/desktop/source/app/crashreport.cxx
index 3689613cb359..2b6a1a57003e 100644
--- a/desktop/source/app/crashreport.cxx
+++ b/desktop/source/app/crashreport.cxx
@@ -76,7 +76,19 @@ static bool dumpCallback(const wchar_t* path, const wchar_t* id,
 
 void CrashReporter::writeToFile(std::ios_base::openmode Openmode)
 {
+#if defined _WIN32
+    const std::string iniPath = getIniFileName();
+    std::wstring iniPathW;
+    const int nChars = MultiByteToWideChar(CP_UTF8, 0, iniPath.c_str(), -1, nullptr, 0);
+    auto buf = std::make_unique<wchar_t[]>(nChars);
+    if (MultiByteToWideChar(CP_UTF8, 0, iniPath.c_str(), -1, buf.get(), nChars) != 0)
+        iniPathW = buf.get();
+
+    std::ofstream ini_file
+        = iniPathW.empty() ? std::ofstream(iniPath, Openmode) : std::ofstream(iniPathW, Openmode);
+#else
     std::ofstream ini_file(getIniFileName(), Openmode);
+#endif
 
     for (auto& keyValue : maKeyValues)
     {
diff --git a/desktop/source/minidump/minidump.cxx b/desktop/source/minidump/minidump.cxx
index 5c245abde693..d61922cdaac6 100644
--- a/desktop/source/minidump/minidump.cxx
+++ b/desktop/source/minidump/minidump.cxx
@@ -16,6 +16,11 @@
 
 #include <curl/curl.h>
 
+#ifdef _WIN32
+#include <memory>
+#include <windows.h>
+#endif
+
 const char kUserAgent[] = "Breakpad/1.0 (Linux)";
 
 static std::map<std::string, std::string> readStrings(std::istream& file)
@@ -192,7 +197,17 @@ namespace crashreport {
 
 bool readConfig(const std::string& iniPath, std::string * response)
 {
+#if defined _WIN32
+    std::wstring iniPathW;
+    const int nChars = MultiByteToWideChar(CP_UTF8, 0, iniPath.c_str(), -1, nullptr, 0);
+    auto buf = std::make_unique<wchar_t[]>(nChars);
+    if (MultiByteToWideChar(CP_UTF8, 0, iniPath.c_str(), -1, buf.get(), nChars) != 0)
+        iniPathW = buf.get();
+
+    std::ifstream file = iniPathW.empty() ? std::ifstream(iniPath) : std::ifstream(iniPathW);
+#else
     std::ifstream file(iniPath);
+#endif
     std::map<std::string, std::string> parameters = readStrings(file);
 
     // make sure that at least the mandatory parameters are in there
diff --git a/desktop/source/minidump/minidump_upload.cxx b/desktop/source/minidump/minidump_upload.cxx
index 15af26430764..0434fda68445 100644
--- a/desktop/source/minidump/minidump_upload.cxx
+++ b/desktop/source/minidump/minidump_upload.cxx
@@ -12,7 +12,14 @@
 #include <iostream>
 #include <string>
 
+#ifdef _WIN32
+#include <memory>
+#include <windows.h>
+
+int wmain(int argc, wchar_t** argv)
+#else
 int main(int argc, char** argv)
+#endif
 {
     if (argc < 2)
     {
@@ -20,7 +27,15 @@ int main(int argc, char** argv)
         return EXIT_FAILURE;
     }
 
+#ifdef _WIN32
+    const int nBytes = WideCharToMultiByte(CP_UTF8, 0, argv[1], -1, nullptr, 0, nullptr, nullptr);
+    auto buf = std::make_unique<char[]>(nBytes);
+    if (WideCharToMultiByte(CP_UTF8, 0, argv[1], -1, buf.get(), nBytes, nullptr, nullptr) == 0)
+        return EXIT_FAILURE;
+    std::string iniPath(buf.get());
+#else
     std::string iniPath(argv[1]);
+#endif
     std::string response;
     if (!crashreport::readConfig(iniPath, &response))
         return EXIT_FAILURE;
diff --git a/include/desktop/minidump.hxx b/include/desktop/minidump.hxx
index 0f49075fad5e..93c02f3e091b 100644
--- a/include/desktop/minidump.hxx
+++ b/include/desktop/minidump.hxx
@@ -19,7 +19,7 @@ namespace crashreport
 // when response = nullptr only make test
 /** Read+Send, Test and send info from the Dump.ini .
 
-        @param [in] iniPath Path-file to the read/test ini-file
+        @param [in] iniPath Path-file to the read/test ini-file (UTF-8 on Windows)
         @param [in] response=nullptr in this case made the Test only
         @param [in] response!=nullptr in this case made the Read+Send
 


More information about the Libreoffice-commits mailing list