mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05:38 +00:00
Added logic to retrieve default setting values.
This commit is contained in:
parent
a365bccff2
commit
e752904ab1
|
@ -724,8 +724,8 @@ void SystemData::setupSystemSortType(FileData* mRootFolder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If no valid sort type was defined in the configuration
|
// If no valid sort type was defined in the configuration file, set to default sorting.
|
||||||
// file, set sorting to "filename, ascending".
|
|
||||||
if (mRootFolder->getSortTypeString() == "")
|
if (mRootFolder->getSortTypeString() == "")
|
||||||
mRootFolder->setSortTypeString(FileSorts::SortTypes.at(0).description);
|
mRootFolder->setSortTypeString(Settings::getInstance()->
|
||||||
|
getDefaultString("DefaultSortOrder"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ void GuiMenu::openUISettings()
|
||||||
// If an invalid sort order was defined in es_settings.cfg, then apply the default
|
// If an invalid sort order was defined in es_settings.cfg, then apply the default
|
||||||
// sort order 'filename, ascending'.
|
// sort order 'filename, ascending'.
|
||||||
if (sortOrder == "")
|
if (sortOrder == "")
|
||||||
sortOrder = "filename, ascending";
|
sortOrder = Settings::getInstance()->getDefaultString("DefaultSortOrder");
|
||||||
for (auto it = FileSorts::SortTypes.cbegin(); it != FileSorts::SortTypes.cend(); it++) {
|
for (auto it = FileSorts::SortTypes.cbegin(); it != FileSorts::SortTypes.cend(); it++) {
|
||||||
const FileData::SortType& sort = *it;
|
const FileData::SortType& sort = *it;
|
||||||
if (sort.description == sortOrder)
|
if (sort.description == sortOrder)
|
||||||
|
|
|
@ -194,7 +194,7 @@ void GuiScreensaverOptions::openSlideshowScreensaverOptions()
|
||||||
Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_RIGHT);
|
Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_RIGHT);
|
||||||
s->addEditableTextComponent("CUSTOM IMAGE DIRECTORY", screensaver_slideshow_image_dir,
|
s->addEditableTextComponent("CUSTOM IMAGE DIRECTORY", screensaver_slideshow_image_dir,
|
||||||
Settings::getInstance()->getString("ScreensaverSlideshowImageDir"),
|
Settings::getInstance()->getString("ScreensaverSlideshowImageDir"),
|
||||||
"~/.emulationstation/slideshow/custom_images");
|
Settings::getInstance()->getDefaultString("ScreensaverSlideshowImageDir"));
|
||||||
s->addSaveFunc([screensaver_slideshow_image_dir, s] {
|
s->addSaveFunc([screensaver_slideshow_image_dir, s] {
|
||||||
if (screensaver_slideshow_image_dir->getValue() !=
|
if (screensaver_slideshow_image_dir->getValue() !=
|
||||||
Settings::getInstance()->getString("ScreensaverSlideshowImageDir")) {
|
Settings::getInstance()->getString("ScreensaverSlideshowImageDir")) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ Settings* Settings::sInstance = nullptr;
|
||||||
// the in-program settings menu. Most can be set using command-line arguments,
|
// 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
|
// but some are debug flags that are either hardcoded or set by internal debug
|
||||||
// functions.
|
// functions.
|
||||||
std::vector<const char*> settings_dont_save {
|
std::vector<std::string> settings_dont_save {
|
||||||
// These options can be set using command-line arguments:
|
// These options can be set using command-line arguments:
|
||||||
"Debug", // --debug
|
"Debug", // --debug
|
||||||
"ForceKid", // --force-kid
|
"ForceKid", // --force-kid
|
||||||
|
@ -75,75 +75,79 @@ void Settings::setDefaults()
|
||||||
mBoolMap.clear();
|
mBoolMap.clear();
|
||||||
mIntMap.clear();
|
mIntMap.clear();
|
||||||
|
|
||||||
|
// All settings are in pairs of default values and current values.
|
||||||
|
// As such, in this function we set these pairs identically.
|
||||||
|
|
||||||
//
|
//
|
||||||
// Settings configured via the in-program settings menu.
|
// Settings configured via the in-program settings menu.
|
||||||
//
|
//
|
||||||
|
|
||||||
// Scraper.
|
// Scraper.
|
||||||
mStringMap["Scraper"] = "screenscraper";
|
mStringMap["Scraper"] = { "screenscraper", "screenscraper" };
|
||||||
mBoolMap["ScraperUseAccountScreenScraper"] = false;
|
mBoolMap["ScraperUseAccountScreenScraper"] = { false, false };
|
||||||
mStringMap["ScraperUsernameScreenScraper"] = "";
|
mStringMap["ScraperUsernameScreenScraper"] = { "", "" };
|
||||||
mStringMap["ScraperPasswordScreenScraper"] = "";
|
mStringMap["ScraperPasswordScreenScraper"] = { "", "" };
|
||||||
mBoolMap["ScrapeGameNames"] = true;
|
mBoolMap["ScrapeGameNames"] = { true, true };
|
||||||
mBoolMap["ScrapeRatings"] = true;
|
mBoolMap["ScrapeRatings"] = { true, true };
|
||||||
mBoolMap["ScrapeMetadata"] = true;
|
mBoolMap["ScrapeMetadata"] = { true, true };
|
||||||
mBoolMap["ScrapeVideos"] = true;
|
mBoolMap["ScrapeVideos"] = { true, true };
|
||||||
mBoolMap["ScrapeScreenshots"] = true;
|
mBoolMap["ScrapeScreenshots"] = { true, true };
|
||||||
mBoolMap["ScrapeCovers"] = true;
|
mBoolMap["ScrapeCovers"] = { true, true };
|
||||||
mBoolMap["ScrapeMarquees"] = true;
|
mBoolMap["ScrapeMarquees"] = { true, true };
|
||||||
mBoolMap["Scrape3DBoxes"] = true;
|
mBoolMap["Scrape3DBoxes"] = { true, true };
|
||||||
mStringMap["ScraperRegion"] = "eu";
|
mStringMap["ScraperRegion"] = { "eu", "eu" };
|
||||||
mStringMap["ScraperLanguage"] = "en";
|
mStringMap["ScraperLanguage"] = { "en", "en" };
|
||||||
mBoolMap["ScraperOverwriteData"] = true;
|
mBoolMap["ScraperOverwriteData"] = { true, true };
|
||||||
mBoolMap["ScraperSearchMetadataName"] = true;
|
mBoolMap["ScraperSearchMetadataName"] = { true, true };
|
||||||
mBoolMap["ScraperInteractive"] = true;
|
mBoolMap["ScraperInteractive"] = { true, true };
|
||||||
mBoolMap["ScraperSemiautomatic"] = true;
|
mBoolMap["ScraperSemiautomatic"] = { true, true };
|
||||||
mBoolMap["ScraperRespectExclusions"] = true;
|
mBoolMap["ScraperRespectExclusions"] = { true, true };
|
||||||
mBoolMap["ScraperExcludeRecursively"] = true;
|
mBoolMap["ScraperExcludeRecursively"] = { true, true };
|
||||||
mBoolMap["ScraperIncludeFolders"] = false;
|
mBoolMap["ScraperIncludeFolders"] = { false, false };
|
||||||
|
|
||||||
// UI settings.
|
// UI settings.
|
||||||
mStringMap["StartupSystem"] = "";
|
mStringMap["StartupSystem"] = { "", "" };
|
||||||
mStringMap["GamelistViewStyle"] = "automatic";
|
mStringMap["GamelistViewStyle"] = { "automatic", "automatic" };
|
||||||
mStringMap["TransitionStyle"] = "slide";
|
mStringMap["TransitionStyle"] = { "slide", "slide" };
|
||||||
mStringMap["ThemeSet"] = "rbsimple-DE";
|
mStringMap["ThemeSet"] = { "rbsimple-DE", "rbsimple-DE" };
|
||||||
mStringMap["UIMode"] = "full";
|
mStringMap["UIMode"] = { "full", "full" };
|
||||||
mStringMap["DefaultSortOrder"] = "filename, ascending";
|
mStringMap["DefaultSortOrder"] = { "filename, ascending", "filename, ascending" };
|
||||||
mStringMap["MenuOpeningEffect"] = "scale-up";
|
mStringMap["MenuOpeningEffect"] = { "scale-up", "scale-up" };
|
||||||
mBoolMap["GamelistVideoPillarbox"] = true;
|
mBoolMap["GamelistVideoPillarbox"] = { true, true };
|
||||||
mBoolMap["GamelistVideoScanlines"] = true;
|
mBoolMap["GamelistVideoScanlines"] = { true, true };
|
||||||
mBoolMap["FoldersOnTop"] = true;
|
mBoolMap["FoldersOnTop"] = { true, true };
|
||||||
mBoolMap["FavoritesFirst"] = true;
|
mBoolMap["FavoritesFirst"] = { true, true };
|
||||||
mBoolMap["FavoritesStar"] = true;
|
mBoolMap["FavoritesStar"] = { true, true };
|
||||||
mBoolMap["FavoritesAddButton"] = true;
|
mBoolMap["FavoritesAddButton"] = { true, true };
|
||||||
mBoolMap["GamelistFilters"] = true;
|
mBoolMap["GamelistFilters"] = { true, true };
|
||||||
mBoolMap["QuickSystemSelect"] = true;
|
mBoolMap["QuickSystemSelect"] = { true, true };
|
||||||
mBoolMap["ShowHelpPrompts"] = true;
|
mBoolMap["ShowHelpPrompts"] = { true, true };
|
||||||
mBoolMap["PlayVideosImmediately"] = false;
|
mBoolMap["PlayVideosImmediately"] = { false, false };
|
||||||
mBoolMap["ShowKidStartMenu"] = false;
|
mBoolMap["ShowKidStartMenu"] = { false, false };
|
||||||
|
|
||||||
// UI settings -> screensaver settings.
|
// UI settings -> screensaver settings.
|
||||||
mIntMap["ScreensaverTimer"] = 5*60*1000; // 5 minutes
|
mIntMap["ScreensaverTimer"] = { 5*60*1000, 5*60*1000 }; // 5 minutes
|
||||||
mStringMap["ScreensaverType"] = "dim";
|
mStringMap["ScreensaverType"] = { "dim", "dim" };
|
||||||
mBoolMap["ScreensaverControls"] = true;
|
mBoolMap["ScreensaverControls"] = { true, true };
|
||||||
|
|
||||||
// UI settings -> screensaver settings -> slideshow screensaver settings.
|
// UI settings -> screensaver settings -> slideshow screensaver settings.
|
||||||
mIntMap["ScreensaverSwapImageTimeout"] = 10000;
|
mIntMap["ScreensaverSwapImageTimeout"] = { 10000, 10000 };
|
||||||
mBoolMap["ScreensaverStretchImages"] = false;
|
mBoolMap["ScreensaverStretchImages"] = { false, false };
|
||||||
mBoolMap["ScreensaverSlideshowGameInfo"] = true;
|
mBoolMap["ScreensaverSlideshowGameInfo"] = { true, true };
|
||||||
mBoolMap["ScreensaverSlideshowScanlines"] = true;
|
mBoolMap["ScreensaverSlideshowScanlines"] = { true, true };
|
||||||
mBoolMap["ScreensaverSlideshowCustomImages"] = false;
|
mBoolMap["ScreensaverSlideshowCustomImages"] = { false, false };
|
||||||
mBoolMap["ScreensaverSlideshowRecurse"] = false;
|
mBoolMap["ScreensaverSlideshowRecurse"] = { false, false };
|
||||||
mStringMap["ScreensaverSlideshowImageDir"] =
|
mStringMap["ScreensaverSlideshowImageDir"] = {
|
||||||
"~/.emulationstation/slideshow/custom_images";
|
"~/.emulationstation/slideshow/custom_images",
|
||||||
|
"~/.emulationstation/slideshow/custom_images" };
|
||||||
|
|
||||||
// UI settings -> screensaver settings -> video screensaver settings.
|
// UI settings -> screensaver settings -> video screensaver settings.
|
||||||
mIntMap["ScreensaverSwapVideoTimeout"] = 0;
|
mIntMap["ScreensaverSwapVideoTimeout"] = { 0, 0 };
|
||||||
mBoolMap["ScreensaverVideoAudio"] = false;
|
mBoolMap["ScreensaverVideoAudio"] = { false, false };
|
||||||
mBoolMap["ScreensaverStretchVideos"] = false;
|
mBoolMap["ScreensaverStretchVideos"] = { false, false };
|
||||||
mBoolMap["ScreensaverVideoGameInfo"] = true;
|
mBoolMap["ScreensaverVideoGameInfo"] = { true, true };
|
||||||
mBoolMap["ScreensaverVideoScanlines"] = true;
|
mBoolMap["ScreensaverVideoScanlines"] = { true, true };
|
||||||
mBoolMap["ScreensaverVideoBlur"] = false;
|
mBoolMap["ScreensaverVideoBlur"] = { false, false };
|
||||||
|
|
||||||
// Sound settings.
|
// Sound settings.
|
||||||
// The ALSA Audio Card and Audio Device selection code is disabled at the moment.
|
// The ALSA Audio Card and Audio Device selection code is disabled at the moment.
|
||||||
|
@ -154,63 +158,63 @@ void Settings::setDefaults()
|
||||||
// The code is still active for Raspberry Pi though as I'm not sure if this is
|
// The code is still active for Raspberry Pi though as I'm not sure if this is
|
||||||
// useful for that device.
|
// useful for that device.
|
||||||
#if defined(_RPI_)
|
#if defined(_RPI_)
|
||||||
mStringMap["AudioCard"] = "default";
|
mStringMap["AudioCard"] = { "default", "default" };
|
||||||
// Audio out device for volume control.
|
// Audio out device for volume control.
|
||||||
//#endif
|
//#endif
|
||||||
//#if defined(_RPI_)
|
//#if defined(_RPI_)
|
||||||
mStringMap["AudioDevice"] = "PCM";
|
mStringMap["AudioDevice"] = { "PCM", "PCM" };
|
||||||
// Audio out device for Video playback using OMX player.
|
// Audio out device for Video playback using OMX player.
|
||||||
mStringMap["OMXAudioDev"] = "both";
|
mStringMap["OMXAudioDev"] = { "both", "both" };
|
||||||
//#else
|
//#else
|
||||||
// mStringMap["AudioDevice"] = "Master";
|
// mStringMap["AudioDevice"] = { "Master", "Master" };
|
||||||
#endif
|
#endif
|
||||||
mBoolMap["GamelistVideoAudio"] = true;
|
mBoolMap["GamelistVideoAudio"] = { true, true };
|
||||||
mBoolMap["NavigationSounds"] = true;
|
mBoolMap["NavigationSounds"] = { true, true };
|
||||||
|
|
||||||
// Game collection settings.
|
// Game collection settings.
|
||||||
mStringMap["CollectionSystemsAuto"] = "";
|
mStringMap["CollectionSystemsAuto"] = { "", "" };
|
||||||
mStringMap["CollectionSystemsCustom"] = "";
|
mStringMap["CollectionSystemsCustom"] = { "", "" };
|
||||||
mBoolMap["FavFirstCustom"] = false;
|
mBoolMap["FavFirstCustom"] = { false, false };
|
||||||
mBoolMap["FavStarCustom"] = false;
|
mBoolMap["FavStarCustom"] = { false, false };
|
||||||
mBoolMap["UseCustomCollectionsSystem"] = true;
|
mBoolMap["UseCustomCollectionsSystem"] = { true, true };
|
||||||
mBoolMap["CollectionShowSystemInfo"] = true;
|
mBoolMap["CollectionShowSystemInfo"] = { true, true };
|
||||||
|
|
||||||
// Other settings.
|
// Other settings.
|
||||||
#if defined(_RPI_)
|
#if defined(_RPI_)
|
||||||
mIntMap["MaxVRAM"] = 80;
|
mIntMap["MaxVRAM"] = { 80, 80 };
|
||||||
#else
|
#else
|
||||||
mIntMap["MaxVRAM"] = 128;
|
mIntMap["MaxVRAM"] = { 128, 128 };
|
||||||
#endif
|
#endif
|
||||||
#if defined (__unix__)
|
#if defined (__unix__)
|
||||||
mStringMap["FullscreenMode"] = "normal";
|
mStringMap["FullscreenMode"] = { "normal", "normal" };
|
||||||
#endif
|
#endif
|
||||||
mStringMap["PowerSaverMode"] = "disabled";
|
mStringMap["PowerSaverMode"] = { "disabled", "disabled" };
|
||||||
#if defined(_RPI_)
|
#if defined(_RPI_)
|
||||||
mBoolMap["VideoOmxPlayer"] = false;
|
mBoolMap["VideoOmxPlayer"] = { false, false };
|
||||||
// We're defaulting to OMX Player for full screen video on the Pi.
|
// We're defaulting to OMX Player for full screen video on the Pi.
|
||||||
mBoolMap["ScreensaverOmxPlayer"] = true;
|
mBoolMap["ScreensaverOmxPlayer"] = { true, true };
|
||||||
#endif
|
#endif
|
||||||
mStringMap["SaveGamelistsMode"] = "always";
|
mStringMap["SaveGamelistsMode"] = { "always", "always" };
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
mBoolMap["HideTaskbar"] = false;
|
mBoolMap["HideTaskbar"] = { false, false };
|
||||||
// This setting may cause problems on some Windows versions, but it seems as if Windows 10
|
// This setting may cause problems on some Windows versions, but it seems as if Windows 10
|
||||||
// handles the suspension of ES correctly. As there are some adverse affects from running ES
|
// handles the suspension of ES correctly. As there are some adverse affects from running ES
|
||||||
// in the background while a game is running, by default this is set to false.
|
// in the background while a game is running, by default this is set to false.
|
||||||
mBoolMap["RunInBackground"] = false;
|
mBoolMap["RunInBackground"] = { false, false };
|
||||||
#endif
|
#endif
|
||||||
mStringMap["MediaDirectory"] = "";
|
mStringMap["MediaDirectory"] = { "", "" };
|
||||||
mBoolMap["LaunchCommandOverride"] = true;
|
mBoolMap["LaunchCommandOverride"] = { true, true };
|
||||||
mBoolMap["ShowHiddenFiles"] = true;
|
mBoolMap["ShowHiddenFiles"] = { true, true };
|
||||||
mBoolMap["ShowHiddenGames"] = true;
|
mBoolMap["ShowHiddenGames"] = { true, true };
|
||||||
mBoolMap["CustomEventScripts"] = false;
|
mBoolMap["CustomEventScripts"] = { false, false };
|
||||||
mBoolMap["ParseGamelistOnly"] = false;
|
mBoolMap["ParseGamelistOnly"] = { false, false };
|
||||||
mBoolMap["ROMDirGameMedia"] = false;
|
mBoolMap["ROMDirGameMedia"] = { false, false };
|
||||||
mBoolMap["DisplayGPUStatistics"] = false;
|
mBoolMap["DisplayGPUStatistics"] = { false, false };
|
||||||
// macOS requires root privileges to reboot and power off so it doesn't make much
|
// macOS requires root privileges to reboot and power off so it doesn't make much
|
||||||
// sense to enable these settings and menu entries for this operating system.
|
// sense to enable these settings and menu entries for this operating system.
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
mBoolMap["ShowRebootSystem"] = true;
|
mBoolMap["ShowRebootSystem"] = { true, true };
|
||||||
mBoolMap["ShowPoweroffSystem"] = true;
|
mBoolMap["ShowPoweroffSystem"] = { true, true };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -218,50 +222,50 @@ void Settings::setDefaults()
|
||||||
//
|
//
|
||||||
|
|
||||||
// Options listed using --help
|
// Options listed using --help
|
||||||
mBoolMap["Debug"] = false;
|
mBoolMap["Debug"] = { false, false };
|
||||||
mBoolMap["ForceKid"] = false;
|
mBoolMap["ForceKid"] = { false, false };
|
||||||
mBoolMap["ForceKiosk"] = false;
|
mBoolMap["ForceKiosk"] = { false, false };
|
||||||
mBoolMap["IgnoreGamelist"] = false;
|
mBoolMap["IgnoreGamelist"] = { false, false };
|
||||||
mBoolMap["ShowExit"] = true;
|
mBoolMap["ShowExit"] = { true, true };
|
||||||
mBoolMap["SplashScreen"] = true;
|
mBoolMap["SplashScreen"] = { true, true };
|
||||||
mBoolMap["VSync"] = true;
|
mBoolMap["VSync"] = { true, true };
|
||||||
#if !defined(_WIN64)
|
#if !defined(_WIN64)
|
||||||
mBoolMap["Windowed"] = false;
|
mBoolMap["Windowed"] = { false, false };
|
||||||
#endif
|
#endif
|
||||||
mIntMap["WindowWidth"] = 0;
|
mIntMap["WindowWidth"] = { 0, 0 };
|
||||||
mIntMap["WindowHeight"] = 0;
|
mIntMap["WindowHeight"] = { 0, 0 };
|
||||||
mIntMap["ScreenWidth"] = 0;
|
mIntMap["ScreenWidth"] = { 0, 0 };
|
||||||
|
|
||||||
// Undocumented options.
|
// Undocumented options.
|
||||||
mIntMap["ScreenHeight"] = 0;
|
mIntMap["ScreenHeight"] = { 0, 0 };
|
||||||
mIntMap["ScreenOffsetX"] = 0;
|
mIntMap["ScreenOffsetX"] = { 0, 0 };
|
||||||
mIntMap["ScreenOffsetY"] = 0;
|
mIntMap["ScreenOffsetY"] = { 0, 0 };
|
||||||
mIntMap["ScreenRotate"] = 0;
|
mIntMap["ScreenRotate"] = { 0, 0 };
|
||||||
|
|
||||||
//
|
//
|
||||||
// Settings that can be changed in es_settings.cfg
|
// Settings that can be changed in es_settings.cfg
|
||||||
// but that are not configurable via the GUI.
|
// but that are not configurable via the GUI.
|
||||||
//
|
//
|
||||||
|
|
||||||
mBoolMap["ShowDefaultKeyboardWarning"] = true;
|
mBoolMap["ShowDefaultKeyboardWarning"] = { true, true };
|
||||||
mStringMap["ROMDirectory"] = "";
|
mStringMap["ROMDirectory"] = { "", "" };
|
||||||
mIntMap["ScraperResizeMaxWidth"] = 600;
|
mIntMap["ScraperResizeMaxWidth"] = { 600, 600 };
|
||||||
mIntMap["ScraperResizeMaxHeight"] = 0;
|
mIntMap["ScraperResizeMaxHeight"] = { 0, 0 };
|
||||||
|
|
||||||
//
|
//
|
||||||
// Hardcoded or program-internal settings.
|
// Hardcoded or program-internal settings.
|
||||||
//
|
//
|
||||||
|
|
||||||
mBoolMap["BackgroundJoystickInput"] = false;
|
mBoolMap["BackgroundJoystickInput"] = { false, false };
|
||||||
mBoolMap["DebugGrid"] = false;
|
mBoolMap["DebugGrid"] = { false, false };
|
||||||
mBoolMap["DebugText"] = false;
|
mBoolMap["DebugText"] = { false, false };
|
||||||
mBoolMap["DebugImage"] = false;
|
mBoolMap["DebugImage"] = { false, false };
|
||||||
mBoolMap["SplashScreenProgress"] = true;
|
mBoolMap["SplashScreenProgress"] = { true, true };
|
||||||
mStringMap["UIMode_passkey"] = "uuddlrlrba";
|
mStringMap["UIMode_passkey"] = { "uuddlrlrba", "uuddlrlrba" };
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
void saveMap(pugi::xml_document& doc, std::map<K, V>& map, const char* type)
|
void saveMap(pugi::xml_document& doc, std::map<K, V>& map, const std::string& type)
|
||||||
{
|
{
|
||||||
for (auto iter = map.cbegin(); iter != map.cend(); iter++) {
|
for (auto iter = map.cbegin(); iter != map.cend(); iter++) {
|
||||||
// Key is on the "don't save" list, so don't save it.
|
// Key is on the "don't save" list, so don't save it.
|
||||||
|
@ -269,9 +273,9 @@ void saveMap(pugi::xml_document& doc, std::map<K, V>& map, const char* type)
|
||||||
iter->first) != settings_dont_save.cend())
|
iter->first) != settings_dont_save.cend())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pugi::xml_node node = doc.append_child(type);
|
pugi::xml_node node = doc.append_child(type.c_str());
|
||||||
node.append_attribute("name").set_value(iter->first.c_str());
|
node.append_attribute("name").set_value(iter->first.c_str());
|
||||||
node.append_attribute("value").set_value(iter->second);
|
node.append_attribute("value").set_value(iter->second.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,14 +287,14 @@ void Settings::saveFile()
|
||||||
|
|
||||||
pugi::xml_document doc;
|
pugi::xml_document doc;
|
||||||
|
|
||||||
saveMap<std::string, bool>(doc, mBoolMap, "bool");
|
saveMap<std::string, std::pair<bool, bool>>(doc, mBoolMap, "bool");
|
||||||
saveMap<std::string, int>(doc, mIntMap, "int");
|
saveMap<std::string, std::pair<int, int>>(doc, mIntMap, "int");
|
||||||
saveMap<std::string, float>(doc, mFloatMap, "float");
|
saveMap<std::string, std::pair<float, float>>(doc, mFloatMap, "float");
|
||||||
|
|
||||||
for (auto iter = mStringMap.cbegin(); iter != mStringMap.cend(); iter++) {
|
for (auto iter = mStringMap.cbegin(); iter != mStringMap.cend(); iter++) {
|
||||||
pugi::xml_node node = doc.append_child("string");
|
pugi::xml_node node = doc.append_child("string");
|
||||||
node.append_attribute("name").set_value(iter->first.c_str());
|
node.append_attribute("name").set_value(iter->first.c_str());
|
||||||
node.append_attribute("value").set_value(iter->second.c_str());
|
node.append_attribute("value").set_value(iter->second.second.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN64)
|
#if defined(_WIN64)
|
||||||
|
@ -334,18 +338,25 @@ void Settings::loadFile()
|
||||||
|
|
||||||
// Print a warning message if the setting we're trying to get doesn't already exist in
|
// 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.
|
// the map. Then return the value in the map.
|
||||||
#define SETTINGS_GETSET(type, mapName, getMethodName, setMethodName) \
|
#define SETTINGS_GETSET(type, mapName, getFunction, getDefaultFunction, setFunction) \
|
||||||
type Settings::getMethodName(const std::string& name) \
|
type Settings::getFunction(const std::string& name) \
|
||||||
{ \
|
{ \
|
||||||
if (mapName.find(name) == mapName.cend()) { \
|
if (mapName.find(name) == mapName.cend()) { \
|
||||||
LOG(LogError) << "Tried to use unset setting " << name << "!"; \
|
LOG(LogError) << "Tried to use unset setting " << name << "!"; \
|
||||||
} \
|
} \
|
||||||
return mapName[name]; \
|
return mapName[name].second; \
|
||||||
} \
|
} \
|
||||||
bool Settings::setMethodName(const std::string& name, type value) \
|
type Settings::getDefaultFunction(const std::string& name) \
|
||||||
{ \
|
{ \
|
||||||
if (mapName.count(name) == 0 || mapName[name] != value) { \
|
if (mapName.find(name) == mapName.cend()) { \
|
||||||
mapName[name] = value; \
|
LOG(LogError) << "Tried to use unset setting " << name << "!"; \
|
||||||
|
} \
|
||||||
|
return mapName[name].first; \
|
||||||
|
} \
|
||||||
|
bool Settings::setFunction(const std::string& name, type value) \
|
||||||
|
{ \
|
||||||
|
if (mapName.count(name) == 0 || mapName[name].second != value) { \
|
||||||
|
mapName[name].second = value; \
|
||||||
\
|
\
|
||||||
if (std::find(settings_dont_save.cbegin(), settings_dont_save.cend(), name) \
|
if (std::find(settings_dont_save.cbegin(), settings_dont_save.cend(), name) \
|
||||||
== settings_dont_save.cend()) \
|
== settings_dont_save.cend()) \
|
||||||
|
@ -356,7 +367,7 @@ bool Settings::setMethodName(const std::string& name, type value) \
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
SETTINGS_GETSET(bool, mBoolMap, getBool, setBool);
|
SETTINGS_GETSET(bool, mBoolMap, getBool, getDefaultBool, setBool);
|
||||||
SETTINGS_GETSET(int, mIntMap, getInt, setInt);
|
SETTINGS_GETSET(int, mIntMap, getInt, getDefaultInt, setInt);
|
||||||
SETTINGS_GETSET(float, mFloatMap, getFloat, setFloat);
|
SETTINGS_GETSET(float, mFloatMap, getFloat, getDefaultFloat, setFloat);
|
||||||
SETTINGS_GETSET(const std::string&, mStringMap, getString, setString);
|
SETTINGS_GETSET(const std::string&, mStringMap, getString, getDefaultString, setString);
|
||||||
|
|
|
@ -24,9 +24,13 @@ public:
|
||||||
|
|
||||||
// You will get a warning if you try a get on a key that is not already present.
|
// You will get a warning if you try a get on a key that is not already present.
|
||||||
bool getBool(const std::string& name);
|
bool getBool(const std::string& name);
|
||||||
|
bool getDefaultBool(const std::string& name);
|
||||||
int getInt(const std::string& name);
|
int getInt(const std::string& name);
|
||||||
|
int getDefaultInt(const std::string& name);
|
||||||
float getFloat(const std::string& name);
|
float getFloat(const std::string& name);
|
||||||
|
float getDefaultFloat(const std::string& name);
|
||||||
const std::string& getString(const std::string& name);
|
const std::string& getString(const std::string& name);
|
||||||
|
const std::string& getDefaultString(const std::string& name);
|
||||||
|
|
||||||
bool setBool(const std::string& name, bool value);
|
bool setBool(const std::string& name, bool value);
|
||||||
bool setInt(const std::string& name, int value);
|
bool setInt(const std::string& name, int value);
|
||||||
|
@ -43,10 +47,11 @@ private:
|
||||||
|
|
||||||
bool mWasChanged;
|
bool mWasChanged;
|
||||||
|
|
||||||
std::map<std::string, bool> mBoolMap;
|
// Pair of settings: default value, current value.
|
||||||
std::map<std::string, int> mIntMap;
|
std::map<std::string, std::pair<bool, bool>> mBoolMap;
|
||||||
std::map<std::string, float> mFloatMap;
|
std::map<std::string, std::pair<int, int>> mIntMap;
|
||||||
std::map<std::string, std::string> mStringMap;
|
std::map<std::string, std::pair<float, float>> mFloatMap;
|
||||||
|
std::map<std::string, std::pair<std::string, std::string>> mStringMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_CORE_SETTINGS_H
|
#endif // ES_CORE_SETTINGS_H
|
||||||
|
|
Loading…
Reference in a new issue