diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a6f90d..b5bb1f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ Versions match `FIP_VERSION` in `src/version.h`. ## [Unreleased] +## [1.8.2] - 2026-10-18 + +### Fixed + +- Directory paths with special characters (e.g. folders named "[unnamed]") are now scanned and removable: FindFirstFile patterns misread such names as wildcards, so folders silently vanished from Find/Remove Dead-Empty Directories. + ## [1.8.1] - 2026-10-18 ### Fixed diff --git a/src/main_menu.cpp b/src/main_menu.cpp index ba7bcb6..118a780 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -370,23 +370,29 @@ class main_find_playing : public mainmenu_commands { t_size removed = 0; t_size failed = 0; for (const auto & dir : dirs) { - // Delete all files in the directory first. - WIN32_FIND_DATAA fd; - HANDLE hFind = FindFirstFileA((dir + std::string("\\*")).c_str(), &fd); - if (hFind != INVALID_HANDLE_VALUE) { - do { - const char *name = fd.cFileName; - if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) - continue; - std::string fullPath = dir + std::string("\\") + name; - if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - RemoveDirectoryA(fullPath.c_str()); - } else { - DeleteFileA(fullPath.c_str()); - } - } while (FindNextFileA(hFind, &fd)); - FindClose(hFind); + // Delete all files in the directory first. std::filesystem is + // used because FindFirstFileA parses [abc] in the path as a + // wildcard pattern, so folder names like "[unnamed]" fail. + namespace fs = std::filesystem; + std::error_code ec; + for (fs::directory_iterator it(fs::path(dir), fs::directory_options::skip_permission_denied, ec), end; + it != end && !ec; it.increment(ec)) { + std::string name; + try { + name = it->path().filename().string(); + } catch (const std::system_error &) { + continue; // undecodable name: skip the entry + } + const std::string fullPath = dir + std::string("\\") + name; + if (it->is_directory(ec)) { + if (ec) + break; + RemoveDirectoryA(fullPath.c_str()); + } else if (!ec) { + DeleteFileA(fullPath.c_str()); + } } + ec.clear(); if (RemoveDirectoryA(dir.c_str())) ++removed; else diff --git a/src/scanner.cpp b/src/scanner.cpp index 20c6932..b33cbdc 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -181,25 +181,32 @@ bool tag_has_invalid_chars(metadb_handle_ptr h) { return false; } -// Enumerate one directory's direct files and subfolders. +// Enumerate one directory's direct files and subfolders. std::filesystem is +// used because FindFirstFileA parses [abc] in the path as a wildcard pattern, +// so folder names like "[unnamed]" silently fail to enumerate. static bool list_dir_entries(const std::string & dir, std::vector & filenames, std::vector & subdirs) { - WIN32_FIND_DATAA fd; - HANDLE hFind = FindFirstFileA((dir + "\\*").c_str(), &fd); - if (hFind == INVALID_HANDLE_VALUE) - return false; - do { - const char *name = fd.cFileName; - if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) - continue; - if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + namespace fs = std::filesystem; + std::error_code ec; + for (fs::directory_iterator it(fs::path(dir), fs::directory_options::skip_permission_denied, ec), end; it != end; + it.increment(ec)) { + if (ec) + break; + std::string name; + try { + name = it->path().filename().string(); + } catch (const std::system_error &) { + continue; // undecodable name: skip the entry + } + if (it->is_directory(ec)) { + if (ec) + break; subdirs.push_back(dir + "\\" + name); - } else { + } else if (!ec) { filenames.push_back(name); } - } while (FindNextFileA(hFind, &fd)); - FindClose(hFind); - return true; + } + return !ec; } std::vector scan_dead_directories() { diff --git a/src/stdafx.h b/src/stdafx.h index 17203e1..6803656 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -19,6 +19,7 @@ #include +#include #include #include #include diff --git a/src/version.h b/src/version.h index d88c627..def9352 100644 --- a/src/version.h +++ b/src/version.h @@ -2,4 +2,4 @@ // Single source of truth for the component version. // Automatically updated by GitHub Actions semantic release. -#define FIP_VERSION "1.8.1" +#define FIP_VERSION "1.8.2"