Skip to content

Commit

Permalink
Gives ANSI path to curl CURLOPT_CAINFO
Browse files Browse the repository at this point in the history
  • Loading branch information
RipleyTom committed Mar 27, 2020
1 parent e817790 commit d00fc9e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Utilities/StrFmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@
#include <errno.h>
#endif

#ifdef _WIN32
std::string utf8_path_to_ansi_path(const std::string& src)
{
std::vector<wchar_t> buf_wide, buf_short;
std::string buf_final;

// Converts the utf-8 path to wide char
auto tmp_size = MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, nullptr, 0);
buf_wide.resize(tmp_size);
MultiByteToWideChar(CP_UTF8, 0, src.c_str(), -1, buf_wide.data(), tmp_size);

// Get the short path from the wide char path(short path should only contain ansi characters)
tmp_size = GetShortPathNameW(buf_wide.data(), nullptr, 0);
buf_short.resize(tmp_size);
GetShortPathNameW(buf_wide.data(), buf_short.data(), tmp_size);

// Convert wide char to ansi
tmp_size = WideCharToMultiByte(CP_ACP, 0, buf_short.data(), -1, nullptr, 0, nullptr, nullptr);
buf_final.resize(tmp_size);
WideCharToMultiByte(CP_ACP, 0, buf_short.data(), -1, buf_final.data(), tmp_size, nullptr, nullptr);

return buf_final;
}
#endif

template <>
void fmt_class_string<std::pair<const fmt_type_info*, u64>>::format(std::string& out, u64 arg)
{
Expand Down
4 changes: 4 additions & 0 deletions Utilities/StrUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <functional>
#include <string_view>

#ifdef _WIN32
std::string utf8_path_to_ansi_path(const std::string& src);
#endif

// Copy null-terminated string from a std::string or a char array to a char array with truncation
template <typename D, typename T>
inline void strcpy_trunc(D& dst, const T& src)
Expand Down
4 changes: 3 additions & 1 deletion rpcs3/rpcs3qt/curl_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ curl_handle::curl_handle(QObject* parent) : QObject(parent)
#ifdef _WIN32
// This shouldn't be needed on linux
const std::string path_to_cert = Emulator::GetEmuDir() + "cacert.pem";
curl_easy_setopt(m_curl, CURLOPT_CAINFO, path_to_cert.c_str());
const std::string ansi_path = utf8_path_to_ansi_path(path_to_cert);

curl_easy_setopt(m_curl, CURLOPT_CAINFO, ansi_path.data());
#endif
}

Expand Down

0 comments on commit d00fc9e

Please sign in to comment.