Added checks for whether video files set using the 'path' and 'default' properties actually exist before attempting to use them in VideoComponent.

This commit is contained in:
Leon Styhre 2022-09-15 17:19:50 +02:00
parent a50a734a6d
commit 0aa1d3bdc7

View file

@ -121,7 +121,7 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("size")) { if (elem->has("size")) {
glm::vec2 videoSize {elem->get<glm::vec2>("size")}; glm::vec2 videoSize {elem->get<glm::vec2>("size")};
if (videoSize == glm::vec2 {0.0f, 0.0f}) { if (videoSize == glm::vec2 {0.0f, 0.0f}) {
LOG(LogWarning) << "VideoComponent: Invalid theme configuration, property <size> " LOG(LogWarning) << "VideoComponent: Invalid theme configuration, property \"size\" "
"for element \"" "for element \""
<< element.substr(6) << "\" is set to zero"; << element.substr(6) << "\" is set to zero";
videoSize = {0.01f, 0.01f}; videoSize = {0.01f, 0.01f};
@ -163,14 +163,23 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
else { else {
mStaticImage.setLinearInterpolation(false); mStaticImage.setLinearInterpolation(false);
LOG(LogWarning) << "ImageComponent: Invalid theme configuration, property " LOG(LogWarning) << "VideoComponent: Invalid theme configuration, property "
"<interpolation> defined as \"" "\"interpolation\" for element \""
<< interpolation << "\""; << element.substr(6) << "\" defined as \"" << interpolation << "\"";
} }
} }
if (elem->has("default")) if (elem->has("default")) {
mConfig.defaultVideoPath = elem->get<std::string>("default"); const std::string defaultVideo {elem->get<std::string>("default")};
if (ResourceManager::getInstance().fileExists(defaultVideo)) {
mConfig.defaultVideoPath = defaultVideo;
}
else {
LOG(LogWarning)
<< "VideoComponent: File defined for property \"default\" for element \""
<< element.substr(6) << "\" does not exist: \"" << defaultVideo << "\"";
}
}
if (elem->has("defaultImage")) { if (elem->has("defaultImage")) {
mStaticImage.setDefaultImage(elem->get<std::string>("defaultImage")); mStaticImage.setDefaultImage(elem->get<std::string>("defaultImage"));
@ -178,8 +187,16 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mDefaultImagePath = elem->get<std::string>("defaultImage"); mDefaultImagePath = elem->get<std::string>("defaultImage");
} }
if (elem->has("path")) if (elem->has("path")) {
mConfig.staticVideoPath = elem->get<std::string>("path"); const std::string staticPath {elem->get<std::string>("path")};
if (ResourceManager::getInstance().fileExists(staticPath)) {
mConfig.staticVideoPath = staticPath;
}
else {
LOG(LogWarning) << "VideoComponent: File defined for property \"path\" for element \""
<< element.substr(6) << "\" does not exist: \"" << staticPath << "\"";
}
}
if ((properties & ThemeFlags::DELAY) && elem->has("delay")) if ((properties & ThemeFlags::DELAY) && elem->has("delay"))
mConfig.startDelay = mConfig.startDelay =
@ -208,17 +225,18 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mThemeImageTypes = Utils::String::delimitedStringToVector(imageTypes, ","); mThemeImageTypes = Utils::String::delimitedStringToVector(imageTypes, ",");
if (mThemeImageTypes.empty()) { if (mThemeImageTypes.empty()) {
LOG(LogError) << "VideoComponent: Invalid theme configuration, property <imageType> " LOG(LogError) << "VideoComponent: Invalid theme configuration, property \"imageType\" "
"contains no values"; "for element \""
<< element.substr(6) << "\" contains no values";
} }
for (std::string& type : mThemeImageTypes) { for (std::string& type : mThemeImageTypes) {
if (std::find(supportedImageTypes.cbegin(), supportedImageTypes.cend(), type) == if (std::find(supportedImageTypes.cbegin(), supportedImageTypes.cend(), type) ==
supportedImageTypes.cend()) { supportedImageTypes.cend()) {
LOG(LogError) LOG(LogError)
<< "VideoComponent: Invalid theme configuration, property <imageType> " << "VideoComponent: Invalid theme configuration, property \"imageType\" "
"defined as \"" "for element \""
<< type << "\""; << element.substr(6) << "\" defined as \"" << type << "\"";
mThemeImageTypes.clear(); mThemeImageTypes.clear();
break; break;
} }
@ -228,8 +246,9 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
std::stable_sort(sortedTypes.begin(), sortedTypes.end()); std::stable_sort(sortedTypes.begin(), sortedTypes.end());
if (std::adjacent_find(sortedTypes.begin(), sortedTypes.end()) != sortedTypes.end()) { if (std::adjacent_find(sortedTypes.begin(), sortedTypes.end()) != sortedTypes.end()) {
LOG(LogError) << "VideoComponent: Invalid theme configuration, property <imageType> " LOG(LogError) << "VideoComponent: Invalid theme configuration, property \"imageType\" "
"contains duplicate values"; "for element \""
<< element.substr(6) << "\" contains duplicate values";
mThemeImageTypes.clear(); mThemeImageTypes.clear();
} }
} }