Fixed an issue where adding trailing directory separators to the MediaDirectory setting could make the Orphaned data cleanup utility remove too many files

This commit is contained in:
Leon Styhre 2024-05-20 19:44:07 +02:00
parent 724ba0cfea
commit 5bad361121

View file

@ -22,7 +22,6 @@ GuiOrphanedDataCleanup::GuiOrphanedDataCleanup(std::function<void()> reloadCallb
, mGrid {glm::ivec2 {4, 11}} , mGrid {glm::ivec2 {4, 11}}
, mReloadCallback {reloadCallback} , mReloadCallback {reloadCallback}
, mCursorPos {0} , mCursorPos {0}
, mMediaDirectory {FileData::getMediaDirectory()}
, mMediaTypes {"3dboxes", "backcovers", "covers", "fanart", , mMediaTypes {"3dboxes", "backcovers", "covers", "fanart",
"manuals", "marquees", "miximages", "physicalmedia", "manuals", "marquees", "miximages", "physicalmedia",
"screenshots", "titlescreens", "videos"} "screenshots", "titlescreens", "videos"}
@ -36,6 +35,23 @@ GuiOrphanedDataCleanup::GuiOrphanedDataCleanup(std::function<void()> reloadCallb
, mCaseSensitiveFilesystem {true} , mCaseSensitiveFilesystem {true}
, mCleanupType {CleanupType::MEDIA} , mCleanupType {CleanupType::MEDIA}
{ {
// Make sure we always have a single trailing directory separator for the media directory.
mMediaDirectory = FileData::getMediaDirectory();
mMediaDirectory.erase(std::find_if(mMediaDirectory.rbegin(), mMediaDirectory.rend(),
[](char c) { return c != '/'; })
.base(),
mMediaDirectory.end());
mMediaDirectory.erase(std::find_if(mMediaDirectory.rbegin(), mMediaDirectory.rend(),
[](char c) { return c != '\\'; })
.base(),
mMediaDirectory.end());
#if defined(_WIN64)
mMediaDirectory.append("\\");
#else
mMediaDirectory.append("/");
#endif
addChild(&mBackground); addChild(&mBackground);
addChild(&mGrid); addChild(&mGrid);