2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// MetaData.h
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Static data for default metadata values as well as functions
|
|
|
|
// to read and write metadata from the gamelist files.
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_APP_META_DATA_H
|
|
|
|
#define ES_APP_META_DATA_H
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-11-26 17:53:00 +00:00
|
|
|
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
|
2020-08-17 17:15:05 +00:00
|
|
|
#include <sstream>
|
|
|
|
#endif
|
|
|
|
|
2017-11-22 21:01:12 +00:00
|
|
|
#include <map>
|
2020-11-28 21:27:00 +00:00
|
|
|
#include <string>
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <vector>
|
2017-11-10 19:16:42 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
namespace pugi
|
|
|
|
{
|
|
|
|
class xml_node;
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
enum MetaDataType {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Generic types.
|
|
|
|
MD_STRING,
|
|
|
|
MD_INT,
|
|
|
|
MD_FLOAT,
|
|
|
|
MD_BOOL,
|
|
|
|
|
|
|
|
// Specialized types.
|
|
|
|
MD_MULTILINE_STRING,
|
2021-10-23 17:08:32 +00:00
|
|
|
MD_CONTROLLER,
|
2021-09-04 09:21:55 +00:00
|
|
|
MD_ALT_EMULATOR,
|
2022-04-12 16:35:57 +00:00
|
|
|
MD_FOLDER_LINK,
|
2020-06-21 12:25:28 +00:00
|
|
|
MD_PATH,
|
|
|
|
MD_RATING,
|
|
|
|
MD_DATE,
|
|
|
|
MD_TIME // Used for lastplayed.
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
struct MetaDataDecl {
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string key;
|
|
|
|
MetaDataType type;
|
|
|
|
std::string defaultValue;
|
2021-07-07 18:03:42 +00:00
|
|
|
// If true, ignore values for this metadata.
|
2020-06-21 12:25:28 +00:00
|
|
|
bool isStatistic;
|
|
|
|
// Displayed as this in editors.
|
|
|
|
std::string displayName;
|
|
|
|
// Phrase displayed in editors when prompted to enter value (currently only for strings).
|
|
|
|
std::string displayPrompt;
|
|
|
|
// If set to false, the scraper will not overwrite this metadata.
|
|
|
|
bool shouldScrape;
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
enum MetaDataListType {
|
2022-06-05 10:36:55 +00:00
|
|
|
GAME_METADATA,
|
2020-06-21 12:25:28 +00:00
|
|
|
FOLDER_METADATA
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const std::vector<MetaDataDecl>& getMDDByType(MetaDataListType type);
|
|
|
|
|
|
|
|
class MetaDataList
|
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
static MetaDataList createFromXML(MetaDataListType type,
|
2021-07-07 18:03:42 +00:00
|
|
|
pugi::xml_node& node,
|
|
|
|
const std::string& relativeTo);
|
|
|
|
void appendToXML(pugi::xml_node& parent,
|
|
|
|
bool ignoreDefaults,
|
|
|
|
const std::string& relativeTo) const;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
MetaDataList(MetaDataListType type);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void set(const std::string& key, const std::string& value);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string& get(const std::string& key) const;
|
|
|
|
int getInt(const std::string& key) const;
|
|
|
|
float getFloat(const std::string& key) const;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool wasChanged() const;
|
|
|
|
void resetChangedFlag();
|
2016-12-19 15:59:40 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
MetaDataListType getType() const { return mType; }
|
|
|
|
const std::vector<MetaDataDecl>& getMDD() const { return getMDDByType(getType()); }
|
|
|
|
const std::vector<MetaDataDecl>& getMDD(MetaDataListType type) const
|
|
|
|
{
|
|
|
|
return getMDDByType(type);
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
MetaDataListType mType;
|
|
|
|
std::map<std::string, std::string> mMap;
|
|
|
|
std::string mNoResult = "";
|
|
|
|
bool mWasChanged;
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_APP_META_DATA_H
|