From 96e2fdd4e2e502cb52fe89bf9fd26b61a07108d9 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 17 Dec 2024 16:13:40 +1100 Subject: [PATCH] When no media-specific top level directories exist, assume everything is music --- src/tangara/database/database.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/tangara/database/database.cpp b/src/tangara/database/database.cpp index f939725a..ce074ef9 100644 --- a/src/tangara/database/database.cpp +++ b/src/tangara/database/database.cpp @@ -292,9 +292,8 @@ auto Database::setTrackData(TrackId id, const TrackData& data) -> void { auto Database::getIndexes() -> std::vector { // TODO(jacqueline): This probably needs to be async? When we have runtime // configurable indexes, they will need to come from somewhere. - return { - kAllTracks, kAllAlbums, kAlbumsByArtist, kTracksByGenre, kPodcasts, kAudiobooks - }; + return {kAllTracks, kAllAlbums, kAlbumsByArtist, + kTracksByGenre, kPodcasts, kAudiobooks}; } Database::UpdateTracker::UpdateTracker() @@ -568,6 +567,23 @@ auto Database::calculateMediaType(TrackTags& tags, std::string_view path) return MediaType::kMusic; } + auto dir_exists = [&](auto path) { + FF_DIR dir; + bool res = f_opendir(&dir, path); + if (res == FR_OK) { + f_closedir(&dir); + } + return res == FR_OK; + }; + + // As a special case, if no media-specific paths exist at all, then assume + // the user doesn't really care about alternate media types and just wants to + // use the device for music. + if (!dir_exists(kMusicMediaPath) && !dir_exists(kPodcastMediaPath) && + !dir_exists(kAudiobookMediaPath)) { + return MediaType::kMusic; + } + return MediaType::kUnknown; }