From 07dfb6496ca703a736eb58afa03da9e5ab261bcd Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 6 Sep 2021 16:05:09 +0100 Subject: [PATCH] Allow aircraft directory name validation. Patch by Michael Danilov: allow an aircraft set XML to define the requied directory name, and if one is provided, validate the actual name against this. This catches common issues where a manually downloaded aircraft has the wrong name and some assets will therefore not load. SF-Ticket-ID: https://sourceforge.net/p/flightgear/codetickets/2647/ --- src/Main/fg_init.cxx | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 17bd57d88..f6b39b9da 100755 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -255,6 +255,7 @@ public: } checkAircraftMinVersion(); + checkAircraftDirName(); // apply state after the -set.xml, but before any options are are set flightgear::applyInitialState(); @@ -340,6 +341,7 @@ public: flightgear::applyInitialState(); checkAircraftMinVersion(); + checkAircraftDirName(); return true; } @@ -450,7 +452,34 @@ private: return true; } - + + bool checkAircraftDirName() + { + auto expectedDirNode = globals->get_props()->getNode("/sim/expected-aircraft-dir-name"); + const string aircraftId = fgGetString("/sim/aircraft"); + if (aircraftId != fgGetString("/sim/aircraft-id")){ + // Skip the check for aircraft installed from catalog. + return true; + } + + if (expectedDirNode) { + const string expectedDir = expectedDirNode->getStringValue(); + const SGPath dir(fgGetString("/sim/aircraft-dir")); + if (dir.file() != expectedDirNode->getStringValue()) { + flightgear::fatalMessageBoxThenExit("Aircraft folder named incorrectly", + "The folder of the selected aircraft must be named '" + expectedDir + + "' (instead of '" + dir.file() + "') to work correctly. If you downloaded it yourself, " + + "please ensure the folder is called '" + + expectedDir + "' and re-name if necessary."); + return false; + } + } else { + // TODO Uncomment for the next release. + //SG_LOG(SG_AIRCRAFT, SG_DEV_ALERT, "Aircraft does not specify the required aircraft directory name: please add one at /sim/expected-aircraft-dir-name"); + } + return true; + } + std::string _searchAircraft; SGPath _foundPath; SGPropertyNode* _cache = nullptr;