impr: Only store paths with forward slashes in project files

Fixes #1657
This commit is contained in:
WerWolv
2024-05-08 21:30:20 +02:00
parent adbcc48de7
commit 19c02be673
9 changed files with 21 additions and 34 deletions

View File

@@ -90,11 +90,7 @@ namespace hex {
bool Tar::contains(const std::fs::path &path) const {
mtar_header_t header;
auto fixedPath = path.string();
#if defined(OS_WINDOWS)
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
#endif
const auto fixedPath = wolv::io::fs::toNormalizedPathString(path);
return mtar_find(m_ctx.get(), fixedPath.c_str(), &header) == MTAR_ESUCCESS;
}
@@ -115,10 +111,7 @@ namespace hex {
std::vector<u8> Tar::readVector(const std::fs::path &path) const {
mtar_header_t header;
auto fixedPath = path.string();
#if defined(OS_WINDOWS)
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
#endif
const auto fixedPath = wolv::io::fs::toNormalizedPathString(path);
int ret = mtar_find(m_ctx.get(), fixedPath.c_str(), &header);
if (ret != MTAR_ESUCCESS){
log::debug("Failed to read vector from path {} in tarred file {}: {}",
@@ -143,18 +136,12 @@ namespace hex {
for (const auto &part : path.parent_path()) {
pathPart /= part;
auto fixedPath = pathPart.string();
#if defined(OS_WINDOWS)
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
#endif
auto fixedPath = wolv::io::fs::toNormalizedPathString(pathPart);
mtar_write_dir_header(m_ctx.get(), fixedPath.c_str());
}
}
auto fixedPath = path.string();
#if defined(OS_WINDOWS)
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
#endif
const auto fixedPath = wolv::io::fs::toNormalizedPathString(path);
mtar_write_file_header(m_ctx.get(), fixedPath.c_str(), data.size());
mtar_write_data(m_ctx.get(), data.data(), data.size());
}

View File

@@ -44,8 +44,8 @@ namespace hex::crash {
log::fatal(message);
nlohmann::json crashData {
{ "logFile", wolv::util::toUTF8String(hex::log::impl::getFile().getPath()) },
{ "project", wolv::util::toUTF8String(ProjectFile::getPath()) },
{ "logFile", wolv::io::fs::toNormalizedPathString(hex::log::impl::getFile().getPath()) },
{ "project", wolv::io::fs::toNormalizedPathString(ProjectFile::getPath()) },
};
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Config)) {

View File

@@ -369,9 +369,9 @@ namespace hex::plugin::builtin {
std::vector<DiskProvider::Description> DiskProvider::getDataDescription() const {
return {
{ "hex.builtin.provider.disk.selected_disk"_lang, wolv::util::toUTF8String(m_path) },
{ "hex.builtin.provider.disk.disk_size"_lang, hex::toByteString(m_diskSize) },
{ "hex.builtin.provider.disk.sector_size"_lang, hex::toByteString(m_sectorSize) }
{ "hex.builtin.provider.disk.selected_disk"_lang, wolv::util::toUTF8String(m_path) },
{ "hex.builtin.provider.disk.disk_size"_lang, hex::toByteString(m_diskSize) },
{ "hex.builtin.provider.disk.sector_size"_lang, hex::toByteString(m_sectorSize) }
};
}
@@ -497,7 +497,7 @@ namespace hex::plugin::builtin {
}
nlohmann::json DiskProvider::storeSettings(nlohmann::json settings) const {
settings["path"] = wolv::util::toUTF8String(m_path);
settings["path"] = wolv::io::fs::toNormalizedPathString(m_path);
settings["friendly_name"] = m_friendlyName;
@@ -527,7 +527,7 @@ namespace hex::plugin::builtin {
std::variant<std::string, i128> DiskProvider::queryInformation(const std::string &category, const std::string &argument) {
if (category == "file_path")
return wolv::util::toUTF8String(m_path);
return wolv::io::fs::toNormalizedPathString(m_path);
else if (category == "sector_size")
return m_sectorSize;
else if (category == "friendly_name")

View File

@@ -147,11 +147,11 @@ namespace hex::plugin::builtin {
std::variant<std::string, i128> FileProvider::queryInformation(const std::string &category, const std::string &argument) {
if (category == "file_path")
return wolv::util::toUTF8String(m_path);
return wolv::io::fs::toNormalizedPathString(m_path);
else if (category == "file_name")
return wolv::util::toUTF8String(m_path.filename());
return wolv::io::fs::toNormalizedPathString(m_path.filename());
else if (category == "file_extension")
return wolv::util::toUTF8String(m_path.extension());
return wolv::io::fs::toNormalizedPathString(m_path.extension());
else if (category == "creation_time")
return m_fileStats->st_ctime;
else if (category == "access_time")
@@ -279,9 +279,9 @@ namespace hex::plugin::builtin {
nlohmann::json FileProvider::storeSettings(nlohmann::json settings) const {
std::string path;
if (auto projectPath = ProjectFile::getPath(); !projectPath.empty())
path = wolv::util::toUTF8String(std::fs::proximate(m_path, projectPath.parent_path()));
path = wolv::io::fs::toNormalizedPathString(std::fs::proximate(m_path, projectPath.parent_path()));
if (path.empty())
path = wolv::util::toUTF8String(m_path);
path = wolv::io::fs::toNormalizedPathString(m_path);
settings["path"] = path;

View File

@@ -282,7 +282,7 @@ namespace hex::plugin::builtin {
}
nlohmann::json IntelHexProvider::storeSettings(nlohmann::json settings) const {
settings["path"] = wolv::util::toUTF8String(m_sourceFilePath);
settings["path"] = wolv::io::fs::toNormalizedPathString(m_sourceFilePath);
return Provider::storeSettings(settings);
}

View File

@@ -152,7 +152,7 @@ namespace hex::plugin::builtin {
std::vector<std::string> pathStrings;
for (const auto &path : m_paths) {
pathStrings.push_back(wolv::util::toUTF8String(path));
pathStrings.push_back(wolv::io::fs::toNormalizedPathString(path));
}
return pathStrings;

View File

@@ -141,7 +141,7 @@ namespace hex::plugin::builtin {
for (const auto &file : virtualFiles) {
const auto &path = file->path;
auto currSegment = wolv::util::toUTF8String(*std::next(path.begin(), level));
auto currSegment = wolv::io::fs::toNormalizedPathString(*std::next(path.begin(), level));
if (std::distance(path.begin(), path.end()) == ptrdiff_t(level + 1)) {
ImGui::TableNextRow();
ImGui::TableNextColumn();