2014-01-22 12:03:32 +05:30
|
|
|
/* Copyright 2013 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-01-24 22:42:02 +05:30
|
|
|
#include "OneSixVersionBuilder.h"
|
2014-01-22 12:03:32 +05:30
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDir>
|
2014-01-22 19:50:48 +05:30
|
|
|
#include <QDebug>
|
2014-01-22 12:03:32 +05:30
|
|
|
|
2014-01-24 22:42:02 +05:30
|
|
|
#include "OneSixVersion.h"
|
|
|
|
#include "OneSixInstance.h"
|
|
|
|
#include "OneSixRule.h"
|
2014-01-24 02:01:41 +05:30
|
|
|
#include "logger/QsLog.h"
|
2014-01-22 12:03:32 +05:30
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
struct VersionFile
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
int order;
|
2014-02-01 19:22:21 +05:30
|
|
|
QString name;
|
|
|
|
QString fileId;
|
|
|
|
QString version;
|
|
|
|
// TODO use the mcVersion to determine if a version file should be removed on update
|
|
|
|
QString mcVersion;
|
|
|
|
QString filename;
|
|
|
|
// TODO requirements
|
|
|
|
// QMap<QString, QString> requirements;
|
2014-01-27 23:50:07 +05:30
|
|
|
QString id;
|
|
|
|
QString mainClass;
|
|
|
|
QString overwriteMinecraftArguments;
|
|
|
|
QString addMinecraftArguments;
|
|
|
|
QString removeMinecraftArguments;
|
|
|
|
QString processArguments;
|
|
|
|
QString type;
|
|
|
|
QString releaseTime;
|
|
|
|
QString time;
|
|
|
|
QString assets;
|
|
|
|
int minimumLauncherVersion = -1;
|
|
|
|
|
|
|
|
bool shouldOverwriteTweakers = false;
|
|
|
|
QStringList overwriteTweakers;
|
|
|
|
QStringList addTweakers;
|
|
|
|
QStringList removeTweakers;
|
|
|
|
|
|
|
|
struct Library
|
|
|
|
{
|
|
|
|
QString name;
|
|
|
|
QString url;
|
|
|
|
QString hint;
|
|
|
|
QString absoluteUrl;
|
|
|
|
bool applyExcludes = false;
|
|
|
|
QStringList excludes;
|
|
|
|
bool applyNatives = false;
|
|
|
|
QList<QPair<OpSys, QString>> natives;
|
|
|
|
bool applyRules = false;
|
|
|
|
QList<std::shared_ptr<Rule>> rules;
|
2014-01-22 12:03:32 +05:30
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
// user for '+' libraries
|
|
|
|
enum InsertType
|
|
|
|
{
|
|
|
|
Apply,
|
|
|
|
Append,
|
|
|
|
Prepend,
|
2014-01-28 02:53:07 +05:30
|
|
|
AppendIfNotExists,
|
|
|
|
PrependIfNotExists,
|
2014-01-27 23:50:07 +05:30
|
|
|
Replace
|
|
|
|
};
|
|
|
|
InsertType insertType;
|
|
|
|
QString insertData;
|
|
|
|
};
|
|
|
|
bool shouldOverwriteLibs = false;
|
|
|
|
QList<Library> overwriteLibs;
|
|
|
|
QList<Library> addLibs;
|
|
|
|
QList<QString> removeLibs;
|
|
|
|
|
|
|
|
static Library fromLibraryJson(const QJsonObject &libObj, const QString &filename,
|
|
|
|
bool &isError)
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
isError = true;
|
|
|
|
Library out;
|
|
|
|
if (!libObj.contains("name"))
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QLOG_ERROR() << filename << "contains a library that doesn't have a 'name' field";
|
|
|
|
return out;
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
out.name = libObj.value("name").toString();
|
2014-01-22 12:03:32 +05:30
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
auto readString = [libObj, filename](const QString &key, QString &variable)
|
|
|
|
{
|
|
|
|
if (libObj.contains(key))
|
|
|
|
{
|
|
|
|
QJsonValue val = libObj.value(key);
|
|
|
|
if (!val.isString())
|
|
|
|
{
|
|
|
|
QLOG_WARN() << key << "is not a string in" << filename << "(skipping)";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
variable = val.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-01-22 12:03:32 +05:30
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
readString("url", out.url);
|
|
|
|
readString("MMC-hint", out.hint);
|
|
|
|
readString("MMC-absulute_url", out.absoluteUrl);
|
|
|
|
readString("MMC-absoluteUrl", out.absoluteUrl);
|
|
|
|
if (libObj.contains("extract"))
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
if (!libObj.value("extract").isObject())
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QLOG_ERROR()
|
|
|
|
<< filename
|
|
|
|
<< "contains a library with an 'extract' field that's not an object";
|
|
|
|
return out;
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
QJsonObject extractObj = libObj.value("extract").toObject();
|
|
|
|
if (!extractObj.contains("exclude") || !extractObj.value("exclude").isArray())
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QLOG_ERROR() << filename
|
|
|
|
<< "contains a library with an invalid 'extract' field";
|
|
|
|
return out;
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
out.applyExcludes = true;
|
|
|
|
QJsonArray excludeArray = extractObj.value("exclude").toArray();
|
|
|
|
for (auto excludeVal : excludeArray)
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
if (!excludeVal.isString())
|
|
|
|
{
|
|
|
|
QLOG_WARN() << filename << "contains a library that contains an 'extract' "
|
|
|
|
"field that contains an invalid 'exclude' entry "
|
|
|
|
"(skipping)";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.excludes.append(excludeVal.toString());
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
if (libObj.contains("natives"))
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
if (!libObj.value("natives").isObject())
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QLOG_ERROR()
|
|
|
|
<< filename
|
|
|
|
<< "contains a library with a 'natives' field that's not an object";
|
|
|
|
return out;
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
out.applyNatives = true;
|
|
|
|
QJsonObject nativesObj = libObj.value("natives").toObject();
|
|
|
|
for (auto it = nativesObj.begin(); it != nativesObj.end(); ++it)
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
if (!it.value().isString())
|
|
|
|
{
|
|
|
|
QLOG_WARN() << filename << "contains an invalid native (skipping)";
|
|
|
|
}
|
|
|
|
OpSys opSys = OpSys_fromString(it.key());
|
|
|
|
if (opSys != Os_Other)
|
|
|
|
{
|
|
|
|
out.natives.append(qMakePair(opSys, it.value().toString()));
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
if (libObj.contains("rules"))
|
|
|
|
{
|
|
|
|
out.applyRules = true;
|
|
|
|
out.rules = rulesFromJsonV4(libObj);
|
|
|
|
}
|
|
|
|
isError = false;
|
|
|
|
return out;
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
static VersionFile fromJson(const QJsonDocument &doc, const QString &filename,
|
|
|
|
const bool requireOrder, bool &isError)
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
VersionFile out;
|
|
|
|
isError = true;
|
|
|
|
if (doc.isEmpty() || doc.isNull())
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QLOG_ERROR() << filename << "is empty or null";
|
|
|
|
return out;
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
if (!doc.isObject())
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QLOG_ERROR() << "The root of" << filename << "is not an object";
|
|
|
|
return out;
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
|
|
|
|
QJsonObject root = doc.object();
|
|
|
|
|
|
|
|
if (requireOrder)
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
if (root.contains("order"))
|
|
|
|
{
|
|
|
|
if (root.value("order").isDouble())
|
|
|
|
{
|
|
|
|
out.order = root.value("order").toDouble();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << "'order' field contains an invalid value in" << filename;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "doesn't contain an order field";
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
|
2014-02-01 19:22:21 +05:30
|
|
|
out.name = root.value("name").toString();
|
2014-02-01 20:56:38 +05:30
|
|
|
out.fileId = root.value("fileId").toString();
|
2014-02-01 19:22:21 +05:30
|
|
|
out.version = root.value("version").toString();
|
|
|
|
out.mcVersion = root.value("mcVersion").toString();
|
|
|
|
out.filename = filename;
|
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
auto readString = [root, filename](const QString &key, QString &variable)
|
|
|
|
{
|
|
|
|
if (root.contains(key))
|
|
|
|
{
|
|
|
|
QJsonValue val = root.value(key);
|
|
|
|
if (!val.isString())
|
|
|
|
{
|
|
|
|
QLOG_WARN() << key << "is not a string in" << filename << "(skipping)";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
variable = val.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
readString("id", out.id);
|
|
|
|
readString("mainClass", out.mainClass);
|
|
|
|
readString("processArguments", out.processArguments);
|
|
|
|
readString("minecraftArguments", out.overwriteMinecraftArguments);
|
|
|
|
readString("+minecraftArguments", out.addMinecraftArguments);
|
|
|
|
readString("-minecraftArguments", out.removeMinecraftArguments);
|
|
|
|
readString("type", out.type);
|
|
|
|
readString("releaseTime", out.releaseTime);
|
|
|
|
readString("time", out.time);
|
|
|
|
readString("assets", out.assets);
|
|
|
|
if (root.contains("minimumLauncherVersion"))
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QJsonValue val = root.value("minimumLauncherVersion");
|
|
|
|
if (!val.isDouble())
|
|
|
|
{
|
|
|
|
QLOG_WARN() << "minimumLauncherVersion is not an int in" << filename
|
|
|
|
<< "(skipping)";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.minimumLauncherVersion = val.toDouble();
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
|
|
|
|
if (root.contains("tweakers"))
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QJsonValue tweakersVal = root.value("tweakers");
|
|
|
|
if (!tweakersVal.isArray())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a 'tweakers' field, but it's not an array";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
out.shouldOverwriteTweakers = true;
|
|
|
|
QJsonArray tweakers = root.value("tweakers").toArray();
|
|
|
|
for (auto tweakerVal : tweakers)
|
|
|
|
{
|
|
|
|
if (!tweakerVal.isString())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a 'tweakers' field entry that's not a string";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
out.overwriteTweakers.append(tweakerVal.toString());
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
if (root.contains("+tweakers"))
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QJsonValue tweakersVal = root.value("+tweakers");
|
|
|
|
if (!tweakersVal.isArray())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a '+tweakers' field, but it's not an array";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
QJsonArray tweakers = root.value("+tweakers").toArray();
|
|
|
|
for (auto tweakerVal : tweakers)
|
|
|
|
{
|
|
|
|
if (!tweakerVal.isString())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a '+tweakers' field entry that's not a string";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
out.addTweakers.append(tweakerVal.toString());
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
if (root.contains("-tweakers"))
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QJsonValue tweakersVal = root.value("-tweakers");
|
|
|
|
if (!tweakersVal.isArray())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a '-tweakers' field, but it's not an array";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
out.shouldOverwriteTweakers = true;
|
|
|
|
QJsonArray tweakers = root.value("-tweakers").toArray();
|
|
|
|
for (auto tweakerVal : tweakers)
|
|
|
|
{
|
|
|
|
if (!tweakerVal.isString())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a '-tweakers' field entry that's not a string";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
out.removeTweakers.append(tweakerVal.toString());
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
if (root.contains("libraries"))
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
out.shouldOverwriteLibs = true;
|
|
|
|
QJsonValue librariesVal = root.value("libraries");
|
|
|
|
if (!librariesVal.isArray())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename
|
|
|
|
<< "contains a 'libraries' field, but its not an array";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
QJsonArray librariesArray = librariesVal.toArray();
|
|
|
|
for (auto libVal : librariesArray)
|
|
|
|
{
|
|
|
|
if (!libVal.isObject())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a library that's not an object";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
QJsonObject libObj = libVal.toObject();
|
|
|
|
bool error;
|
|
|
|
Library lib = fromLibraryJson(libObj, filename, error);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << "Error while reading a library entry in" << filename;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
out.overwriteLibs.append(lib);
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
if (root.contains("+libraries"))
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QJsonValue librariesVal = root.value("+libraries");
|
|
|
|
if (!librariesVal.isArray())
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QLOG_ERROR() << filename
|
|
|
|
<< "contains a '+libraries' field, but its not an array";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
QJsonArray librariesArray = librariesVal.toArray();
|
|
|
|
for (auto libVal : librariesArray)
|
|
|
|
{
|
|
|
|
if (!libVal.isObject())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a library that's not an object";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
QJsonObject libObj = libVal.toObject();
|
|
|
|
bool error;
|
|
|
|
Library lib = fromLibraryJson(libObj, filename, error);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << "Error while reading a library entry in" << filename;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
if (!libObj.contains("insert"))
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QLOG_ERROR() << "Missing 'insert' field in '+libraries' field in"
|
|
|
|
<< filename;
|
|
|
|
return out;
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
QJsonValue insertVal = libObj.value("insert");
|
|
|
|
QString insertString;
|
|
|
|
{
|
|
|
|
if (insertVal.isString())
|
|
|
|
{
|
|
|
|
insertString = insertVal.toString();
|
|
|
|
}
|
|
|
|
else if (insertVal.isObject())
|
|
|
|
{
|
|
|
|
QJsonObject insertObj = insertVal.toObject();
|
|
|
|
if (insertObj.isEmpty())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << "One library has an empty insert object in"
|
|
|
|
<< filename;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
insertString = insertObj.keys().first();
|
|
|
|
lib.insertData = insertObj.value(insertString).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (insertString == "apply")
|
|
|
|
{
|
|
|
|
lib.insertType = Library::Apply;
|
|
|
|
}
|
|
|
|
else if (insertString == "append")
|
|
|
|
{
|
|
|
|
lib.insertType = Library::Append;
|
|
|
|
}
|
|
|
|
else if (insertString == "prepend")
|
|
|
|
{
|
|
|
|
lib.insertType = Library::Prepend;
|
|
|
|
}
|
2014-01-28 02:53:07 +05:30
|
|
|
else if (insertString == "prepend-if-not-exists")
|
2014-01-27 23:50:07 +05:30
|
|
|
{
|
2014-01-28 02:53:07 +05:30
|
|
|
lib.insertType = Library::PrependIfNotExists;
|
2014-01-27 23:50:07 +05:30
|
|
|
}
|
2014-01-28 02:53:07 +05:30
|
|
|
else if (insertString == "append-if-not-exists")
|
2014-01-27 23:50:07 +05:30
|
|
|
{
|
2014-01-28 02:53:07 +05:30
|
|
|
lib.insertType = Library::PrependIfNotExists;
|
2014-01-27 23:50:07 +05:30
|
|
|
}
|
|
|
|
else if (insertString == "replace")
|
|
|
|
{
|
|
|
|
lib.insertType = Library::Replace;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << "A '+' library in" << filename
|
|
|
|
<< "contains an invalid insert type";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
out.addLibs.append(lib);
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
if (root.contains("-libraries"))
|
|
|
|
{
|
|
|
|
QJsonValue librariesVal = root.value("-libraries");
|
|
|
|
if (!librariesVal.isArray())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename
|
|
|
|
<< "contains a '-libraries' field, but its not an array";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
QJsonArray librariesArray = librariesVal.toArray();
|
|
|
|
for (auto libVal : librariesArray)
|
|
|
|
{
|
|
|
|
if (!libVal.isObject())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a library that's not an object";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
QJsonObject libObj = libVal.toObject();
|
|
|
|
if (!libObj.contains("name"))
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename << "contains a library without a name";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
if (!libObj.value("name").isString())
|
|
|
|
{
|
|
|
|
QLOG_ERROR() << filename
|
|
|
|
<< "contains a library without a valid 'name' field";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
out.removeLibs.append(libObj.value("name").toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isError = false;
|
|
|
|
return out;
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
static std::shared_ptr<OneSixLibrary> createLibrary(const Library &lib)
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
std::shared_ptr<OneSixLibrary> out(new OneSixLibrary(lib.name));
|
2014-02-02 00:12:47 +05:30
|
|
|
if (!lib.url.isEmpty())
|
|
|
|
{
|
|
|
|
out->setBaseUrl(lib.url);
|
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
out->setHint(lib.hint);
|
2014-02-02 00:12:47 +05:30
|
|
|
if (!lib.absoluteUrl.isEmpty())
|
|
|
|
{
|
|
|
|
out->setAbsoluteUrl(lib.absoluteUrl);
|
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
out->setAbsoluteUrl(lib.absoluteUrl);
|
|
|
|
out->extract_excludes = lib.excludes;
|
|
|
|
for (auto native : lib.natives)
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
out->addNative(native.first, native.second);
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
out->setRules(lib.rules);
|
|
|
|
out->finalize();
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
int findLibrary(QList<std::shared_ptr<OneSixLibrary>> haystack, const QString &needle)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < haystack.size(); ++i)
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
if (QRegExp(needle, Qt::CaseSensitive, QRegExp::WildcardUnix)
|
|
|
|
.indexIn(haystack.at(i)->rawName()) != -1)
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
return i;
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
return -1;
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
void applyTo(OneSixVersion *version, bool &isError)
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
isError = true;
|
|
|
|
if (!id.isNull())
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
version->id = id;
|
|
|
|
}
|
|
|
|
if (!mainClass.isNull())
|
|
|
|
{
|
|
|
|
version->mainClass = mainClass;
|
|
|
|
}
|
|
|
|
if (!processArguments.isNull())
|
|
|
|
{
|
|
|
|
version->processArguments = processArguments;
|
|
|
|
}
|
|
|
|
if (!type.isNull())
|
|
|
|
{
|
|
|
|
version->type = type;
|
|
|
|
}
|
|
|
|
if (!releaseTime.isNull())
|
|
|
|
{
|
|
|
|
version->releaseTime = releaseTime;
|
|
|
|
}
|
|
|
|
if (!time.isNull())
|
|
|
|
{
|
|
|
|
version->time = time;
|
|
|
|
}
|
|
|
|
if (!assets.isNull())
|
|
|
|
{
|
|
|
|
version->assets = assets;
|
|
|
|
}
|
|
|
|
if (minimumLauncherVersion >= 0)
|
|
|
|
{
|
|
|
|
version->minimumLauncherVersion = minimumLauncherVersion;
|
|
|
|
}
|
|
|
|
if (!overwriteMinecraftArguments.isNull())
|
|
|
|
{
|
|
|
|
version->minecraftArguments = overwriteMinecraftArguments;
|
|
|
|
}
|
|
|
|
if (!addMinecraftArguments.isNull())
|
|
|
|
{
|
|
|
|
version->minecraftArguments += addMinecraftArguments;
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
if (!removeMinecraftArguments.isNull())
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
version->minecraftArguments.remove(removeMinecraftArguments);
|
|
|
|
}
|
|
|
|
if (shouldOverwriteTweakers)
|
|
|
|
{
|
|
|
|
version->tweakers = overwriteTweakers;
|
|
|
|
}
|
|
|
|
for (auto tweaker : addTweakers)
|
|
|
|
{
|
|
|
|
version->tweakers += tweaker;
|
|
|
|
}
|
|
|
|
for (auto tweaker : removeTweakers)
|
|
|
|
{
|
|
|
|
version->tweakers.removeAll(tweaker);
|
|
|
|
}
|
|
|
|
if (shouldOverwriteLibs)
|
|
|
|
{
|
|
|
|
version->libraries.clear();
|
|
|
|
for (auto lib : overwriteLibs)
|
|
|
|
{
|
|
|
|
version->libraries.append(createLibrary(lib));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto lib : addLibs)
|
|
|
|
{
|
|
|
|
switch (lib.insertType)
|
|
|
|
{
|
|
|
|
case Library::Apply:
|
|
|
|
{
|
|
|
|
|
|
|
|
int index = findLibrary(version->libraries, lib.name);
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
auto library = version->libraries[index];
|
|
|
|
if (!lib.url.isNull())
|
|
|
|
{
|
|
|
|
library->setBaseUrl(lib.url);
|
|
|
|
}
|
|
|
|
if (!lib.hint.isNull())
|
|
|
|
{
|
|
|
|
library->setHint(lib.hint);
|
|
|
|
}
|
|
|
|
if (!lib.absoluteUrl.isNull())
|
|
|
|
{
|
|
|
|
library->setAbsoluteUrl(lib.absoluteUrl);
|
|
|
|
}
|
|
|
|
if (lib.applyExcludes)
|
|
|
|
{
|
|
|
|
library->extract_excludes = lib.excludes;
|
|
|
|
}
|
|
|
|
if (lib.applyNatives)
|
|
|
|
{
|
|
|
|
library->clearSuffixes();
|
|
|
|
for (auto native : lib.natives)
|
|
|
|
{
|
|
|
|
library->addNative(native.first, native.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lib.applyRules)
|
|
|
|
{
|
|
|
|
library->setRules(lib.rules);
|
|
|
|
}
|
|
|
|
library->finalize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QLOG_WARN() << "Couldn't find" << lib.insertData << "(skipping)";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Library::Append:
|
|
|
|
version->libraries.append(createLibrary(lib));
|
|
|
|
break;
|
|
|
|
case Library::Prepend:
|
|
|
|
version->libraries.prepend(createLibrary(lib));
|
|
|
|
break;
|
2014-01-28 02:53:07 +05:30
|
|
|
case Library::AppendIfNotExists:
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
|
2014-01-28 02:53:07 +05:30
|
|
|
int index = findLibrary(version->libraries, lib.name);
|
|
|
|
if (index < 0)
|
2014-01-27 23:50:07 +05:30
|
|
|
{
|
2014-01-28 02:53:07 +05:30
|
|
|
version->libraries.append(createLibrary(lib));
|
2014-01-27 23:50:07 +05:30
|
|
|
}
|
|
|
|
break;
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-28 02:53:07 +05:30
|
|
|
case Library::PrependIfNotExists:
|
2014-01-27 23:50:07 +05:30
|
|
|
{
|
2014-01-22 12:03:32 +05:30
|
|
|
|
2014-01-28 02:53:07 +05:30
|
|
|
int index = findLibrary(version->libraries, lib.name);
|
|
|
|
if (index < 0)
|
2014-01-27 23:50:07 +05:30
|
|
|
{
|
2014-01-28 02:53:07 +05:30
|
|
|
version->libraries.prepend(createLibrary(lib));
|
2014-01-27 23:50:07 +05:30
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Library::Replace:
|
|
|
|
{
|
|
|
|
int index = findLibrary(version->libraries, lib.insertData);
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
version->libraries.replace(index, createLibrary(lib));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QLOG_WARN() << "Couldn't find" << lib.insertData << "(skipping)";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto lib : removeLibs)
|
|
|
|
{
|
|
|
|
int index = findLibrary(version->libraries, lib);
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
version->libraries.removeAt(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QLOG_WARN() << "Couldn't find" << lib << "(skipping)";
|
|
|
|
}
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
|
2014-02-01 19:22:21 +05:30
|
|
|
OneSixVersion::VersionFile versionFile;
|
|
|
|
versionFile.name = name;
|
|
|
|
versionFile.id = fileId;
|
|
|
|
versionFile.version = this->version;
|
|
|
|
versionFile.mcVersion = mcVersion;
|
|
|
|
versionFile.filename = filename;
|
|
|
|
version->versionFiles.append(versionFile);
|
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
isError = false;
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
};
|
2014-01-23 02:45:50 +05:30
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
OneSixVersionBuilder::OneSixVersionBuilder()
|
|
|
|
{
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
bool OneSixVersionBuilder::build(OneSixVersion *version, OneSixInstance *instance,
|
|
|
|
QWidget *widgetParent, const bool excludeCustom)
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
OneSixVersionBuilder builder;
|
|
|
|
builder.m_version = version;
|
|
|
|
builder.m_instance = instance;
|
|
|
|
builder.m_widgetParent = widgetParent;
|
|
|
|
return builder.build(excludeCustom);
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
bool OneSixVersionBuilder::read(OneSixVersion *version, const QJsonObject &obj)
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
OneSixVersionBuilder builder;
|
|
|
|
builder.m_version = version;
|
|
|
|
builder.m_instance = 0;
|
|
|
|
builder.m_widgetParent = 0;
|
|
|
|
return builder.read(obj);
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
bool OneSixVersionBuilder::build(const bool excludeCustom)
|
|
|
|
{
|
|
|
|
m_version->clear();
|
|
|
|
|
|
|
|
QDir root(m_instance->instanceRoot());
|
|
|
|
QDir patches(root.absoluteFilePath("patches/"));
|
|
|
|
|
2014-01-28 12:09:43 +05:30
|
|
|
if (QFile::exists(root.absoluteFilePath("custom.json")))
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-28 12:09:43 +05:30
|
|
|
QLOG_INFO() << "Reading custom.json";
|
2014-01-27 23:50:07 +05:30
|
|
|
VersionFile file;
|
2014-01-28 12:09:43 +05:30
|
|
|
if (!read(QFileInfo(root.absoluteFilePath("custom.json")), false, &file))
|
2014-01-27 23:50:07 +05:30
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-02 00:12:47 +05:30
|
|
|
file.name = "custom.json";
|
|
|
|
file.filename = "custom.json";
|
|
|
|
file.fileId = "org.multimc.custom.json";
|
|
|
|
file.version = QString();
|
2014-01-27 23:50:07 +05:30
|
|
|
bool isError = false;
|
|
|
|
file.applyTo(m_version, isError);
|
|
|
|
if (isError)
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QMessageBox::critical(
|
|
|
|
m_widgetParent, QObject::tr("Error"),
|
|
|
|
QObject::tr(
|
|
|
|
"Error while applying %1. Please check MultiMC-0.log for more info.")
|
2014-01-28 12:09:43 +05:30
|
|
|
.arg(root.absoluteFilePath("custom.json")));
|
2014-01-27 23:50:07 +05:30
|
|
|
return false;
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
|
|
|
}
|
2014-01-28 12:09:43 +05:30
|
|
|
else
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-28 12:09:43 +05:30
|
|
|
// version.json -> patches/*.json -> instance.json
|
2014-01-23 02:45:50 +05:30
|
|
|
|
2014-01-28 12:09:43 +05:30
|
|
|
// version.json
|
2014-01-24 02:01:41 +05:30
|
|
|
{
|
2014-01-28 12:09:43 +05:30
|
|
|
QLOG_INFO() << "Reading version.json";
|
2014-01-27 23:50:07 +05:30
|
|
|
VersionFile file;
|
2014-01-28 12:09:43 +05:30
|
|
|
if (!read(QFileInfo(root.absoluteFilePath("version.json")), false, &file))
|
2014-01-24 02:01:41 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
return false;
|
2014-01-24 02:01:41 +05:30
|
|
|
}
|
2014-02-01 19:22:21 +05:30
|
|
|
file.name = "version.json";
|
|
|
|
file.fileId = "org.multimc.version.json";
|
|
|
|
file.version = m_instance->intendedVersionId();
|
|
|
|
file.mcVersion = m_instance->intendedVersionId();
|
2014-01-27 23:50:07 +05:30
|
|
|
bool isError = false;
|
2014-01-28 12:09:43 +05:30
|
|
|
file.applyTo(m_version, isError);
|
2014-01-27 23:50:07 +05:30
|
|
|
if (isError)
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QMessageBox::critical(
|
2014-01-28 12:09:43 +05:30
|
|
|
m_widgetParent, QObject::tr("Error"),
|
|
|
|
QObject::tr(
|
|
|
|
"Error while applying %1. Please check MultiMC-0.log for more info.")
|
|
|
|
.arg(root.absoluteFilePath("version.json")));
|
2014-01-27 23:50:07 +05:30
|
|
|
return false;
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
|
2014-01-28 12:09:43 +05:30
|
|
|
// patches/
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-28 12:09:43 +05:30
|
|
|
// load all, put into map for ordering, apply in the right order
|
|
|
|
|
|
|
|
QMap<int, QPair<QString, VersionFile>> files;
|
|
|
|
for (auto info : patches.entryInfoList(QStringList() << "*.json", QDir::Files))
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
2014-01-28 12:09:43 +05:30
|
|
|
QLOG_INFO() << "Reading" << info.fileName();
|
|
|
|
VersionFile file;
|
|
|
|
if (!read(info, true, &file))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
files.insert(file.order, qMakePair(info.fileName(), file));
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-28 12:09:43 +05:30
|
|
|
for (auto order : files.keys())
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-28 12:09:43 +05:30
|
|
|
QLOG_DEBUG() << "Applying file with order" << order;
|
|
|
|
auto filePair = files[order];
|
|
|
|
bool isError = false;
|
|
|
|
filePair.second.applyTo(m_version, isError);
|
|
|
|
if (isError)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(
|
|
|
|
m_widgetParent, QObject::tr("Error"),
|
|
|
|
QObject::tr(
|
|
|
|
"Error while applying %1. Please check MultiMC-0.log for more info.")
|
|
|
|
.arg(filePair.first));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-01 19:22:21 +05:30
|
|
|
// user.json
|
2014-01-28 12:09:43 +05:30
|
|
|
if (!excludeCustom)
|
|
|
|
{
|
2014-02-01 19:22:21 +05:30
|
|
|
if (QFile::exists(root.absoluteFilePath("user.json")))
|
2014-01-28 12:09:43 +05:30
|
|
|
{
|
2014-02-01 19:22:21 +05:30
|
|
|
QLOG_INFO() << "Reading user.json";
|
2014-01-28 12:09:43 +05:30
|
|
|
VersionFile file;
|
2014-02-01 19:22:21 +05:30
|
|
|
if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file))
|
2014-01-28 12:09:43 +05:30
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-01 19:22:21 +05:30
|
|
|
file.name = "user.json";
|
|
|
|
file.fileId = "org.multimc.user.json";
|
|
|
|
file.version = QString();
|
|
|
|
file.mcVersion = QString();
|
2014-01-28 12:09:43 +05:30
|
|
|
bool isError = false;
|
|
|
|
file.applyTo(m_version, isError);
|
|
|
|
if (isError)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(
|
|
|
|
m_widgetParent, QObject::tr("Error"),
|
|
|
|
QObject::tr(
|
|
|
|
"Error while applying %1. Please check MultiMC-0.log for more info.")
|
2014-02-01 19:22:21 +05:30
|
|
|
.arg(root.absoluteFilePath("user.json")));
|
2014-01-28 12:09:43 +05:30
|
|
|
return false;
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
// some final touches
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
if (m_version->assets.isEmpty())
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
m_version->assets = "legacy";
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
if (m_version->minecraftArguments.isEmpty())
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QString toCompare = m_version->processArguments.toLower();
|
|
|
|
if (toCompare == "legacy")
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
m_version->minecraftArguments = " ${auth_player_name} ${auth_session}";
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
else if (toCompare == "username_session")
|
2014-01-23 02:45:50 +05:30
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
m_version->minecraftArguments =
|
|
|
|
"--username ${auth_player_name} --session ${auth_session}";
|
|
|
|
}
|
|
|
|
else if (toCompare == "username_session_version")
|
|
|
|
{
|
|
|
|
m_version->minecraftArguments = "--username ${auth_player_name} "
|
|
|
|
"--session ${auth_session} "
|
|
|
|
"--version ${profile_name}";
|
2014-01-23 02:45:50 +05:30
|
|
|
}
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OneSixVersionBuilder::read(const QJsonObject &obj)
|
|
|
|
{
|
|
|
|
m_version->clear();
|
|
|
|
|
|
|
|
bool isError = false;
|
|
|
|
VersionFile file = VersionFile::fromJson(QJsonDocument(obj), QString(), false, isError);
|
|
|
|
if (isError)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(
|
|
|
|
m_widgetParent, QObject::tr("Error"),
|
|
|
|
QObject::tr("Error while reading. Please check MultiMC-0.log for more info."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
file.applyTo(m_version, isError);
|
|
|
|
if (isError)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(
|
|
|
|
m_widgetParent, QObject::tr("Error"),
|
|
|
|
QObject::tr("Error while applying. Please check MultiMC-0.log for more info."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-22 12:03:32 +05:30
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-27 23:50:07 +05:30
|
|
|
bool OneSixVersionBuilder::read(const QFileInfo &fileInfo, const bool requireOrder,
|
|
|
|
VersionFile *out)
|
2014-01-22 12:03:32 +05:30
|
|
|
{
|
|
|
|
QFile file(fileInfo.absoluteFilePath());
|
|
|
|
if (!file.open(QFile::ReadOnly))
|
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QMessageBox::critical(
|
|
|
|
m_widgetParent, QObject::tr("Error"),
|
|
|
|
QObject::tr("Unable to open %1: %2").arg(file.fileName(), file.errorString()));
|
2014-01-22 12:03:32 +05:30
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QJsonParseError error;
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error);
|
|
|
|
if (error.error != QJsonParseError::NoError)
|
|
|
|
{
|
2014-01-27 23:50:07 +05:30
|
|
|
QMessageBox::critical(m_widgetParent, QObject::tr("Error"),
|
|
|
|
QObject::tr("Unable to parse %1: %2 at %3")
|
|
|
|
.arg(file.fileName(), error.errorString())
|
|
|
|
.arg(error.offset));
|
2014-01-22 12:03:32 +05:30
|
|
|
return false;
|
|
|
|
}
|
2014-01-27 23:50:07 +05:30
|
|
|
bool isError = false;
|
|
|
|
*out = VersionFile::fromJson(doc, file.fileName(), requireOrder, isError);
|
|
|
|
if (isError)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(
|
|
|
|
m_widgetParent, QObject::tr("Error"),
|
|
|
|
QObject::tr("Error while reading %1. Please check MultiMC-0.log for more info.")
|
|
|
|
.arg(file.fileName()));
|
|
|
|
;
|
|
|
|
}
|
2014-01-22 12:03:32 +05:30
|
|
|
return true;
|
|
|
|
}
|