diff --git a/CHANGELOG.md b/CHANGELOG.md index ff77ac2..acd0362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ Versions match `FIP_VERSION` in `src/version.h`. ## [Unreleased] +## [1.8.6] - 2026-11-23 + +### Fixed + +- Dead-track removal failures are now reported per entry with a reason (stale playlist index, duplicate entry, or playlist API failure) in the report file and the foobar console, and the popup includes the report file path. + ## [1.8.5] - 2026-11-23 ### Changed diff --git a/src/logic.cpp b/src/logic.cpp index d5eefd7..82244f1 100644 --- a/src/logic.cpp +++ b/src/logic.cpp @@ -187,10 +187,18 @@ void format_report(const std::vector & reports, pfc::string_base & } void format_dead_report(const std::vector & dead, bool removed, pfc::string_base & out) { - const std::vector none; + const std::vector none; format_dead_report(dead, removed, none, out); } +void format_dead_report(const std::vector & dead, bool removed, + const std::vector & failedPlaylists, pfc::string_base & out) { + std::vector failures; + for (const auto & name : failedPlaylists) + failures.push_back({name, "", "playlist removal failed"}); + format_dead_report(dead, removed, failures, out); +} + static void append_dead_entry_item(pfc::string_base & body, const dead_entry & entry) { body << " - " << entry.header.c_str(); if (!entry.path.empty()) @@ -213,7 +221,7 @@ static void append_dead_summary_header(pfc::string_base & head, size_t deadCount } void format_dead_report(const std::vector & dead, bool removed, - const std::vector & failedPlaylists, pfc::string_base & out) { + const std::vector & failures, pfc::string_base & out) { if (dead.empty()) { out << "No dead tracks found. Nothing to do.\n"; return; @@ -230,6 +238,11 @@ void format_dead_report(const std::vector & dead, bool removed, i = j; } + std::vector failedPlaylists; + for (const auto & f : failures) + if (std::find(failedPlaylists.begin(), failedPlaylists.end(), f.playlist) == failedPlaylists.end()) + failedPlaylists.push_back(f.playlist); + append_dead_summary_header(out, dead.size(), affected, removed); // Pass 2: Stream group headers and items directly into out with O(1) group counts @@ -246,6 +259,14 @@ void format_dead_report(const std::vector & dead, bool removed, i = j; } + + if (!failures.empty()) { + out << "\nFAILED REMOVALS (" << failures.size() << "):\n"; + for (const auto & f : failures) { + out << " - [" << f.playlist.c_str() << "] " << f.entry.c_str() << "\n"; + out << " Reason: " << f.reason.c_str() << "\n"; + } + } } static bool is_forbidden_filename_char(char c) { diff --git a/src/logic.h b/src/logic.h index 4ba4e75..58c535f 100644 --- a/src/logic.h +++ b/src/logic.h @@ -65,10 +65,19 @@ std::vector derive_orphans(const scan_result & result, const std::unor // Formatters ---------------------------------------------------------------- +// One dead entry that could not be removed, with the reason it was skipped. +struct removal_failure { + std::string playlist; + std::string entry; + std::string reason; +}; + void format_report(const std::vector & reports, pfc::string_base & out); void format_dead_report(const std::vector & dead, bool removed, pfc::string_base & out); void format_dead_report(const std::vector & dead, bool removed, const std::vector & failedPlaylists, pfc::string_base & out); +void format_dead_report(const std::vector & dead, bool removed, + const std::vector & failures, pfc::string_base & out); std::string safe_filename(const char *name); // Writes body to %TEMP%\foo_findplaylists_report.txt. Returns the path. diff --git a/src/main_menu.cpp b/src/main_menu.cpp index 08e1c41..0cf7bf7 100644 --- a/src/main_menu.cpp +++ b/src/main_menu.cpp @@ -348,17 +348,29 @@ class main_find_playing : public mainmenu_commands { static void run_remove_dead() { auto dead = scan_dead_tracks(); - std::vector failed; + std::vector failed; const t_size removed = apply_dead_removal(dead, failed); pfc::string_formatter msg; format_dead_report(dead, true, failed, msg); - report("Find in Playlists: dead tracks", msg); + const std::string path = report_path("Find in Playlists: dead tracks", msg); + + for (const auto & f : failed) { + pfc::string_formatter line; + line << "FAILED [" << f.playlist.c_str() << "] " << f.entry.c_str() << " - " << f.reason.c_str(); + FB2K_console_formatter() << line; + } + pfc::string_formatter sum; - if (dead.empty()) + if (dead.empty()) { sum << "No dead tracks found. Nothing changed."; - else - sum << "Removed " << removed << " of " << dead.size() << " dead entries." - << (failed.empty() ? "" : " Some removals FAILED, see report.") << "\nUndo with Ctrl+Z per playlist."; + } else { + sum << "Removed " << removed << " of " << dead.size() << " dead entries."; + if (!failed.empty()) + sum << "\n" << failed.size() << " FAILED - details in console and report: " << path.c_str(); + else + sum << "\nReport: " << path.c_str(); + sum << "\nUndo with Ctrl+Z per playlist."; + } confirm("Find in Playlists", sum); } diff --git a/src/playlist_ops.cpp b/src/playlist_ops.cpp index e01e90f..b07e01c 100644 --- a/src/playlist_ops.cpp +++ b/src/playlist_ops.cpp @@ -51,8 +51,8 @@ t_size collect_into(const char *plname, const std::vector & t return add.get_count(); } -t_size apply_dead_removal(const std::vector & dead, std::vector & failedPlaylists) { - failedPlaylists.clear(); +t_size apply_dead_removal(const std::vector & dead, std::vector & failures) { + failures.clear(); if (dead.empty()) return 0; static_api_ptr_t pm; @@ -68,8 +68,16 @@ t_size apply_dead_removal(const std::vector & dead, std::vector= items.get_count()) { + failures.push_back({entry.playlistName, entry.header, + "entry index " + std::to_string(entry.item) + " no longer exists in playlist (" + + std::to_string(items.get_count()) + " items); playlist changed since scan"}); + } else if (mask.m[entry.item]) { + failures.push_back( + {entry.playlistName, entry.header, "duplicate dead entry at index " + std::to_string(entry.item)}); + } else { + mask.m[entry.item] = 1; ++marked; } ++j; @@ -78,10 +86,16 @@ t_size apply_dead_removal(const std::vector & dead, std::vectorplaylist_remove_items(pl, mask)) + if (pm->playlist_remove_items(pl, mask)) { total += marked; - else - failedPlaylists.push_back(dead[i].playlistName); + } else { + for (size_t k = i; k < j; ++k) { + if (dead[k].item < items.get_count() && mask.m[dead[k].item]) { + failures.push_back({dead[k].playlistName, dead[k].header, + "playlist_remove_items failed (playlist unavailable or read-only)"}); + } + } + } i = j; } return total; diff --git a/src/playlist_ops.h b/src/playlist_ops.h index 98bfd66..a63f60d 100644 --- a/src/playlist_ops.h +++ b/src/playlist_ops.h @@ -12,4 +12,6 @@ t_size find_or_create_playlist(const char *name); // them; anything added manually is wiped on the next run. t_size collect_into(const char *plname, const std::vector & tracks); -t_size apply_dead_removal(const std::vector & dead, std::vector & failedPlaylists); +// Removes dead entries grouped by playlist. failures receives one record per +// entry that could not be removed, with the playlist, entry and reason. +t_size apply_dead_removal(const std::vector & dead, std::vector & failures); diff --git a/src/version.h b/src/version.h index d66a11a..33c4a2f 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.5" +#define FIP_VERSION "1.8.6" diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 6b4d8f0..ab102e9 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -86,6 +86,15 @@ static void test_format_dead() { "(Undo per playlist with Ctrl+Z if anything looks wrong.)\n" "Mix A: 1\n - Artist - One\n Z:\\path\\one.mp3\n"); CHECK_STR_EQ(fmt_dead({}, false), "No dead tracks found. Nothing to do.\n"); + + // Failed removals are reported individually with a reason + pfc::string_formatter withFailure; + format_dead_report({a}, true, std::vector{{"Mix A", "Artist - One", "playlist unavailable"}}, + withFailure); + const std::string text(withFailure.c_str()); + CHECK(text.find("FAILED REMOVALS (1)") != std::string::npos); + CHECK(text.find("Reason: playlist unavailable") != std::string::npos); + CHECK(text.find("(REMOVAL FAILED, untouched)") != std::string::npos); } static void test_write_report_file() {