mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-17 22:25:37 +00:00
GameList: Move entry to global scope so it can be forward declared
This commit is contained in:
parent
183928b0f6
commit
82b4229f1b
|
@ -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<const char*, 2> names = {{"Disc", "PSExe"}};
|
||||
return names[static_cast<int>(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<u64>(CDImage::RAW_SECTOR_SIZE) * static_cast<u64>(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<u8>(ConsoleRegion::Count) || !ReadU8(stream, &type) ||
|
||||
type > static_cast<u8>(EntryType::PSExe))
|
||||
type > static_cast<u8>(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<ConsoleRegion>(region);
|
||||
ge.type = static_cast<EntryType>(type);
|
||||
ge.type = static_cast<GameListEntryType>(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();
|
||||
|
|
|
@ -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<std::string, GameDatabaseEntry>;
|
||||
|
||||
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<GameListEntry>;
|
||||
using CacheMap = std::unordered_map<std::string, GameListEntry>;
|
||||
|
||||
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<ConsoleRegion> GetRegionForImage(CDImage* cdi);
|
||||
static std::optional<ConsoleRegion> 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<u32>(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<std::string, GameDatabaseEntry>;
|
||||
using CacheMap = std::unordered_map<std::string, GameListEntry>;
|
||||
|
||||
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);
|
||||
|
|
|
@ -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<int>(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<int>(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#pragma once
|
||||
#include "core/game_list.h"
|
||||
#include <QtWidgets/QStackedWidget>
|
||||
#include <QtWidgets/QTableView>
|
||||
|
||||
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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue