2020-05-25 19:34:42 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Settings.cpp
|
2020-05-25 19:34:42 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Functions to read from and write to the configuration file es_settings.cfg.
|
|
|
|
// The default values for the application settings are defined here as well.
|
2020-05-25 19:34:42 +00:00
|
|
|
//
|
|
|
|
|
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"
|
2020-07-10 16:32:23 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2013-06-17 19:01:03 +00:00
|
|
|
#include "Log.h"
|
2018-01-30 00:49:08 +00:00
|
|
|
#include "Scripting.h"
|
2020-06-21 10:26:21 +00:00
|
|
|
#include "Platform.h"
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2020-06-24 15:38:41 +00:00
|
|
|
#include <pugixml.hpp>
|
2018-01-09 22:55:09 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2013-06-17 19:01:03 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
Settings* Settings::sInstance = nullptr;
|
2013-06-17 19:01:03 +00:00
|
|
|
|
2020-05-25 19:34:42 +00:00
|
|
|
// These values are NOT saved to es_settings.cfg since they're not set via
|
|
|
|
// the in-program settings menu. Most can be set using command-line arguments,
|
|
|
|
// but some are debug flags that are either hardcoded or set by internal debug
|
|
|
|
// functions.
|
2017-11-03 00:33:08 +00:00
|
|
|
std::vector<const char*> settings_dont_save {
|
2020-06-21 12:25:28 +00:00
|
|
|
// These options can be set using command-line arguments:
|
2020-06-25 17:52:38 +00:00
|
|
|
"Debug", // --debug
|
|
|
|
"ForceKid", // --force-kid
|
|
|
|
"ForceKiosk", // --force-kiosk
|
|
|
|
"IgnoreGamelist", // --ignore-gamelist
|
|
|
|
"ShowExit", // --no-exit
|
|
|
|
"SplashScreen", // --no-splash
|
|
|
|
"VSync", // --vsync [1/on or 0/off]
|
|
|
|
"Windowed", // --windowed
|
|
|
|
"WindowWidth", // Set via --resolution [width] [height]
|
|
|
|
"WindowHeight", // set via --resolution [width] [height]
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// These options are not shown in the --help text and are intended
|
|
|
|
// for debugging and testing purposes:
|
2020-06-25 17:52:38 +00:00
|
|
|
"ScreenWidth", // Set via --screensize [width] [height]
|
|
|
|
"ScreenHeight", // set via --screensize [width] [height]
|
|
|
|
"ScreenOffsetX", // Set via --screenoffset [X] [Y]
|
|
|
|
"ScreenOffsetY", // Set via --screenoffset [X] [Y]
|
|
|
|
"ScreenRotate", // --screenrotate [0-3]
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// These options are not configurable from the command-line:
|
2020-06-25 17:52:38 +00:00
|
|
|
"DebugGrid",
|
|
|
|
"DebugText",
|
|
|
|
"DebugImage",
|
|
|
|
"SplashScreenProgress"
|
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
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mWasChanged = false;
|
|
|
|
setDefaults();
|
|
|
|
loadFile();
|
2013-06-17 19:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Settings* Settings::getInstance()
|
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
if (sInstance == nullptr)
|
2020-06-21 12:25:28 +00:00
|
|
|
sInstance = new Settings();
|
2013-06-17 19:01:03 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return sInstance;
|
2013-06-17 19:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setDefaults()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mBoolMap.clear();
|
|
|
|
mIntMap.clear();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Settings configured via the in-program settings menu.
|
|
|
|
//
|
|
|
|
|
|
|
|
// UI settings.
|
|
|
|
mStringMap["StartupSystem"] = "";
|
2020-07-09 17:24:20 +00:00
|
|
|
mStringMap["GamelistViewStyle"] = "detailed";
|
2020-06-21 12:25:28 +00:00
|
|
|
mStringMap["TransitionStyle"] = "instant";
|
|
|
|
mStringMap["ThemeSet"] = "";
|
|
|
|
mStringMap["UIMode"] = "Full";
|
|
|
|
mBoolMap["FavoritesFirst"] = true;
|
|
|
|
mBoolMap["ForceDisableFilters"] = false;
|
|
|
|
mBoolMap["QuickSystemSelect"] = true;
|
|
|
|
mBoolMap["MoveCarousel"] = true;
|
|
|
|
mBoolMap["ShowHelpPrompts"] = true;
|
2020-07-09 17:24:20 +00:00
|
|
|
mBoolMap["ShowKidStartMenu"] = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// UI settings -> scrensaver settings.
|
|
|
|
mIntMap["ScreenSaverTime"] = 5*60*1000; // 5 minutes
|
|
|
|
mBoolMap["ScreenSaverControls"] = true;
|
|
|
|
mStringMap["ScreenSaverBehavior"] = "dim";
|
|
|
|
|
|
|
|
// UI settings -> screensaver settings -> video screensaver settings.
|
|
|
|
mIntMap["ScreenSaverSwapVideoTimeout"] = 30000;
|
|
|
|
mBoolMap["StretchVideoOnScreenSaver"] = false;
|
|
|
|
mStringMap["ScreenSaverGameInfo"] = "never";
|
|
|
|
mBoolMap["ScreenSaverVideoMute"] = false; // Raspberry Pi only
|
|
|
|
mBoolMap["CaptionsCompatibility"] = true;
|
|
|
|
|
|
|
|
// UI settings -> screensaver settings -> slideshow screensaver settings.
|
|
|
|
mIntMap["ScreenSaverSwapImageTimeout"] = 10000;
|
|
|
|
mBoolMap["SlideshowScreenSaverStretch"] = false;
|
|
|
|
mStringMap["SlideshowScreenSaverBackgroundAudioFile"] = Utils::FileSystem::getHomePath() +
|
|
|
|
"/.emulationstation/slideshow/audio/slideshow_bg.wav";
|
|
|
|
mBoolMap["SlideshowScreenSaverCustomImageSource"] = false;
|
|
|
|
mStringMap["SlideshowScreenSaverImageDir"] = Utils::FileSystem::getHomePath() +
|
|
|
|
"/.emulationstation/slideshow/image";
|
|
|
|
mBoolMap["SlideshowScreenSaverRecurse"] = false;
|
|
|
|
mStringMap["SlideshowScreenSaverImageFilter"] = ".png,.jpg";
|
|
|
|
|
|
|
|
// Sound settings.
|
2020-07-09 17:24:20 +00:00
|
|
|
// The ALSA Audio Card and Audio Device selection code is disabled at the moment.
|
|
|
|
// As PulseAudio controls the sound devices for the desktop environment, it doesn't
|
|
|
|
// make much sense to be able to select ALSA devices directly. Normally (always?)
|
|
|
|
// the selection doesn't make any difference at all. But maybe some PulseAudio
|
|
|
|
// settings could be added later on, if needed.
|
|
|
|
// The code is still active for Raspberry Pi though as I'm not sure if this is
|
|
|
|
// useful for that device.
|
|
|
|
#ifdef _RPI_
|
2020-06-21 12:25:28 +00:00
|
|
|
mStringMap["AudioCard"] = "default";
|
|
|
|
// Audio out device for volume control.
|
2020-07-09 17:24:20 +00:00
|
|
|
//#endif
|
|
|
|
//#ifdef _RPI_
|
|
|
|
mStringMap["AudioDevice"] = "PCM";
|
2020-06-21 12:25:28 +00:00
|
|
|
// Audio out device for Video playback using OMX player.
|
|
|
|
mStringMap["OMXAudioDev"] = "both";
|
2020-07-09 17:24:20 +00:00
|
|
|
//#else
|
|
|
|
// mStringMap["AudioDevice"] = "Master";
|
|
|
|
#endif
|
|
|
|
mBoolMap["VideoAudio"] = true;
|
|
|
|
mBoolMap["NavigationSounds"] = true;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Game collection settings.
|
|
|
|
mStringMap["CollectionSystemsAuto"] = "";
|
|
|
|
mStringMap["CollectionSystemsCustom"] = "";
|
|
|
|
mBoolMap["UseCustomCollectionsSystem"] = true;
|
|
|
|
mBoolMap["FavFirstCustom"] = true;
|
|
|
|
mBoolMap["CollectionShowSystemInfo"] = true;
|
|
|
|
|
|
|
|
// Scraper.
|
|
|
|
mStringMap["Scraper"] = "ScreenScraper";
|
|
|
|
mStringMap["ScraperRegion"] = "eu";
|
|
|
|
mStringMap["ScraperLanguage"] = "en";
|
2020-06-06 11:10:33 +00:00
|
|
|
// mBoolMap["ScraperGenerateMiximages"] = false;
|
|
|
|
// mBoolMap["ScraperGenerateThumbnails"] = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
mBoolMap["ScraperInteractive"] = true;
|
|
|
|
mBoolMap["ScraperSemiautomatic"] = true;
|
2020-07-09 17:24:20 +00:00
|
|
|
mBoolMap["ScraperOverwriteData"] = true;
|
2020-06-21 12:25:28 +00:00
|
|
|
mBoolMap["ScrapeMetadata"] = true;
|
|
|
|
mBoolMap["ScrapeGameNames"] = true;
|
|
|
|
mBoolMap["ScrapeRatings"] = true;
|
|
|
|
mBoolMap["Scrape3DBoxes"] = true;
|
|
|
|
mBoolMap["ScrapeCovers"] = true;
|
|
|
|
mBoolMap["ScrapeMarquees"] = true;
|
|
|
|
mBoolMap["ScrapeScreenshots"] = true;
|
|
|
|
|
|
|
|
// Other settings.
|
|
|
|
#ifdef _RPI_
|
|
|
|
mIntMap["MaxVRAM"] = 80;
|
|
|
|
#else
|
|
|
|
mIntMap["MaxVRAM"] = 100;
|
|
|
|
#endif
|
|
|
|
mStringMap["FullscreenMode"] = "normal";
|
|
|
|
mStringMap["PowerSaverMode"] = "disabled";
|
|
|
|
// 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;
|
|
|
|
#ifdef _RPI_
|
|
|
|
// We're defaulting to OMX Player for full screen video on the Pi.
|
|
|
|
mBoolMap["ScreenSaverOmxPlayer"] = true;
|
|
|
|
// 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";
|
|
|
|
#else
|
|
|
|
mBoolMap["ScreenSaverOmxPlayer"] = false;
|
|
|
|
#endif
|
|
|
|
mStringMap["SaveGamelistsMode"] = "always";
|
2020-07-08 15:06:34 +00:00
|
|
|
mBoolMap["LaunchCommandOverride"] = true;
|
2020-07-09 17:24:20 +00:00
|
|
|
mBoolMap["CustomEventScripts"] = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
mBoolMap["ParseGamelistOnly"] = false;
|
|
|
|
mBoolMap["LocalArt"] = false;
|
|
|
|
mBoolMap["ShowHiddenFiles"] = false;
|
|
|
|
mBoolMap["DrawFramerate"] = false;
|
|
|
|
mBoolMap["ShowRebootSystem"] = true;
|
|
|
|
mBoolMap["ShowPoweroffSystem"] = true;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Settings configured via command-line arguments.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Options listed using --help
|
|
|
|
mBoolMap["Debug"] = false;
|
|
|
|
mBoolMap["ForceKid"] = false;
|
|
|
|
mBoolMap["ForceKiosk"] = false;
|
|
|
|
mBoolMap["IgnoreGamelist"] = false;
|
|
|
|
mBoolMap["ShowExit"] = true;
|
|
|
|
mBoolMap["SplashScreen"] = true;
|
|
|
|
mBoolMap["VSync"] = true;
|
|
|
|
mBoolMap["Windowed"] = false;
|
|
|
|
mIntMap["WindowWidth"] = 0;
|
|
|
|
mIntMap["WindowHeight"] = 0;
|
|
|
|
mIntMap["ScreenWidth"] = 0;
|
|
|
|
|
|
|
|
// Undocumented options.
|
|
|
|
mIntMap["ScreenHeight"] = 0;
|
|
|
|
mIntMap["ScreenOffsetX"] = 0;
|
|
|
|
mIntMap["ScreenOffsetY"] = 0;
|
|
|
|
mIntMap["ScreenRotate"] = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Settings that can be changed in es_settings.cfg
|
|
|
|
// but that are not configurable via the GUI (yet).
|
|
|
|
//
|
|
|
|
|
|
|
|
mStringMap["DefaultSortOrder"] = "filename, ascending";
|
|
|
|
mStringMap["MediaDirectory"] = "";
|
|
|
|
mStringMap["ROMDirectory"] = "";
|
2020-07-09 17:24:20 +00:00
|
|
|
mIntMap["ScraperResizeMaxWidth"] = 600;
|
|
|
|
mIntMap["ScraperResizeMaxHeight"] = 0;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Hardcoded or program-internal settings.
|
|
|
|
//
|
|
|
|
|
|
|
|
mBoolMap["BackgroundJoystickInput"] = false;
|
|
|
|
mBoolMap["DebugGrid"] = false;
|
|
|
|
mBoolMap["DebugText"] = false;
|
|
|
|
mBoolMap["DebugImage"] = false;
|
|
|
|
mBoolMap["SplashScreenProgress"] = true;
|
|
|
|
mStringMap["UIMode_passkey"] = "uuddlrlrba";
|
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)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (auto iter = map.cbegin(); iter != map.cend(); iter++) {
|
|
|
|
// Key is on the "don't save" list, so don't save it.
|
|
|
|
if (std::find(settings_dont_save.cbegin(), settings_dont_save.cend(),
|
|
|
|
iter->first) != settings_dont_save.cend())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2013-06-19 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::saveFile()
|
|
|
|
{
|
2020-07-11 08:10:07 +00:00
|
|
|
LOG(LogDebug) << "Settings::saveFile(): Saving Settings to file.";
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string path = Utils::FileSystem::getHomePath() +
|
|
|
|
"/.emulationstation/es_settings.cfg";
|
2013-06-19 21:02:42 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_document doc;
|
2013-06-19 21:02:42 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
saveMap<std::string, bool>(doc, mBoolMap, "bool");
|
|
|
|
saveMap<std::string, int>(doc, mIntMap, "int");
|
|
|
|
saveMap<std::string, float>(doc, mFloatMap, "float");
|
2013-06-19 21:02:42 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
//saveMap<std::string, std::string>(doc, mStringMap, "string");
|
|
|
|
for (auto iter = mStringMap.cbegin(); iter != mStringMap.cend(); iter++) {
|
|
|
|
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());
|
|
|
|
}
|
2014-03-22 16:44:57 +00:00
|
|
|
|
2020-07-10 16:32:23 +00:00
|
|
|
#ifdef _WIN64
|
|
|
|
doc.save_file(Utils::String::stringToWideString(path).c_str());
|
|
|
|
#else
|
2020-06-21 12:25:28 +00:00
|
|
|
doc.save_file(path.c_str());
|
2020-07-10 16:32:23 +00:00
|
|
|
#endif
|
2018-01-30 00:49:08 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Scripting::fireEvent("config-changed");
|
|
|
|
Scripting::fireEvent("settings-changed");
|
2013-06-19 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::loadFile()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string path = Utils::FileSystem::getHomePath() +
|
|
|
|
"/.emulationstation/es_settings.cfg";
|
|
|
|
|
|
|
|
if (!Utils::FileSystem::exists(path))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
2020-07-10 16:32:23 +00:00
|
|
|
#ifdef _WIN64
|
|
|
|
pugi::xml_parse_result result = doc.load_file(Utils::String::stringToWideString(path).c_str());
|
|
|
|
#else
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_parse_result result = doc.load_file(path.c_str());
|
2020-07-10 16:32:23 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!result) {
|
2020-07-09 17:24:20 +00:00
|
|
|
LOG(LogError) << "Error - Could not parse Settings file!\n " << result.description();
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pugi::xml_node node = doc.child("bool"); node; node = node.next_sibling("bool"))
|
|
|
|
setBool(node.attribute("name").as_string(), node.attribute("value").as_bool());
|
|
|
|
for (pugi::xml_node node = doc.child("int"); node; node = node.next_sibling("int"))
|
|
|
|
setInt(node.attribute("name").as_string(), node.attribute("value").as_int());
|
|
|
|
for (pugi::xml_node node = doc.child("float"); node; node = node.next_sibling("float"))
|
|
|
|
setFloat(node.attribute("name").as_string(), node.attribute("value").as_float());
|
|
|
|
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());
|
2013-10-06 02:56:06 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 19:34:42 +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.
|
|
|
|
#define SETTINGS_GETSET(type, mapName, getMethodName, setMethodName) \
|
2020-06-21 12:25:28 +00:00
|
|
|
type Settings::getMethodName(const std::string& name) \
|
2013-06-17 19:01:03 +00:00
|
|
|
{ \
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mapName.find(name) == mapName.cend()) { \
|
2020-07-09 17:24:20 +00:00
|
|
|
LOG(LogError) << "Error - Tried to use unset setting " << name << "!"; \
|
2020-06-21 12:25:28 +00:00
|
|
|
} \
|
|
|
|
return mapName[name]; \
|
2013-06-19 21:02:42 +00:00
|
|
|
} \
|
2020-05-15 15:42:36 +00:00
|
|
|
bool Settings::setMethodName(const std::string& name, type value) \
|
2013-06-19 21:02:42 +00:00
|
|
|
{ \
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mapName.count(name) == 0 || mapName[name] != value) { \
|
|
|
|
mapName[name] = value; \
|
2020-05-15 15:42:36 +00:00
|
|
|
\
|
2020-06-21 12:25:28 +00:00
|
|
|
if (std::find(settings_dont_save.cbegin(), settings_dont_save.cend(), name) \
|
|
|
|
== settings_dont_save.cend()) \
|
|
|
|
mWasChanged = true; \
|
2020-05-15 15:42:36 +00:00
|
|
|
\
|
2020-06-21 12:25:28 +00:00
|
|
|
return true; \
|
|
|
|
} \
|
|
|
|
return false; \
|
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);
|