From 06c03a067203ef0b4f07bc9a2524026e10522fc3 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 29 Aug 2021 19:24:36 +0100 Subject: [PATCH] Tolerate Aircraft/ prefix in preview paths Reuqested by Jonathan R, allow Aircraft//foo paths to work for preview iamges. SF-ID: https://sourceforge.net/p/flightgear/codetickets/2644/ --- src/GUI/LocalAircraftCache.cxx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/GUI/LocalAircraftCache.cxx b/src/GUI/LocalAircraftCache.cxx index 66e212a30..b1cd1f591 100644 --- a/src/GUI/LocalAircraftCache.cxx +++ b/src/GUI/LocalAircraftCache.cxx @@ -122,11 +122,28 @@ bool AircraftItem::initFromFile(QDir dir, QString filePath) if (sim->hasChild("previews")) { SGPropertyNode_ptr previewsNode = sim->getChild("previews"); + const QString aircraftPrefix = "Aircraft/" + dir.dirName() + "/"; + for (auto previewNode : previewsNode->getChildren("preview")) { // add file path as url QString pathInXml = QString::fromStdString(previewNode->getStringValue("path")); + + // https://sourceforge.net/p/flightgear/codetickets/2644/ + // allow Aircraft/ prefixed paths in previews; what we're actually doing here + // is trimming them back to the style we expect + if (pathInXml.startsWith(aircraftPrefix)) { + pathInXml = pathInXml.mid(aircraftPrefix.length()); + } + QString previewPath = dir.absoluteFilePath(pathInXml); + + if (!QFile::exists(previewPath)) { + qWarning() << "Missing local preview file" << previewPath; + continue; + } + previews.append(QUrl::fromLocalFile(previewPath)); + } }