diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2020-12-28 19:18:50 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-01-01 17:31:25 +0100 |
commit | 51092f2baafab6153fead06f5e22575ef3b9fe95 (patch) | |
tree | 87cb7af3492b06f3cddbf13a5f163ac20e534618 /desktop | |
parent | fd7ec8b8a5e9eec0347356b2126333dd840b5a73 (diff) |
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@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/app/crashreport.cxx | 12 | ||||
-rw-r--r-- | desktop/source/minidump/minidump.cxx | 15 | ||||
-rw-r--r-- | desktop/source/minidump/minidump_upload.cxx | 15 |
3 files changed, 42 insertions, 0 deletions
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; |