Added checks for valid imageType property values to ImageComponent and VideoComponent.

This commit is contained in:
Leon Styhre 2022-08-19 17:07:45 +02:00
parent 9d2a9ed9d9
commit 0b34bd8991
4 changed files with 60 additions and 0 deletions

View file

@ -555,6 +555,32 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
imageTypes = Utils::String::replace(imageTypes, ",,", ",");
mThemeImageTypes = Utils::String::delimitedStringToVector(imageTypes, ",");
if (mThemeImageTypes.empty()) {
LOG(LogError) << "ImageComponent: Invalid theme configuration, property <imageType> "
"contains no values";
}
for (std::string& type : mThemeImageTypes) {
if (std::find(supportedImageTypes.cbegin(), supportedImageTypes.cend(), type) ==
supportedImageTypes.cend()) {
LOG(LogError)
<< "ImageComponent: Invalid theme configuration, property <imageType> "
"defined as \""
<< type << "\"";
mThemeImageTypes.clear();
break;
}
}
std::vector<std::string> sortedTypes {mThemeImageTypes};
std::stable_sort(sortedTypes.begin(), sortedTypes.end());
if (std::adjacent_find(sortedTypes.begin(), sortedTypes.end()) != sortedTypes.end()) {
LOG(LogError) << "ImageComponent: Invalid theme configuration, property <imageType> "
"contains duplicate values";
mThemeImageTypes.clear();
}
}
if (elem->has("metadataElement") && elem->get<bool>("metadataElement"))

View file

@ -128,6 +128,10 @@ private:
std::string mDefaultPath;
static inline std::vector<std::string> supportedImageTypes {
"image", "miximage", "marquee", "screenshot", "titlescreen",
"cover", "backcover", "3dbox", "physicalmedia", "fanart"};
std::shared_ptr<TextureResource> mTexture;
float mFadeOpacity;
float mReflectionsFalloff;

View file

@ -206,6 +206,32 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
imageTypes = Utils::String::replace(imageTypes, ",,", ",");
mThemeImageTypes = Utils::String::delimitedStringToVector(imageTypes, ",");
if (mThemeImageTypes.empty()) {
LOG(LogError) << "VideoComponent: Invalid theme configuration, property <imageType> "
"contains no values";
}
for (std::string& type : mThemeImageTypes) {
if (std::find(supportedImageTypes.cbegin(), supportedImageTypes.cend(), type) ==
supportedImageTypes.cend()) {
LOG(LogError)
<< "VideoComponent: Invalid theme configuration, property <imageType> "
"defined as \""
<< type << "\"";
mThemeImageTypes.clear();
break;
}
}
std::vector<std::string> sortedTypes {mThemeImageTypes};
std::stable_sort(sortedTypes.begin(), sortedTypes.end());
if (std::adjacent_find(sortedTypes.begin(), sortedTypes.end()) != sortedTypes.end()) {
LOG(LogError) << "VideoComponent: Invalid theme configuration, property <imageType> "
"contains duplicate values";
mThemeImageTypes.clear();
}
}
if (elem->has("pillarboxes"))

View file

@ -113,6 +113,10 @@ protected:
std::string mStaticImagePath;
std::string mDefaultImagePath;
static inline std::vector<std::string> supportedImageTypes {
"image", "miximage", "marquee", "screenshot", "titlescreen",
"cover", "backcover", "3dbox", "physicalmedia", "fanart"};
std::string mVideoPath;
unsigned mStartTime;
std::atomic<bool> mIsPlaying;