summaryrefslogtreecommitdiffstats
path: root/logic/minecraft/ProfileUtils.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-03-18 15:02:54 +0100
committerPetr Mrázek <peterix@gmail.com>2016-03-26 17:05:27 +0100
commitb7d8e512f4184a755809fe9a964a04921f8abf7c (patch)
tree2d67f30a2c57743dac5fc9dc819e6c5d58b41962 /logic/minecraft/ProfileUtils.cpp
parentfb9dfcb951d9cf9c19fc868703cb66e15aa9a1e6 (diff)
downloadMultiMC-b7d8e512f4184a755809fe9a964a04921f8abf7c.tar
MultiMC-b7d8e512f4184a755809fe9a964a04921f8abf7c.tar.gz
MultiMC-b7d8e512f4184a755809fe9a964a04921f8abf7c.tar.lz
MultiMC-b7d8e512f4184a755809fe9a964a04921f8abf7c.tar.xz
MultiMC-b7d8e512f4184a755809fe9a964a04921f8abf7c.zip
NOISSUE Use patch problems and problem levels instead of exceptions for minecraft profiles.
Diffstat (limited to 'logic/minecraft/ProfileUtils.cpp')
-rw-r--r--logic/minecraft/ProfileUtils.cpp45
1 files changed, 33 insertions, 12 deletions
diff --git a/logic/minecraft/ProfileUtils.cpp b/logic/minecraft/ProfileUtils.cpp
index a1ca4507..ef9b3b28 100644
--- a/logic/minecraft/ProfileUtils.cpp
+++ b/logic/minecraft/ProfileUtils.cpp
@@ -99,20 +99,42 @@ bool readOverrideOrders(QString path, PatchOrder &order)
return true;
}
+static VersionFilePtr createErrorVersionFile(QString fileId, QString filepath, QString error)
+{
+ auto outError = std::make_shared<VersionFile>();
+ outError->fileId = outError->name = fileId;
+ outError->filename = filepath;
+ outError->addProblem(PROBLEM_ERROR, error);
+ return outError;
+}
+
+static VersionFilePtr guardedParseJson(const QJsonDocument & doc,const QString &fileId,const QString &filepath,const bool &requireOrder)
+{
+ try
+ {
+ return OneSixVersionFormat::versionFileFromJson(doc, filepath, requireOrder);
+ }
+ catch (Exception & e)
+ {
+ return createErrorVersionFile(fileId, filepath, e.cause());
+ }
+}
+
VersionFilePtr parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder)
{
QFile file(fileInfo.absoluteFilePath());
if (!file.open(QFile::ReadOnly))
{
- throw JSONValidationError(QObject::tr("Unable to open the version file %1: %2.")
- .arg(fileInfo.fileName(), file.errorString()));
+ auto errorStr = QObject::tr("Unable to open the version file %1: %2.").arg(fileInfo.fileName(), file.errorString());
+ return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr);
}
QJsonParseError error;
auto data = file.readAll();
QJsonDocument doc = QJsonDocument::fromJson(data, &error);
+ file.close();
if (error.error != QJsonParseError::NoError)
{
- int line = 0;
+ int line = 1;
int column = 0;
for(int i = 0; i < error.offset; i++)
{
@@ -124,12 +146,12 @@ VersionFilePtr parseJsonFile(const QFileInfo &fileInfo, const bool requireOrder)
}
column++;
}
- throw JSONValidationError(
- QObject::tr("Unable to process the version file %1: %2 at line %3 column %4.")
+ auto errorStr = QObject::tr("Unable to process the version file %1: %2 at line %3 column %4.")
.arg(fileInfo.fileName(), error.errorString())
- .arg(line).arg(column));
+ .arg(line).arg(column);
+ return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr);
}
- return OneSixVersionFormat::versionFileFromJson(doc, file.fileName(), requireOrder);
+ return guardedParseJson(doc, fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), requireOrder);
}
VersionFilePtr parseBinaryJsonFile(const QFileInfo &fileInfo)
@@ -137,18 +159,17 @@ VersionFilePtr parseBinaryJsonFile(const QFileInfo &fileInfo)
QFile file(fileInfo.absoluteFilePath());
if (!file.open(QFile::ReadOnly))
{
- throw JSONValidationError(QObject::tr("Unable to open the version file %1: %2.")
- .arg(fileInfo.fileName(), file.errorString()));
+ auto errorStr = QObject::tr("Unable to open the version file %1: %2.").arg(fileInfo.fileName(), file.errorString());
+ return createErrorVersionFile(fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), errorStr);
}
QJsonDocument doc = QJsonDocument::fromBinaryData(file.readAll());
file.close();
if (doc.isNull())
{
file.remove();
- throw JSONValidationError(
- QObject::tr("Unable to process the version file %1.").arg(fileInfo.fileName()));
+ throw JSONValidationError(QObject::tr("Unable to process the version file %1.").arg(fileInfo.fileName()));
}
- return OneSixVersionFormat::versionFileFromJson(doc, file.fileName(), false);
+ return guardedParseJson(doc, fileInfo.completeBaseName(), fileInfo.absoluteFilePath(), false);
}
void removeLwjglFromPatch(VersionFilePtr patch)