2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-25 19:34:42 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// Settings.cpp
|
2020-05-25 19:34:42 +00:00
|
|
|
//
|
2021-06-16 17:05:24 +00:00
|
|
|
// Functions to read from and write to the configuration file es_settings.xml.
|
2020-06-21 12:25:28 +00:00
|
|
|
// 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"
|
2020-06-21 10:26:21 +00:00
|
|
|
#include "Platform.h"
|
2020-09-21 17:17:34 +00:00
|
|
|
#include "Scripting.h"
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2018-01-09 22:55:09 +00:00
|
|
|
#include <algorithm>
|
2020-09-21 17:17:34 +00:00
|
|
|
#include <pugixml.hpp>
|
2018-01-09 22:55:09 +00:00
|
|
|
#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
|
|
|
|
2021-06-16 17:05:24 +00:00
|
|
|
// These values are NOT saved to es_settings.xml since they're not set via
|
2020-05-25 19:34:42 +00:00
|
|
|
// 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.
|
2020-12-14 16:25:41 +00:00
|
|
|
std::vector<std::string> settings_dont_save {
|
2020-06-21 12:25:28 +00:00
|
|
|
// These options can be set using command-line arguments:
|
2021-01-01 17:16:54 +00:00
|
|
|
"WindowWidth", // Set via --resolution [width] [height]
|
|
|
|
"WindowHeight", // set via --resolution [width] [height]
|
|
|
|
"ParseGamelistOnly" // --gamelist-only
|
2020-06-25 17:52:38 +00:00
|
|
|
"IgnoreGamelist", // --ignore-gamelist
|
|
|
|
"SplashScreen", // --no-splash
|
2021-01-01 17:16:54 +00:00
|
|
|
"Debug", // --debug
|
2020-08-23 19:53:21 +00:00
|
|
|
#if !defined(_WIN64)
|
2020-06-25 17:52:38 +00:00
|
|
|
"Windowed", // --windowed
|
2020-07-18 11:21:44 +00:00
|
|
|
#endif
|
2021-01-01 17:16:54 +00:00
|
|
|
"VSync", // --vsync [1/on or 0/off]
|
|
|
|
"ForceFull", // --force-full
|
|
|
|
"ForceKiosk", // --force-kiosk
|
|
|
|
"ForceKid", // --force-kid
|
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",
|
2020-12-16 16:35:23 +00:00
|
|
|
"SplashScreenProgress",
|
|
|
|
"ScraperFilter"
|
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
|
|
|
}
|
|
|
|
|
2021-03-19 17:40:37 +00:00
|
|
|
void Settings::deinit()
|
|
|
|
{
|
|
|
|
if (sInstance) {
|
|
|
|
delete sInstance;
|
|
|
|
sInstance = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 19:01:03 +00:00
|
|
|
void Settings::setDefaults()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mBoolMap.clear();
|
|
|
|
mIntMap.clear();
|
2021-03-19 17:40:37 +00:00
|
|
|
mStringMap.clear();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-12-14 16:25:41 +00:00
|
|
|
// All settings are in pairs of default values and current values.
|
|
|
|
// As such, in this function we set these pairs identically.
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
// Settings configured via the in-program settings menu.
|
|
|
|
//
|
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
// Scraper.
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["Scraper"] = { "screenscraper", "screenscraper" };
|
|
|
|
mBoolMap["ScraperUseAccountScreenScraper"] = { false, false };
|
|
|
|
mStringMap["ScraperUsernameScreenScraper"] = { "", "" };
|
|
|
|
mStringMap["ScraperPasswordScreenScraper"] = { "", "" };
|
2021-06-07 21:02:42 +00:00
|
|
|
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["ScrapeGameNames"] = { true, true };
|
|
|
|
mBoolMap["ScrapeRatings"] = { true, true };
|
|
|
|
mBoolMap["ScrapeMetadata"] = { true, true };
|
|
|
|
mBoolMap["ScrapeVideos"] = { true, true };
|
|
|
|
mBoolMap["ScrapeScreenshots"] = { true, true };
|
|
|
|
mBoolMap["ScrapeCovers"] = { true, true };
|
|
|
|
mBoolMap["ScrapeMarquees"] = { true, true };
|
|
|
|
mBoolMap["Scrape3DBoxes"] = { true, true };
|
2021-06-07 21:02:42 +00:00
|
|
|
|
|
|
|
mStringMap["MiximageResolution"] = { "1280x960", "1280x960" };
|
|
|
|
mStringMap["MiximageScreenshotScaling"] = { "sharp", "sharp" };
|
|
|
|
mBoolMap["MiximageGenerate"] = { true, true };
|
|
|
|
mBoolMap["MiximageOverwrite"] = { true, true };
|
|
|
|
mBoolMap["MiximageRemoveLetterboxes"] = { true, true };
|
|
|
|
mBoolMap["MiximageRemovePillarboxes"] = { true, true };
|
|
|
|
mBoolMap["MiximageIncludeMarquee"] = { true, true };
|
|
|
|
mBoolMap["MiximageIncludeBox"] = { true, true };
|
|
|
|
mBoolMap["MiximageCoverFallback"] = { true, true };
|
|
|
|
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["ScraperRegion"] = { "eu", "eu" };
|
|
|
|
mStringMap["ScraperLanguage"] = { "en", "en" };
|
|
|
|
mBoolMap["ScraperOverwriteData"] = { true, true };
|
2020-12-18 15:35:19 +00:00
|
|
|
mBoolMap["ScraperHaltOnInvalidMedia"] = { true, true };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["ScraperSearchMetadataName"] = { true, true };
|
|
|
|
mBoolMap["ScraperInteractive"] = { true, true };
|
|
|
|
mBoolMap["ScraperSemiautomatic"] = { true, true };
|
|
|
|
mBoolMap["ScraperRespectExclusions"] = { true, true };
|
|
|
|
mBoolMap["ScraperExcludeRecursively"] = { true, true };
|
|
|
|
mBoolMap["ScraperIncludeFolders"] = { false, false };
|
2021-05-24 16:51:16 +00:00
|
|
|
mBoolMap["ScraperRetryPeerVerification"] = { false, false };
|
2020-11-05 17:18:11 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// UI settings.
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["StartupSystem"] = { "", "" };
|
|
|
|
mStringMap["GamelistViewStyle"] = { "automatic", "automatic" };
|
|
|
|
mStringMap["TransitionStyle"] = { "slide", "slide" };
|
|
|
|
mStringMap["ThemeSet"] = { "rbsimple-DE", "rbsimple-DE" };
|
|
|
|
mStringMap["UIMode"] = { "full", "full" };
|
|
|
|
mStringMap["DefaultSortOrder"] = { "filename, ascending", "filename, ascending" };
|
|
|
|
mStringMap["MenuOpeningEffect"] = { "scale-up", "scale-up" };
|
2021-06-14 17:15:22 +00:00
|
|
|
mStringMap["LaunchScreenDuration"] = { "normal", "normal" };
|
2021-03-18 18:46:45 +00:00
|
|
|
mBoolMap["MenuBlurBackground"] = { true, true };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["GamelistVideoPillarbox"] = { true, true };
|
2021-06-10 20:47:22 +00:00
|
|
|
mBoolMap["GamelistVideoScanlines"] = { false, false };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["FoldersOnTop"] = { true, true };
|
|
|
|
mBoolMap["FavoritesFirst"] = { true, true };
|
|
|
|
mBoolMap["FavoritesStar"] = { true, true };
|
2021-06-28 20:05:24 +00:00
|
|
|
mBoolMap["SpecialCharsASCII"] = { false, false };
|
2021-01-12 21:41:28 +00:00
|
|
|
mBoolMap["ListScrollOverlay"] = { false, false };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["FavoritesAddButton"] = { true, true };
|
2021-06-27 10:21:18 +00:00
|
|
|
mBoolMap["RandomAddButton"] = { false, false };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["GamelistFilters"] = { true, true };
|
|
|
|
mBoolMap["QuickSystemSelect"] = { true, true };
|
|
|
|
mBoolMap["ShowHelpPrompts"] = { true, true };
|
|
|
|
mBoolMap["PlayVideosImmediately"] = { false, false };
|
2020-12-17 22:45:29 +00:00
|
|
|
mBoolMap["EnableMenuKidMode"] = { false, false };
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-05-16 11:12:31 +00:00
|
|
|
// UI settings -> media viewer settings.
|
|
|
|
mBoolMap["MediaViewerKeepVideoRunning"] = { true, true };
|
|
|
|
mBoolMap["MediaViewerStretchVideos"] = { false, false };
|
|
|
|
mBoolMap["MediaViewerVideoScanlines"] = { true, true };
|
|
|
|
mBoolMap["MediaViewerVideoBlur"] = { false, false };
|
|
|
|
mBoolMap["MediaViewerScreenshotScanlines"] = { true, true };
|
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
// UI settings -> screensaver settings.
|
2021-05-16 16:02:07 +00:00
|
|
|
mIntMap["ScreensaverTimer"] = { 5 * 60 * 1000, 5 * 60 * 1000 }; // 5 minutes.
|
|
|
|
mStringMap["ScreensaverType"] = { "video", "video" };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["ScreensaverControls"] = { true, true };
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// UI settings -> screensaver settings -> slideshow screensaver settings.
|
2020-12-14 16:25:41 +00:00
|
|
|
mIntMap["ScreensaverSwapImageTimeout"] = { 10000, 10000 };
|
|
|
|
mBoolMap["ScreensaverStretchImages"] = { false, false };
|
|
|
|
mBoolMap["ScreensaverSlideshowGameInfo"] = { true, true };
|
|
|
|
mBoolMap["ScreensaverSlideshowScanlines"] = { true, true };
|
|
|
|
mBoolMap["ScreensaverSlideshowCustomImages"] = { false, false };
|
|
|
|
mBoolMap["ScreensaverSlideshowRecurse"] = { false, false };
|
|
|
|
mStringMap["ScreensaverSlideshowImageDir"] = {
|
|
|
|
"~/.emulationstation/slideshow/custom_images",
|
|
|
|
"~/.emulationstation/slideshow/custom_images" };
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-09-13 11:21:38 +00:00
|
|
|
// UI settings -> screensaver settings -> video screensaver settings.
|
2020-12-14 16:25:41 +00:00
|
|
|
mIntMap["ScreensaverSwapVideoTimeout"] = { 0, 0 };
|
|
|
|
mBoolMap["ScreensaverStretchVideos"] = { false, false };
|
|
|
|
mBoolMap["ScreensaverVideoGameInfo"] = { true, true };
|
|
|
|
mBoolMap["ScreensaverVideoScanlines"] = { true, true };
|
|
|
|
mBoolMap["ScreensaverVideoBlur"] = { false, false };
|
2020-09-13 11:21:38 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// 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.
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_RPI_)
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["AudioCard"] = { "default", "default" };
|
2020-06-21 12:25:28 +00:00
|
|
|
// Audio out device for volume control.
|
2020-07-09 17:24:20 +00:00
|
|
|
//#endif
|
2020-08-23 15:04:30 +00:00
|
|
|
//#if defined(_RPI_)
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["AudioDevice"] = { "PCM", "PCM" };
|
2020-06-21 12:25:28 +00:00
|
|
|
// Audio out device for Video playback using OMX player.
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["OMXAudioDev"] = { "both", "both" };
|
2020-07-09 17:24:20 +00:00
|
|
|
//#else
|
2020-12-14 16:25:41 +00:00
|
|
|
// mStringMap["AudioDevice"] = { "Master", "Master" };
|
2020-07-09 17:24:20 +00:00
|
|
|
#endif
|
2020-12-20 15:41:58 +00:00
|
|
|
mIntMap["SoundVolumeNavigation"] = { 80, 80 };
|
|
|
|
mIntMap["SoundVolumeVideos"] = { 100, 100 };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["GamelistVideoAudio"] = { true, true };
|
2021-05-16 11:12:31 +00:00
|
|
|
mBoolMap["MediaViewerVideoAudio"] = { true, true };
|
|
|
|
mBoolMap["ScreensaverVideoAudio"] = { false, false };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["NavigationSounds"] = { true, true };
|
2021-05-23 09:45:45 +00:00
|
|
|
|
|
|
|
// Input device settings.
|
2021-05-23 17:12:31 +00:00
|
|
|
mStringMap["InputControllerType"] = { "xbox", "xbox" };
|
2021-05-23 09:45:45 +00:00
|
|
|
mBoolMap["InputOnlyFirstController"] = { false, false };
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Game collection settings.
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["CollectionSystemsAuto"] = { "", "" };
|
|
|
|
mStringMap["CollectionSystemsCustom"] = { "", "" };
|
|
|
|
mBoolMap["FavFirstCustom"] = { false, false };
|
|
|
|
mBoolMap["FavStarCustom"] = { false, false };
|
|
|
|
mBoolMap["UseCustomCollectionsSystem"] = { true, true };
|
|
|
|
mBoolMap["CollectionShowSystemInfo"] = { true, true };
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Other settings.
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_RPI_)
|
2020-12-14 16:25:41 +00:00
|
|
|
mIntMap["MaxVRAM"] = { 80, 80 };
|
2020-06-21 12:25:28 +00:00
|
|
|
#else
|
2021-01-17 09:15:17 +00:00
|
|
|
mIntMap["MaxVRAM"] = { 256, 256 };
|
2020-06-21 12:25:28 +00:00
|
|
|
#endif
|
2021-01-24 22:44:50 +00:00
|
|
|
mIntMap["DisplayIndex"] = { 1, 1 };
|
2020-08-18 15:48:21 +00:00
|
|
|
#if defined (__unix__)
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["FullscreenMode"] = { "normal", "normal" };
|
2020-07-18 11:21:44 +00:00
|
|
|
#endif
|
2021-06-22 22:24:15 +00:00
|
|
|
#if defined(BUILD_VLC_PLAYER)
|
2021-05-14 08:53:50 +00:00
|
|
|
mStringMap["VideoPlayer"] = { "ffmpeg", "ffmpeg" };
|
2021-06-22 22:24:15 +00:00
|
|
|
#endif
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_RPI_)
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["VideoOmxPlayer"] = { false, false };
|
2020-06-21 12:25:28 +00:00
|
|
|
// We're defaulting to OMX Player for full screen video on the Pi.
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["ScreensaverOmxPlayer"] = { true, true };
|
2020-06-21 12:25:28 +00:00
|
|
|
#endif
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["SaveGamelistsMode"] = { "always", "always" };
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["HideTaskbar"] = { false, false };
|
2020-07-18 11:21:44 +00:00
|
|
|
#endif
|
2021-06-30 15:19:57 +00:00
|
|
|
mBoolMap["RunInBackground"] = { false, false };
|
2021-06-30 16:08:13 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
mBoolMap["LaunchWorkaround"] = { true, true };
|
|
|
|
#endif
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["MediaDirectory"] = { "", "" };
|
2021-05-29 08:55:40 +00:00
|
|
|
mBoolMap["VideoUpscaleFrameRate"] = { false, false };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["LaunchCommandOverride"] = { true, true };
|
|
|
|
mBoolMap["ShowHiddenFiles"] = { true, true };
|
|
|
|
mBoolMap["ShowHiddenGames"] = { true, true };
|
|
|
|
mBoolMap["CustomEventScripts"] = { false, false };
|
|
|
|
mBoolMap["ParseGamelistOnly"] = { false, false };
|
2021-02-22 20:13:06 +00:00
|
|
|
#if defined(__unix__)
|
|
|
|
mBoolMap["DisableComposition"] = { true, true };
|
|
|
|
#endif
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["DisplayGPUStatistics"] = { false, false };
|
2020-08-23 17:17:06 +00:00
|
|
|
// macOS requires root privileges to reboot and power off so it doesn't make much
|
2021-05-23 08:56:49 +00:00
|
|
|
// sense to enable this setting and menu entry for that operating system.
|
|
|
|
#if !defined(__APPLE__)
|
2020-12-17 22:45:29 +00:00
|
|
|
mBoolMap["ShowQuitMenu"] = { false, false };
|
2020-08-23 17:17:06 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Settings configured via command-line arguments.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Options listed using --help
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["Debug"] = { false, false };
|
2020-12-17 22:45:29 +00:00
|
|
|
mBoolMap["ForceFull"] = { false, false };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["ForceKid"] = { false, false };
|
|
|
|
mBoolMap["ForceKiosk"] = { false, false };
|
|
|
|
mBoolMap["IgnoreGamelist"] = { false, false };
|
|
|
|
mBoolMap["SplashScreen"] = { true, true };
|
|
|
|
mBoolMap["VSync"] = { true, true };
|
2020-08-23 19:53:21 +00:00
|
|
|
#if !defined(_WIN64)
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["Windowed"] = { false, false };
|
2020-07-18 11:21:44 +00:00
|
|
|
#endif
|
2020-12-14 16:25:41 +00:00
|
|
|
mIntMap["WindowWidth"] = { 0, 0 };
|
|
|
|
mIntMap["WindowHeight"] = { 0, 0 };
|
|
|
|
mIntMap["ScreenWidth"] = { 0, 0 };
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Undocumented options.
|
2020-12-14 16:25:41 +00:00
|
|
|
mIntMap["ScreenHeight"] = { 0, 0 };
|
|
|
|
mIntMap["ScreenOffsetX"] = { 0, 0 };
|
|
|
|
mIntMap["ScreenOffsetY"] = { 0, 0 };
|
|
|
|
mIntMap["ScreenRotate"] = { 0, 0 };
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
//
|
2021-06-16 17:05:24 +00:00
|
|
|
// Settings that can be changed in es_settings.xml
|
2020-07-14 17:16:21 +00:00
|
|
|
// but that are not configurable via the GUI.
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
|
2021-06-22 15:42:35 +00:00
|
|
|
mBoolMap["DebugSkipInputLogging"] = { false, false };
|
2020-12-14 16:25:41 +00:00
|
|
|
mStringMap["ROMDirectory"] = { "", "" };
|
2021-05-24 19:34:08 +00:00
|
|
|
mStringMap["UIMode_passkey"] = { "uuddlrlrba", "uuddlrlrba" };
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Hardcoded or program-internal settings.
|
|
|
|
//
|
|
|
|
|
2021-06-22 15:47:01 +00:00
|
|
|
mStringMap["ApplicationVersion"] = { "", "" };
|
2020-12-14 16:25:41 +00:00
|
|
|
mBoolMap["DebugGrid"] = { false, false };
|
|
|
|
mBoolMap["DebugText"] = { false, false };
|
|
|
|
mBoolMap["DebugImage"] = { false, false };
|
|
|
|
mBoolMap["SplashScreenProgress"] = { true, true };
|
2020-12-16 16:35:23 +00:00
|
|
|
mIntMap["ScraperFilter"] = { 0, 0 };
|
2013-06-17 19:01:03 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 21:02:42 +00:00
|
|
|
template <typename K, typename V>
|
2020-12-14 16:25:41 +00:00
|
|
|
void saveMap(pugi::xml_document& doc, std::map<K, V>& map, const std::string& type)
|
2013-06-19 21:02:42 +00:00
|
|
|
{
|
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;
|
|
|
|
|
2020-12-14 16:25:41 +00:00
|
|
|
pugi::xml_node node = doc.append_child(type.c_str());
|
2020-06-21 12:25:28 +00:00
|
|
|
node.append_attribute("name").set_value(iter->first.c_str());
|
2020-12-14 16:25:41 +00:00
|
|
|
node.append_attribute("value").set_value(iter->second.second);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2013-06-19 21:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::saveFile()
|
|
|
|
{
|
2021-06-16 17:05:24 +00:00
|
|
|
LOG(LogDebug) << "Settings::saveFile(): Saving settings to es_settings.xml";
|
2020-06-21 12:25:28 +00:00
|
|
|
const std::string path = Utils::FileSystem::getHomePath() +
|
2021-06-16 17:05:24 +00:00
|
|
|
"/.emulationstation/es_settings.xml";
|
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-12-14 16:25:41 +00:00
|
|
|
saveMap<std::string, std::pair<bool, bool>>(doc, mBoolMap, "bool");
|
|
|
|
saveMap<std::string, std::pair<int, int>>(doc, mIntMap, "int");
|
|
|
|
saveMap<std::string, std::pair<float, float>>(doc, mFloatMap, "float");
|
2013-06-19 21:02:42 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
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());
|
2020-12-14 16:25:41 +00:00
|
|
|
node.append_attribute("value").set_value(iter->second.second.c_str());
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2014-03-22 16:44:57 +00:00
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-10 16:32:23 +00:00
|
|
|
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()
|
|
|
|
{
|
2021-06-16 17:05:24 +00:00
|
|
|
// Prior to ES-DE v1.1, the configuration file had the .cfg suffix instead of .xml
|
|
|
|
const std::string legacyConfigFile = Utils::FileSystem::getHomePath() +
|
2020-06-21 12:25:28 +00:00
|
|
|
"/.emulationstation/es_settings.cfg";
|
|
|
|
|
2021-06-16 17:05:24 +00:00
|
|
|
const std::string configFile = Utils::FileSystem::getHomePath() +
|
|
|
|
"/.emulationstation/es_settings.xml";
|
|
|
|
|
|
|
|
if (Utils::FileSystem::exists(legacyConfigFile) && !Utils::FileSystem::exists(configFile))
|
2021-06-20 10:51:32 +00:00
|
|
|
Utils::FileSystem::copyFile(legacyConfigFile, configFile, false);
|
2021-06-16 17:05:24 +00:00
|
|
|
|
|
|
|
if (!Utils::FileSystem::exists(configFile))
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2021-06-16 17:05:24 +00:00
|
|
|
pugi::xml_parse_result result =
|
|
|
|
doc.load_file(Utils::String::stringToWideString(configFile).c_str());
|
2020-07-10 16:32:23 +00:00
|
|
|
#else
|
2021-06-16 17:05:24 +00:00
|
|
|
pugi::xml_parse_result result = doc.load_file(configFile.c_str());
|
2020-07-10 16:32:23 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!result) {
|
2021-06-16 17:05:24 +00:00
|
|
|
LOG(LogError) << "Could not parse the es_settings.xml 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.
|
2020-12-14 16:25:41 +00:00
|
|
|
#define SETTINGS_GETSET(type, mapName, getFunction, getDefaultFunction, setFunction) \
|
|
|
|
type Settings::getFunction(const std::string& name) \
|
|
|
|
{ \
|
|
|
|
if (mapName.find(name) == mapName.cend()) { \
|
2021-01-25 17:15:01 +00:00
|
|
|
LOG(LogError) << "Tried to use unset setting " << name; \
|
2020-12-14 16:25:41 +00:00
|
|
|
} \
|
|
|
|
return mapName[name].second; \
|
|
|
|
} \
|
|
|
|
type Settings::getDefaultFunction(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()) { \
|
2021-01-25 17:15:01 +00:00
|
|
|
LOG(LogError) << "Tried to use unset setting " << name; \
|
2020-06-21 12:25:28 +00:00
|
|
|
} \
|
2020-12-14 16:25:41 +00:00
|
|
|
return mapName[name].first; \
|
2013-06-19 21:02:42 +00:00
|
|
|
} \
|
2020-12-14 16:25:41 +00:00
|
|
|
bool Settings::setFunction(const std::string& name, type value) \
|
2013-06-19 21:02:42 +00:00
|
|
|
{ \
|
2020-12-14 16:25:41 +00:00
|
|
|
if (mapName.count(name) == 0 || mapName[name].second != value) { \
|
|
|
|
mapName[name].second = 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
|
|
|
}
|
|
|
|
|
2020-12-14 16:25:41 +00:00
|
|
|
SETTINGS_GETSET(bool, mBoolMap, getBool, getDefaultBool, setBool);
|
|
|
|
SETTINGS_GETSET(int, mIntMap, getInt, getDefaultInt, setInt);
|
|
|
|
SETTINGS_GETSET(float, mFloatMap, getFloat, getDefaultFloat, setFloat);
|
|
|
|
SETTINGS_GETSET(const std::string&, mStringMap, getString, getDefaultString, setString);
|