2013-06-17 19:01:03 +00:00
|
|
|
#include "Settings.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2018-01-09 22:55:09 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2013-06-17 19:01:03 +00:00
|
|
|
#include "Log.h"
|
2018-01-30 00:49:08 +00:00
|
|
|
#include "Scripting.h"
|
2013-06-19 21:02:42 +00:00
|
|
|
#include "platform.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <pugixml/src/pugixml.hpp>
|
2018-01-09 22:55:09 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2013-06-17 19:01:03 +00:00
|
|
|
|
|
|
|
Settings* Settings::sInstance = NULL;
|
|
|
|
|
2014-06-05 20:43:19 +00:00
|
|
|
// these values are NOT saved to es_settings.xml
|
|
|
|
// since they're set through command-line arguments, and not the in-program settings menu
|
2017-11-03 00:33:08 +00:00
|
|
|
std::vector<const char*> settings_dont_save {
|
|
|
|
{ "Debug" },
|
|
|
|
{ "DebugGrid" },
|
|
|
|
{ "DebugText" },
|
2018-01-23 00:31:18 +00:00
|
|
|
{ "DebugImage" },
|
2017-11-03 00:33:08 +00:00
|
|
|
{ "ForceKid" },
|
|
|
|
{ "ForceKiosk" },
|
|
|
|
{ "IgnoreGamelist" },
|
|
|
|
{ "HideConsole" },
|
|
|
|
{ "ShowExit" },
|
|
|
|
{ "SplashScreen" },
|
2019-01-31 20:19:34 +00:00
|
|
|
{ "SplashScreenProgress" },
|
2017-11-03 00:33:08 +00:00
|
|
|
{ "VSync" },
|
2019-03-08 23:39:43 +00:00
|
|
|
{ "FullscreenBorderless" },
|
2017-12-01 17:42:27 +00:00
|
|
|
{ "Windowed" },
|
|
|
|
{ "WindowWidth" },
|
|
|
|
{ "WindowHeight" },
|
|
|
|
{ "ScreenWidth" },
|
|
|
|
{ "ScreenHeight" },
|
|
|
|
{ "ScreenOffsetX" },
|
2018-01-18 23:50:15 +00:00
|
|
|
{ "ScreenOffsetY" },
|
2019-08-25 15:23:02 +00:00
|
|
|
{ "ScreenRotate" }
|
2017-11-03 00:33:08 +00:00
|
|
|
};
|
2014-06-05 20:43:19 +00:00
|
|
|
|
2013-10-06 02:56:06 +00:00
|
|
|
Settings::Settings()
|
2013-06-17 19:01:03 +00:00
|
|
|
{
|
|
|
|
setDefaults();
|
2013-06-19 21:02:42 +00:00
|
|
|
loadFile();
|
2013-06-17 19:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Settings* Settings::getInstance()
|
|
|
|
{
|
|
|
|
if(sInstance == NULL)
|
|
|
|
sInstance = new Settings();
|
|
|
|
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setDefaults()
|
|
|
|
{
|
|
|
|
mBoolMap.clear();
|
|
|
|
mIntMap.clear();
|
|
|
|
|
2015-01-14 01:36:25 +00:00
|
|
|
mBoolMap["BackgroundJoystickInput"] = false;
|
2014-03-08 19:00:18 +00:00
|
|
|
mBoolMap["ParseGamelistOnly"] = false;
|
2017-07-24 23:12:40 +00:00
|
|
|
mBoolMap["ShowHiddenFiles"] = false;
|
2014-03-08 19:00:18 +00:00
|
|
|
mBoolMap["DrawFramerate"] = false;
|
|
|
|
mBoolMap["ShowExit"] = true;
|
2019-03-08 23:39:43 +00:00
|
|
|
mBoolMap["FullscreenBorderless"] = false;
|
2014-03-08 19:00:18 +00:00
|
|
|
mBoolMap["Windowed"] = false;
|
2017-01-12 19:17:53 +00:00
|
|
|
mBoolMap["SplashScreen"] = true;
|
2019-01-31 20:19:34 +00:00
|
|
|
mBoolMap["SplashScreenProgress"] = true;
|
2017-10-24 15:38:25 +00:00
|
|
|
mStringMap["StartupSystem"] = "";
|
2014-11-22 17:00:11 +00:00
|
|
|
|
|
|
|
mBoolMap["VSync"] = true;
|
|
|
|
|
2014-03-08 19:00:18 +00:00
|
|
|
mBoolMap["EnableSounds"] = true;
|
|
|
|
mBoolMap["ShowHelpPrompts"] = true;
|
2013-10-16 22:05:02 +00:00
|
|
|
mBoolMap["ScrapeRatings"] = true;
|
2014-04-04 19:12:28 +00:00
|
|
|
mBoolMap["IgnoreGamelist"] = false;
|
2014-11-25 02:49:11 +00:00
|
|
|
mBoolMap["HideConsole"] = true;
|
2014-05-15 02:31:26 +00:00
|
|
|
mBoolMap["QuickSystemSelect"] = true;
|
2017-06-28 16:50:37 +00:00
|
|
|
mBoolMap["MoveCarousel"] = true;
|
2013-06-17 19:01:03 +00:00
|
|
|
|
2014-03-25 22:46:58 +00:00
|
|
|
mBoolMap["Debug"] = false;
|
|
|
|
mBoolMap["DebugGrid"] = false;
|
2014-04-05 17:48:38 +00:00
|
|
|
mBoolMap["DebugText"] = false;
|
2018-01-27 00:11:32 +00:00
|
|
|
mBoolMap["DebugImage"] = false;
|
2014-03-25 22:46:58 +00:00
|
|
|
|
2014-05-28 16:31:58 +00:00
|
|
|
mIntMap["ScreenSaverTime"] = 5*60*1000; // 5 minutes
|
2013-10-16 22:05:02 +00:00
|
|
|
mIntMap["ScraperResizeWidth"] = 400;
|
2013-10-05 20:28:59 +00:00
|
|
|
mIntMap["ScraperResizeHeight"] = 0;
|
2017-08-28 10:08:56 +00:00
|
|
|
#ifdef _RPI_
|
|
|
|
mIntMap["MaxVRAM"] = 80;
|
|
|
|
#else
|
|
|
|
mIntMap["MaxVRAM"] = 100;
|
|
|
|
#endif
|
2013-07-02 21:14:33 +00:00
|
|
|
|
2014-03-22 16:44:57 +00:00
|
|
|
mStringMap["TransitionStyle"] = "fade";
|
2014-05-01 02:12:45 +00:00
|
|
|
mStringMap["ThemeSet"] = "";
|
2014-05-28 16:31:58 +00:00
|
|
|
mStringMap["ScreenSaverBehavior"] = "dim";
|
2014-06-03 23:30:03 +00:00
|
|
|
mStringMap["Scraper"] = "TheGamesDB";
|
2017-03-24 19:30:20 +00:00
|
|
|
mStringMap["GamelistViewStyle"] = "automatic";
|
2019-08-24 14:22:02 +00:00
|
|
|
mStringMap["SaveGamelistsMode"] = "on exit";
|
2017-01-25 15:00:56 +00:00
|
|
|
|
2017-06-01 20:08:44 +00:00
|
|
|
mBoolMap["ScreenSaverControls"] = true;
|
|
|
|
mStringMap["ScreenSaverGameInfo"] = "never";
|
|
|
|
mBoolMap["StretchVideoOnScreenSaver"] = false;
|
2017-08-11 17:03:12 +00:00
|
|
|
mStringMap["PowerSaverMode"] = "disabled";
|
2017-06-01 20:08:44 +00:00
|
|
|
|
2017-09-09 03:45:50 +00:00
|
|
|
mIntMap["ScreenSaverSwapImageTimeout"] = 10000;
|
|
|
|
mBoolMap["SlideshowScreenSaverStretch"] = false;
|
2018-01-27 20:04:08 +00:00
|
|
|
mStringMap["SlideshowScreenSaverBackgroundAudioFile"] = Utils::FileSystem::getHomePath() + "/.emulationstation/slideshow/audio/slideshow_bg.wav";
|
2017-09-09 03:45:50 +00:00
|
|
|
mBoolMap["SlideshowScreenSaverCustomImageSource"] = false;
|
2018-01-27 20:04:08 +00:00
|
|
|
mStringMap["SlideshowScreenSaverImageDir"] = Utils::FileSystem::getHomePath() + "/.emulationstation/slideshow/image";
|
2017-09-09 03:45:50 +00:00
|
|
|
mStringMap["SlideshowScreenSaverImageFilter"] = ".png,.jpg";
|
|
|
|
mBoolMap["SlideshowScreenSaverRecurse"] = false;
|
|
|
|
|
2017-01-25 15:00:56 +00:00
|
|
|
// This setting only applies to raspberry pi but set it for all platforms so
|
|
|
|
// we don't get a warning if we encounter it on a different platform
|
|
|
|
mBoolMap["VideoOmxPlayer"] = false;
|
2017-06-01 20:08:44 +00:00
|
|
|
#ifdef _RPI_
|
|
|
|
// we're defaulting to OMX Player for full screen video on the Pi
|
|
|
|
mBoolMap["ScreenSaverOmxPlayer"] = true;
|
2019-06-19 17:51:32 +00:00
|
|
|
// use OMX Player defaults
|
|
|
|
mStringMap["SubtitleFont"] = "/usr/share/fonts/truetype/freefont/FreeSans.ttf";
|
|
|
|
mStringMap["SubtitleItalicFont"] = "/usr/share/fonts/truetype/freefont/FreeSansOblique.ttf";
|
|
|
|
mIntMap["SubtitleSize"] = 55;
|
|
|
|
mStringMap["SubtitleAlignment"] = "left";
|
2017-06-01 20:08:44 +00:00
|
|
|
#else
|
|
|
|
mBoolMap["ScreenSaverOmxPlayer"] = false;
|
|
|
|
#endif
|
|
|
|
|
2017-08-23 08:21:31 +00:00
|
|
|
mIntMap["ScreenSaverSwapVideoTimeout"] = 30000;
|
|
|
|
|
2017-03-25 17:02:28 +00:00
|
|
|
mBoolMap["VideoAudio"] = true;
|
2017-06-01 20:08:44 +00:00
|
|
|
mBoolMap["CaptionsCompatibility"] = true;
|
2017-06-02 15:58:44 +00:00
|
|
|
// Audio out device for Video playback using OMX player.
|
|
|
|
mStringMap["OMXAudioDev"] = "both";
|
2017-06-12 16:38:59 +00:00
|
|
|
mStringMap["CollectionSystemsAuto"] = "";
|
2017-07-18 09:45:50 +00:00
|
|
|
mStringMap["CollectionSystemsCustom"] = "";
|
2019-07-11 06:38:23 +00:00
|
|
|
mBoolMap["CollectionShowSystemInfo"] = true;
|
2017-07-18 09:45:50 +00:00
|
|
|
mBoolMap["SortAllSystems"] = false;
|
|
|
|
mBoolMap["UseCustomCollectionsSystem"] = true;
|
2017-06-02 15:58:44 +00:00
|
|
|
|
2019-02-08 21:35:50 +00:00
|
|
|
mBoolMap["LocalArt"] = false;
|
|
|
|
|
2017-06-02 15:58:44 +00:00
|
|
|
// Audio out device for volume control
|
|
|
|
#ifdef _RPI_
|
|
|
|
mStringMap["AudioDevice"] = "PCM";
|
|
|
|
#else
|
|
|
|
mStringMap["AudioDevice"] = "Master";
|
|
|
|
#endif
|
2017-03-25 17:02:28 +00:00
|
|
|
|
2019-01-25 13:48:03 +00:00
|
|
|
mStringMap["AudioCard"] = "default";
|
2017-09-08 14:49:47 +00:00
|
|
|
mStringMap["UIMode"] = "Full";
|
|
|
|
mStringMap["UIMode_passkey"] = "uuddlrlrba";
|
|
|
|
mBoolMap["ForceKiosk"] = false;
|
2017-09-08 13:20:07 +00:00
|
|
|
mBoolMap["ForceKid"] = false;
|
2018-05-10 20:08:04 +00:00
|
|
|
mBoolMap["ForceDisableFilters"] = false;
|
2017-12-01 17:42:27 +00:00
|
|
|
|
|
|
|
mIntMap["WindowWidth"] = 0;
|
|
|
|
mIntMap["WindowHeight"] = 0;
|
|
|
|
mIntMap["ScreenWidth"] = 0;
|
|
|
|
mIntMap["ScreenHeight"] = 0;
|
|
|
|
mIntMap["ScreenOffsetX"] = 0;
|
|
|
|
mIntMap["ScreenOffsetY"] = 0;
|
2018-01-18 23:50:15 +00:00
|
|
|
mIntMap["ScreenRotate"] = 0;
|
2013-06-17 19:01:03 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 21:02:42 +00:00
|
|
|
template <typename K, typename V>
|
|
|
|
void saveMap(pugi::xml_document& doc, std::map<K, V>& map, const char* type)
|
|
|
|
{
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto iter = map.cbegin(); iter != map.cend(); iter++)
|
2013-06-19 21:02:42 +00:00
|
|
|
{
|
2014-06-05 20:43:19 +00:00
|
|
|
// key is on the "don't save" list, so don't save it
|
2017-11-11 14:56:22 +00:00
|
|
|
if(std::find(settings_dont_save.cbegin(), settings_dont_save.cend(), iter->first) != settings_dont_save.cend())
|
2014-06-05 20:43:19 +00:00
|
|
|
continue;
|
|
|
|
|
2013-06-19 21:02:42 +00:00
|
|
|
pugi::xml_node node = doc.append_child(type);
|
|
|
|
node.append_attribute("name").set_value(iter->first.c_str());
|
|
|
|
node.append_attribute("value").set_value(iter->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::saveFile()
|
|
|
|
{
|
2017-11-18 22:23:56 +00:00
|
|
|
LOG(LogDebug) << "Settings::saveFile() : Saving Settings to file.";
|
2018-01-27 20:04:08 +00:00
|
|
|
const std::string path = Utils::FileSystem::getHomePath() + "/.emulationstation/es_settings.cfg";
|
2013-06-19 21:02:42 +00:00
|
|
|
|
|
|
|
pugi::xml_document doc;
|
|
|
|
|
|
|
|
saveMap<std::string, bool>(doc, mBoolMap, "bool");
|
|
|
|
saveMap<std::string, int>(doc, mIntMap, "int");
|
|
|
|
saveMap<std::string, float>(doc, mFloatMap, "float");
|
|
|
|
|
2014-03-22 16:44:57 +00:00
|
|
|
//saveMap<std::string, std::string>(doc, mStringMap, "string");
|
2017-11-11 14:56:22 +00:00
|
|
|
for(auto iter = mStringMap.cbegin(); iter != mStringMap.cend(); iter++)
|
2014-03-22 16:44:57 +00:00
|
|
|
{
|
|
|
|
pugi::xml_node node = doc.append_child("string");
|
|
|
|
node.append_attribute("name").set_value(iter->first.c_str());
|
|
|
|
node.append_attribute("value").set_value(iter->second.c_str());
|
|
|
|
}
|
|
|
|
|
2013-06-19 21:02:42 +00:00
|
|
|
doc.save_file(path.c_str());
|
2018-01-30 00:49:08 +00:00
|
|
|
|
|
|
|
Scripting::fireEvent("config-changed");
|
|
|
|
Scripting::fireEvent("settings-changed");
|
2013-06-19 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::loadFile()
|
|
|
|
{
|
2018-01-27 20:04:08 +00:00
|
|
|
const std::string path = Utils::FileSystem::getHomePath() + "/.emulationstation/es_settings.cfg";
|
2013-06-19 21:02:42 +00:00
|
|
|
|
2018-01-09 22:55:09 +00:00
|
|
|
if(!Utils::FileSystem::exists(path))
|
2013-06-19 21:02:42 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
|
|
|
pugi::xml_parse_result result = doc.load_file(path.c_str());
|
|
|
|
if(!result)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "Could not parse Settings file!\n " << result.description();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-16 23:20:21 +00:00
|
|
|
for(pugi::xml_node node = doc.child("bool"); node; node = node.next_sibling("bool"))
|
2013-06-19 21:02:42 +00:00
|
|
|
setBool(node.attribute("name").as_string(), node.attribute("value").as_bool());
|
2013-10-16 23:20:21 +00:00
|
|
|
for(pugi::xml_node node = doc.child("int"); node; node = node.next_sibling("int"))
|
2013-06-19 21:02:42 +00:00
|
|
|
setInt(node.attribute("name").as_string(), node.attribute("value").as_int());
|
2013-10-16 23:20:21 +00:00
|
|
|
for(pugi::xml_node node = doc.child("float"); node; node = node.next_sibling("float"))
|
2013-06-19 21:02:42 +00:00
|
|
|
setFloat(node.attribute("name").as_string(), node.attribute("value").as_float());
|
2014-03-22 16:44:57 +00:00
|
|
|
for(pugi::xml_node node = doc.child("string"); node; node = node.next_sibling("string"))
|
|
|
|
setString(node.attribute("name").as_string(), node.attribute("value").as_string());
|
2019-08-24 14:22:02 +00:00
|
|
|
|
|
|
|
processBackwardCompatibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::processBackwardCompatibility()
|
|
|
|
{
|
|
|
|
{ // SaveGamelistsOnExit -> SaveGamelistsMode
|
|
|
|
std::map<std::string, bool>::const_iterator it = mBoolMap.find("SaveGamelistsOnExit");
|
|
|
|
if (it != mBoolMap.end()) {
|
|
|
|
mStringMap["SaveGamelistsMode"] = it->second ? "on exit" : "never";
|
|
|
|
mBoolMap.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2013-10-06 02:56:06 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 19:01:03 +00:00
|
|
|
//Print a warning message if the setting we're trying to get doesn't already exist in the map, then return the value in the map.
|
2013-06-19 23:31:59 +00:00
|
|
|
#define SETTINGS_GETSET(type, mapName, getMethodName, setMethodName) type Settings::getMethodName(const std::string& name) \
|
2013-06-17 19:01:03 +00:00
|
|
|
{ \
|
2017-11-11 14:56:22 +00:00
|
|
|
if(mapName.find(name) == mapName.cend()) \
|
2013-06-17 19:01:03 +00:00
|
|
|
{ \
|
|
|
|
LOG(LogError) << "Tried to use unset setting " << name << "!"; \
|
|
|
|
} \
|
|
|
|
return mapName[name]; \
|
2013-06-19 21:02:42 +00:00
|
|
|
} \
|
2013-06-19 23:31:59 +00:00
|
|
|
void Settings::setMethodName(const std::string& name, type value) \
|
2013-06-19 21:02:42 +00:00
|
|
|
{ \
|
|
|
|
mapName[name] = value; \
|
2013-06-17 19:01:03 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 21:02:42 +00:00
|
|
|
SETTINGS_GETSET(bool, mBoolMap, getBool, setBool);
|
|
|
|
SETTINGS_GETSET(int, mIntMap, getInt, setInt);
|
|
|
|
SETTINGS_GETSET(float, mFloatMap, getFloat, setFloat);
|
2017-01-22 23:28:06 +00:00
|
|
|
SETTINGS_GETSET(const std::string&, mStringMap, getString, setString);
|