fix: Issue opening files that contain special characters on Linux
This is a (hopefully temporary) hack. Fixes #568
This commit is contained in:
parent
b401059678
commit
31a746f3fc
@ -44,6 +44,7 @@ namespace hex {
|
||||
std::future<Response<void>> 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; }
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <hex/helpers/fs_macos.hpp>
|
||||
#include <hex/helpers/file.hpp>
|
||||
#include <hex/helpers/intrinsics.hpp>
|
||||
#include <hex/helpers/net.hpp>
|
||||
|
||||
#include <xdg.hpp>
|
||||
|
||||
@ -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<char8_t*>(outPath);
|
||||
#endif
|
||||
|
||||
if (result == NFD_OKAY) {
|
||||
callback(reinterpret_cast<const char8_t *>(outPath));
|
||||
callback(path);
|
||||
NFD::FreePath(outPath);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user