diff --git a/launcher/BaseInstance.cpp b/launcher/BaseInstance.cpp index 3b4612c73..aa7812649 100644 --- a/launcher/BaseInstance.cpp +++ b/launcher/BaseInstance.cpp @@ -427,7 +427,19 @@ QList BaseInstance::shortcuts() const QList results; for (const auto& elem : document.array()) { auto dict = elem.toObject(); - results.append({ dict["name"].toString(), dict["filePath"].toString(), static_cast(dict["target"].toInt()) }); + if (!dict.contains("name") || !dict.contains("filePath") || !dict.contains("target")) + return {}; + int value = dict["target"].toInt(-1); + if (!dict["name"].isString() || !dict["filePath"].isString() || value < 0 || value >= 3) + return {}; + + QString shortcutName = dict["name"].toString(); + QString filePath = dict["filePath"].toString(); + if (!QDir(filePath).exists()) { + qWarning() << "Shortcut" << shortcutName << "for instance" << name() << "have non-existent path" << filePath; + continue; + } + results.append({ shortcutName, filePath, static_cast(value) }); } return results; } diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index f6512b25d..de94db7c3 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -686,18 +686,7 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id) } qDebug() << "Loaded instance" << inst->name() << "from" << inst->instanceRoot(); - // Fixup the shortcuts by pruning all non-existing links auto shortcut = inst->shortcuts(); - for (auto it = shortcut.begin(); it != shortcut.end();) { - const auto& [name, filePath, target] = *it; - if (!QDir(filePath).exists()) { - qWarning() << "Shortcut" << name << "have non-existent path" << filePath; - it = shortcut.erase(it); - continue; - } - ++it; - } - inst->setShortcuts(shortcut); if (!shortcut.isEmpty()) qDebug() << "Loaded" << shortcut.size() << "shortcut(s) for instance" << inst->name();