From 863ae19d1dabebf83e95ef3b492a06751956f340 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 29 Nov 2016 15:36:00 +0000 Subject: [PATCH] Package::indexOfvariant works on fully-qualified IDs. Should fix issues restoring variants in the launcher. --- simgear/package/CatalogTest.cxx | 5 +++++ simgear/package/Package.cxx | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx index 8881fd3a..6a700eff 100644 --- a/simgear/package/CatalogTest.cxx +++ b/simgear/package/CatalogTest.cxx @@ -175,9 +175,14 @@ int parseTest() // expected } + unsigned int skisVariantFull = p2->indexOfVariant("org.flightgear.test.catalog1.c172p-skis"); + VERIFY(skisVariantFull > 0); + unsigned int skisVariant = p2->indexOfVariant("c172p-skis"); VERIFY(skisVariant > 0); + COMPARE(skisVariant, skisVariantFull); + pkg::Package::ThumbnailVec thumbs2 = p2->thumbnailsForVariant(skisVariant); COMPARE(thumbs2.size(), 2); diff --git a/simgear/package/Package.cxx b/simgear/package/Package.cxx index 70ceb1ae..70d3aec2 100644 --- a/simgear/package/Package.cxx +++ b/simgear/package/Package.cxx @@ -340,13 +340,25 @@ std::string Package::nameForVariant(const std::string& vid) const unsigned int Package::indexOfVariant(const std::string& vid) const { - if (vid == id()) { + // accept fully-qualified IDs here + std::string actualId = vid; + size_t lastDot = vid.rfind('.'); + if (lastDot != std::string::npos) { + std::string catalogId = vid.substr(0, lastDot); + if (catalogId != catalog()->id()) { + throw sg_exception("Bad fully-qualified ID:" + vid + ", package mismatch" ); + } + actualId = vid.substr(lastDot + 1); + } + + + if (actualId == id()) { return 0; } unsigned int result = 1; for (SGPropertyNode* var : m_props->getChildren("variant")) { - if (var->getStringValue("id") == vid) { + if (var->getStringValue("id") == actualId) { return result; }