Don't skip CSL package parsing after an error occurred

Summary:
This patch fixes X-Plane CSL package parsing to no longer skip the rest
of the package when an error occurred. Instead CSL planes are marked
having errors and are removed after the full package has been parsed.

Reviewers: #gatekeepers, msutcliffe

Reviewed By: #gatekeepers, msutcliffe

Maniphest Tasks: T616

Differential Revision: https://dev.swift-project.org/D101
This commit is contained in:
Roland Rossgotterer
2019-04-25 14:53:09 +02:00
committed by Klaus Basan
parent 92e7a6c83f
commit 267a9720da
3 changed files with 17 additions and 11 deletions

View File

@@ -377,6 +377,8 @@ namespace BlackMisc
bool CAircraftModelLoaderXPlane::parseObjectCommand(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum) bool CAircraftModelLoaderXPlane::parseObjectCommand(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum)
{ {
package.planes.push_back(CSLPlane());
if (tokens.size() != 2) if (tokens.size() != 2)
{ {
const CStatusMessage m = CStatusMessage(this).error(u"%1/xsb_aircraft.txt Line %2 : OBJECT command requires 1 argument.") << path << lineNum; const CStatusMessage m = CStatusMessage(this).error(u"%1/xsb_aircraft.txt Line %2 : OBJECT command requires 1 argument.") << path << lineNum;
@@ -422,7 +424,6 @@ namespace BlackMisc
objFile.close(); objFile.close();
package.planes.push_back(CSLPlane());
QFileInfo fileInfo(fullPath); QFileInfo fileInfo(fullPath);
QStringList dirNames; QStringList dirNames;
@@ -465,7 +466,7 @@ namespace BlackMisc
QFileInfo fileInfo(absoluteTexPath); QFileInfo fileInfo(absoluteTexPath);
if (!fileInfo.exists()) if (!fileInfo.exists())
{ {
const CStatusMessage m = CStatusMessage(this).error(u"%1/xsb_aircraft.txt Line %2 : Texture '%1' does not exist.") << path << lineNum << absoluteTexPath; const CStatusMessage m = CStatusMessage(this).error(u"%1/xsb_aircraft.txt Line %2 : Texture '%3' does not exist.") << path << lineNum << absoluteTexPath;
m_loadingMessages.push_back(m); m_loadingMessages.push_back(m);
return false; return false;
} }
@@ -493,6 +494,8 @@ namespace BlackMisc
bool CAircraftModelLoaderXPlane::parseObj8AircraftCommand(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum) bool CAircraftModelLoaderXPlane::parseObj8AircraftCommand(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum)
{ {
package.planes.push_back(CSLPlane());
// OBJ8_AIRCRAFT <path> // OBJ8_AIRCRAFT <path>
if (tokens.size() != 2) if (tokens.size() != 2)
{ {
@@ -500,8 +503,6 @@ namespace BlackMisc
m_loadingMessages.push_back(m); m_loadingMessages.push_back(m);
return false; return false;
} }
package.planes.push_back(CSLPlane());
return true; return true;
} }
@@ -560,7 +561,7 @@ namespace BlackMisc
QFileInfo fileInfo(absoluteTexPath); QFileInfo fileInfo(absoluteTexPath);
if (!fileInfo.exists()) if (!fileInfo.exists())
{ {
const CStatusMessage m = CStatusMessage(this).error(u"%1/xsb_aircraft.txt Line %2 : Texture '%1' does not exist.") << path << lineNum << absoluteTexPath; const CStatusMessage m = CStatusMessage(this).error(u"%1/xsb_aircraft.txt Line %2 : Texture '%3' does not exist.") << path << lineNum << absoluteTexPath;
m_loadingMessages.push_back(m); m_loadingMessages.push_back(m);
return false; return false;
} }
@@ -703,26 +704,29 @@ namespace BlackMisc
auto tokens = splitString(line, [](QChar c) { return c.isSpace(); }); auto tokens = splitString(line, [](QChar c) { return c.isSpace(); });
if (!tokens.empty()) if (!tokens.empty())
{ {
const CStatusMessage parserErrorMessage = CStatusMessage(this).error(u"Ignoring rest of CSL package '%1' due to previous parser error. Please fix the error and reload the model cache!") << package.name;
auto it = commands.find(tokens[0]); auto it = commands.find(tokens[0]);
if (it != commands.end()) if (it != commands.end())
{ {
bool result = it.value()(tokens, package, package.path, lineNum); bool result = it.value()(tokens, package, package.path, lineNum);
if (!result) if (!result)
{ {
m_loadingMessages.push_back(parserErrorMessage); package.planes.back().hasErrors = true;
break;
} }
} }
else else
{ {
const CStatusMessage m = CStatusMessage(this).error(u"%1/xsb_aircraft.txt Line %2 : Unrecognized CSL command: '%3'") << package.path << lineNum << tokens[0]; const CStatusMessage m = CStatusMessage(this).error(u"%1/xsb_aircraft.txt Line %2 : Unrecognized CSL command: '%3'") << package.path << lineNum << tokens[0];
m_loadingMessages.push_back(m); m_loadingMessages.push_back(m);
m_loadingMessages.push_back(parserErrorMessage);
break;
} }
} }
} }
// Remove all planes with errors
auto it = std::remove_if(package.planes.begin(), package.planes.end(), [](const CSLPlane &plane)
{
return plane.hasErrors;
});
package.planes.erase(it, package.planes.end());
} }
const QString &CAircraftModelLoaderXPlane::fileFilterFlyable() const QString &CAircraftModelLoaderXPlane::fileFilterFlyable()

View File

@@ -82,6 +82,8 @@ namespace BlackMisc
QString livery; //!< Livery identifier. Can be empty. QString livery; //!< Livery identifier. Can be empty.
ObjectVersion objectVersion; ObjectVersion objectVersion;
bool hasErrors = false;
}; };
//! CSL package //! CSL package