From 8915d8bc91d243c56f2ed73d3aca6eef946c35f5 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 10 Nov 2021 11:37:49 +0100 Subject: [PATCH] Improvement of previous commit: - use boost::nowide instead of WinAPI for the encoding conversion - only add the node when it is not empty --- src/slic3r/GUI/SendSystemInfoDialog.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/SendSystemInfoDialog.cpp b/src/slic3r/GUI/SendSystemInfoDialog.cpp index 4b11347e2..fb3205af3 100644 --- a/src/slic3r/GUI/SendSystemInfoDialog.cpp +++ b/src/slic3r/GUI/SendSystemInfoDialog.cpp @@ -485,21 +485,18 @@ static std::string generate_system_info_json() pt::ptree blacklisted_node; std::vector blacklisted_libraries; BlacklistedLibraryCheck::get_instance().get_blacklisted(blacklisted_libraries); - for (const std::wstring& str : blacklisted_libraries) { - std::string utf8; - const size_t num_bytes = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.size(), utf8.data(), 0, 0, 0); - utf8.resize(num_bytes); - if (WideCharToMultiByte(CP_UTF8, 0, str.c_str(), str.size(), utf8.data(), num_bytes, 0, 0)) { - if (size_t last_bs_pos = utf8.find_last_of("\\"); last_bs_pos < utf8.size() - 1) { - // Remove anything before last backslash so we don't send the path to the DLL. - utf8.erase(0, last_bs_pos + 1); - } - pt::ptree node; // Create an unnamed node containing the value - node.put("", utf8); - blacklisted_node.push_back(std::make_pair("", node)); // Add this node to the list. + for (const std::wstring& wstr : blacklisted_libraries) { + std::string utf8 = boost::nowide::narrow(wstr); + if (size_t last_bs_pos = utf8.find_last_of("\\"); last_bs_pos < utf8.size() - 1) { + // Remove anything before last backslash so we don't send the path to the DLL. + utf8.erase(0, last_bs_pos + 1); } + pt::ptree node; // Create an unnamed node containing the value + node.put("", utf8); + blacklisted_node.push_back(std::make_pair("", node)); // Add this node to the list. } - data_node.add_child("Blacklisted libraries", blacklisted_node); + if (! blacklisted_libraries.empty()) + data_node.add_child("Blacklisted libraries", blacklisted_node); } #endif // _WIN32