From 0af45b03e37ed29f86373932ed4444fd60d86dfe Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 31 Jan 2024 21:03:28 +0100 Subject: [PATCH] (Android) Added creation of .nomedia files in the themes and downloaded_media directories --- es-app/src/MiximageGenerator.cpp | 11 +++++++++++ es-app/src/main.cpp | 33 ++++++++++++++++++++++++++++++++ es-app/src/scrapers/Scraper.cpp | 11 +++++++++++ 3 files changed, 55 insertions(+) diff --git a/es-app/src/MiximageGenerator.cpp b/es-app/src/MiximageGenerator.cpp index 75bb65a4b..a2714643e 100644 --- a/es-app/src/MiximageGenerator.cpp +++ b/es-app/src/MiximageGenerator.cpp @@ -895,6 +895,17 @@ std::string MiximageGenerator::getSavePath() const if (!Utils::FileSystem::exists(path)) Utils::FileSystem::createDirectory(path); +#if defined(__ANDROID__) + if (!Utils::FileSystem::exists(path + ".nomedia")) { + LOG(LogInfo) << "Creating \"no media\" file \"" << path + ".nomedia" + << "\"..."; + Utils::FileSystem::createEmptyFile(path + ".nomedia"); + if (!Utils::FileSystem::exists(path + ".nomedia")) { + LOG(LogWarning) << "Couldn't create file, permission problems?"; + } + } +#endif + path += mGame->getSystemName() + "/miximages" + subFolders + "/"; if (!Utils::FileSystem::exists(path)) diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index eb43bdcd0..31ed07f1b 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -796,6 +796,14 @@ int main(int argc, char* argv[]) LOG(LogWarning) << "Couldn't create directory, permission problems?"; } } + if (!Utils::FileSystem::exists(themeDir + "/.nomedia")) { + LOG(LogInfo) << "Creating \"no media\" file \"" << themeDir + "/.nomedia" + << "\"..."; + Utils::FileSystem::createEmptyFile(themeDir + "/.nomedia"); + if (!Utils::FileSystem::exists(themeDir + "/.nomedia")) { + LOG(LogWarning) << "Couldn't create file, permission problems?"; + } + } #else // Create the themes folder in the application data directory (or elsewhere if the // UserThemeDirectory setting has been defined). @@ -821,6 +829,21 @@ int main(int argc, char* argv[]) #endif } + { +#if defined(__ANDROID__) + const std::string mediaDirectory {FileData::getMediaDirectory()}; + if (Utils::FileSystem::exists(mediaDirectory)) + if (!Utils::FileSystem::exists(mediaDirectory + ".nomedia")) { + LOG(LogInfo) << "Creating \"no media\" file \"" << mediaDirectory + ".nomedia" + << "\"..."; + Utils::FileSystem::createEmptyFile(mediaDirectory + ".nomedia"); + if (!Utils::FileSystem::exists(mediaDirectory + ".nomedia")) { + LOG(LogWarning) << "Couldn't create file, permission problems?"; + } + } +#endif + } + { // Create the scripts folder in the application data directory. This is only required // for custom event scripts so it's also created as a convenience. @@ -847,6 +870,16 @@ int main(int argc, char* argv[]) LOG(LogWarning) << "Couldn't create directory, permission problems?"; } } +#if defined(__ANDROID__) + if (!Utils::FileSystem::exists(screensaversDir + "/.nomedia")) { + LOG(LogInfo) << "Creating \"no media\" file \"" << screensaversDir + "/.nomedia" + << "\"..."; + Utils::FileSystem::createEmptyFile(screensaversDir + "/.nomedia"); + if (!Utils::FileSystem::exists(screensaversDir + "/.nomedia")) { + LOG(LogWarning) << "Couldn't create file, permission problems?"; + } + } +#endif if (!Utils::FileSystem::exists(slideshowDir)) { LOG(LogInfo) << "Creating custom_slideshow directory \"" << slideshowDir << "\"..."; Utils::FileSystem::createDirectory(slideshowDir); diff --git a/es-app/src/scrapers/Scraper.cpp b/es-app/src/scrapers/Scraper.cpp index aaec7aad6..f4c01c993 100644 --- a/es-app/src/scrapers/Scraper.cpp +++ b/es-app/src/scrapers/Scraper.cpp @@ -714,6 +714,17 @@ std::string getSaveAsPath(const ScraperSearchParams& params, if (!Utils::FileSystem::exists(path)) Utils::FileSystem::createDirectory(path); +#if defined(__ANDROID__) + if (!Utils::FileSystem::exists(path + ".nomedia")) { + LOG(LogInfo) << "Creating \"no media\" file \"" << path + ".nomedia" + << "\"..."; + Utils::FileSystem::createEmptyFile(path + ".nomedia"); + if (!Utils::FileSystem::exists(path + ".nomedia")) { + LOG(LogWarning) << "Couldn't create file, permission problems?"; + } + } +#endif + path.append(systemsubdirectory) .append("/") .append(filetypeSubdirectory)