diff -r 0135e64c6c66 -r c4fd2813b127 QTfrontend/model/ThemeModel.cpp --- a/QTfrontend/model/ThemeModel.cpp Wed May 16 18:22:28 2018 +0200 +++ b/QTfrontend/model/ThemeModel.cpp Wed Jul 31 23:14:27 2019 +0200 @@ -124,38 +124,49 @@ { QMap dataset; + // Ignore directories without theme.cfg + QFile themeCfgFile(QString("physfs://Themes/%1/theme.cfg").arg(theme)); + if (!themeCfgFile.open(QFile::ReadOnly)) + { + continue; + } + // themes without icon are supposed to be hidden QString iconpath = QString("physfs://Themes/%1/icon.png").arg(theme); - if (!QFile::exists(iconpath)) { dataset.insert(IsHiddenRole, true); } else { - // themes with the key “hidden” in theme.cfg are hidden, too - QFile themeCfgFile(QString("physfs://Themes/%1/theme.cfg").arg(theme)); - if (themeCfgFile.open(QFile::ReadOnly)) + QTextStream stream(&themeCfgFile); + QString line = stream.readLine(); + QString key; + while (!line.isNull()) { - QTextStream stream(&themeCfgFile); - QString line = stream.readLine(); - QString key; - while (!line.isNull()) + key = QString(line); + int equalsPos = line.indexOf('='); + key.truncate(equalsPos - 1); + key = key.simplified(); + if (!line.startsWith(';') && key == "hidden") { - key = QString(line); - int equalsPos = line.indexOf('='); - key.truncate(equalsPos - 1); - key = key.simplified(); - if (!line.startsWith(';') && key == "hidden") - { - dataset.insert(IsHiddenRole, true); - break; - } - line = stream.readLine(); + dataset.insert(IsHiddenRole, true); + break; } + line = stream.readLine(); } } + // Themes without land textures are considered "background themes" + // since they cannot be used for generated maps, but they can be used + // for image maps. + QString landtexpath = QString("physfs://Themes/%1/LandTex.png").arg(theme); + QString bordertexpath = QString("physfs://Themes/%1/Border.png").arg(theme); + if ((!QFile::exists(landtexpath)) || (!QFile::exists(bordertexpath))) + { + dataset.insert(IsBackgroundThemeRole, true); + } + // detect if theme is dlc QString themeDir = PHYSFS_getRealDir(QString("Themes/%1").arg(theme).toLocal8Bit().data()); bool isDLC = !themeDir.startsWith(datadir->absolutePath()); @@ -179,5 +190,6 @@ } m_data.append(dataset); + themeCfgFile.close(); } }