Skip to content

Commit 19c02be

Browse files
committed
impr: Only store paths with forward slashes in project files
Fixes #1657
1 parent adbcc48 commit 19c02be

File tree

9 files changed

+21
-34
lines changed

9 files changed

+21
-34
lines changed

lib/libimhex/source/helpers/tar.cpp

+4-17
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ namespace hex {
9090
bool Tar::contains(const std::fs::path &path) const {
9191
mtar_header_t header;
9292

93-
auto fixedPath = path.string();
94-
#if defined(OS_WINDOWS)
95-
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
96-
#endif
97-
93+
const auto fixedPath = wolv::io::fs::toNormalizedPathString(path);
9894
return mtar_find(m_ctx.get(), fixedPath.c_str(), &header) == MTAR_ESUCCESS;
9995
}
10096

@@ -115,10 +111,7 @@ namespace hex {
115111
std::vector<u8> Tar::readVector(const std::fs::path &path) const {
116112
mtar_header_t header;
117113

118-
auto fixedPath = path.string();
119-
#if defined(OS_WINDOWS)
120-
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
121-
#endif
114+
const auto fixedPath = wolv::io::fs::toNormalizedPathString(path);
122115
int ret = mtar_find(m_ctx.get(), fixedPath.c_str(), &header);
123116
if (ret != MTAR_ESUCCESS){
124117
log::debug("Failed to read vector from path {} in tarred file {}: {}",
@@ -143,18 +136,12 @@ namespace hex {
143136
for (const auto &part : path.parent_path()) {
144137
pathPart /= part;
145138

146-
auto fixedPath = pathPart.string();
147-
#if defined(OS_WINDOWS)
148-
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
149-
#endif
139+
auto fixedPath = wolv::io::fs::toNormalizedPathString(pathPart);
150140
mtar_write_dir_header(m_ctx.get(), fixedPath.c_str());
151141
}
152142
}
153143

154-
auto fixedPath = path.string();
155-
#if defined(OS_WINDOWS)
156-
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
157-
#endif
144+
const auto fixedPath = wolv::io::fs::toNormalizedPathString(path);
158145
mtar_write_file_header(m_ctx.get(), fixedPath.c_str(), data.size());
159146
mtar_write_data(m_ctx.get(), data.data(), data.size());
160147
}

main/gui/source/crash_handlers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ namespace hex::crash {
4444
log::fatal(message);
4545

4646
nlohmann::json crashData {
47-
{ "logFile", wolv::util::toUTF8String(hex::log::impl::getFile().getPath()) },
48-
{ "project", wolv::util::toUTF8String(ProjectFile::getPath()) },
47+
{ "logFile", wolv::io::fs::toNormalizedPathString(hex::log::impl::getFile().getPath()) },
48+
{ "project", wolv::io::fs::toNormalizedPathString(ProjectFile::getPath()) },
4949
};
5050

5151
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Config)) {

plugins/builtin/source/content/providers/disk_provider.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ namespace hex::plugin::builtin {
369369

370370
std::vector<DiskProvider::Description> DiskProvider::getDataDescription() const {
371371
return {
372-
{ "hex.builtin.provider.disk.selected_disk"_lang, wolv::util::toUTF8String(m_path) },
373-
{ "hex.builtin.provider.disk.disk_size"_lang, hex::toByteString(m_diskSize) },
374-
{ "hex.builtin.provider.disk.sector_size"_lang, hex::toByteString(m_sectorSize) }
372+
{ "hex.builtin.provider.disk.selected_disk"_lang, wolv::util::toUTF8String(m_path) },
373+
{ "hex.builtin.provider.disk.disk_size"_lang, hex::toByteString(m_diskSize) },
374+
{ "hex.builtin.provider.disk.sector_size"_lang, hex::toByteString(m_sectorSize) }
375375
};
376376
}
377377

@@ -497,7 +497,7 @@ namespace hex::plugin::builtin {
497497
}
498498

499499
nlohmann::json DiskProvider::storeSettings(nlohmann::json settings) const {
500-
settings["path"] = wolv::util::toUTF8String(m_path);
500+
settings["path"] = wolv::io::fs::toNormalizedPathString(m_path);
501501

502502
settings["friendly_name"] = m_friendlyName;
503503

@@ -527,7 +527,7 @@ namespace hex::plugin::builtin {
527527

528528
std::variant<std::string, i128> DiskProvider::queryInformation(const std::string &category, const std::string &argument) {
529529
if (category == "file_path")
530-
return wolv::util::toUTF8String(m_path);
530+
return wolv::io::fs::toNormalizedPathString(m_path);
531531
else if (category == "sector_size")
532532
return m_sectorSize;
533533
else if (category == "friendly_name")

plugins/builtin/source/content/providers/file_provider.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ namespace hex::plugin::builtin {
147147

148148
std::variant<std::string, i128> FileProvider::queryInformation(const std::string &category, const std::string &argument) {
149149
if (category == "file_path")
150-
return wolv::util::toUTF8String(m_path);
150+
return wolv::io::fs::toNormalizedPathString(m_path);
151151
else if (category == "file_name")
152-
return wolv::util::toUTF8String(m_path.filename());
152+
return wolv::io::fs::toNormalizedPathString(m_path.filename());
153153
else if (category == "file_extension")
154-
return wolv::util::toUTF8String(m_path.extension());
154+
return wolv::io::fs::toNormalizedPathString(m_path.extension());
155155
else if (category == "creation_time")
156156
return m_fileStats->st_ctime;
157157
else if (category == "access_time")
@@ -279,9 +279,9 @@ namespace hex::plugin::builtin {
279279
nlohmann::json FileProvider::storeSettings(nlohmann::json settings) const {
280280
std::string path;
281281
if (auto projectPath = ProjectFile::getPath(); !projectPath.empty())
282-
path = wolv::util::toUTF8String(std::fs::proximate(m_path, projectPath.parent_path()));
282+
path = wolv::io::fs::toNormalizedPathString(std::fs::proximate(m_path, projectPath.parent_path()));
283283
if (path.empty())
284-
path = wolv::util::toUTF8String(m_path);
284+
path = wolv::io::fs::toNormalizedPathString(m_path);
285285

286286
settings["path"] = path;
287287

plugins/builtin/source/content/providers/intel_hex_provider.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ namespace hex::plugin::builtin {
282282
}
283283

284284
nlohmann::json IntelHexProvider::storeSettings(nlohmann::json settings) const {
285-
settings["path"] = wolv::util::toUTF8String(m_sourceFilePath);
285+
settings["path"] = wolv::io::fs::toNormalizedPathString(m_sourceFilePath);
286286

287287
return Provider::storeSettings(settings);
288288
}

plugins/builtin/source/content/settings_entries.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ namespace hex::plugin::builtin {
152152
std::vector<std::string> pathStrings;
153153

154154
for (const auto &path : m_paths) {
155-
pathStrings.push_back(wolv::util::toUTF8String(path));
155+
pathStrings.push_back(wolv::io::fs::toNormalizedPathString(path));
156156
}
157157

158158
return pathStrings;

plugins/builtin/source/content/views/view_pattern_editor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace hex::plugin::builtin {
141141
for (const auto &file : virtualFiles) {
142142
const auto &path = file->path;
143143

144-
auto currSegment = wolv::util::toUTF8String(*std::next(path.begin(), level));
144+
auto currSegment = wolv::io::fs::toNormalizedPathString(*std::next(path.begin(), level));
145145
if (std::distance(path.begin(), path.end()) == ptrdiff_t(level + 1)) {
146146
ImGui::TableNextRow();
147147
ImGui::TableNextColumn();

0 commit comments

Comments
 (0)