From 45867058f02e27a6df7397b1d036ddcebd6c4fd1 Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Sun, 10 Dec 2017 19:20:49 +0100 Subject: [PATCH] addon-metadata.xml: add meta section (non-leaf node) and file-type node Move the format-version node inside /meta. It's not compatible of course, but since the stuff this is breaking is only 2 or 3 days old, let's go for it for nicer code and file format. Sorry if you had already written an addon-metadata.xml file of your own. In this case, just replace: 1 with: FlightGear add-on metadata 1 --- src/Add-ons/AddonManager.cxx | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Add-ons/AddonManager.cxx b/src/Add-ons/AddonManager.cxx index 8609e0748..b33fa8b42 100644 --- a/src/Add-ons/AddonManager.cxx +++ b/src/Add-ons/AddonManager.cxx @@ -140,11 +140,35 @@ AddonManager::registerAddonMetadata(const SGPath& addonPath) e.getFormattedMessage()); } - // Check the format version of the metadata file - SGPropertyNode *fmtVersionNode = addonRoot.getChild("format-version"); + // Check the 'meta' section + SGPropertyNode *metaNode = addonRoot.getChild("meta"); + if (metaNode == nullptr) { + throw addon_errors::error_loading_metadata_file( + "no /meta node found in add-on metadata file '" + + metadataFile.utf8Str() + "'"); + } + + // Check the file type + SGPropertyNode *fileTypeNode = metaNode->getChild("file-type"); + if (fileTypeNode == nullptr) { + throw addon_errors::error_loading_metadata_file( + "no /meta/file-type node found in add-on metadata file '" + + metadataFile.utf8Str() + "'"); + } + + string fileType = fileTypeNode->getStringValue(); + if (fileType != "FlightGear add-on metadata") { + throw addon_errors::error_loading_metadata_file( + "Invalid /meta/file-type value for add-on metadata file '" + + metadataFile.utf8Str() + "': '" + fileType + "' " + "(expected 'FlightGear add-on metadata')"); + } + + // Check the format version + SGPropertyNode *fmtVersionNode = metaNode->getChild("format-version"); if (fmtVersionNode == nullptr) { throw addon_errors::error_loading_metadata_file( - "no 'format-version' node found in add-on metadata file '" + + "no /meta/format-version node found in add-on metadata file '" + metadataFile.utf8Str() + "'"); }