Filter out non-image files from the launcher collection (closes #1693)

This commit is contained in:
Alexander Bock
2021-07-22 21:19:35 +02:00
parent 527bc4d108
commit 05c577bd3d
@@ -312,8 +312,24 @@ void LauncherWindow::setBackgroundImage(const std::string& syncPath) {
std::mt19937 g(rd());
std::shuffle(files.begin(), files.end(), g);
// We know there has to be at least one folder, so it's fine to just pick the first
std::string image = files.front();
_backgroundImage->setPixmap(QPixmap(QString::fromStdString(image)));
while (!files.empty()) {
std::string p = files.front();
if (std::filesystem::path(p).extension() == ".png") {
// If the top path starts with the png extension, we have found our candidate
break;
}
else {
// There shouldn't be any non-png images in here, but you never know. So we
// just remove non-image files here
files.erase(files.begin());
}
}
// There better be at least one file left, but just in in case
if (!files.empty()) {
std::string image = files.front();
_backgroundImage->setPixmap(QPixmap(QString::fromStdString(image)));
}
}
void LauncherWindow::populateProfilesList(std::string preset) {