2014-06-25 16:29:58 +00:00
|
|
|
#include "MetaData.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "Log.h"
|
|
|
|
#include "Util.h"
|
2017-11-10 19:16:42 +00:00
|
|
|
#include <pugixml/src/pugixml.hpp>
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
MetaDataDecl gameDecls[] = {
|
|
|
|
// key, type, default, statistic, name in GuiMetaDataEd, prompt in GuiMetaDataEd
|
|
|
|
{"name", MD_STRING, "", false, "name", "enter game name"},
|
|
|
|
{"desc", MD_MULTILINE_STRING, "", false, "description", "enter description"},
|
|
|
|
{"image", MD_PATH, "", false, "image", "enter path to image"},
|
|
|
|
{"video", MD_PATH , "", false, "video", "enter path to video"},
|
|
|
|
{"marquee", MD_PATH, "", false, "marquee", "enter path to marquee"},
|
|
|
|
{"thumbnail", MD_PATH, "", false, "thumbnail", "enter path to thumbnail"},
|
|
|
|
{"rating", MD_RATING, "0.000000", false, "rating", "enter rating"},
|
|
|
|
{"releasedate", MD_DATE, "not-a-date-time", false, "release date", "enter release date"},
|
|
|
|
{"developer", MD_STRING, "unknown", false, "developer", "enter game developer"},
|
|
|
|
{"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher"},
|
|
|
|
{"genre", MD_STRING, "unknown", false, "genre", "enter game genre"},
|
|
|
|
{"players", MD_INT, "1", false, "players", "enter number of players"},
|
|
|
|
{"favorite", MD_BOOL, "false", false, "favorite", "enter favorite off/on"},
|
2017-09-08 13:20:07 +00:00
|
|
|
{"hidden", MD_BOOL, "false", false, "hidden", "enter hidden off/on" },
|
|
|
|
{"kidgame", MD_BOOL, "false", false, "kidgame", "enter kidgame off/on" },
|
2017-06-12 16:38:59 +00:00
|
|
|
{"playcount", MD_INT, "0", true, "play count", "enter number of times played"},
|
|
|
|
{"lastplayed", MD_TIME, "0", true, "last played", "enter last played date"}
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
const std::vector<MetaDataDecl> gameMDD(gameDecls, gameDecls + sizeof(gameDecls) / sizeof(gameDecls[0]));
|
|
|
|
|
2017-06-12 16:38:59 +00:00
|
|
|
MetaDataDecl folderDecls[] = {
|
|
|
|
{"name", MD_STRING, "", false, "name", "enter game name"},
|
|
|
|
{"desc", MD_MULTILINE_STRING, "", false, "description", "enter description"},
|
|
|
|
{"image", MD_PATH, "", false, "image", "enter path to image"},
|
|
|
|
{"thumbnail", MD_PATH, "", false, "thumbnail", "enter path to thumbnail"},
|
|
|
|
{"video", MD_PATH, "", false, "video", "enter path to video"},
|
|
|
|
{"marquee", MD_PATH, "", false, "marquee", "enter path to marquee"},
|
|
|
|
{"rating", MD_RATING, "0.000000", false, "rating", "enter rating"},
|
|
|
|
{"releasedate", MD_DATE, "not-a-date-time", false, "release date", "enter release date"},
|
|
|
|
{"developer", MD_STRING, "unknown", false, "developer", "enter game developer"},
|
|
|
|
{"publisher", MD_STRING, "unknown", false, "publisher", "enter game publisher"},
|
|
|
|
{"genre", MD_STRING, "unknown", false, "genre", "enter game genre"},
|
|
|
|
{"players", MD_INT, "1", false, "players", "enter number of players"}
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
const std::vector<MetaDataDecl> folderMDD(folderDecls, folderDecls + sizeof(folderDecls) / sizeof(folderDecls[0]));
|
|
|
|
|
|
|
|
const std::vector<MetaDataDecl>& getMDDByType(MetaDataListType type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case GAME_METADATA:
|
|
|
|
return gameMDD;
|
|
|
|
case FOLDER_METADATA:
|
|
|
|
return folderMDD;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogError) << "Invalid MDD type";
|
|
|
|
return gameMDD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MetaDataList::MetaDataList(MetaDataListType type)
|
2016-12-19 15:59:40 +00:00
|
|
|
: mType(type), mWasChanged(false)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
const std::vector<MetaDataDecl>& mdd = getMDD();
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto iter = mdd.cbegin(); iter != mdd.cend(); iter++)
|
2014-06-25 16:29:58 +00:00
|
|
|
set(iter->key, iter->defaultValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-04 23:30:25 +00:00
|
|
|
MetaDataList MetaDataList::createFromXML(MetaDataListType type, pugi::xml_node& node, const boost::filesystem::path& relativeTo)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
MetaDataList mdl(type);
|
|
|
|
|
|
|
|
const std::vector<MetaDataDecl>& mdd = mdl.getMDD();
|
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto iter = mdd.cbegin(); iter != mdd.cend(); iter++)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
pugi::xml_node md = node.child(iter->key.c_str());
|
|
|
|
if(md)
|
|
|
|
{
|
|
|
|
// if it's a path, resolve relative paths
|
|
|
|
std::string value = md.text().get();
|
2016-12-04 23:47:34 +00:00
|
|
|
if (iter->type == MD_PATH)
|
|
|
|
{
|
2014-06-25 16:29:58 +00:00
|
|
|
value = resolvePath(value, relativeTo, true).generic_string();
|
2016-12-04 23:47:34 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
mdl.set(iter->key, value);
|
|
|
|
}else{
|
|
|
|
mdl.set(iter->key, iter->defaultValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mdl;
|
|
|
|
}
|
|
|
|
|
2017-12-04 23:30:25 +00:00
|
|
|
void MetaDataList::appendToXML(pugi::xml_node& parent, bool ignoreDefaults, const boost::filesystem::path& relativeTo) const
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
const std::vector<MetaDataDecl>& mdd = getMDD();
|
|
|
|
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto mddIter = mdd.cbegin(); mddIter != mdd.cend(); mddIter++)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
auto mapIter = mMap.find(mddIter->key);
|
2017-11-11 14:56:22 +00:00
|
|
|
if(mapIter != mMap.cend())
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
// we have this value!
|
|
|
|
// if it's just the default (and we ignore defaults), don't write it
|
|
|
|
if(ignoreDefaults && mapIter->second == mddIter->defaultValue)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// try and make paths relative if we can
|
|
|
|
std::string value = mapIter->second;
|
2016-12-04 23:47:34 +00:00
|
|
|
if (mddIter->type == MD_PATH)
|
2014-06-25 16:29:58 +00:00
|
|
|
value = makeRelativePath(value, relativeTo, true).generic_string();
|
|
|
|
|
|
|
|
parent.append_child(mapIter->first.c_str()).text().set(value.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetaDataList::set(const std::string& key, const std::string& value)
|
|
|
|
{
|
|
|
|
mMap[key] = value;
|
2016-12-19 15:59:40 +00:00
|
|
|
mWasChanged = true;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& MetaDataList::get(const std::string& key) const
|
|
|
|
{
|
|
|
|
return mMap.at(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
int MetaDataList::getInt(const std::string& key) const
|
|
|
|
{
|
|
|
|
return atoi(get(key).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
float MetaDataList::getFloat(const std::string& key) const
|
|
|
|
{
|
|
|
|
return (float)atof(get(key).c_str());
|
|
|
|
}
|
|
|
|
|
2016-09-03 20:45:52 +00:00
|
|
|
bool MetaDataList::isDefault()
|
|
|
|
{
|
2016-12-20 14:46:55 +00:00
|
|
|
const std::vector<MetaDataDecl>& mdd = getMDD();
|
|
|
|
|
2017-10-18 14:19:32 +00:00
|
|
|
for (unsigned int i = 1; i < mMap.size(); i++) {
|
2016-12-20 14:46:55 +00:00
|
|
|
if (mMap.at(mdd[i].key) != mdd[i].defaultValue) return false;
|
2016-09-03 20:45:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-19 15:59:40 +00:00
|
|
|
|
|
|
|
bool MetaDataList::wasChanged() const
|
|
|
|
{
|
|
|
|
return mWasChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetaDataList::resetChangedFlag()
|
|
|
|
{
|
|
|
|
mWasChanged = false;
|
|
|
|
}
|