mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 21:27:44 +02:00
Validate JSON parsing results
Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
@ -427,7 +427,19 @@ QList<ShortcutData> BaseInstance::shortcuts() const
|
||||
QList<ShortcutData> results;
|
||||
for (const auto& elem : document.array()) {
|
||||
auto dict = elem.toObject();
|
||||
results.append({ dict["name"].toString(), dict["filePath"].toString(), static_cast<ShortcutTarget>(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<ShortcutTarget>(value) });
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
Reference in New Issue
Block a user