From 1ef6ec41787270d95523e29754ab90fce41e57c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 1 Apr 2014 21:58:15 +0200 Subject: Fix library replace issue --- logic/VersionFile.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'logic') diff --git a/logic/VersionFile.cpp b/logic/VersionFile.cpp index 831b086e..564229d7 100644 --- a/logic/VersionFile.cpp +++ b/logic/VersionFile.cpp @@ -294,15 +294,19 @@ OneSixLibraryPtr VersionFile::createLibrary(RawLibraryPtr lib) int VersionFile::findLibrary(QList haystack, const QString &needle) { + int retval = -1; for (int i = 0; i < haystack.size(); ++i) { - if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix) - .indexIn(haystack.at(i)->rawName()) != -1) + QString chunk = haystack.at(i)->rawName(); + if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix).indexIn(chunk) != -1) { - return i; + // only one is allowed. + if(retval != -1) + return -1; + retval = i; } } - return -1; + return retval; } void VersionFile::applyTo(VersionFinal *version) @@ -394,7 +398,7 @@ void VersionFile::applyTo(VersionFinal *version) { case RawLibrary::Apply: { - + QLOG_INFO() << "Applying lib " << lib->name; int index = findLibrary(version->libraries, lib->name); if (index >= 0) { @@ -438,7 +442,7 @@ void VersionFile::applyTo(VersionFinal *version) case RawLibrary::Append: case RawLibrary::Prepend: { - + QLOG_INFO() << "Adding lib " << lib->name; const int startOfVersion = lib->name.lastIndexOf(':') + 1; const int index = findLibrary( version->libraries, QString(lib->name).replace(startOfVersion, INT_MAX, '*')); @@ -507,14 +511,23 @@ void VersionFile::applyTo(VersionFinal *version) } case RawLibrary::Replace: { - int index = findLibrary(version->libraries, lib->insertData); + QString toReplace; + if(lib->insertData.isEmpty()) + { + const int startOfVersion = lib->name.lastIndexOf(':') + 1; + toReplace = QString(lib->name).replace(startOfVersion, INT_MAX, '*'); + } + else + toReplace = lib->insertData; + QLOG_INFO() << "Replacing lib " << toReplace << " with " << lib->name; + int index = findLibrary(version->libraries, toReplace); if (index >= 0) { version->libraries.replace(index, createLibrary(lib)); } else { - QLOG_WARN() << "Couldn't find" << lib->insertData << "(skipping)"; + QLOG_WARN() << "Couldn't find" << toReplace << "(skipping)"; } break; } @@ -525,6 +538,7 @@ void VersionFile::applyTo(VersionFinal *version) int index = findLibrary(version->libraries, lib); if (index >= 0) { + QLOG_INFO() << "Removing lib " << lib; version->libraries.removeAt(index); } else -- cgit v1.2.3