Duckstation/src/frontend-common/game_list.h

170 lines
5.1 KiB
C
Raw Normal View History

#pragma once
#include "core/types.h"
#include "game_settings.h"
2020-01-10 03:31:12 +00:00
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
2019-11-30 15:27:01 +00:00
#include <vector>
class CDImage;
2020-01-08 03:37:43 +00:00
class ByteStream;
class ProgressCallback;
2019-12-31 06:17:17 +00:00
class SettingsInterface;
enum class GameListEntryType
{
Disc,
2020-08-15 09:54:33 +00:00
PSExe,
Playlist
};
2019-12-04 11:12:50 +00:00
enum class GameListCompatibilityRating
{
Unknown = 0,
DoesntBoot = 1,
CrashesInIntro = 2,
CrashesInGame = 3,
GraphicalAudioIssues = 4,
NoIssues = 5,
Count,
};
struct GameListDatabaseEntry
{
std::string code;
std::string title;
DiscRegion region;
};
struct GameListEntry
{
std::string path;
std::string code;
std::string title;
u64 total_size;
u64 last_modified_time;
DiscRegion region;
GameListEntryType type;
GameListCompatibilityRating compatibility_rating;
GameSettings::Entry settings;
};
struct GameListCompatibilityEntry
{
std::string code;
std::string title;
std::string version_tested;
std::string upscaling_issues;
std::string comments;
DiscRegion region;
GameListCompatibilityRating compatibility_rating;
};
class GameList
{
public:
using EntryList = std::vector<GameListEntry>;
GameList();
~GameList();
static const char* EntryTypeToString(GameListEntryType type);
static const char* EntryCompatibilityRatingToString(GameListCompatibilityRating rating);
/// Returns a string representation of a compatibility level.
static const char* GetGameListCompatibilityRatingString(GameListCompatibilityRating rating);
const EntryList& GetEntries() const { return m_entries; }
2019-11-30 15:27:01 +00:00
const u32 GetEntryCount() const { return static_cast<u32>(m_entries.size()); }
const GameListEntry* GetEntryForPath(const char* path) const;
const GameListDatabaseEntry* GetDatabaseEntryForCode(const std::string& code) const;
const GameListCompatibilityEntry* GetCompatibilityEntryForCode(const std::string& code) const;
void SetCacheFilename(std::string filename) { m_cache_filename = std::move(filename); }
void SetUserDatabaseFilename(std::string filename) { m_user_database_filename = std::move(filename); }
void SetUserCompatibilityListFilename(std::string filename) { m_user_compatibility_list_filename = std::move(filename); }
void SetUserGameSettingsFilename(std::string filename) { m_user_game_settings_filename = std::move(filename); }
void SetSearchDirectoriesFromSettings(SettingsInterface& si);
2019-12-31 06:17:17 +00:00
void AddDirectory(std::string path, bool recursive);
void Refresh(bool invalidate_cache, bool invalidate_database, ProgressCallback* progress = nullptr);
void UpdateCompatibilityEntry(GameListCompatibilityEntry new_entry, bool save_to_list = true);
static std::string ExportCompatibilityEntry(const GameListCompatibilityEntry* entry);
const GameSettings::Entry* GetGameSettings(const std::string& filename, const std::string& game_code);
void UpdateGameSettings(const std::string& filename, const std::string& game_code, const std::string& game_title,
const GameSettings::Entry& new_entry, bool save_to_list = true);
2020-11-27 13:56:09 +00:00
std::string GetCoverImagePathForEntry(const GameListEntry* entry) const;
std::string GetNewCoverImagePathForEntry(const GameListEntry* entry, const char* new_filename) const;
private:
2020-01-08 03:37:43 +00:00
enum : u32
{
GAME_LIST_CACHE_SIGNATURE = 0x45434C47,
GAME_LIST_CACHE_VERSION = 18
2020-01-08 03:37:43 +00:00
};
using DatabaseMap = std::unordered_map<std::string, GameListDatabaseEntry>;
using CacheMap = std::unordered_map<std::string, GameListEntry>;
using CompatibilityMap = std::unordered_map<std::string, GameListCompatibilityEntry>;
2019-12-31 06:17:17 +00:00
struct DirectoryEntry
{
std::string path;
bool recursive;
};
class RedumpDatVisitor;
class CompatibilityListVisitor;
GameListEntry* GetMutableEntryForPath(const char* path);
2019-12-04 11:12:50 +00:00
static bool GetExeListEntry(const char* path, GameListEntry* entry);
2020-08-15 09:54:33 +00:00
bool GetM3UListEntry(const char* path, GameListEntry* entry);
2020-01-08 03:37:43 +00:00
bool GetGameListEntry(const std::string& path, GameListEntry* entry);
bool GetGameListEntryFromCache(const std::string& path, GameListEntry* entry);
void ScanDirectory(const char* path, bool recursive, ProgressCallback* progress);
2020-01-08 03:37:43 +00:00
void LoadCache();
bool LoadEntriesFromCache(ByteStream* stream);
bool OpenCacheForWriting();
bool WriteEntryToCache(const GameListEntry* entry, ByteStream* stream);
void FlushCacheFileStream();
2020-01-08 03:37:43 +00:00
void CloseCacheFileStream();
void RewriteCacheFile();
2020-01-08 03:37:43 +00:00
void DeleteCacheFile();
void LoadDatabase();
void ClearDatabase();
void LoadCompatibilityList();
bool LoadCompatibilityListFromXML(const std::string& xml);
bool SaveCompatibilityDatabaseForEntry(const GameListCompatibilityEntry* entry);
void LoadGameSettings();
DatabaseMap m_database;
EntryList m_entries;
2020-01-08 03:37:43 +00:00
CacheMap m_cache_map;
CompatibilityMap m_compatibility_list;
GameSettings::Database m_game_settings;
2020-01-10 03:31:12 +00:00
std::unique_ptr<ByteStream> m_cache_write_stream;
2019-12-31 06:17:17 +00:00
std::vector<DirectoryEntry> m_search_directories;
2020-01-08 03:37:43 +00:00
std::string m_cache_filename;
std::string m_user_database_filename;
std::string m_user_compatibility_list_filename;
std::string m_user_game_settings_filename;
2020-01-08 03:37:43 +00:00
bool m_database_load_tried = false;
bool m_compatibility_list_load_tried = false;
bool m_game_settings_load_tried = false;
};