Package::indexOfvariant works on fully-qualified IDs.

Should fix issues restoring variants in the launcher.
This commit is contained in:
James Turner 2016-11-29 15:36:00 +00:00
parent 1c39daec07
commit 5a0908d5bb
2 changed files with 19 additions and 3 deletions

View File

@ -175,10 +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);
COMPARE(p2->getLocalisedProp("description", skisVariant), "A plane with skis");
COMPARE(p2->getLocalisedProp("author", skisVariant), "Standard author");

View File

@ -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;
}