From e87d507c0cebb23d6043dee2211331dcaba82fcc Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 23 Jun 2022 21:58:14 +1000 Subject: [PATCH] GameList: Populate game list from cache in batch mode Stop-gap until we make CDVD/scanning thread-safe, and can create game list entries on demand. --- pcsx2-qt/GameList/GameListRefreshThread.cpp | 2 +- pcsx2-qt/QtHost.cpp | 8 ++++-- pcsx2/Frontend/GameList.cpp | 29 ++++++++++----------- pcsx2/Frontend/GameList.h | 6 ++++- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/pcsx2-qt/GameList/GameListRefreshThread.cpp b/pcsx2-qt/GameList/GameListRefreshThread.cpp index 9e0e6ea37c..89c809d066 100644 --- a/pcsx2-qt/GameList/GameListRefreshThread.cpp +++ b/pcsx2-qt/GameList/GameListRefreshThread.cpp @@ -122,6 +122,6 @@ void GameListRefreshThread::cancel() void GameListRefreshThread::run() { - GameList::Refresh(m_invalidate_cache, &m_progress); + GameList::Refresh(m_invalidate_cache, false, &m_progress); emit refreshComplete(); } diff --git a/pcsx2-qt/QtHost.cpp b/pcsx2-qt/QtHost.cpp index 3d3fbf2e1e..d36f133870 100644 --- a/pcsx2-qt/QtHost.cpp +++ b/pcsx2-qt/QtHost.cpp @@ -708,16 +708,20 @@ int main(int argc, char* argv[]) QtHost::HookSignals(); EmuThread::start(); - // Actually show the window, the emuthread might still be starting up at this point. + // Create all window objects, the emuthread might still be starting up at this point. main_window->initialize(); - // Skip scanning the game list when running in batch mode. + // When running in batch mode, ensure game list is loaded, but don't scan for any new files. if (!s_batch_mode) main_window->refreshGameList(false); + else + GameList::Refresh(false, true); + // Don't bother showing the window in no-gui mode. if (!s_nogui_mode) main_window->show(); + // Skip the update check if we're booting a game directly. if (autoboot) g_emu_thread->startVM(std::move(autoboot)); else diff --git a/pcsx2/Frontend/GameList.cpp b/pcsx2/Frontend/GameList.cpp index 6de514677e..a0b011f19c 100644 --- a/pcsx2/Frontend/GameList.cpp +++ b/pcsx2/Frontend/GameList.cpp @@ -52,8 +52,8 @@ namespace GameList static bool GetIsoListEntry(const std::string& path, GameList::Entry* entry); static bool GetGameListEntryFromCache(const std::string& path, GameList::Entry* entry); - static void ScanDirectory(const char* path, bool recursive, const std::vector& excluded_paths, - ProgressCallback* progress); + static void ScanDirectory( + const char* path, bool recursive, bool only_cache, const std::vector& excluded_paths, ProgressCallback* progress); static bool AddFileFromCache(const std::string& path, std::time_t timestamp); static bool ScanFile(std::string path, std::time_t timestamp); @@ -81,8 +81,7 @@ bool GameList::IsGameListLoaded() const char* GameList::EntryTypeToString(EntryType type) { - static std::array(EntryType::Count)> names = { - {"PS2Disc", "PS1Disc", "ELF", "Playlist"}}; + static std::array(EntryType::Count)> names = {{"PS2Disc", "PS1Disc", "ELF", "Playlist"}}; return names[static_cast(type)]; } @@ -94,11 +93,10 @@ const char* GameList::EntryTypeToDisplayString(EntryType type) const char* GameList::RegionToString(Region region) { - static std::array(Region::Count)> names = { - {"NTSC-B", "NTSC-C", "NTSC-HK", "NTSC-J", "NTSC-K", "NTSC-T", "NTSC-U", - "Other", - "PAL-A", "PAL-AF", "PAL-AU", "PAL-BE", "PAL-E", "PAL-F", "PAL-FI", "PAL-G", "PAL-GR", "PAL-I", "PAL-IN", "PAL-M", "PAL-NL", "PAL-NO", "PAL-P", "PAL-R", "PAL-S", "PAL-SC", "PAL-SW", "PAL-SWI", "PAL-UK"}}; - + static std::array(Region::Count)> names = {{"NTSC-B", "NTSC-C", "NTSC-HK", "NTSC-J", "NTSC-K", "NTSC-T", + "NTSC-U", "Other", "PAL-A", "PAL-AF", "PAL-AU", "PAL-BE", "PAL-E", "PAL-F", "PAL-FI", "PAL-G", "PAL-GR", "PAL-I", "PAL-IN", "PAL-M", + "PAL-NL", "PAL-NO", "PAL-P", "PAL-R", "PAL-S", "PAL-SC", "PAL-SW", "PAL-SWI", "PAL-UK"}}; + return names[static_cast(region)]; } @@ -536,8 +534,7 @@ static bool IsPathExcluded(const std::vector& excluded_paths, const return (std::find(excluded_paths.begin(), excluded_paths.end(), path) != excluded_paths.end()); } -void GameList::ScanDirectory(const char* path, bool recursive, const std::vector& excluded_paths, - ProgressCallback* progress) +void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache, const std::vector& excluded_paths, ProgressCallback* progress) { Console.WriteLn("Scanning %s%s", path, recursive ? " (recursively)" : ""); @@ -563,7 +560,9 @@ void GameList::ScanDirectory(const char* path, bool recursive, const std::vector { std::unique_lock lock(s_mutex); - if (GetEntryForPath(ffd.FileName.c_str()) || AddFileFromCache(ffd.FileName, ffd.ModificationTime)) + if (GetEntryForPath(ffd.FileName.c_str()) || + AddFileFromCache(ffd.FileName, ffd.ModificationTime) || + only_cache) { progress->IncrementProgressValue(); continue; @@ -679,7 +678,7 @@ u32 GameList::GetEntryCount() return static_cast(m_entries.size()); } -void GameList::Refresh(bool invalidate_cache, ProgressCallback* progress /* = nullptr */) +void GameList::Refresh(bool invalidate_cache, bool only_cache, ProgressCallback* progress /* = nullptr */) { m_game_list_loaded = true; @@ -714,7 +713,7 @@ void GameList::Refresh(bool invalidate_cache, ProgressCallback* progress /* = nu if (progress->IsCancelled()) break; - ScanDirectory(dir.c_str(), false, excluded_paths, progress); + ScanDirectory(dir.c_str(), false, only_cache, excluded_paths, progress); progress->SetProgressValue(++directory_counter); } for (const std::string& dir : recursive_dirs) @@ -722,7 +721,7 @@ void GameList::Refresh(bool invalidate_cache, ProgressCallback* progress /* = nu if (progress->IsCancelled()) break; - ScanDirectory(dir.c_str(), true, excluded_paths, progress); + ScanDirectory(dir.c_str(), true, only_cache, excluded_paths, progress); progress->SetProgressValue(++directory_counter); } } diff --git a/pcsx2/Frontend/GameList.h b/pcsx2/Frontend/GameList.h index 7cbfb9d277..48f80dd0e9 100644 --- a/pcsx2/Frontend/GameList.h +++ b/pcsx2/Frontend/GameList.h @@ -118,7 +118,11 @@ namespace GameList u32 GetEntryCount(); bool IsGameListLoaded(); - void Refresh(bool invalidate_cache, ProgressCallback* progress = nullptr); + + /// Populates the game list with files in the configured directories. + /// If invalidate_cache is set, all files will be re-scanned. + /// If only_cache is set, no new files will be scanned, only those present in the cache. + void Refresh(bool invalidate_cache, bool only_cache = false, ProgressCallback* progress = nullptr); std::string GetCoverImagePathForEntry(const Entry* entry); std::string GetCoverImagePath(const std::string& path, const std::string& code, const std::string& title);