# HG changeset patch # User Paper # Date 1718339865 14400 # Node ID 71396ecb6f7e88de38edf5fc37bebd2b378b54cf # Parent b5d6c27c308fd03fe830864361617c8a0478f954 library: convert to class + database it also stores std::filesystem::paths now... diff -r b5d6c27c308f -r 71396ecb6f7e include/library/library.h --- a/include/library/library.h Thu Jun 13 01:49:18 2024 -0400 +++ b/include/library/library.h Fri Jun 14 00:37:45 2024 -0400 @@ -3,15 +3,19 @@ #include "library/library.h" -#include +#include #include namespace Library { -// int = anime id, map = episode, paths -extern std::unordered_map> library; +class Database { +public: + void Refresh(); -void SearchLibraryFolders(); + std::unordered_map> items; +}; + +extern Database db; } // namespace Library diff -r b5d6c27c308f -r 71396ecb6f7e src/gui/window.cc --- a/src/gui/window.cc Thu Jun 13 01:49:18 2024 -0400 +++ b/src/gui/window.cc Fri Jun 14 00:37:45 2024 -0400 @@ -176,7 +176,7 @@ } { - menu->addAction(tr("&Scan available episodes"), [] { Library::SearchLibraryFolders(); }); + menu->addAction(tr("&Scan available episodes"), [] { Library::db.Refresh(); }); } menu->addSeparator(); diff -r b5d6c27c308f -r 71396ecb6f7e src/library/library.cc --- a/src/library/library.cc Thu Jun 13 01:49:18 2024 -0400 +++ b/src/library/library.cc Fri Jun 14 00:37:45 2024 -0400 @@ -13,11 +13,8 @@ namespace Library { -// int = anime id, map = episode, paths -std::unordered_map> library; - -void SearchLibraryFolders() { - library.clear(); +void Database::Refresh() { + items.clear(); for (const auto& folder : session.config.library.paths) { for (const auto& entry : std::filesystem::recursive_directory_iterator(folder)) { @@ -38,12 +35,14 @@ if (id <= 0) continue; - const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber))); + const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber))); // we have an ID now! - library[id][episode] = path.u8string(); + items[id][episode] = path; } } } +Database db; + } // namespace Library