From 82b4229f1b8e1796fc6548a71b54d683bec0d502 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 24 Jan 2020 14:50:44 +1000 Subject: [PATCH] GameList: Move entry to global scope so it can be forward declared --- src/core/game_list.cpp | 26 +++++++++--- src/core/game_list.h | 61 ++++++++++++++------------- src/duckstation-qt/gamelistwidget.cpp | 15 ++++--- src/duckstation-qt/gamelistwidget.h | 8 ++-- src/duckstation-qt/mainwindow.cpp | 4 +- 5 files changed, 66 insertions(+), 48 deletions(-) diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index cf1a9b30c..0b3554e30 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -20,7 +20,7 @@ GameList::GameList() = default; GameList::~GameList() = default; -const char* GameList::EntryTypeToString(GameList::EntryType type) +const char* GameList::EntryTypeToString(GameListEntryType type) { static std::array names = {{"Disc", "PSExe"}}; return names[static_cast(type)]; @@ -266,7 +266,7 @@ bool GameList::GetExeListEntry(const char* path, GameListEntry* entry) entry->region = ConsoleRegion::NTSC_U; entry->total_size = ZeroExtend64(file_size); entry->last_modified_time = ffd.ModificationTime.AsUnixTimestamp(); - entry->type = EntryType::PSExe; + entry->type = GameListEntryType::PSExe; return true; } @@ -285,7 +285,7 @@ bool GameList::GetGameListEntry(const std::string& path, GameListEntry* entry) entry->region = GetRegionFromSystemArea(cdi.get()).value_or(GetRegionForCode(entry->code).value_or(ConsoleRegion::NTSC_U)); entry->total_size = static_cast(CDImage::RAW_SECTOR_SIZE) * static_cast(cdi->GetLBACount()); - entry->type = EntryType::Disc; + entry->type = GameListEntryType::Disc; cdi.reset(); if (entry->code.empty()) @@ -421,7 +421,7 @@ bool GameList::LoadEntriesFromCache(ByteStream* stream) if (!ReadString(stream, &path) || !ReadString(stream, &code) || !ReadString(stream, &title) || !ReadU64(stream, &total_size) || !ReadU64(stream, &last_modified_time) || !ReadU8(stream, ®ion) || region >= static_cast(ConsoleRegion::Count) || !ReadU8(stream, &type) || - type > static_cast(EntryType::PSExe)) + type > static_cast(GameListEntryType::PSExe)) { Log_WarningPrintf("Game list cache entry is corrupted"); return false; @@ -434,7 +434,7 @@ bool GameList::LoadEntriesFromCache(ByteStream* stream) ge.total_size = total_size; ge.last_modified_time = last_modified_time; ge.region = static_cast(region); - ge.type = static_cast(type); + ge.type = static_cast(type); auto iter = m_cache_map.find(ge.path); if (iter != m_cache_map.end()) @@ -566,10 +566,10 @@ void GameList::ScanDirectory(const char* path, bool recursive) } } -class RedumpDatVisitor final : public tinyxml2::XMLVisitor +class GameList::RedumpDatVisitor final : public tinyxml2::XMLVisitor { public: - RedumpDatVisitor(GameList::DatabaseMap& database) : m_database(database) {} + RedumpDatVisitor(DatabaseMap& database) : m_database(database) {} static std::string FixupSerial(const std::string_view str) { @@ -657,6 +657,18 @@ void GameList::AddDirectory(std::string path, bool recursive) m_search_directories.push_back({path, recursive}); } +const GameListEntry* GameList::GetEntryForPath(const char* path) const +{ + const size_t path_length = std::strlen(path); + for (const GameListEntry& entry : m_entries) + { + if (entry.path.size() == path_length && StringUtil::Strcasecmp(entry.path.c_str(), path)) + return &entry; + } + + return nullptr; +} + void GameList::SetPathsFromSettings(SettingsInterface& si) { m_search_directories.clear(); diff --git a/src/core/game_list.h b/src/core/game_list.h index a67aa51f9..bf7c8ee13 100644 --- a/src/core/game_list.h +++ b/src/core/game_list.h @@ -12,42 +12,32 @@ class ByteStream; class SettingsInterface; +enum class GameListEntryType +{ + Disc, + PSExe +}; + +struct GameListEntry +{ + std::string path; + std::string code; + std::string title; + u64 total_size; + u64 last_modified_time; + ConsoleRegion region; + GameListEntryType type; +}; + class GameList { public: - struct GameDatabaseEntry - { - std::string code; - std::string title; - ConsoleRegion region; - }; - - using DatabaseMap = std::unordered_map; - - enum class EntryType - { - Disc, - PSExe - }; - - struct GameListEntry - { - std::string path; - std::string code; - std::string title; - u64 total_size; - u64 last_modified_time; - ConsoleRegion region; - EntryType type; - }; - using EntryList = std::vector; - using CacheMap = std::unordered_map; GameList(); ~GameList(); - static const char* EntryTypeToString(EntryType type); + static const char* EntryTypeToString(GameListEntryType type); /// Returns true if the filename is a PlayStation executable we can inject. static bool IsExeFileName(const char* path); @@ -59,10 +49,11 @@ public: static std::optional GetRegionForImage(CDImage* cdi); static std::optional GetRegionForPath(const char* image_path); - const DatabaseMap& GetDatabase() const { return m_database; } const EntryList& GetEntries() const { return m_entries; } const u32 GetEntryCount() const { return static_cast(m_entries.size()); } + const GameListEntry* GetEntryForPath(const char* path) const; + void SetPathsFromSettings(SettingsInterface& si); void AddDirectory(std::string path, bool recursive); void Refresh(bool invalidate_cache, bool invalidate_database); @@ -74,12 +65,24 @@ private: GAME_LIST_CACHE_VERSION = 2 }; + struct GameDatabaseEntry + { + std::string code; + std::string title; + ConsoleRegion region; + }; + + using DatabaseMap = std::unordered_map; + using CacheMap = std::unordered_map; + struct DirectoryEntry { std::string path; bool recursive; }; + class RedumpDatVisitor; + static bool GetExeListEntry(const char* path, GameListEntry* entry); bool GetGameListEntry(const std::string& path, GameListEntry* entry); diff --git a/src/duckstation-qt/gamelistwidget.cpp b/src/duckstation-qt/gamelistwidget.cpp index 9b045e6a2..ef80d0da0 100644 --- a/src/duckstation-qt/gamelistwidget.cpp +++ b/src/duckstation-qt/gamelistwidget.cpp @@ -1,4 +1,5 @@ #include "gamelistwidget.h" +#include "core/game_list.h" #include "core/settings.h" #include "qthostinterface.h" #include "qtutils.h" @@ -52,7 +53,7 @@ public: if (row < 0 || row >= static_cast(m_game_list->GetEntryCount())) return {}; - const GameList::GameListEntry& ge = m_game_list->GetEntries()[row]; + const GameListEntry& ge = m_game_list->GetEntries()[row]; switch (role) { @@ -106,9 +107,9 @@ public: { switch (ge.type) { - case GameList::EntryType::Disc: + case GameListEntryType::Disc: return m_type_disc_pixmap; - case GameList::EntryType::PSExe: + case GameListEntryType::PSExe: default: return m_type_exe_pixmap; } @@ -186,8 +187,8 @@ public: return false; } - const GameList::GameListEntry& left = m_game_list->GetEntries().at(left_row); - const GameList::GameListEntry& right = m_game_list->GetEntries().at(right_row); + const GameListEntry& left = m_game_list->GetEntries().at(left_row); + const GameListEntry& right = m_game_list->GetEntries().at(right_row); return ascending ? (left.title < right.title) : (right.title < left.title); } @@ -287,7 +288,7 @@ void GameListWidget::onTableViewItemDoubleClicked(const QModelIndex& index) if (!source_index.isValid() || source_index.row() >= static_cast(m_game_list->GetEntryCount())) return; - const GameList::GameListEntry& entry = m_game_list->GetEntries().at(source_index.row()); + const GameListEntry& entry = m_game_list->GetEntries().at(source_index.row()); emit bootEntryRequested(&entry); } @@ -300,7 +301,7 @@ void GameListWidget::onSelectionModelCurrentChanged(const QModelIndex& current, return; } - const GameList::GameListEntry& entry = m_game_list->GetEntries().at(source_index.row()); + const GameListEntry& entry = m_game_list->GetEntries().at(source_index.row()); emit entrySelected(&entry); } diff --git a/src/duckstation-qt/gamelistwidget.h b/src/duckstation-qt/gamelistwidget.h index b59c3d76b..03d25a178 100644 --- a/src/duckstation-qt/gamelistwidget.h +++ b/src/duckstation-qt/gamelistwidget.h @@ -1,8 +1,10 @@ #pragma once -#include "core/game_list.h" #include #include +class GameList; +struct GameListEntry; + class GameListModel; class GameListSortModel; @@ -19,8 +21,8 @@ public: void initialize(QtHostInterface* host_interface); Q_SIGNALS: - void entrySelected(const GameList::GameListEntry* entry); - void bootEntryRequested(const GameList::GameListEntry* entry); + void entrySelected(const GameListEntry* entry); + void bootEntryRequested(const GameListEntry* entry); private Q_SLOTS: void onGameListRefreshed(); diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 0c70a2f8f..0b61f6636 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -293,7 +293,7 @@ void MainWindow::connectSignals() connect(m_host_interface, &QtHostInterface::recreateDisplayWidgetRequested, this, &MainWindow::recreateDisplayWidget, Qt::BlockingQueuedConnection); - connect(m_game_list_widget, &GameListWidget::bootEntryRequested, [this](const GameList::GameListEntry* entry) { + connect(m_game_list_widget, &GameListWidget::bootEntryRequested, [this](const GameListEntry* entry) { // if we're not running, boot the system, otherwise swap discs QString path = QString::fromStdString(entry->path); if (!m_emulation_running) @@ -307,7 +307,7 @@ void MainWindow::connectSignals() switchToEmulationView(); } }); - connect(m_game_list_widget, &GameListWidget::entrySelected, [this](const GameList::GameListEntry* entry) { + connect(m_game_list_widget, &GameListWidget::entrySelected, [this](const GameListEntry* entry) { if (!entry) { m_ui.statusBar->clearMessage();