GameList: Move entry to global scope so it can be forward declared

This commit is contained in:
Connor McLaughlin
2020-01-24 14:50:44 +10:00
parent 183928b0f6
commit 82b4229f1b
5 changed files with 66 additions and 48 deletions

View File

@ -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, &region) ||
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();

View File

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