1
0
Fork 0

Make the launcher defensive about bad add-ons

Tolerate missing add-on data if a bogus add-on is added by the user.

https://sourceforge.net/p/flightgear/codetickets/2266/
This commit is contained in:
James Turner 2020-07-01 11:57:04 +01:00
parent 736485ab76
commit bb75d24fc0

View file

@ -84,7 +84,17 @@ QVariant AddonsModel::get(int idx, int role) const
{
if (idx >= 0 && idx < m_addonsList.size()) {
auto path = m_addonsList[idx];
if (!m_addonsMap.contains(path)) {
if ((role == PathRole) || (role == Qt::DisplayRole)) {
return path;
}
return {};
}
auto addon = m_addonsMap[path].addon;
if (!addon)
return {};
if (role == Qt::DisplayRole) {
QString name = QString::fromStdString(addon->getName());
@ -198,6 +208,9 @@ void AddonsModel::enable(int index, bool enable)
}
auto path = m_addonsList[index];
if (!m_addonsMap.contains(path))
return;
m_addonsMap[path].enable = enable && checkVersion(path);
emit modulesChanged();
@ -207,6 +220,10 @@ bool AddonsModel::checkVersion(QString path) const
{
using namespace simgear;
if (!m_addonsMap.contains(path)) {
return false;
}
// Check that the FlightGear version satisfies the add-on requirements
std::string minFGversion = m_addonsMap[path].addon->getMinFGVersionRequired();
if (strutils::compare_versions(FLIGHTGEAR_VERSION, minFGversion) < 0) {
@ -220,4 +237,4 @@ bool AddonsModel::checkVersion(QString path) const
}
return true;
}
}