diff --git a/lib/libimhex/include/hex/helpers/net.hpp b/lib/libimhex/include/hex/helpers/net.hpp index f85087f87..138813389 100644 --- a/lib/libimhex/include/hex/helpers/net.hpp +++ b/lib/libimhex/include/hex/helpers/net.hpp @@ -44,6 +44,7 @@ namespace hex { std::future> downloadFile(const std::string &url, const std::fs::path &filePath, u32 timeout = DefaultTimeout); [[nodiscard]] std::string encode(const std::string &input); + [[nodiscard]] std::string decode(const std::string &input); [[nodiscard]] float getProgress() const { return this->m_progress; } diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index 6a23849e5..b756769be 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -86,8 +87,18 @@ namespace hex::fs { hex::unreachable(); } + std::fs::path path; + #if defined(OS_LINUX) + // xdg-desktop-portal, which is the file picker backend used on Linux, returns all paths with URI encoding. + // This is a bit ugly and will most likely be fixed sometime in the future but until then, we'll just use + // curl to decode the URI string into a valid file path string + path = Net().decode(outPath); + #else + path = reinterpret_cast(outPath); + #endif + if (result == NFD_OKAY) { - callback(reinterpret_cast(outPath)); + callback(path); NFD::FreePath(outPath); } diff --git a/lib/libimhex/source/helpers/net.cpp b/lib/libimhex/source/helpers/net.cpp index 9ec22e8de..9f95c518c 100644 --- a/lib/libimhex/source/helpers/net.cpp +++ b/lib/libimhex/source/helpers/net.cpp @@ -245,6 +245,19 @@ namespace hex { return {}; } + std::string Net::decode(const std::string &input) { + auto unescapedString = curl_easy_unescape(this->m_ctx, input.c_str(), std::strlen(input.c_str()), nullptr); + + if (unescapedString != nullptr) { + std::string output = unescapedString; + curl_free(unescapedString); + + return output; + } + + return {}; + } + std::string Net::s_proxyUrl; void Net::setProxy(const std::string &url) {