2013-07-29 04:29:35 +05:30
|
|
|
#include "VersionFactory.h"
|
|
|
|
#include "OneSixVersion.h"
|
2013-07-27 15:11:45 +05:30
|
|
|
|
|
|
|
// Library rules (if any)
|
|
|
|
QList<QSharedPointer<Rule> > FullVersionFactory::parse4rules(QJsonObject & baseObj)
|
|
|
|
{
|
|
|
|
QList<QSharedPointer<Rule> > rules;
|
|
|
|
auto rulesVal = baseObj.value("rules");
|
|
|
|
if(rulesVal.isArray())
|
|
|
|
{
|
|
|
|
QJsonArray ruleList = rulesVal.toArray();
|
|
|
|
for(auto ruleVal : ruleList)
|
|
|
|
{
|
|
|
|
QSharedPointer<Rule> rule;
|
|
|
|
if(!ruleVal.isObject())
|
|
|
|
continue;
|
|
|
|
auto ruleObj = ruleVal.toObject();
|
|
|
|
auto actionVal = ruleObj.value("action");
|
|
|
|
if(!actionVal.isString())
|
|
|
|
continue;
|
|
|
|
auto action = RuleAction_fromString(actionVal.toString());
|
|
|
|
if(action == Defer)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto osVal = ruleObj.value("os");
|
|
|
|
if(!osVal.isObject())
|
|
|
|
{
|
|
|
|
// add a new implicit action rule
|
|
|
|
rules.append(ImplicitRule::create(action));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto osObj = osVal.toObject();
|
|
|
|
auto osNameVal = osObj.value("name");
|
|
|
|
if(!osNameVal.isString())
|
|
|
|
continue;
|
|
|
|
OpSys requiredOs = OpSys_fromString(osNameVal.toString());
|
|
|
|
QString versionRegex = osObj.value("version").toString();
|
|
|
|
// add a new OS rule
|
|
|
|
rules.append(OsRule::create(action, requiredOs, versionRegex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rules;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-28 08:08:29 +05:30
|
|
|
QSharedPointer<OneSixVersion> FullVersionFactory::parse4(QJsonObject root, QSharedPointer<OneSixVersion> fullVersion)
|
2013-07-22 05:31:56 +05:30
|
|
|
{
|
2013-07-25 03:14:00 +05:30
|
|
|
fullVersion->id = root.value("id").toString();
|
2013-07-22 05:31:56 +05:30
|
|
|
|
2013-07-25 03:14:00 +05:30
|
|
|
fullVersion->mainClass = root.value("mainClass").toString();
|
2013-07-22 05:31:56 +05:30
|
|
|
auto procArgsValue = root.value("processArguments");
|
|
|
|
if(procArgsValue.isString())
|
|
|
|
{
|
2013-07-25 03:14:00 +05:30
|
|
|
fullVersion->processArguments = procArgsValue.toString();
|
|
|
|
QString toCompare = fullVersion->processArguments.toLower();
|
2013-07-22 05:31:56 +05:30
|
|
|
if(toCompare == "legacy")
|
|
|
|
{
|
2013-07-25 03:14:00 +05:30
|
|
|
fullVersion->minecraftArguments = " ${auth_player_name} ${auth_session}";
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
|
|
|
else if(toCompare == "username_session")
|
|
|
|
{
|
2013-07-25 03:14:00 +05:30
|
|
|
fullVersion->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}";
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
|
|
|
else if(toCompare == "username_session_version")
|
|
|
|
{
|
2013-07-25 03:14:00 +05:30
|
|
|
fullVersion->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}";
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto minecraftArgsValue = root.value("minecraftArguments");
|
|
|
|
if(minecraftArgsValue.isString())
|
|
|
|
{
|
2013-07-25 03:14:00 +05:30
|
|
|
fullVersion->minecraftArguments = minecraftArgsValue.toString();
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
|
|
|
|
2013-08-07 05:08:18 +05:30
|
|
|
auto minecraftTypeValue = root.value("type");
|
|
|
|
if(minecraftTypeValue.isString())
|
|
|
|
{
|
2013-08-11 22:28:24 +05:30
|
|
|
fullVersion->type = minecraftTypeValue.toString();
|
2013-08-07 05:08:18 +05:30
|
|
|
}
|
|
|
|
|
2013-07-25 03:14:00 +05:30
|
|
|
fullVersion->releaseTime = root.value("releaseTime").toString();
|
|
|
|
fullVersion->time = root.value("time").toString();
|
2013-07-22 05:31:56 +05:30
|
|
|
|
2013-07-25 03:14:00 +05:30
|
|
|
// Iterate through the list, if it's a list.
|
2013-07-22 05:31:56 +05:30
|
|
|
auto librariesValue = root.value("libraries");
|
2013-07-25 03:14:00 +05:30
|
|
|
if(!librariesValue.isArray())
|
|
|
|
return fullVersion;
|
|
|
|
|
|
|
|
QJsonArray libList = root.value("libraries").toArray();
|
|
|
|
for (auto libVal : libList)
|
2013-07-22 05:31:56 +05:30
|
|
|
{
|
2013-07-25 03:14:00 +05:30
|
|
|
if (!libVal.isObject())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject libObj = libVal.toObject();
|
|
|
|
|
|
|
|
// Library name
|
|
|
|
auto nameVal = libObj.value("name");
|
|
|
|
if(!nameVal.isString())
|
|
|
|
continue;
|
2013-07-27 15:11:45 +05:30
|
|
|
QSharedPointer<Library> library(new Library(nameVal.toString()));
|
2013-07-25 03:14:00 +05:30
|
|
|
|
2013-08-05 07:40:53 +05:30
|
|
|
auto urlVal = libObj.value("url");
|
|
|
|
if(urlVal.isString())
|
|
|
|
{
|
2013-08-11 22:28:24 +05:30
|
|
|
library->setBaseUrl(urlVal.toString());
|
2013-08-05 07:40:53 +05:30
|
|
|
}
|
|
|
|
|
2013-07-25 03:14:00 +05:30
|
|
|
// Extract excludes (if any)
|
|
|
|
auto extractVal = libObj.value("extract");
|
|
|
|
if(extractVal.isObject())
|
2013-07-22 05:31:56 +05:30
|
|
|
{
|
2013-07-25 03:14:00 +05:30
|
|
|
QStringList excludes;
|
|
|
|
auto extractObj = extractVal.toObject();
|
|
|
|
auto excludesVal = extractObj.value("exclude");
|
|
|
|
if(!excludesVal.isArray())
|
|
|
|
goto SKIP_EXTRACTS;
|
|
|
|
auto excludesList = excludesVal.toArray();
|
|
|
|
for(auto excludeVal : excludesList)
|
2013-07-22 05:31:56 +05:30
|
|
|
{
|
2013-07-25 03:14:00 +05:30
|
|
|
if(excludeVal.isString())
|
|
|
|
excludes.append(excludeVal.toString());
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
2013-07-25 03:14:00 +05:30
|
|
|
library->extract_excludes = excludes;
|
|
|
|
}
|
|
|
|
SKIP_EXTRACTS:
|
|
|
|
|
|
|
|
auto nativesVal = libObj.value("natives");
|
|
|
|
if(nativesVal.isObject())
|
|
|
|
{
|
2013-07-27 15:11:45 +05:30
|
|
|
library->setIsNative();
|
2013-07-25 03:14:00 +05:30
|
|
|
auto nativesObj = nativesVal.toObject();
|
|
|
|
auto iter = nativesObj.begin();
|
|
|
|
while(iter != nativesObj.end())
|
|
|
|
{
|
|
|
|
auto osType = OpSys_fromString(iter.key());
|
|
|
|
if(osType == Os_Other)
|
|
|
|
continue;
|
|
|
|
if(!iter.value().isString())
|
|
|
|
continue;
|
2013-07-27 15:11:45 +05:30
|
|
|
library->addNative(osType, iter.value().toString());
|
2013-07-25 03:14:00 +05:30
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
2013-07-27 15:11:45 +05:30
|
|
|
library->setRules(parse4rules(libObj));
|
|
|
|
library->finalize();
|
|
|
|
fullVersion->libraries.append(library);
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
2013-07-25 03:14:00 +05:30
|
|
|
return fullVersion;
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
|
|
|
|
2013-08-28 08:08:29 +05:30
|
|
|
QSharedPointer<OneSixVersion> FullVersionFactory::parse(QByteArray data)
|
2013-07-22 05:31:56 +05:30
|
|
|
{
|
2013-08-28 08:08:29 +05:30
|
|
|
QSharedPointer<OneSixVersion> readVersion(new OneSixVersion());
|
2013-07-22 05:31:56 +05:30
|
|
|
|
|
|
|
QJsonParseError jsonError;
|
|
|
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
|
|
|
|
|
|
|
|
if (jsonError.error != QJsonParseError::NoError)
|
|
|
|
{
|
|
|
|
error_string = QString( "Error reading version file :") + " " + jsonError.errorString();
|
|
|
|
m_error = FullVersionFactory::ParseError;
|
2013-08-28 08:08:29 +05:30
|
|
|
return QSharedPointer<OneSixVersion>();
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if(!jsonDoc.isObject())
|
|
|
|
{
|
|
|
|
error_string = "Error reading version file.";
|
|
|
|
m_error = FullVersionFactory::ParseError;
|
2013-08-28 08:08:29 +05:30
|
|
|
return QSharedPointer<OneSixVersion>();
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
|
|
|
QJsonObject root = jsonDoc.object();
|
|
|
|
|
2013-08-07 05:08:18 +05:30
|
|
|
int launcher_ver = readVersion->minimumLauncherVersion = root.value("minimumLauncherVersion").toDouble();
|
|
|
|
// ADD MORE HERE :D
|
|
|
|
if(launcher_ver > 0 && launcher_ver <= 7)
|
|
|
|
return parse4(root, readVersion);
|
|
|
|
else
|
2013-07-22 05:31:56 +05:30
|
|
|
{
|
2013-08-07 05:08:18 +05:30
|
|
|
error_string = "Version file was for an unrecognized launcher version. RIP";
|
|
|
|
m_error = FullVersionFactory::UnsupportedVersion;
|
2013-08-28 08:08:29 +05:30
|
|
|
return QSharedPointer<OneSixVersion>();
|
2013-07-22 05:31:56 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FullVersionFactory::FullVersionFactory()
|
|
|
|
{
|
|
|
|
m_error = FullVersionFactory::AllOK;
|
|
|
|
}
|