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.
This commit is contained in:
Connor McLaughlin 2022-06-23 21:58:14 +10:00 committed by refractionpcsx2
parent 5fc07180dd
commit e87d507c0c
4 changed files with 26 additions and 19 deletions

View File

@ -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();
}

View File

@ -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

View File

@ -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<std::string>& excluded_paths,
ProgressCallback* progress);
static void ScanDirectory(
const char* path, bool recursive, bool only_cache, const std::vector<std::string>& 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<const char*, static_cast<int>(EntryType::Count)> names = {
{"PS2Disc", "PS1Disc", "ELF", "Playlist"}};
static std::array<const char*, static_cast<int>(EntryType::Count)> names = {{"PS2Disc", "PS1Disc", "ELF", "Playlist"}};
return names[static_cast<int>(type)];
}
@ -94,11 +93,10 @@ const char* GameList::EntryTypeToDisplayString(EntryType type)
const char* GameList::RegionToString(Region region)
{
static std::array<const char*, static_cast<int>(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<const char*, static_cast<int>(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<int>(region)];
}
@ -536,8 +534,7 @@ static bool IsPathExcluded(const std::vector<std::string>& 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<std::string>& excluded_paths,
ProgressCallback* progress)
void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache, const std::vector<std::string>& 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<u32>(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);
}
}

View File

@ -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);