1
0
mirror of synced 2024-11-24 07:40:17 +01:00

fix: Opening files with unicode characters in their path

This commit is contained in:
WerWolv 2022-02-16 10:04:05 +01:00
parent 33a1e7f055
commit 60af9970c1
4 changed files with 35 additions and 22 deletions

View File

@ -22,6 +22,8 @@
#include <ApplicationServices/ApplicationServices.h>
#endif
#include <hex/helpers/logger.hpp>
namespace hex {
long double operator""_scaled(long double value) {
@ -111,6 +113,18 @@ namespace hex {
return result;
}
std::string makeStringPrintable(const std::string &string) {
std::string result;
for (char c : string) {
if (std::isprint(c))
result += c;
else
result += hex::format("\\x{0:02X}", u8(c));
}
return result;
}
std::string makePrintable(u8 c) {
switch (c) {
case 0:
@ -282,7 +296,7 @@ namespace hex {
}
if (result == NFD_OKAY) {
callback(outPath);
callback(reinterpret_cast<const char8_t *>(outPath));
NFD::FreePath(outPath);
}

View File

@ -99,7 +99,7 @@ namespace hex {
EventManager::post<RequestChangeWindowTitle>("");
});
EventManager::subscribe<RequestChangeWindowTitle>(this, [this](std::string windowTitle) {
EventManager::subscribe<RequestChangeWindowTitle>(this, [this](const std::string &windowTitle) {
std::string title = "ImHex";
if (ImHexApi::Provider::isValid()) {
@ -108,6 +108,9 @@ namespace hex {
if (ProjectFile::hasUnsavedChanges())
title += " (*)";
if (!ImHexApi::Provider::get()->isWritable())
title += " (Read Only)";
}
this->m_windowTitle = title;
@ -600,7 +603,7 @@ namespace hex {
return;
for (u32 i = 0; i < count; i++) {
auto path = std::filesystem::path(paths[i]);
auto path = std::filesystem::path(reinterpret_cast<const char8_t *>(paths[i]));
bool handled = false;
for (const auto &[extensions, handler] : ContentRegistry::FileHandler::getEntries()) {
@ -616,7 +619,7 @@ namespace hex {
}
if (!handled)
EventManager::post<RequestOpenFile>(path.string());
EventManager::post<RequestOpenFile>(path);
}
});

View File

@ -60,9 +60,9 @@ namespace hex::plugin::builtin::prv {
void *m_mappedFile = nullptr;
size_t m_fileSize = 0;
struct stat m_fileStats = { 0 };
bool m_fileStatsValid = false;
bool m_emptyFile = false;
struct stat m_fileStats = { 0 };
bool m_readable = false, m_writable = false;
};

View File

@ -28,7 +28,7 @@ namespace hex::plugin::builtin {
this->m_searchHexBuffer.resize(0xFFF, 0x00);
ContentRegistry::FileHandler::add({ ".hexproj" }, [](const auto &path) {
return ProjectFile::load(path.string());
return ProjectFile::load(path);
});
ContentRegistry::FileHandler::add({ ".tbl" }, [this](const auto &path) {
@ -566,8 +566,7 @@ namespace hex::plugin::builtin {
this->m_searchRequested = false;
}
if (ImGui::InputText("##nolabel", currBuffer->data(), currBuffer->size(),
flags, ViewHexEditor::inputCallback, this)) {
if (ImGui::InputText("##nolabel", currBuffer->data(), currBuffer->size(), flags, ViewHexEditor::inputCallback, this)) {
this->m_searchRequested = true;
if (this->m_lastSearchBuffer == nullptr || this->m_lastSearchBuffer->empty())
performSearch(currBuffer->data());
@ -637,8 +636,7 @@ namespace hex::plugin::builtin {
this->m_lastSearchBuffer = &this->m_lastStringSearch;
currBuffer = &this->m_searchStringBuffer;
drawSearchInput(currBuffer, ImGuiInputTextFlags_CallbackCompletion |
ImGuiInputTextFlags_EnterReturnsTrue);
drawSearchInput(currBuffer, ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_EnterReturnsTrue);
}
if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.search.hex"_lang)) {
@ -646,9 +644,7 @@ namespace hex::plugin::builtin {
this->m_lastSearchBuffer = &this->m_lastHexSearch;
currBuffer = &this->m_searchHexBuffer;
drawSearchInput(currBuffer, ImGuiInputTextFlags_CharsHexadecimal |
ImGuiInputTextFlags_CallbackCompletion |
ImGuiInputTextFlags_EnterReturnsTrue);
drawSearchInput(currBuffer, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_EnterReturnsTrue);
}
if (currBuffer != nullptr) {
@ -989,13 +985,13 @@ namespace hex::plugin::builtin {
ShortcutManager::addShortcut(this, CTRL + Keys::F, [this] {
this->m_searchRequested = true;
ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hex_editor.name").c_str(),
"hex.builtin.view.hex_editor.menu.file.search"_lang);
"hex.builtin.view.hex_editor.menu.file.search"_lang);
});
ShortcutManager::addShortcut(this, CTRL + Keys::G, [this] {
this->m_gotoRequested = true;
ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hex_editor.name").c_str(),
"hex.builtin.view.hex_editor.menu.file.goto"_lang);
"hex.builtin.view.hex_editor.menu.file.goto"_lang);
});
ShortcutManager::addShortcut(this, CTRL + Keys::O, [] {
@ -1071,12 +1067,12 @@ namespace hex::plugin::builtin {
hex::openFileBrowser("hex.builtin.view.hex_editor.save_project"_lang, DialogMode::Save, {
{"Project File", "hexproj"}
},
[](const auto &path) {
if (path.extension() == ".hexproj") {
ProjectFile::store(path);
} else {
ProjectFile::store(path.string() + ".hexproj");
[](fs::path path) {
if (path.extension() != ".hexproj") {
path.replace_extension(".hexproj");
}
ProjectFile::store(path);
});
} else
ProjectFile::store();
@ -1270,13 +1266,13 @@ namespace hex::plugin::builtin {
ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1400, [&, this] {
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.search"_lang, "CTRL + F")) {
this->getWindowOpenState() = true;
this->m_searchRequested = true;
this->m_searchRequested = true;
ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hex_editor.name").c_str(), "hex.builtin.view.hex_editor.menu.file.search"_lang);
}
if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.goto"_lang, "CTRL + G")) {
this->getWindowOpenState() = true;
this->m_gotoRequested = true;
this->m_gotoRequested = true;
ImGui::OpenPopupInWindow(View::toWindowName("hex.builtin.view.hex_editor.name").c_str(), "hex.builtin.view.hex_editor.menu.file.goto"_lang);
}
});