From 610a35042970089d6051015b283627a6ea0a6709 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 14 Aug 2023 19:12:50 +0200 Subject: [PATCH] Added support to GuiOrphanedDataCleanup for deleting empty media directories --- es-app/src/guis/GuiOrphanedDataCleanup.cpp | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/es-app/src/guis/GuiOrphanedDataCleanup.cpp b/es-app/src/guis/GuiOrphanedDataCleanup.cpp index ca95e3c7c..ed91691dc 100644 --- a/es-app/src/guis/GuiOrphanedDataCleanup.cpp +++ b/es-app/src/guis/GuiOrphanedDataCleanup.cpp @@ -394,9 +394,37 @@ void GuiOrphanedDataCleanup::cleanupMediaFiles() } } + int directoryDeleteCounter {0}; + const Utils::FileSystem::StringList& emptyDirCheck { + Utils::FileSystem::getDirContent(systemMediaDir, true)}; + + for (auto& entry : emptyDirCheck) { + if (!Utils::FileSystem::isDirectory(entry)) + continue; + std::string path {entry}; + while (path != systemMediaDir) { + if (Utils::FileSystem::getDirContent(path).size() == 0) { + +#if defined(_WIN64) + LOG(LogInfo) << "Deleting empty directory \"" + << Utils::String::replace(path, "/", "\\") << "\""; +#else + LOG(LogInfo) << "Deleting empty directory \"" << path << "\""; +#endif + if (Utils::FileSystem::removeDirectory(path, false)) + ++directoryDeleteCounter; + path = Utils::FileSystem::getParent(path); + } + else { + break; + } + } + } + LOG(LogInfo) << "Removed " << systemProcessedCount << " file" - << (systemProcessedCount == 1 ? " " : "s ") << "from system \"" - << currentSystem << "\""; + << (systemProcessedCount == 1 ? " " : "s ") << "and " << directoryDeleteCounter + << (directoryDeleteCounter == 1 ? " directory " : " directories ") + << "for system \"" << currentSystem << "\""; SDL_Delay(500); }