From 7948d820c3d8a5a97a9f71f3b2a0208c5551853e Mon Sep 17 00:00:00 2001 From: Green Sky Date: Tue, 30 Jan 2024 15:16:01 +0100 Subject: [PATCH] fix filepaths on windows --- src/chat_gui4.cpp | 16 ++++++++-------- src/file_selector.cpp | 6 +++--- src/tox_avatar_manager.cpp | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index a11625b..eaccac3 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -562,7 +562,7 @@ void ChatGui4::render(float time_delta) { _fss.requestFile( [](const auto& path) -> bool { return std::filesystem::is_regular_file(path); }, [this](const auto& path){ - _rmm.sendFilePath(*_selected_contact, path.filename().u8string(), path.u8string()); + _rmm.sendFilePath(*_selected_contact, path.filename().generic_u8string(), path.generic_u8string()); }, [](){} ); @@ -625,7 +625,7 @@ void ChatGui4::render(float time_delta) { void ChatGui4::sendFilePath(const char* file_path) { if (_selected_contact && std::filesystem::is_regular_file(file_path)) { - _rmm.sendFilePath(*_selected_contact, std::filesystem::path(file_path).filename().u8string(), file_path); + _rmm.sendFilePath(*_selected_contact, std::filesystem::path(file_path).filename().generic_u8string(), file_path); } } @@ -719,10 +719,10 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) { //for (const auto& c : _cr.view, entt::exclude_t>()) { for (const auto& c : _cr.view()) { if (renderContactListContactSmall(c, false)) { - //_rmm.sendFilePath(*_selected_contact, path.filename().u8string(), path.u8string()); + //_rmm.sendFilePath(*_selected_contact, path.filename().generic_u8string(), path.generic_u8string()); const auto& fil = reg.get(e); for (const auto& path : fil.file_list) { - _rmm.sendFilePath(c, std::filesystem::path{path}.filename().u8string(), path); + _rmm.sendFilePath(c, std::filesystem::path{path}.filename().generic_u8string(), path); } } } @@ -809,17 +809,17 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) { const auto& local_info = reg.get(e); if (local_info.file_list.size() > i && ImGui::BeginPopupContextItem("##file_c")) { if (ImGui::MenuItem("open")) { - const std::string url{"file://" + file_path_url_escape(std::filesystem::canonical(local_info.file_list.at(i)).u8string())}; + const std::string url{"file://" + file_path_url_escape(std::filesystem::canonical(local_info.file_list.at(i)).generic_u8string())}; std::cout << "opening file '" << url << "'\n"; SDL_OpenURL(url.c_str()); } if (ImGui::MenuItem("copy file")) { - const std::string url{"file://" + file_path_url_escape(std::filesystem::canonical(local_info.file_list.at(i)).u8string())}; + const std::string url{"file://" + file_path_url_escape(std::filesystem::canonical(local_info.file_list.at(i)).generic_u8string())}; //ImGui::SetClipboardText(url.c_str()); setClipboardData({"text/uri-list", "text/x-moz-url"}, std::make_shared>(url.begin(), url.end())); } if (ImGui::MenuItem("copy filepath")) { - const auto file_path = std::filesystem::canonical(local_info.file_list.at(i)).u8string(); + const auto file_path = std::filesystem::canonical(local_info.file_list.at(i)).u8string(); //TODO: use generic over native? ImGui::SetClipboardText(file_path.c_str()); } ImGui::EndPopup(); @@ -1122,7 +1122,7 @@ void ChatGui4::pasteFile(const char* mime_type) { std::ofstream(tmp_file_path, std::ios_base::out | std::ios_base::binary) .write(reinterpret_cast(img_data.data()), img_data.size()); - _rmm.sendFilePath(*_selected_contact, tmp_file_name.str(), tmp_file_path.u8string()); + _rmm.sendFilePath(*_selected_contact, tmp_file_name.str(), tmp_file_path.generic_u8string()); }, [](){} ); diff --git a/src/file_selector.cpp b/src/file_selector.cpp index 3045d62..cc5a7d2 100644 --- a/src/file_selector.cpp +++ b/src/file_selector.cpp @@ -47,7 +47,7 @@ void FileSelector::render(void) { std::filesystem::path current_path = _current_file_path; current_path.remove_filename(); - ImGui::Text("path: %s", _current_file_path.u8string().c_str()); + ImGui::Text("path: %s", _current_file_path.generic_u8string().c_str()); // begin table with selectables constexpr ImGuiTableFlags table_flags = @@ -175,7 +175,7 @@ void FileSelector::render(void) { } if (ImGui::TableNextColumn()) { - ImGui::TextUnformatted((dir_entry.path().filename().u8string() + "/").c_str()); + ImGui::TextUnformatted((dir_entry.path().filename().generic_u8string() + "/").c_str()); } if (ImGui::TableNextColumn()) { @@ -206,7 +206,7 @@ void FileSelector::render(void) { } if (ImGui::TableNextColumn()) { - ImGui::TextUnformatted(dir_entry.path().filename().u8string().c_str()); + ImGui::TextUnformatted(dir_entry.path().filename().generic_u8string().c_str()); } if (ImGui::TableNextColumn()) { diff --git a/src/tox_avatar_manager.cpp b/src/tox_avatar_manager.cpp index 5573823..20e7732 100644 --- a/src/tox_avatar_manager.cpp +++ b/src/tox_avatar_manager.cpp @@ -83,7 +83,7 @@ std::string ToxAvatarManager::getAvatarPath(const ToxKey& key) const { const std::string_view avatar_save_path {_conf.get_string("ToxAvatarManager", "save_path").value()}; const auto pub_key_string = bin2hex({key.data.cbegin(), key.data.cend()}); const auto file_path = std::filesystem::path(avatar_save_path) / (pub_key_string + ".png"); - return file_path.u8string(); + return file_path.generic_u8string(); } void ToxAvatarManager::addAvatarFileToContact(const Contact3 c, const ToxKey& key) {