2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// ThemeData.cpp
|
|
|
|
//
|
2022-01-29 17:41:22 +00:00
|
|
|
// Finds available themes on the file system and loads and parses these.
|
|
|
|
// Basic error checking for valid elements and data types is done here,
|
|
|
|
// with additional validation handled by the individual components.
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
|
2013-11-12 23:28:15 +00:00
|
|
|
#include "ThemeData.h"
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "Log.h"
|
|
|
|
#include "Settings.h"
|
2014-01-03 14:26:39 +00:00
|
|
|
#include "components/ImageComponent.h"
|
|
|
|
#include "components/TextComponent.h"
|
2018-01-09 22:55:09 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2019-07-06 14:50:50 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2020-09-21 17:17:34 +00:00
|
|
|
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <algorithm>
|
2020-09-21 17:17:34 +00:00
|
|
|
#include <pugixml.hpp>
|
2014-01-26 22:20:21 +00:00
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
#define MINIMUM_LEGACY_THEME_FORMAT_VERSION 3
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
std::vector<std::string> ThemeData::sSupportedViews {
|
|
|
|
{"all"},
|
|
|
|
{"system"},
|
|
|
|
{"gamelist"}};
|
|
|
|
|
|
|
|
std::vector<std::string> ThemeData::sLegacySupportedViews {
|
|
|
|
{"all"},
|
|
|
|
{"system"},
|
|
|
|
{"basic"},
|
|
|
|
{"detailed"},
|
|
|
|
{"grid"},
|
|
|
|
{"video"}};
|
|
|
|
|
|
|
|
std::vector<std::string> ThemeData::sLegacySupportedFeatures {
|
|
|
|
{"navigationsounds"},
|
|
|
|
{"video"},
|
|
|
|
{"carousel"},
|
|
|
|
{"z-index"},
|
|
|
|
{"visible"}};
|
|
|
|
|
2022-02-10 23:19:08 +00:00
|
|
|
std::vector<std::string> ThemeData::sLegacyElements {
|
|
|
|
{"showSnapshotNoVideo"},
|
|
|
|
{"showSnapshotDelay"},
|
|
|
|
{"forceUppercase"},
|
|
|
|
{"alignment"},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"defaultLogo"},
|
|
|
|
{"logoSize"},
|
|
|
|
{"logoScale"},
|
|
|
|
{"logoRotation"},
|
|
|
|
{"logoRotationOrigin"},
|
|
|
|
{"logoAlignment"},
|
|
|
|
{"maxLogoCount"}};
|
2022-02-10 23:19:08 +00:00
|
|
|
|
2022-01-31 22:22:42 +00:00
|
|
|
std::vector<std::pair<std::string, std::string>> ThemeData::sSupportedAspectRatios {
|
|
|
|
{"16:9", "16:9"},
|
|
|
|
{"16:9_vertical", "16:9 vertical"},
|
|
|
|
{"16:10", "16:10"},
|
|
|
|
{"16:10_vertical", "16:10 vertical"},
|
|
|
|
{"3:2", "3:2"},
|
|
|
|
{"3:2_vertical", "3:2 vertical"},
|
|
|
|
{"4:3", "4:3"},
|
|
|
|
{"4:3_vertical", "4:3 vertical"},
|
|
|
|
{"5:4", "5:4"},
|
|
|
|
{"5:4_vertical", "5:4 vertical"},
|
|
|
|
{"21:9", "21:9"},
|
|
|
|
{"21:9_vertical", "21:9 vertical"},
|
|
|
|
{"32:9", "32:0"},
|
|
|
|
{"32:9_vertical", "32:9 vertical"}};
|
2022-01-29 17:41:22 +00:00
|
|
|
|
|
|
|
std::map<std::string, std::map<std::string, std::string>> ThemeData::sPropertyAttributeMap
|
|
|
|
// The data type is defined by the parent property.
|
|
|
|
{
|
|
|
|
{"badges",
|
|
|
|
{{"customBadgeIcon", "badge"},
|
|
|
|
{"customControllerIcon", "controller"}}},
|
|
|
|
{"helpsystem",
|
|
|
|
{{"customButtonIcon", "button"}}},
|
|
|
|
};
|
2021-08-17 16:41:45 +00:00
|
|
|
|
2022-01-16 11:09:55 +00:00
|
|
|
std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
2022-01-29 17:41:22 +00:00
|
|
|
ThemeData::sElementMap {
|
|
|
|
{"image",
|
2022-01-16 11:09:55 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
|
|
|
{"maxSize", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
|
|
|
{"rotation", FLOAT},
|
|
|
|
{"rotationOrigin", NORMALIZED_PAIR},
|
|
|
|
{"path", PATH},
|
|
|
|
{"default", PATH},
|
2022-02-13 10:45:06 +00:00
|
|
|
{"imageType", STRING},
|
2022-08-18 20:51:21 +00:00
|
|
|
{"metadataElement", BOOLEAN},
|
2022-02-14 18:32:07 +00:00
|
|
|
{"gameselector", STRING},
|
2022-02-13 14:01:55 +00:00
|
|
|
{"tile", BOOLEAN},
|
2022-09-06 19:33:50 +00:00
|
|
|
{"tileSize", NORMALIZED_PAIR},
|
2022-09-07 18:18:15 +00:00
|
|
|
{"tileHorizontalAlignment", STRING},
|
|
|
|
{"tileVerticalAlignment", STRING},
|
2022-02-13 10:45:06 +00:00
|
|
|
{"interpolation", STRING},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"color", COLOR},
|
|
|
|
{"colorEnd", COLOR},
|
|
|
|
{"gradientType", STRING},
|
2022-01-30 18:30:38 +00:00
|
|
|
{"scrollFadeIn", BOOLEAN},
|
2022-02-12 16:38:55 +00:00
|
|
|
{"opacity", FLOAT},
|
2022-03-17 18:33:09 +00:00
|
|
|
{"saturation", FLOAT},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"visible", BOOLEAN},
|
|
|
|
{"zIndex", FLOAT}}},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"video",
|
2022-01-16 11:09:55 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"maxSize", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
|
|
|
{"path", PATH},
|
|
|
|
{"default", PATH},
|
2022-01-30 18:30:38 +00:00
|
|
|
{"defaultImage", PATH},
|
2022-02-13 10:45:06 +00:00
|
|
|
{"imageType", STRING},
|
2022-09-16 17:43:36 +00:00
|
|
|
{"metadataElement", BOOLEAN},
|
2022-02-19 20:22:46 +00:00
|
|
|
{"gameselector", STRING},
|
2022-02-19 20:45:31 +00:00
|
|
|
{"audio", BOOLEAN},
|
2022-02-13 10:45:06 +00:00
|
|
|
{"interpolation", STRING},
|
2022-02-12 16:38:55 +00:00
|
|
|
{"pillarboxes", BOOLEAN},
|
2022-10-16 14:40:52 +00:00
|
|
|
{"pillarboxThreshold", NORMALIZED_PAIR},
|
2022-02-12 16:38:55 +00:00
|
|
|
{"scanlines", BOOLEAN},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"delay", FLOAT},
|
2022-02-15 20:26:40 +00:00
|
|
|
{"fadeInTime", FLOAT},
|
2022-01-30 18:30:38 +00:00
|
|
|
{"scrollFadeIn", BOOLEAN},
|
2022-02-12 16:38:55 +00:00
|
|
|
{"opacity", FLOAT},
|
2022-03-17 18:33:09 +00:00
|
|
|
{"saturation", FLOAT},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"visible", BOOLEAN},
|
|
|
|
{"zIndex", FLOAT},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"showSnapshotNoVideo", BOOLEAN}, // For backward compatibility with legacy themes.
|
|
|
|
{"showSnapshotDelay", BOOLEAN}}}, // For backward compatibility with legacy themes.
|
2022-01-29 17:41:22 +00:00
|
|
|
{"animation",
|
2022-01-16 11:09:55 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
|
|
|
{"rotation", FLOAT},
|
|
|
|
{"rotationOrigin", NORMALIZED_PAIR},
|
2022-08-18 20:51:21 +00:00
|
|
|
{"metadataElement", BOOLEAN},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"path", PATH},
|
|
|
|
{"speed", FLOAT},
|
|
|
|
{"direction", STRING},
|
|
|
|
{"keepAspectRatio", BOOLEAN},
|
2022-03-05 19:56:47 +00:00
|
|
|
{"interpolation", STRING},
|
2022-02-12 16:38:55 +00:00
|
|
|
{"opacity", FLOAT},
|
2022-03-17 18:33:09 +00:00
|
|
|
{"saturation", FLOAT},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"visible", BOOLEAN},
|
|
|
|
{"zIndex", FLOAT}}},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"badges",
|
2022-01-16 11:09:55 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"rotation", FLOAT},
|
|
|
|
{"rotationOrigin", NORMALIZED_PAIR},
|
2022-02-10 23:19:08 +00:00
|
|
|
{"horizontalAlignment", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"alignment", STRING}, // For backward compatibility with legacy themes.
|
2022-01-29 17:41:22 +00:00
|
|
|
{"direction", STRING},
|
2022-02-13 14:01:55 +00:00
|
|
|
{"lines", UNSIGNED_INTEGER},
|
|
|
|
{"itemsPerLine", UNSIGNED_INTEGER},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"itemMargin", NORMALIZED_PAIR},
|
|
|
|
{"slots", STRING},
|
|
|
|
{"controllerPos", NORMALIZED_PAIR},
|
|
|
|
{"controllerSize", FLOAT},
|
|
|
|
{"customBadgeIcon", PATH},
|
|
|
|
{"customControllerIcon", PATH},
|
2022-04-13 14:53:28 +00:00
|
|
|
{"folderLinkPos", NORMALIZED_PAIR},
|
|
|
|
{"folderLinkSize", FLOAT},
|
|
|
|
{"customFolderLinkIcon", PATH},
|
2022-02-12 16:38:55 +00:00
|
|
|
{"opacity", FLOAT},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"visible", BOOLEAN},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"zIndex", FLOAT}}},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"text",
|
2022-01-16 11:09:55 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"rotation", FLOAT},
|
|
|
|
{"rotationOrigin", NORMALIZED_PAIR},
|
2022-01-22 20:21:13 +00:00
|
|
|
{"text", STRING},
|
2022-02-13 10:45:06 +00:00
|
|
|
{"systemdata", STRING},
|
2022-01-22 20:21:13 +00:00
|
|
|
{"metadata", STRING},
|
2022-08-18 20:51:21 +00:00
|
|
|
{"metadataElement", BOOLEAN},
|
2022-02-14 18:32:07 +00:00
|
|
|
{"gameselector", STRING},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"container", BOOLEAN},
|
2022-09-16 16:51:36 +00:00
|
|
|
{"containerVerticalSnap", BOOLEAN},
|
2022-02-10 19:02:56 +00:00
|
|
|
{"containerScrollSpeed", FLOAT},
|
|
|
|
{"containerStartDelay", FLOAT},
|
|
|
|
{"containerResetDelay", FLOAT},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"fontPath", PATH},
|
|
|
|
{"fontSize", FLOAT},
|
2022-02-10 23:19:08 +00:00
|
|
|
{"horizontalAlignment", STRING},
|
|
|
|
{"verticalAlignment", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"alignment", STRING}, // For backward compatibility with legacy themes.
|
2022-01-29 17:41:22 +00:00
|
|
|
{"color", COLOR},
|
|
|
|
{"backgroundColor", COLOR},
|
2022-02-09 19:44:22 +00:00
|
|
|
{"letterCase", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"forceUppercase", BOOLEAN}, // For backward compatibility with legacy themes.
|
2022-01-29 17:41:22 +00:00
|
|
|
{"lineSpacing", FLOAT},
|
2022-02-12 16:38:55 +00:00
|
|
|
{"opacity", FLOAT},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"visible", BOOLEAN},
|
|
|
|
{"zIndex", FLOAT}}},
|
|
|
|
{"datetime",
|
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
|
|
|
{"rotation", FLOAT},
|
|
|
|
{"rotationOrigin", NORMALIZED_PAIR},
|
2022-01-22 20:21:13 +00:00
|
|
|
{"metadata", STRING},
|
2022-02-20 14:49:32 +00:00
|
|
|
{"gameselector", STRING},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"fontPath", PATH},
|
|
|
|
{"fontSize", FLOAT},
|
2022-02-10 23:19:08 +00:00
|
|
|
{"horizontalAlignment", STRING},
|
|
|
|
{"verticalAlignment", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"alignment", STRING}, // For backward compatibility with legacy themes.
|
2022-01-29 17:41:22 +00:00
|
|
|
{"color", COLOR},
|
|
|
|
{"backgroundColor", COLOR},
|
2022-02-09 19:44:22 +00:00
|
|
|
{"letterCase", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"forceUppercase", BOOLEAN}, // For backward compatibility with legacy themes.
|
2022-01-16 11:09:55 +00:00
|
|
|
{"lineSpacing", FLOAT},
|
|
|
|
{"format", STRING},
|
|
|
|
{"displayRelative", BOOLEAN},
|
2022-02-12 16:38:55 +00:00
|
|
|
{"opacity", FLOAT},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"visible", BOOLEAN},
|
|
|
|
{"zIndex", FLOAT}}},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"gamelistinfo",
|
2022-01-16 11:09:55 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
|
|
|
{"rotation", FLOAT},
|
|
|
|
{"rotationOrigin", NORMALIZED_PAIR},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"fontPath", PATH},
|
|
|
|
{"fontSize", FLOAT},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"color", COLOR},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"backgroundColor", COLOR},
|
2022-02-10 23:19:08 +00:00
|
|
|
{"horizontalAlignment", STRING},
|
|
|
|
{"verticalAlignment", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"alignment", STRING}, // For backward compatibility with legacy themes.
|
2022-02-12 16:38:55 +00:00
|
|
|
{"opacity", FLOAT},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"visible", BOOLEAN},
|
|
|
|
{"zIndex", FLOAT}}},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"rating",
|
2022-01-16 11:09:55 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
|
|
|
{"rotation", FLOAT},
|
|
|
|
{"rotationOrigin", NORMALIZED_PAIR},
|
2022-03-18 21:16:53 +00:00
|
|
|
{"gameselector", STRING},
|
2022-08-28 18:45:04 +00:00
|
|
|
{"interpolation", STRING},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"color", COLOR},
|
|
|
|
{"filledPath", PATH},
|
|
|
|
{"unfilledPath", PATH},
|
2022-09-01 15:40:29 +00:00
|
|
|
{"overlay", BOOLEAN},
|
2022-02-12 16:38:55 +00:00
|
|
|
{"opacity", FLOAT},
|
|
|
|
{"visible", BOOLEAN},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"zIndex", FLOAT}}},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"carousel",
|
2022-09-16 16:51:36 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"size", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
2022-09-16 16:51:36 +00:00
|
|
|
{"type", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"staticItem", PATH},
|
|
|
|
{"itemType", STRING},
|
|
|
|
{"defaultItem", PATH},
|
2022-09-16 16:51:36 +00:00
|
|
|
{"maxItemCount", FLOAT},
|
|
|
|
{"maxLogoCount", FLOAT}, // For backward compatibility with legacy themes.
|
2022-09-19 16:51:05 +00:00
|
|
|
{"itemsBeforeCenter", UNSIGNED_INTEGER},
|
|
|
|
{"itemsAfterCenter", UNSIGNED_INTEGER},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"itemSize", NORMALIZED_PAIR},
|
|
|
|
{"itemScale", FLOAT},
|
2022-09-17 10:42:27 +00:00
|
|
|
{"itemTransitions", STRING},
|
2022-09-16 16:51:36 +00:00
|
|
|
{"itemInterpolation", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"itemRotation", FLOAT},
|
|
|
|
{"itemRotationOrigin", NORMALIZED_PAIR},
|
2022-09-20 15:05:24 +00:00
|
|
|
{"itemAxisHorizontal", BOOLEAN},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"itemHorizontalAlignment", STRING},
|
|
|
|
{"itemVerticalAlignment", STRING},
|
2022-06-03 18:53:15 +00:00
|
|
|
{"wheelHorizontalAlignment", STRING},
|
2022-04-18 19:37:58 +00:00
|
|
|
{"horizontalOffset", FLOAT},
|
|
|
|
{"verticalOffset", FLOAT},
|
|
|
|
{"reflections", BOOLEAN},
|
|
|
|
{"reflectionsOpacity", FLOAT},
|
|
|
|
{"reflectionsFalloff", FLOAT},
|
2022-04-17 11:08:28 +00:00
|
|
|
{"unfocusedItemOpacity", FLOAT},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"defaultLogo", PATH}, // For backward compatibility with legacy themes.
|
|
|
|
{"logoSize", NORMALIZED_PAIR}, // For backward compatibility with legacy themes.
|
|
|
|
{"logoScale", FLOAT}, // For backward compatibility with legacy themes.
|
|
|
|
{"logoRotation", FLOAT}, // For backward compatibility with legacy themes.
|
|
|
|
{"logoRotationOrigin", NORMALIZED_PAIR}, // For backward compatibility with legacy themes.
|
|
|
|
{"logoAlignment", STRING}, // For backward compatibility with legacy themes.
|
2022-09-16 16:51:36 +00:00
|
|
|
{"color", COLOR},
|
|
|
|
{"colorEnd", COLOR},
|
|
|
|
{"gradientType", STRING},
|
2022-02-07 20:05:56 +00:00
|
|
|
{"text", STRING},
|
|
|
|
{"textColor", COLOR},
|
|
|
|
{"textBackgroundColor", COLOR},
|
|
|
|
{"fontPath", PATH},
|
|
|
|
{"fontSize", FLOAT},
|
2022-09-16 16:51:36 +00:00
|
|
|
{"letterCase", STRING},
|
2022-02-07 20:05:56 +00:00
|
|
|
{"lineSpacing", FLOAT},
|
2022-09-26 18:02:31 +00:00
|
|
|
{"fadeAbovePrimary", BOOLEAN},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"zIndex", FLOAT},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"legacyZIndexMode", STRING}}}, // For backward compatibility with legacy themes.
|
2022-01-29 17:41:22 +00:00
|
|
|
{"textlist",
|
2022-01-16 11:09:55 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
|
|
|
{"origin", NORMALIZED_PAIR},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"selectorHeight", FLOAT},
|
|
|
|
{"selectorOffsetY", FLOAT},
|
|
|
|
{"selectorColor", COLOR},
|
|
|
|
{"selectorColorEnd", COLOR},
|
|
|
|
{"selectorGradientType", STRING},
|
|
|
|
{"selectorImagePath", PATH},
|
|
|
|
{"selectorImageTile", BOOLEAN},
|
|
|
|
{"selectedColor", COLOR},
|
|
|
|
{"primaryColor", COLOR},
|
|
|
|
{"secondaryColor", COLOR},
|
|
|
|
{"fontPath", PATH},
|
|
|
|
{"fontSize", FLOAT},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"scrollSound", PATH}, // For backward compatibility with legacy themes.
|
2022-02-10 23:19:08 +00:00
|
|
|
{"horizontalAlignment", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"alignment", STRING}, // For backward compatibility with legacy themes.
|
2022-01-29 17:41:22 +00:00
|
|
|
{"horizontalMargin", FLOAT},
|
2022-02-09 19:44:22 +00:00
|
|
|
{"letterCase", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"forceUppercase", BOOLEAN}, // For backward compatibility with legacy themes.
|
2022-01-29 17:41:22 +00:00
|
|
|
{"lineSpacing", FLOAT},
|
2022-04-15 15:06:33 +00:00
|
|
|
{"indicators", STRING},
|
2022-04-15 19:20:43 +00:00
|
|
|
{"collectionIndicators", STRING},
|
2022-09-26 18:02:31 +00:00
|
|
|
{"fadeAbovePrimary", BOOLEAN},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"zIndex", FLOAT}}},
|
2022-02-13 19:03:34 +00:00
|
|
|
{"gameselector",
|
|
|
|
{{"selection", STRING},
|
2022-02-14 18:32:07 +00:00
|
|
|
{"gameCount", UNSIGNED_INTEGER}}},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"helpsystem",
|
|
|
|
{{"pos", NORMALIZED_PAIR},
|
2022-03-20 18:07:52 +00:00
|
|
|
{"origin", NORMALIZED_PAIR},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"textColor", COLOR},
|
|
|
|
{"textColorDimmed", COLOR},
|
|
|
|
{"iconColor", COLOR},
|
|
|
|
{"iconColorDimmed", COLOR},
|
|
|
|
{"fontPath", PATH},
|
|
|
|
{"fontSize", FLOAT},
|
|
|
|
{"entrySpacing", FLOAT},
|
|
|
|
{"iconTextSpacing", FLOAT},
|
2022-02-09 19:44:22 +00:00
|
|
|
{"letterCase", STRING},
|
2022-04-16 19:54:58 +00:00
|
|
|
{"textStyle", STRING}, // For backward compatibility with legacy themes.
|
2022-02-13 11:18:33 +00:00
|
|
|
{"opacity", FLOAT},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"customButtonIcon", PATH}}},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"sound",
|
|
|
|
{{"path", PATH}}},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"navigationsounds",
|
|
|
|
{{"systembrowseSound", PATH},
|
|
|
|
{"quicksysselectSound", PATH},
|
|
|
|
{"selectSound", PATH},
|
|
|
|
{"backSound", PATH},
|
|
|
|
{"scrollSound", PATH},
|
|
|
|
{"favoriteSound", PATH},
|
|
|
|
{"launchSound", PATH}}},
|
2022-01-29 17:41:22 +00:00
|
|
|
// Legacy components below, not in use any longer but needed for backward compatibility.
|
|
|
|
{"imagegrid",
|
2022-01-16 11:09:55 +00:00
|
|
|
{{"pos", NORMALIZED_PAIR},
|
|
|
|
{"size", NORMALIZED_PAIR},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"margin", NORMALIZED_PAIR},
|
|
|
|
{"padding", NORMALIZED_RECT},
|
|
|
|
{"autoLayout", NORMALIZED_PAIR},
|
|
|
|
{"autoLayoutSelectedZoom", FLOAT},
|
|
|
|
{"gameImage", PATH},
|
|
|
|
{"folderImage", PATH},
|
|
|
|
{"imageSource", STRING},
|
|
|
|
{"scrollDirection", STRING},
|
|
|
|
{"centerSelection", BOOLEAN},
|
|
|
|
{"scrollLoop", BOOLEAN},
|
|
|
|
{"animate", BOOLEAN},
|
|
|
|
{"zIndex", FLOAT}}},
|
|
|
|
{"gridtile",
|
|
|
|
{{"size", NORMALIZED_PAIR},
|
|
|
|
{"padding", NORMALIZED_PAIR},
|
|
|
|
{"imageColor", COLOR},
|
|
|
|
{"backgroundImage", PATH},
|
|
|
|
{"backgroundCornerSize", NORMALIZED_PAIR},
|
|
|
|
{"backgroundColor", COLOR},
|
|
|
|
{"backgroundCenterColor", COLOR},
|
|
|
|
{"backgroundEdgeColor", COLOR}}},
|
|
|
|
{"ninepatch",
|
|
|
|
{{"pos", NORMALIZED_PAIR},
|
2022-01-16 11:09:55 +00:00
|
|
|
{"size", NORMALIZED_PAIR},
|
2022-01-29 17:41:22 +00:00
|
|
|
{"path", PATH},
|
|
|
|
{"visible", BOOLEAN},
|
|
|
|
{"zIndex", FLOAT}}}};
|
|
|
|
// clang-format on
|
2021-07-07 18:31:46 +00:00
|
|
|
|
2013-12-30 23:23:34 +00:00
|
|
|
ThemeData::ThemeData()
|
2022-08-14 18:24:26 +00:00
|
|
|
: mLegacyTheme {false}
|
2022-10-29 11:04:00 +00:00
|
|
|
, mCustomCollection {false}
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
2022-08-14 18:24:26 +00:00
|
|
|
mCurrentThemeSet = mThemeSets.find(Settings::getInstance()->getString("ThemeSet"));
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 16:50:51 +00:00
|
|
|
void ThemeData::loadFile(const std::map<std::string, std::string>& sysDataMap,
|
2022-10-29 11:04:00 +00:00
|
|
|
const std::string& path,
|
|
|
|
const bool customCollection)
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
2022-10-29 11:04:00 +00:00
|
|
|
mCustomCollection = customCollection;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mPaths.push_back(path);
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
ThemeException error;
|
2022-01-23 16:50:51 +00:00
|
|
|
error << "ThemeData::loadFile(): ";
|
2020-06-21 12:25:28 +00:00
|
|
|
error.setFiles(mPaths);
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!Utils::FileSystem::exists(path))
|
2021-01-17 21:33:02 +00:00
|
|
|
throw error << "File does not exist";
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mViews.clear();
|
|
|
|
mVariables.clear();
|
2017-05-14 04:07:28 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mVariables.insert(sysDataMap.cbegin(), sysDataMap.cend());
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_document doc;
|
2021-07-07 18:31:46 +00:00
|
|
|
#if defined(_WIN64)
|
2022-01-23 16:50:51 +00:00
|
|
|
pugi::xml_parse_result res {doc.load_file(Utils::String::stringToWideString(path).c_str())};
|
2021-07-07 18:31:46 +00:00
|
|
|
#else
|
2022-01-23 16:50:51 +00:00
|
|
|
pugi::xml_parse_result res {doc.load_file(path.c_str())};
|
2021-07-07 18:31:46 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!res)
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": XML parsing error: " << res.description();
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2022-01-23 16:50:51 +00:00
|
|
|
pugi::xml_node root {doc.child("theme")};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!root)
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": Missing <theme> tag";
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
if (mCurrentThemeSet != mThemeSets.cend())
|
|
|
|
mLegacyTheme = mCurrentThemeSet->second.capabilities.legacyTheme;
|
|
|
|
|
2022-04-10 09:32:55 +00:00
|
|
|
// The resolution tag introduced in RetroPie EmulationStation in 2020 is a very bad idea
|
|
|
|
// as it changes sizing of components from relative values to absolute pixel values.
|
|
|
|
// So themes using it will simply not get loaded at all.
|
|
|
|
if (root.child("resolution") != nullptr)
|
|
|
|
throw error << ": <resolution> tag not supported";
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
// Check for legacy theme version.
|
|
|
|
int legacyVersion {root.child("formatVersion").text().as_int(-1)};
|
|
|
|
|
|
|
|
if (mLegacyTheme) {
|
|
|
|
if (legacyVersion == -1)
|
|
|
|
throw error << ": <formatVersion> tag missing for legacy theme set";
|
|
|
|
|
|
|
|
if (legacyVersion < MINIMUM_LEGACY_THEME_FORMAT_VERSION)
|
|
|
|
throw error << ": Defined legacy format version " << legacyVersion
|
|
|
|
<< " is less than the minimum supported version "
|
|
|
|
<< MINIMUM_LEGACY_THEME_FORMAT_VERSION;
|
|
|
|
}
|
|
|
|
else if (legacyVersion != -1) {
|
|
|
|
throw error << ": Legacy <formatVersion> tag found for non-legacy theme set";
|
|
|
|
}
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
if (!mLegacyTheme) {
|
|
|
|
if (mCurrentThemeSet->second.capabilities.variants.size() > 0) {
|
|
|
|
for (auto& variant : mCurrentThemeSet->second.capabilities.variants)
|
|
|
|
mVariants.emplace_back(variant.name);
|
|
|
|
|
|
|
|
if (std::find(mVariants.cbegin(), mVariants.cend(),
|
|
|
|
Settings::getInstance()->getString("ThemeVariant")) != mVariants.cend())
|
|
|
|
mSelectedVariant = Settings::getInstance()->getString("ThemeVariant");
|
|
|
|
else
|
|
|
|
mSelectedVariant = mVariants.front();
|
2022-10-28 19:08:44 +00:00
|
|
|
// Special shortcut variant to apply configuration to all defined variants.
|
|
|
|
mVariants.emplace_back("all");
|
2022-01-29 17:41:22 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
if (mCurrentThemeSet->second.capabilities.colorSchemes.size() > 0) {
|
|
|
|
for (auto& colorScheme : mCurrentThemeSet->second.capabilities.colorSchemes)
|
|
|
|
mColorSchemes.emplace_back(colorScheme.name);
|
|
|
|
|
|
|
|
if (std::find(mColorSchemes.cbegin(), mColorSchemes.cend(),
|
|
|
|
Settings::getInstance()->getString("ThemeColorScheme")) !=
|
|
|
|
mColorSchemes.cend())
|
|
|
|
mSelectedColorScheme = Settings::getInstance()->getString("ThemeColorScheme");
|
|
|
|
else
|
|
|
|
mSelectedColorScheme = mColorSchemes.front();
|
|
|
|
}
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
if (mCurrentThemeSet->second.capabilities.aspectRatios.size() > 0) {
|
2022-01-31 22:22:42 +00:00
|
|
|
if (std::find(mCurrentThemeSet->second.capabilities.aspectRatios.cbegin(),
|
|
|
|
mCurrentThemeSet->second.capabilities.aspectRatios.cend(),
|
2022-01-29 17:41:22 +00:00
|
|
|
Settings::getInstance()->getString("ThemeAspectRatio")) !=
|
2022-01-31 22:22:42 +00:00
|
|
|
mCurrentThemeSet->second.capabilities.aspectRatios.cend())
|
2022-01-29 17:41:22 +00:00
|
|
|
mSelectedAspectRatio = Settings::getInstance()->getString("ThemeAspectRatio");
|
|
|
|
else
|
2022-01-31 22:22:42 +00:00
|
|
|
mSelectedAspectRatio = mCurrentThemeSet->second.capabilities.aspectRatios.front();
|
2022-01-29 17:41:22 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
parseVariables(root);
|
|
|
|
parseIncludes(root);
|
|
|
|
parseViews(root);
|
2022-01-29 17:41:22 +00:00
|
|
|
// For non-legacy themes this will simply check for the presence of a feature tag and throw
|
|
|
|
// an error if it's found.
|
2020-06-21 12:25:28 +00:00
|
|
|
parseFeatures(root);
|
2022-01-29 17:41:22 +00:00
|
|
|
|
|
|
|
if (!mLegacyTheme) {
|
|
|
|
parseVariants(root);
|
2022-10-31 18:32:13 +00:00
|
|
|
parseColorSchemes(root);
|
2022-01-29 17:41:22 +00:00
|
|
|
parseAspectRatios(root);
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 19:03:50 +00:00
|
|
|
bool ThemeData::hasView(const std::string& view)
|
|
|
|
{
|
|
|
|
auto viewIt = mViews.find(view);
|
|
|
|
return (viewIt != mViews.cend());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<GuiComponent*> ThemeData::makeExtras(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view)
|
|
|
|
{
|
|
|
|
std::vector<GuiComponent*> comps;
|
|
|
|
|
|
|
|
auto viewIt = theme->mViews.find(view);
|
|
|
|
if (viewIt == theme->mViews.cend())
|
|
|
|
return comps;
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
for (auto it = viewIt->second.legacyOrderedKeys.cbegin(); // Line break.
|
|
|
|
it != viewIt->second.legacyOrderedKeys.cend(); ++it) {
|
2022-01-23 19:03:50 +00:00
|
|
|
ThemeElement& elem {viewIt->second.elements.at(*it)};
|
|
|
|
if (elem.extra) {
|
|
|
|
GuiComponent* comp {nullptr};
|
|
|
|
const std::string& t {elem.type};
|
|
|
|
if (t == "image")
|
|
|
|
comp = new ImageComponent;
|
|
|
|
else if (t == "text")
|
|
|
|
comp = new TextComponent;
|
|
|
|
|
|
|
|
if (comp) {
|
|
|
|
comp->setDefaultZIndex(10.0f);
|
|
|
|
comp->applyTheme(theme, view, *it, ThemeFlags::ALL);
|
|
|
|
comps.push_back(comp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return comps;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ThemeData::ThemeElement* ThemeData::getElement(const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
const std::string& expectedType) const
|
|
|
|
{
|
|
|
|
auto viewIt = mViews.find(view);
|
|
|
|
if (viewIt == mViews.cend())
|
|
|
|
return nullptr; // Not found.
|
|
|
|
|
|
|
|
auto elemIt = viewIt->second.elements.find(element);
|
|
|
|
if (elemIt == viewIt->second.elements.cend())
|
|
|
|
return nullptr;
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
// If expectedType is an empty string, then skip type checking.
|
2022-01-23 19:03:50 +00:00
|
|
|
if (elemIt->second.type != expectedType && !expectedType.empty()) {
|
2022-09-15 15:29:34 +00:00
|
|
|
LOG(LogWarning) << "ThemeData::getElement(): Requested element \"" << view << "." << element
|
|
|
|
<< "\" has the wrong type, expected \"" << expectedType << "\", got \""
|
|
|
|
<< elemIt->second.type << "\"";
|
2022-01-23 19:03:50 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &elemIt->second;
|
|
|
|
}
|
|
|
|
|
2022-06-11 16:34:53 +00:00
|
|
|
void ThemeData::populateThemeSets()
|
2022-01-23 19:03:50 +00:00
|
|
|
{
|
2022-06-11 16:34:53 +00:00
|
|
|
assert(mThemeSets.empty());
|
2022-01-29 17:41:22 +00:00
|
|
|
|
|
|
|
LOG(LogInfo) << "Checking for available theme sets...";
|
2022-01-23 19:03:50 +00:00
|
|
|
|
|
|
|
// Check for themes first under the home directory, then under the data installation
|
|
|
|
// directory (Unix only) and last under the ES-DE binary directory.
|
|
|
|
|
|
|
|
#if defined(__unix__) || defined(__APPLE__)
|
2022-08-20 09:30:15 +00:00
|
|
|
#if defined(APPIMAGE_BUILD)
|
|
|
|
static const size_t pathCount {2};
|
2022-01-23 19:03:50 +00:00
|
|
|
#else
|
2022-08-20 09:30:15 +00:00
|
|
|
static const size_t pathCount {3};
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
static const size_t pathCount {2};
|
2022-01-23 19:03:50 +00:00
|
|
|
#endif
|
|
|
|
std::string paths[pathCount] = {
|
|
|
|
Utils::FileSystem::getExePath() + "/themes",
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
Utils::FileSystem::getExePath() + "/../Resources/themes",
|
2022-08-20 09:30:15 +00:00
|
|
|
#elif defined(__unix__) && !defined(APPIMAGE_BUILD)
|
2022-01-23 19:03:50 +00:00
|
|
|
Utils::FileSystem::getProgramDataPath() + "/themes",
|
|
|
|
#endif
|
|
|
|
Utils::FileSystem::getHomePath() + "/.emulationstation/themes"
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < pathCount; ++i) {
|
|
|
|
if (!Utils::FileSystem::isDirectory(paths[i]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Utils::FileSystem::StringList dirContent {Utils::FileSystem::getDirContent(paths[i])};
|
|
|
|
|
|
|
|
for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin();
|
|
|
|
it != dirContent.cend(); ++it) {
|
|
|
|
if (Utils::FileSystem::isDirectory(*it)) {
|
2022-07-01 14:39:18 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
LOG(LogDebug) << "Loading theme set capabilities for \""
|
|
|
|
<< Utils::String::replace(*it, "/", "\\") << "\"...";
|
|
|
|
#else
|
2022-01-29 17:41:22 +00:00
|
|
|
LOG(LogDebug) << "Loading theme set capabilities for \"" << *it << "\"...";
|
2022-07-01 14:39:18 +00:00
|
|
|
#endif
|
2022-01-29 17:41:22 +00:00
|
|
|
ThemeCapability capabilities {parseThemeCapabilities(*it)};
|
|
|
|
|
2022-07-01 14:39:18 +00:00
|
|
|
#if defined(_WIN64)
|
|
|
|
LOG(LogInfo) << "Added" << (capabilities.legacyTheme ? " legacy" : "")
|
|
|
|
<< " theme set \"" << Utils::String::replace(*it, "/", "\\") << "\"";
|
|
|
|
#else
|
2022-01-29 17:41:22 +00:00
|
|
|
LOG(LogInfo) << "Added" << (capabilities.legacyTheme ? " legacy" : "")
|
|
|
|
<< " theme set \"" << *it << "\"";
|
2022-07-01 14:39:18 +00:00
|
|
|
#endif
|
2022-01-29 17:41:22 +00:00
|
|
|
if (!capabilities.legacyTheme) {
|
|
|
|
LOG(LogDebug) << "Theme set includes support for "
|
|
|
|
<< capabilities.variants.size() << " variant"
|
2022-10-31 18:32:13 +00:00
|
|
|
<< (capabilities.variants.size() != 1 ? "s" : "") << ", "
|
|
|
|
<< capabilities.colorSchemes.size() << " color scheme"
|
|
|
|
<< (capabilities.colorSchemes.size() != 1 ? "s" : "") << " and "
|
2022-01-29 17:41:22 +00:00
|
|
|
<< capabilities.aspectRatios.size() << " aspect ratio"
|
|
|
|
<< (capabilities.aspectRatios.size() != 1 ? "s" : "");
|
|
|
|
}
|
|
|
|
ThemeSet set {*it, capabilities};
|
|
|
|
mThemeSets[set.getName()] = set;
|
2022-01-23 19:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-11 16:35:44 +00:00
|
|
|
|
|
|
|
if (mThemeSets.empty()) {
|
|
|
|
LOG(LogWarning) << "Couldn't find any theme sets, creating dummy entry";
|
|
|
|
ThemeSet set {"no-theme-sets", ThemeCapability()};
|
|
|
|
mThemeSets[set.getName()] = set;
|
2022-08-14 18:24:26 +00:00
|
|
|
mCurrentThemeSet = mThemeSets.begin();
|
2022-06-11 16:35:44 +00:00
|
|
|
}
|
2022-01-23 19:03:50 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 22:22:42 +00:00
|
|
|
const std::string ThemeData::getThemeFromCurrentSet(const std::string& system)
|
2022-01-23 19:03:50 +00:00
|
|
|
{
|
2022-01-29 17:41:22 +00:00
|
|
|
if (mThemeSets.empty())
|
|
|
|
getThemeSets();
|
|
|
|
|
|
|
|
if (mThemeSets.empty())
|
2022-01-23 19:03:50 +00:00
|
|
|
// No theme sets available.
|
|
|
|
return "";
|
|
|
|
|
2022-04-09 13:57:37 +00:00
|
|
|
std::map<std::string, ThemeSet, StringComparator>::const_iterator set {
|
2022-01-29 17:41:22 +00:00
|
|
|
mThemeSets.find(Settings::getInstance()->getString("ThemeSet"))};
|
|
|
|
if (set == mThemeSets.cend()) {
|
2022-01-23 19:03:50 +00:00
|
|
|
// Currently configured theme set is missing, attempt to load the default theme set
|
2022-04-14 20:46:30 +00:00
|
|
|
// slate-DE instead, and if that's also missing then pick the first available set.
|
2022-01-23 19:03:50 +00:00
|
|
|
bool defaultSetFound {true};
|
|
|
|
|
2022-04-14 20:46:30 +00:00
|
|
|
set = mThemeSets.find("slate-DE");
|
2022-01-23 19:03:50 +00:00
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
if (set == mThemeSets.cend()) {
|
|
|
|
set = mThemeSets.cbegin();
|
2022-01-23 19:03:50 +00:00
|
|
|
defaultSetFound = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(LogWarning) << "Configured theme set \""
|
|
|
|
<< Settings::getInstance()->getString("ThemeSet")
|
|
|
|
<< "\" does not exist, loading" << (defaultSetFound ? " default " : " ")
|
|
|
|
<< "theme set \"" << set->first << "\" instead";
|
|
|
|
|
|
|
|
Settings::getInstance()->setString("ThemeSet", set->first);
|
2022-08-14 18:24:26 +00:00
|
|
|
mCurrentThemeSet = mThemeSets.find(Settings::getInstance()->getString("ThemeSet"));
|
2022-01-23 19:03:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return set->second.getThemePath(system);
|
|
|
|
}
|
|
|
|
|
2022-01-31 22:22:42 +00:00
|
|
|
const std::string ThemeData::getAspectRatioLabel(const std::string& aspectRatio)
|
|
|
|
{
|
|
|
|
auto it = std::find_if(sSupportedAspectRatios.cbegin(), sSupportedAspectRatios.cend(),
|
|
|
|
[&aspectRatio](const std::pair<std::string, std::string>& entry) {
|
|
|
|
return entry.first == aspectRatio;
|
|
|
|
});
|
|
|
|
if (it != sSupportedAspectRatios.cend())
|
|
|
|
return it->second;
|
|
|
|
else
|
|
|
|
return "invalid ratio";
|
|
|
|
}
|
|
|
|
|
2022-01-23 19:03:50 +00:00
|
|
|
unsigned int ThemeData::getHexColor(const std::string& str)
|
|
|
|
{
|
|
|
|
ThemeException error;
|
|
|
|
|
|
|
|
if (str == "")
|
|
|
|
throw error << "Empty color property";
|
|
|
|
|
|
|
|
size_t len {str.size()};
|
|
|
|
if (len != 6 && len != 8)
|
|
|
|
throw error << "Invalid color property \"" << str
|
|
|
|
<< "\" (must be 6 or 8 characters in length)";
|
|
|
|
|
|
|
|
unsigned int val;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << str;
|
|
|
|
ss >> std::hex >> val;
|
|
|
|
|
|
|
|
if (len == 6)
|
|
|
|
val = (val << 8) | 0xFF;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ThemeData::resolvePlaceholders(const std::string& in)
|
|
|
|
{
|
|
|
|
if (in.empty())
|
|
|
|
return in;
|
|
|
|
|
|
|
|
const size_t variableBegin {in.find("${")};
|
|
|
|
const size_t variableEnd {in.find("}", variableBegin)};
|
|
|
|
|
|
|
|
if ((variableBegin == std::string::npos) || (variableEnd == std::string::npos))
|
|
|
|
return in;
|
|
|
|
|
|
|
|
std::string prefix {in.substr(0, variableBegin)};
|
|
|
|
std::string replace {in.substr(variableBegin + 2, variableEnd - (variableBegin + 2))};
|
|
|
|
std::string suffix {resolvePlaceholders(in.substr(variableEnd + 1).c_str())};
|
|
|
|
|
|
|
|
return prefix + mVariables[replace] + suffix;
|
|
|
|
}
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string& path)
|
|
|
|
{
|
|
|
|
ThemeCapability capabilities;
|
2022-01-31 22:22:42 +00:00
|
|
|
std::vector<std::string> aspectRatiosTemp;
|
2022-01-29 17:41:22 +00:00
|
|
|
|
|
|
|
std::string capFile {path + "/capabilities.xml"};
|
|
|
|
|
|
|
|
if (Utils::FileSystem::isRegularFile(capFile) || Utils::FileSystem::isSymlink(capFile)) {
|
|
|
|
capabilities.legacyTheme = false;
|
|
|
|
|
|
|
|
pugi::xml_document doc;
|
|
|
|
#if defined(_WIN64)
|
2022-10-31 18:32:13 +00:00
|
|
|
pugi::xml_parse_result res {
|
|
|
|
doc.load_file(Utils::String::stringToWideString(capFile).c_str())};
|
2022-01-29 17:41:22 +00:00
|
|
|
#else
|
2022-10-31 18:32:13 +00:00
|
|
|
pugi::xml_parse_result res {doc.load_file(capFile.c_str())};
|
2022-01-29 17:41:22 +00:00
|
|
|
#endif
|
|
|
|
if (res.status == pugi::status_no_document_element) {
|
|
|
|
LOG(LogDebug) << "Found a capabilities.xml file with no configuration";
|
|
|
|
}
|
|
|
|
else if (!res) {
|
|
|
|
LOG(LogError) << "Couldn't parse capabilities.xml: " << res.description();
|
|
|
|
return capabilities;
|
|
|
|
}
|
|
|
|
pugi::xml_node themeCapabilities {doc.child("themeCapabilities")};
|
|
|
|
if (!themeCapabilities) {
|
|
|
|
LOG(LogError) << "Missing <themeCapabilities> tag in capabilities.xml";
|
|
|
|
return capabilities;
|
|
|
|
}
|
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node aspectRatio {themeCapabilities.child("aspectRatio")}; aspectRatio;
|
2022-01-29 17:41:22 +00:00
|
|
|
aspectRatio = aspectRatio.next_sibling("aspectRatio")) {
|
2022-10-31 18:32:13 +00:00
|
|
|
std::string value {aspectRatio.text().get()};
|
2022-01-31 22:22:42 +00:00
|
|
|
if (std::find_if(sSupportedAspectRatios.cbegin(), sSupportedAspectRatios.cend(),
|
|
|
|
[&value](const std::pair<std::string, std::string>& entry) {
|
|
|
|
return entry.first == value;
|
|
|
|
}) == sSupportedAspectRatios.cend()) {
|
2022-01-29 17:41:22 +00:00
|
|
|
LOG(LogWarning) << "Declared aspect ratio \"" << value
|
|
|
|
<< "\" is not supported, ignoring entry in \"" << capFile << "\"";
|
|
|
|
}
|
|
|
|
else {
|
2022-01-31 22:22:42 +00:00
|
|
|
if (std::find(aspectRatiosTemp.cbegin(), aspectRatiosTemp.cend(), value) !=
|
|
|
|
aspectRatiosTemp.cend()) {
|
2022-01-29 17:41:22 +00:00
|
|
|
LOG(LogWarning)
|
|
|
|
<< "Aspect ratio \"" << value
|
|
|
|
<< "\" is declared multiple times, ignoring entry in \"" << capFile << "\"";
|
|
|
|
}
|
|
|
|
else {
|
2022-01-31 22:22:42 +00:00
|
|
|
aspectRatiosTemp.emplace_back(value);
|
2022-01-29 17:41:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-31 22:22:42 +00:00
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node variant {themeCapabilities.child("variant")}; variant;
|
2022-01-29 17:41:22 +00:00
|
|
|
variant = variant.next_sibling("variant")) {
|
|
|
|
ThemeVariant readVariant;
|
|
|
|
std::string name {variant.attribute("name").as_string()};
|
|
|
|
if (name.empty()) {
|
|
|
|
LOG(LogWarning)
|
2022-01-30 20:35:39 +00:00
|
|
|
<< "Found <variant> tag without name attribute, ignoring entry in \"" << capFile
|
2022-01-29 17:41:22 +00:00
|
|
|
<< "\"";
|
|
|
|
}
|
2022-10-28 19:08:44 +00:00
|
|
|
else if (name == "all") {
|
|
|
|
LOG(LogWarning)
|
|
|
|
<< "Found <variant> tag using reserved name \"all\", ignoring entry in \""
|
|
|
|
<< capFile << "\"";
|
|
|
|
}
|
2022-01-29 17:41:22 +00:00
|
|
|
else {
|
|
|
|
readVariant.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
pugi::xml_node labelTag {variant.child("label")};
|
|
|
|
if (labelTag == nullptr) {
|
|
|
|
LOG(LogDebug)
|
|
|
|
<< "No variant <label> tag found, setting label value to the variant name \""
|
|
|
|
<< name << "\" for \"" << capFile << "\"";
|
|
|
|
readVariant.label = name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::string labelValue {labelTag.text().as_string()};
|
|
|
|
if (labelValue == "") {
|
|
|
|
LOG(LogWarning) << "No variant <label> value defined, setting value to "
|
|
|
|
"the variant name \""
|
|
|
|
<< name << "\" for \"" << capFile << "\"";
|
|
|
|
readVariant.label = name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
readVariant.label = labelValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pugi::xml_node selectableTag {variant.child("selectable")};
|
|
|
|
if (selectableTag != nullptr) {
|
|
|
|
std::string value {selectableTag.text().as_string()};
|
|
|
|
if (value.front() == '0' || value.front() == 'f' || value.front() == 'F' ||
|
|
|
|
value.front() == 'n' || value.front() == 'N')
|
|
|
|
readVariant.selectable = false;
|
|
|
|
else
|
|
|
|
readVariant.selectable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pugi::xml_node overrideTag {variant.child("override")};
|
|
|
|
if (overrideTag != nullptr) {
|
|
|
|
pugi::xml_node triggerTag {overrideTag.child("trigger")};
|
|
|
|
if (triggerTag != nullptr) {
|
|
|
|
std::string triggerValue {triggerTag.text().as_string()};
|
|
|
|
if (triggerValue == "") {
|
|
|
|
LOG(LogWarning)
|
|
|
|
<< "No <trigger> tag value defined for variant \"" << readVariant.name
|
2022-01-30 20:35:39 +00:00
|
|
|
<< "\", ignoring entry in \"" << capFile << "\"";
|
2022-01-29 17:41:22 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pugi::xml_node useVariantTag {overrideTag.child("useVariant")};
|
|
|
|
if (useVariantTag != nullptr) {
|
|
|
|
std::string useVariantValue {useVariantTag.text().as_string()};
|
|
|
|
if (useVariantValue == "") {
|
|
|
|
LOG(LogWarning)
|
|
|
|
<< "No <useVariant> tag value defined for variant \""
|
2022-01-30 20:35:39 +00:00
|
|
|
<< readVariant.name << "\", ignoring entry in \"" << capFile
|
2022-01-29 17:41:22 +00:00
|
|
|
<< "\"";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
readVariant.override = true;
|
|
|
|
readVariant.overrideTrigger = triggerValue;
|
|
|
|
readVariant.overrideVariant = useVariantValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogWarning) << "Found an <override> tag without a corresponding "
|
|
|
|
"<useVariant> tag, "
|
2022-01-30 20:35:39 +00:00
|
|
|
<< "ignoring entry for variant \"" << readVariant.name
|
2022-01-29 17:41:22 +00:00
|
|
|
<< "\" in \"" << capFile << "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogWarning)
|
|
|
|
<< "Found an <override> tag without a corresponding <trigger> tag, "
|
2022-01-30 20:35:39 +00:00
|
|
|
<< "ignoring entry for variant \"" << readVariant.name << "\" in \""
|
2022-01-29 17:41:22 +00:00
|
|
|
<< capFile << "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (readVariant.name != "") {
|
|
|
|
bool duplicate {false};
|
|
|
|
for (auto& variant : capabilities.variants) {
|
|
|
|
if (variant.name == readVariant.name) {
|
|
|
|
LOG(LogWarning) << "Variant \"" << readVariant.name
|
|
|
|
<< "\" is declared multiple times, ignoring entry in \""
|
|
|
|
<< capFile << "\"";
|
|
|
|
duplicate = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!duplicate)
|
|
|
|
capabilities.variants.emplace_back(readVariant);
|
|
|
|
}
|
|
|
|
}
|
2022-10-31 18:32:13 +00:00
|
|
|
|
|
|
|
for (pugi::xml_node colorScheme {themeCapabilities.child("colorScheme")}; colorScheme;
|
|
|
|
colorScheme = colorScheme.next_sibling("colorScheme")) {
|
|
|
|
ThemeColorScheme readColorScheme;
|
|
|
|
std::string name {colorScheme.attribute("name").as_string()};
|
|
|
|
if (name.empty()) {
|
|
|
|
LOG(LogWarning)
|
|
|
|
<< "Found <colorScheme> tag without name attribute, ignoring entry in \""
|
|
|
|
<< capFile << "\"";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
readColorScheme.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
pugi::xml_node labelTag {colorScheme.child("label")};
|
|
|
|
if (labelTag == nullptr) {
|
|
|
|
LOG(LogDebug) << "No colorScheme <label> tag found, setting label value to the "
|
|
|
|
"color scheme name \""
|
|
|
|
<< name << "\" for \"" << capFile << "\"";
|
|
|
|
readColorScheme.label = name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::string labelValue {labelTag.text().as_string()};
|
|
|
|
if (labelValue == "") {
|
|
|
|
LOG(LogWarning) << "No colorScheme <label> value defined, setting value to "
|
|
|
|
"the color scheme name \""
|
|
|
|
<< name << "\" for \"" << capFile << "\"";
|
|
|
|
readColorScheme.label = name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
readColorScheme.label = labelValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (readColorScheme.name != "") {
|
|
|
|
bool duplicate {false};
|
|
|
|
for (auto& colorScheme : capabilities.colorSchemes) {
|
|
|
|
if (colorScheme.name == readColorScheme.name) {
|
|
|
|
LOG(LogWarning) << "Color scheme \"" << readColorScheme.name
|
|
|
|
<< "\" is declared multiple times, ignoring entry in \""
|
|
|
|
<< capFile << "\"";
|
|
|
|
duplicate = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!duplicate)
|
|
|
|
capabilities.colorSchemes.emplace_back(readColorScheme);
|
|
|
|
}
|
|
|
|
}
|
2022-01-29 17:41:22 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(LogDebug) << "No capabilities.xml file found, flagging as legacy theme set";
|
|
|
|
capabilities.legacyTheme = true;
|
|
|
|
}
|
|
|
|
|
2022-01-31 22:22:42 +00:00
|
|
|
// Add the aspect ratios in the order they are defined in sSupportedAspectRatios so they
|
|
|
|
// always show up in the same order in the UI Settings menu.
|
|
|
|
if (!aspectRatiosTemp.empty()) {
|
|
|
|
for (auto& aspectRatio : sSupportedAspectRatios) {
|
|
|
|
if (std::find(aspectRatiosTemp.cbegin(), aspectRatiosTemp.cend(), aspectRatio.first) !=
|
|
|
|
aspectRatiosTemp.cend()) {
|
|
|
|
capabilities.aspectRatios.emplace_back(aspectRatio.first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
return capabilities;
|
|
|
|
}
|
|
|
|
|
2013-12-31 03:48:28 +00:00
|
|
|
void ThemeData::parseIncludes(const pugi::xml_node& root)
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
ThemeException error;
|
2022-01-23 16:50:51 +00:00
|
|
|
error << "ThemeData::parseIncludes(): ";
|
2020-06-21 12:25:28 +00:00
|
|
|
error.setFiles(mPaths);
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
if (!mLegacyTheme) {
|
|
|
|
if (root.child("formatVersion").text().as_int(-1) != -1)
|
|
|
|
throw error << ": Legacy <formatVersion> tag found for non-legacy theme set";
|
|
|
|
}
|
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node node {root.child("include")}; node; node = node.next_sibling("include")) {
|
2022-01-23 16:50:51 +00:00
|
|
|
std::string relPath {resolvePlaceholders(node.text().as_string())};
|
|
|
|
std::string path {Utils::FileSystem::resolveRelativePath(relPath, mPaths.back(), true)};
|
2022-10-29 11:04:00 +00:00
|
|
|
|
|
|
|
if (!ResourceManager::getInstance().fileExists(path)) {
|
|
|
|
// For explicit paths, throw an error if the file couldn't be found, but only
|
|
|
|
// print a debug message if it was set using a variable.
|
|
|
|
if (relPath == node.text().get()) {
|
|
|
|
throw error << " -> \"" << relPath << "\" not found (resolved to \"" << path
|
|
|
|
<< "\")";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!(Settings::getInstance()->getBool("DebugSkipMissingThemeFiles") ||
|
|
|
|
(mCustomCollection && Settings::getInstance()->getBool(
|
|
|
|
"DebugSkipMissingThemeFilesCustomCollections")))) {
|
|
|
|
LOG(LogDebug) << error.message << ": Couldn't find file \"" << node.text().get()
|
|
|
|
<< "\" "
|
|
|
|
<< ((node.text().get() != path) ?
|
|
|
|
"which resolves to \"" + path + "\"" :
|
|
|
|
"");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-08 19:53:39 +00:00
|
|
|
error << " -> \"" << relPath << "\"";
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mPaths.push_back(path);
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
pugi::xml_document includeDoc;
|
2021-07-07 18:31:46 +00:00
|
|
|
#if defined(_WIN64)
|
2022-01-23 16:50:51 +00:00
|
|
|
pugi::xml_parse_result result {
|
|
|
|
includeDoc.load_file(Utils::String::stringToWideString(path).c_str())};
|
2021-07-07 18:31:46 +00:00
|
|
|
#else
|
2022-01-23 16:50:51 +00:00
|
|
|
pugi::xml_parse_result result {includeDoc.load_file(path.c_str())};
|
2021-07-07 18:31:46 +00:00
|
|
|
#endif
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!result)
|
2021-02-08 19:53:39 +00:00
|
|
|
throw error << ": Error parsing file: " << result.description();
|
2013-12-31 03:48:28 +00:00
|
|
|
|
2022-01-23 16:50:51 +00:00
|
|
|
pugi::xml_node theme {includeDoc.child("theme")};
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!theme)
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": Missing <theme> tag";
|
2013-12-30 23:23:34 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
parseVariables(theme);
|
|
|
|
parseIncludes(theme);
|
|
|
|
parseViews(theme);
|
2022-01-29 17:41:22 +00:00
|
|
|
// For non-legacy themes this will simply check for the presence of a feature tag and throw
|
|
|
|
// an error if it's found.
|
2020-06-21 12:25:28 +00:00
|
|
|
parseFeatures(theme);
|
2013-12-31 03:48:28 +00:00
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
if (!mLegacyTheme) {
|
|
|
|
parseVariants(theme);
|
2022-10-31 18:32:13 +00:00
|
|
|
parseColorSchemes(theme);
|
2022-01-29 17:41:22 +00:00
|
|
|
parseAspectRatios(theme);
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mPaths.pop_back();
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 18:49:15 +00:00
|
|
|
void ThemeData::parseFeatures(const pugi::xml_node& root)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
ThemeException error;
|
2022-01-23 16:50:51 +00:00
|
|
|
error << "ThemeData::parseFeatures(): ";
|
2020-06-21 12:25:28 +00:00
|
|
|
error.setFiles(mPaths);
|
2017-03-10 18:49:15 +00:00
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
if (!mLegacyTheme && root.child("feature") != nullptr)
|
|
|
|
throw error << ": Legacy <feature> tag found for non-legacy theme set";
|
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node node {root.child("feature")}; node; node = node.next_sibling("feature")) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!node.attribute("supported"))
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": Feature missing \"supported\" attribute";
|
2017-03-10 18:49:15 +00:00
|
|
|
|
2022-01-23 16:50:51 +00:00
|
|
|
const std::string supportedAttr {node.attribute("supported").as_string()};
|
2017-03-10 18:49:15 +00:00
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
if (std::find(sLegacySupportedFeatures.cbegin(), sLegacySupportedFeatures.cend(),
|
|
|
|
supportedAttr) != sLegacySupportedFeatures.cend()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
parseViews(node);
|
2021-07-07 18:31:46 +00:00
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2017-03-10 18:49:15 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
void ThemeData::parseVariants(const pugi::xml_node& root)
|
|
|
|
{
|
|
|
|
if (mCurrentThemeSet == mThemeSets.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mSelectedVariant == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
ThemeException error;
|
|
|
|
error << "ThemeData::parseVariants(): ";
|
|
|
|
error.setFiles(mPaths);
|
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node node {root.child("variant")}; node; node = node.next_sibling("variant")) {
|
2022-01-29 17:41:22 +00:00
|
|
|
if (!node.attribute("name"))
|
|
|
|
throw error << ": <variant> tag missing \"name\" attribute";
|
|
|
|
|
|
|
|
const std::string delim {" \t\r\n,"};
|
|
|
|
const std::string nameAttr {node.attribute("name").as_string()};
|
|
|
|
size_t prevOff {nameAttr.find_first_not_of(delim, 0)};
|
|
|
|
size_t off {nameAttr.find_first_of(delim, prevOff)};
|
|
|
|
std::string viewKey;
|
|
|
|
while (off != std::string::npos || prevOff != std::string::npos) {
|
|
|
|
viewKey = nameAttr.substr(prevOff, off - prevOff);
|
|
|
|
prevOff = nameAttr.find_first_not_of(delim, off);
|
|
|
|
off = nameAttr.find_first_of(delim, prevOff);
|
|
|
|
|
|
|
|
if (std::find(mVariants.cbegin(), mVariants.cend(), viewKey) == mVariants.cend()) {
|
|
|
|
throw error << ": <variant> value \"" << viewKey
|
|
|
|
<< "\" is not defined in capabilities.xml";
|
|
|
|
}
|
|
|
|
|
2022-10-28 19:08:44 +00:00
|
|
|
if (mSelectedVariant == viewKey || viewKey == "all") {
|
2022-10-28 19:06:01 +00:00
|
|
|
parseVariables(node);
|
2022-01-29 17:41:22 +00:00
|
|
|
parseIncludes(node);
|
|
|
|
parseViews(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
void ThemeData::parseColorSchemes(const pugi::xml_node& root)
|
|
|
|
{
|
|
|
|
if (mCurrentThemeSet == mThemeSets.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mSelectedColorScheme == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
ThemeException error;
|
|
|
|
error << "ThemeData::parseColorSchemes(): ";
|
|
|
|
error.setFiles(mPaths);
|
|
|
|
|
|
|
|
for (pugi::xml_node node {root.child("colorScheme")}; node;
|
|
|
|
node = node.next_sibling("colorScheme")) {
|
|
|
|
if (!node.attribute("name"))
|
|
|
|
throw error << ": <colorScheme> tag missing \"name\" attribute";
|
|
|
|
|
|
|
|
const std::string delim {" \t\r\n,"};
|
|
|
|
const std::string nameAttr {node.attribute("name").as_string()};
|
|
|
|
size_t prevOff {nameAttr.find_first_not_of(delim, 0)};
|
|
|
|
size_t off {nameAttr.find_first_of(delim, prevOff)};
|
|
|
|
std::string viewKey;
|
|
|
|
while (off != std::string::npos || prevOff != std::string::npos) {
|
|
|
|
viewKey = nameAttr.substr(prevOff, off - prevOff);
|
|
|
|
prevOff = nameAttr.find_first_not_of(delim, off);
|
|
|
|
off = nameAttr.find_first_of(delim, prevOff);
|
|
|
|
|
|
|
|
if (std::find(mColorSchemes.cbegin(), mColorSchemes.cend(), viewKey) ==
|
|
|
|
mColorSchemes.cend()) {
|
|
|
|
throw error << ": <colorScheme> value \"" << viewKey
|
|
|
|
<< "\" is not defined in capabilities.xml";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSelectedColorScheme == viewKey) {
|
|
|
|
parseVariables(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
void ThemeData::parseAspectRatios(const pugi::xml_node& root)
|
|
|
|
{
|
|
|
|
if (mCurrentThemeSet == mThemeSets.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mSelectedAspectRatio == "")
|
|
|
|
return;
|
|
|
|
|
|
|
|
ThemeException error;
|
|
|
|
error << "ThemeData::parseAspectRatios(): ";
|
|
|
|
error.setFiles(mPaths);
|
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node node {root.child("aspectRatio")}; node;
|
2022-01-29 17:41:22 +00:00
|
|
|
node = node.next_sibling("aspectRatio")) {
|
|
|
|
if (!node.attribute("name"))
|
|
|
|
throw error << ": <aspectRatio> tag missing \"name\" attribute";
|
|
|
|
|
|
|
|
const std::string delim {" \t\r\n,"};
|
|
|
|
const std::string nameAttr {node.attribute("name").as_string()};
|
|
|
|
size_t prevOff {nameAttr.find_first_not_of(delim, 0)};
|
|
|
|
size_t off {nameAttr.find_first_of(delim, prevOff)};
|
|
|
|
std::string viewKey;
|
|
|
|
while (off != std::string::npos || prevOff != std::string::npos) {
|
|
|
|
viewKey = nameAttr.substr(prevOff, off - prevOff);
|
|
|
|
prevOff = nameAttr.find_first_not_of(delim, off);
|
|
|
|
off = nameAttr.find_first_of(delim, prevOff);
|
|
|
|
|
2022-01-31 22:22:42 +00:00
|
|
|
if (std::find(mCurrentThemeSet->second.capabilities.aspectRatios.cbegin(),
|
|
|
|
mCurrentThemeSet->second.capabilities.aspectRatios.cend(),
|
|
|
|
viewKey) == mCurrentThemeSet->second.capabilities.aspectRatios.cend()) {
|
2022-10-31 18:32:13 +00:00
|
|
|
throw error << ": <aspectRatio> value \"" << viewKey
|
2022-01-29 17:41:22 +00:00
|
|
|
<< "\" is not defined in capabilities.xml";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSelectedAspectRatio == viewKey) {
|
|
|
|
parseIncludes(node);
|
|
|
|
parseViews(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-14 04:07:28 +00:00
|
|
|
void ThemeData::parseVariables(const pugi::xml_node& root)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
ThemeException error;
|
|
|
|
error.setFiles(mPaths);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node node {root.child("variables")}; node;
|
2022-10-28 19:06:01 +00:00
|
|
|
node = node.next_sibling("variables")) {
|
2017-05-14 04:07:28 +00:00
|
|
|
|
2022-10-28 19:06:01 +00:00
|
|
|
for (pugi::xml_node_iterator it = node.begin(); it != node.end(); ++it) {
|
|
|
|
const std::string key {it->name()};
|
|
|
|
const std::string val {resolvePlaceholders(it->text().as_string())};
|
2017-05-14 04:07:28 +00:00
|
|
|
|
2022-10-28 19:06:01 +00:00
|
|
|
if (!val.empty()) {
|
|
|
|
// Overriding existing variables is not allowed for legacy themes.
|
|
|
|
if (!mLegacyTheme && mVariables.find(key) != mVariables.end())
|
|
|
|
mVariables[key] = val;
|
|
|
|
else
|
|
|
|
mVariables.insert(std::pair<std::string, std::string>(key, val));
|
|
|
|
}
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2017-05-14 04:07:28 +00:00
|
|
|
}
|
|
|
|
|
2013-12-31 03:48:28 +00:00
|
|
|
void ThemeData::parseViews(const pugi::xml_node& root)
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
ThemeException error;
|
2022-01-23 16:50:51 +00:00
|
|
|
error << "ThemeData::parseViews(): ";
|
2020-06-21 12:25:28 +00:00
|
|
|
error.setFiles(mPaths);
|
|
|
|
|
|
|
|
// Parse views.
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node node {root.child("view")}; node; node = node.next_sibling("view")) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!node.attribute("name"))
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": View missing \"name\" attribute";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-23 16:50:51 +00:00
|
|
|
const std::string delim {" \t\r\n,"};
|
|
|
|
const std::string nameAttr {node.attribute("name").as_string()};
|
|
|
|
size_t prevOff {nameAttr.find_first_not_of(delim, 0)};
|
|
|
|
size_t off {nameAttr.find_first_of(delim, prevOff)};
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string viewKey;
|
2020-07-13 18:58:25 +00:00
|
|
|
while (off != std::string::npos || prevOff != std::string::npos) {
|
2020-06-21 12:25:28 +00:00
|
|
|
viewKey = nameAttr.substr(prevOff, off - prevOff);
|
|
|
|
prevOff = nameAttr.find_first_not_of(delim, off);
|
|
|
|
off = nameAttr.find_first_of(delim, prevOff);
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
if (mLegacyTheme) {
|
|
|
|
if (std::find(sLegacySupportedViews.cbegin(), sLegacySupportedViews.cend(),
|
|
|
|
viewKey) != sLegacySupportedViews.cend()) {
|
|
|
|
ThemeView& view {
|
|
|
|
mViews.insert(std::pair<std::string, ThemeView>(viewKey, ThemeView()))
|
|
|
|
.first->second};
|
|
|
|
parseView(node, view);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw error << ": Unsupported \"" << viewKey << "\" view style defined";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (std::find(sSupportedViews.cbegin(), sSupportedViews.cend(), viewKey) !=
|
|
|
|
sSupportedViews.cend()) {
|
|
|
|
ThemeView& view {
|
|
|
|
mViews.insert(std::pair<std::string, ThemeView>(viewKey, ThemeView()))
|
|
|
|
.first->second};
|
|
|
|
parseView(node, view);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw error << ": Unsupported \"" << viewKey << "\" view style defined";
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2013-12-31 03:48:28 +00:00
|
|
|
void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view)
|
2013-11-12 23:28:15 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
ThemeException error;
|
2022-01-23 16:50:51 +00:00
|
|
|
error << "ThemeData::parseView(): ";
|
2020-06-21 12:25:28 +00:00
|
|
|
error.setFiles(mPaths);
|
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node node {root.first_child()}; node; node = node.next_sibling()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!node.attribute("name"))
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": Element of type \"" << node.name() << "\" missing \"name\" attribute";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
auto elemTypeIt = sElementMap.find(node.name());
|
|
|
|
if (elemTypeIt == sElementMap.cend())
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": Unknown element type \"" << node.name() << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-23 16:50:51 +00:00
|
|
|
const std::string delim {" \t\r\n,"};
|
|
|
|
const std::string nameAttr {node.attribute("name").as_string()};
|
|
|
|
size_t prevOff {nameAttr.find_first_not_of(delim, 0)};
|
|
|
|
size_t off {nameAttr.find_first_of(delim, prevOff)};
|
2020-06-21 12:25:28 +00:00
|
|
|
while (off != std::string::npos || prevOff != std::string::npos) {
|
2022-01-23 16:50:51 +00:00
|
|
|
std::string elemKey {nameAttr.substr(prevOff, off - prevOff)};
|
2020-06-21 12:25:28 +00:00
|
|
|
prevOff = nameAttr.find_first_not_of(delim, off);
|
|
|
|
off = nameAttr.find_first_of(delim, prevOff);
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
// Add the element type as a prefix to avoid name collisions between different
|
2022-09-09 16:03:58 +00:00
|
|
|
// component types. Also include workarounds for legacy theme sets for when the
|
|
|
|
// fixed labels have been defined with the wrong element type.
|
2022-01-29 17:41:22 +00:00
|
|
|
const std::string elementType {node.name()};
|
2022-09-09 16:03:58 +00:00
|
|
|
LegacyWorkaround legacyWorkaround {LegacyWorkaround::NONE};
|
2022-08-14 12:46:56 +00:00
|
|
|
|
|
|
|
if (mLegacyTheme && elementType == "text" &&
|
|
|
|
(elemKey == "md_releasedate" || elemKey == "md_lastplayed")) {
|
|
|
|
LOG(LogDebug) << "ThemeData::parseView(): Element type for \"" << elemKey
|
|
|
|
<< "\" incorrectly set to \"text\" "
|
|
|
|
"instead of \"datetime\", applying workaround";
|
2022-09-09 16:03:58 +00:00
|
|
|
legacyWorkaround = LegacyWorkaround::DATETIME;
|
2022-08-14 12:46:56 +00:00
|
|
|
elemKey = "datetime_" + elemKey;
|
|
|
|
}
|
2022-09-09 16:03:58 +00:00
|
|
|
else if (mLegacyTheme && elementType == "datetime" &&
|
|
|
|
(elemKey == "md_lbl_releasedate" || elemKey == "md_lbl_lastplayed")) {
|
|
|
|
LOG(LogDebug) << "ThemeData::parseView(): Element type for \"" << elemKey
|
|
|
|
<< "\" incorrectly set to \"datetime\" "
|
|
|
|
"instead of \"text\", applying workaround";
|
|
|
|
legacyWorkaround = LegacyWorkaround::TEXT;
|
|
|
|
elemKey = "text_" + elemKey;
|
|
|
|
}
|
|
|
|
else if (mLegacyTheme && elementType == "text" && elemKey == "md_rating") {
|
|
|
|
LOG(LogDebug) << "ThemeData::parseView(): Element type for \"" << elemKey
|
|
|
|
<< "\" incorrectly set to \"text\" "
|
|
|
|
"instead of \"rating\", applying workaround";
|
|
|
|
legacyWorkaround = LegacyWorkaround::RATING;
|
|
|
|
elemKey = "rating_" + elemKey;
|
|
|
|
}
|
2022-08-14 12:46:56 +00:00
|
|
|
else {
|
|
|
|
elemKey = elementType + "_" + elemKey;
|
|
|
|
}
|
2022-01-29 17:41:22 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
parseElement(
|
|
|
|
node, elemTypeIt->second,
|
|
|
|
view.elements.insert(std::pair<std::string, ThemeElement>(elemKey, ThemeElement()))
|
2022-08-14 12:46:56 +00:00
|
|
|
.first->second,
|
2022-09-09 16:03:58 +00:00
|
|
|
legacyWorkaround);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-30 20:13:49 +00:00
|
|
|
if (mLegacyTheme &&
|
|
|
|
std::find(view.legacyOrderedKeys.cbegin(), view.legacyOrderedKeys.cend(),
|
2022-01-29 17:41:22 +00:00
|
|
|
elemKey) == view.legacyOrderedKeys.cend())
|
|
|
|
view.legacyOrderedKeys.push_back(elemKey);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void ThemeData::parseElement(const pugi::xml_node& root,
|
2021-07-07 18:31:46 +00:00
|
|
|
const std::map<std::string, ElementPropertyType>& typeMap,
|
2022-08-14 12:46:56 +00:00
|
|
|
ThemeElement& element,
|
2022-09-09 16:03:58 +00:00
|
|
|
const LegacyWorkaround legacyWorkaround)
|
2013-12-30 23:23:34 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
ThemeException error;
|
2022-01-23 16:50:51 +00:00
|
|
|
error << "ThemeData::parseElement(): ";
|
2020-06-21 12:25:28 +00:00
|
|
|
error.setFiles(mPaths);
|
|
|
|
|
2022-09-09 16:03:58 +00:00
|
|
|
if (legacyWorkaround == LegacyWorkaround::DATETIME)
|
2022-08-14 12:46:56 +00:00
|
|
|
element.type = "datetime";
|
2022-09-15 15:29:34 +00:00
|
|
|
else if (legacyWorkaround == LegacyWorkaround::TEXT)
|
2022-09-09 16:03:58 +00:00
|
|
|
element.type = "text";
|
|
|
|
else if (legacyWorkaround == LegacyWorkaround::RATING)
|
|
|
|
element.type = "rating";
|
2022-08-14 12:46:56 +00:00
|
|
|
else
|
|
|
|
element.type = root.name();
|
2022-01-29 17:41:22 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
element.extra = root.attribute("extra").as_bool(false);
|
2022-01-30 20:13:49 +00:00
|
|
|
if (mLegacyTheme)
|
|
|
|
element.extra = root.attribute("extra").as_bool(false);
|
|
|
|
else if (!mLegacyTheme && std::string(root.attribute("extra").as_string("")) != "")
|
|
|
|
throw error << ": Legacy \"extra\" attribute found for non-legacy theme set";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-10-31 18:32:13 +00:00
|
|
|
for (pugi::xml_node node {root.first_child()}; node; node = node.next_sibling()) {
|
2020-06-21 12:25:28 +00:00
|
|
|
auto typeIt = typeMap.find(node.name());
|
|
|
|
if (typeIt == typeMap.cend())
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": Unknown property type \"" << node.name()
|
|
|
|
<< "\" for element of type \"" << root.name() << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-23 16:50:51 +00:00
|
|
|
std::string str {resolvePlaceholders(node.text().as_string())};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-10-17 20:21:52 +00:00
|
|
|
// Handle the special case with mutually exclusive system variables, for example
|
|
|
|
// system.fullName.collections and system.fullName.noCollections which can never
|
|
|
|
// exist at the same time. A backspace is assigned in SystemData to flag the
|
|
|
|
// variables that do not apply and if it's encountered here we simply skip the
|
|
|
|
// property.
|
|
|
|
if (!mLegacyTheme && str == "\b")
|
|
|
|
continue;
|
|
|
|
|
2022-01-29 17:41:22 +00:00
|
|
|
// Skip this check for legacy themes to not break backward compatibility with some
|
|
|
|
// themes sets that include empty property values.
|
|
|
|
if (!mLegacyTheme && str == "")
|
|
|
|
throw error << ": Property \"" << typeIt->first << "\" for element \"" << element.type
|
|
|
|
<< "\" has no value defined";
|
|
|
|
|
|
|
|
std::string nodeName = node.name();
|
|
|
|
|
2022-02-10 23:19:08 +00:00
|
|
|
// Strictly enforce removal of legacy elements for non-legacy theme sets by creating
|
|
|
|
// an unthemed system if they're present in the configuration.
|
2022-02-09 21:06:34 +00:00
|
|
|
if (!mLegacyTheme) {
|
2022-02-10 23:19:08 +00:00
|
|
|
for (auto& legacyElement : sLegacyElements) {
|
|
|
|
if (nodeName == legacyElement) {
|
|
|
|
throw error << ": Legacy <" << nodeName
|
|
|
|
<< "> property found for non-legacy theme set";
|
|
|
|
}
|
2022-02-09 21:06:34 +00:00
|
|
|
}
|
2022-01-29 17:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If an attribute exists, then replace nodeName with its name.
|
|
|
|
auto attributeEntry = sPropertyAttributeMap.find(element.type);
|
|
|
|
if (attributeEntry != sPropertyAttributeMap.end()) {
|
|
|
|
auto attribute = attributeEntry->second.find(typeIt->first);
|
|
|
|
if (attribute != attributeEntry->second.end()) {
|
|
|
|
if (node.attribute(attribute->second.c_str()) == nullptr) {
|
|
|
|
throw error << ": Unknown attribute \"" << node.first_attribute().name()
|
|
|
|
<< "\" for property \"" << typeIt->first << "\" (element \""
|
|
|
|
<< attributeEntry->first << "\")";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Add the attribute name as a prefix to avoid potential name collisions.
|
|
|
|
nodeName = attribute->second + "_" +
|
|
|
|
node.attribute(attribute->second.c_str()).as_string("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
switch (typeIt->second) {
|
2021-07-07 18:31:46 +00:00
|
|
|
case NORMALIZED_RECT: {
|
2021-08-15 20:03:17 +00:00
|
|
|
glm::vec4 val;
|
2021-07-07 18:31:46 +00:00
|
|
|
|
|
|
|
auto splits = Utils::String::delimitedStringToVector(str, " ");
|
|
|
|
if (splits.size() == 2) {
|
2022-01-16 11:09:55 +00:00
|
|
|
val = glm::vec4 {static_cast<float>(atof(splits.at(0).c_str())),
|
|
|
|
static_cast<float>(atof(splits.at(1).c_str())),
|
|
|
|
static_cast<float>(atof(splits.at(0).c_str())),
|
|
|
|
static_cast<float>(atof(splits.at(1).c_str()))};
|
2021-07-07 18:31:46 +00:00
|
|
|
}
|
|
|
|
else if (splits.size() == 4) {
|
2022-01-16 11:09:55 +00:00
|
|
|
val = glm::vec4 {static_cast<float>(atof(splits.at(0).c_str())),
|
|
|
|
static_cast<float>(atof(splits.at(1).c_str())),
|
|
|
|
static_cast<float>(atof(splits.at(2).c_str())),
|
|
|
|
static_cast<float>(atof(splits.at(3).c_str()))};
|
2021-07-07 18:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
element.properties[node.name()] = val;
|
|
|
|
break;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2021-07-07 18:31:46 +00:00
|
|
|
case NORMALIZED_PAIR: {
|
|
|
|
size_t divider = str.find(' ');
|
|
|
|
if (divider == std::string::npos)
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": Invalid normalized pair value \"" << str.c_str()
|
|
|
|
<< "\" for property \"" << node.name() << "\"";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-16 11:09:55 +00:00
|
|
|
std::string first {str.substr(0, divider)};
|
|
|
|
std::string second {str.substr(divider, std::string::npos)};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-16 11:09:55 +00:00
|
|
|
glm::vec2 val {static_cast<float>(atof(first.c_str())),
|
|
|
|
static_cast<float>(atof(second.c_str()))};
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
element.properties[node.name()] = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STRING: {
|
|
|
|
element.properties[node.name()] = str;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PATH: {
|
2022-01-29 17:41:22 +00:00
|
|
|
std::string path;
|
|
|
|
|
|
|
|
if (!str.empty() && str.front() == ':')
|
|
|
|
path = ResourceManager::getInstance().getResourcePath(str);
|
|
|
|
else
|
|
|
|
path = Utils::FileSystem::resolveRelativePath(str, mPaths.back(), true);
|
|
|
|
|
2022-01-04 20:21:26 +00:00
|
|
|
if (!ResourceManager::getInstance().fileExists(path)) {
|
2021-07-07 18:31:46 +00:00
|
|
|
std::stringstream ss;
|
2022-10-29 11:04:00 +00:00
|
|
|
// For explicit paths, print a warning if the file couldn't be found, but
|
2022-02-09 17:45:03 +00:00
|
|
|
// only print a debug message if it was set using a variable.
|
|
|
|
if (str == node.text().as_string()) {
|
|
|
|
LOG(LogWarning)
|
|
|
|
<< error.message << ": Couldn't find file \"" << node.text().get()
|
|
|
|
<< "\" "
|
|
|
|
<< ((node.text().get() != path) ? "which resolves to \"" + path + "\"" :
|
2022-10-29 11:04:00 +00:00
|
|
|
"")
|
|
|
|
<< "(element type \"" << element.type << "\", name \""
|
|
|
|
<< root.attribute("name").as_string() << "\", property \"" << nodeName
|
|
|
|
<< "\")";
|
2022-02-09 17:45:03 +00:00
|
|
|
}
|
2022-10-29 11:04:00 +00:00
|
|
|
else if (!(Settings::getInstance()->getBool("DebugSkipMissingThemeFiles") ||
|
|
|
|
(mCustomCollection &&
|
|
|
|
Settings::getInstance()->getBool(
|
|
|
|
"DebugSkipMissingThemeFilesCustomCollections")))) {
|
2022-02-09 17:45:03 +00:00
|
|
|
LOG(LogDebug)
|
|
|
|
<< error.message << ": Couldn't find file \"" << node.text().get()
|
|
|
|
<< "\" "
|
|
|
|
<< ((node.text().get() != path) ? "which resolves to \"" + path + "\"" :
|
2022-10-29 11:04:00 +00:00
|
|
|
"")
|
|
|
|
<< " (element type \"" << element.type << "\", name \""
|
|
|
|
<< root.attribute("name").as_string() << "\", property \"" << nodeName
|
|
|
|
<< "\")";
|
2022-02-09 17:45:03 +00:00
|
|
|
}
|
2021-07-07 18:31:46 +00:00
|
|
|
}
|
2022-01-29 17:41:22 +00:00
|
|
|
element.properties[nodeName] = path;
|
2021-07-07 18:31:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case COLOR: {
|
2022-01-23 16:50:51 +00:00
|
|
|
try {
|
|
|
|
element.properties[node.name()] = getHexColor(str);
|
|
|
|
}
|
|
|
|
catch (ThemeException& e) {
|
|
|
|
throw error << ": " << e.what();
|
|
|
|
}
|
2021-07-07 18:31:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-02-13 14:01:55 +00:00
|
|
|
case UNSIGNED_INTEGER: {
|
|
|
|
unsigned int integerVal {static_cast<unsigned int>(strtoul(str.c_str(), 0, 0))};
|
|
|
|
element.properties[node.name()] = integerVal;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-07 18:31:46 +00:00
|
|
|
case FLOAT: {
|
2022-01-23 16:50:51 +00:00
|
|
|
float floatVal {static_cast<float>(strtod(str.c_str(), 0))};
|
2021-07-07 18:31:46 +00:00
|
|
|
element.properties[node.name()] = floatVal;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BOOLEAN: {
|
2022-01-29 17:41:22 +00:00
|
|
|
bool boolVal = false;
|
|
|
|
// Only look at the first character.
|
2022-02-09 22:12:12 +00:00
|
|
|
if (str.size() > 0) {
|
|
|
|
if (str.front() == '1' || str.front() == 't' || str.front() == 'T' ||
|
|
|
|
str.front() == 'y' || str.front() == 'Y')
|
|
|
|
boolVal = true;
|
|
|
|
}
|
2021-07-07 18:31:46 +00:00
|
|
|
|
|
|
|
element.properties[node.name()] = boolVal;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2022-01-23 16:50:51 +00:00
|
|
|
throw error << ": Unknown ElementPropertyType for \""
|
2021-07-07 18:31:46 +00:00
|
|
|
<< root.attribute("name").as_string() << "\", property " << node.name();
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|