fix: Various issues with UTF-8 paths

This commit is contained in:
WerWolv
2022-06-30 19:39:06 +02:00
parent 96aa929c31
commit 3db50a690c
6 changed files with 27 additions and 8 deletions

View File

@@ -67,6 +67,8 @@ namespace hex::fs {
bool isPathWritable(const std::fs::path &path);
std::fs::path toShortPath(const std::fs::path &path);
enum class DialogMode
{
Open,

View File

@@ -313,4 +313,20 @@ namespace hex::fs {
return result;
}
std::fs::path toShortPath(const std::fs::path &path) {
#if defined(OS_WINDOWS)
size_t size = GetShortPathNameW(path.c_str(), nullptr, 0) * sizeof(TCHAR);
if (size == 0)
return path;
std::wstring newPath(size, 0x00);
GetShortPathNameW(path.c_str(), newPath.data(), newPath.size());
return newPath;
#else
return path;
#endif
}
}

View File

@@ -26,8 +26,9 @@ namespace hex::magic {
std::error_code error;
for (const auto &dir : fs::getDefaultPaths(fs::ImHexPath::Magic)) {
for (const auto &entry : std::fs::directory_iterator(dir, error)) {
if (entry.is_regular_file() && ((sourceFiles && entry.path().extension().empty()) || (!sourceFiles && entry.path().extension() == ".mgc")))
magicFiles += entry.path().string() + MAGIC_PATH_SEPARATOR;
if (entry.is_regular_file() && ((sourceFiles && entry.path().extension().empty()) || (!sourceFiles && entry.path().extension() == ".mgc"))) {
magicFiles += fs::toShortPath(entry.path()).string() + MAGIC_PATH_SEPARATOR;
}
}
}