2014-03-01 22:06:47 +00:00
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
2015-02-02 01:14:14 +00:00
|
|
|
#include <QDebug>
|
2014-05-08 20:20:10 +01:00
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "minecraft/VersionFile.h"
|
2016-03-07 01:01:28 +00:00
|
|
|
#include "minecraft/Library.h"
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "minecraft/MinecraftProfile.h"
|
|
|
|
#include "minecraft/JarMod.h"
|
2014-05-10 00:53:32 +01:00
|
|
|
#include "ParseUtils.h"
|
2014-03-01 22:06:47 +00:00
|
|
|
|
2014-05-10 00:53:32 +01:00
|
|
|
#include "VersionBuildError.h"
|
2015-10-05 00:47:27 +01:00
|
|
|
#include <Version.h>
|
2014-05-10 00:53:32 +01:00
|
|
|
|
2016-03-07 01:01:28 +00:00
|
|
|
int findLibraryByName(QList<LibraryPtr> haystack, const GradleSpecifier &needle)
|
2014-03-01 22:06:47 +00:00
|
|
|
{
|
2014-05-09 16:16:25 +01:00
|
|
|
int retval = -1;
|
|
|
|
for (int i = 0; i < haystack.size(); ++i)
|
2014-03-01 22:06:47 +00:00
|
|
|
{
|
2014-09-06 17:16:56 +01:00
|
|
|
if (haystack.at(i)->rawName().matchName(needle))
|
2014-03-01 22:06:47 +00:00
|
|
|
{
|
2014-05-09 16:16:25 +01:00
|
|
|
// only one is allowed.
|
2014-05-10 00:53:32 +01:00
|
|
|
if (retval != -1)
|
2014-05-09 16:16:25 +01:00
|
|
|
return -1;
|
|
|
|
retval = i;
|
2014-03-01 22:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-09 16:16:25 +01:00
|
|
|
return retval;
|
2014-03-01 22:06:47 +00:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:37:21 +01:00
|
|
|
bool VersionFile::isMinecraftVersion()
|
2014-04-23 01:27:40 +01:00
|
|
|
{
|
2015-01-27 21:31:07 +00:00
|
|
|
return fileId == "net.minecraft";
|
2014-04-23 01:27:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VersionFile::hasJarMods()
|
|
|
|
{
|
|
|
|
return !jarMods.isEmpty();
|
|
|
|
}
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
void VersionFile::applyTo(MinecraftProfile *version)
|
2014-03-01 22:06:47 +00:00
|
|
|
{
|
|
|
|
if (!version->id.isNull() && !mcVersion.isNull())
|
|
|
|
{
|
|
|
|
if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(version->id) ==
|
|
|
|
-1)
|
|
|
|
{
|
2014-03-09 22:42:25 +00:00
|
|
|
throw MinecraftVersionMismatch(fileId, mcVersion, version->id);
|
2014-03-01 22:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!id.isNull())
|
|
|
|
{
|
|
|
|
version->id = id;
|
|
|
|
}
|
|
|
|
if (!mainClass.isNull())
|
|
|
|
{
|
|
|
|
version->mainClass = mainClass;
|
|
|
|
}
|
2014-05-08 18:05:07 +01:00
|
|
|
if (!appletClass.isNull())
|
|
|
|
{
|
|
|
|
version->appletClass = appletClass;
|
|
|
|
}
|
2014-03-01 22:06:47 +00:00
|
|
|
if (!processArguments.isNull())
|
|
|
|
{
|
2014-05-11 11:37:21 +01:00
|
|
|
if (isMinecraftVersion())
|
2014-04-23 01:27:40 +01:00
|
|
|
{
|
|
|
|
version->vanillaProcessArguments = processArguments;
|
|
|
|
}
|
2014-03-01 22:06:47 +00:00
|
|
|
version->processArguments = processArguments;
|
|
|
|
}
|
2014-05-11 11:37:21 +01:00
|
|
|
if (isMinecraftVersion())
|
2014-03-01 22:06:47 +00:00
|
|
|
{
|
2014-05-10 00:53:32 +01:00
|
|
|
if (!type.isNull())
|
|
|
|
{
|
|
|
|
version->type = type;
|
|
|
|
}
|
2016-03-02 02:03:44 +00:00
|
|
|
if (!m_releaseTime.isNull())
|
2014-05-10 00:53:32 +01:00
|
|
|
{
|
|
|
|
version->m_releaseTime = m_releaseTime;
|
|
|
|
}
|
2016-03-02 02:03:44 +00:00
|
|
|
if (!m_updateTime.isNull())
|
2014-05-10 00:53:32 +01:00
|
|
|
{
|
|
|
|
version->m_updateTime = m_updateTime;
|
|
|
|
}
|
2014-03-01 22:06:47 +00:00
|
|
|
}
|
|
|
|
if (!assets.isNull())
|
|
|
|
{
|
|
|
|
version->assets = assets;
|
|
|
|
}
|
|
|
|
if (!overwriteMinecraftArguments.isNull())
|
|
|
|
{
|
2014-05-11 11:37:21 +01:00
|
|
|
if (isMinecraftVersion())
|
2014-04-23 01:27:40 +01:00
|
|
|
{
|
|
|
|
version->vanillaMinecraftArguments = overwriteMinecraftArguments;
|
|
|
|
}
|
2014-03-01 22:06:47 +00:00
|
|
|
version->minecraftArguments = overwriteMinecraftArguments;
|
|
|
|
}
|
|
|
|
if (!addMinecraftArguments.isNull())
|
|
|
|
{
|
|
|
|
version->minecraftArguments += addMinecraftArguments;
|
|
|
|
}
|
|
|
|
if (shouldOverwriteTweakers)
|
|
|
|
{
|
|
|
|
version->tweakers = overwriteTweakers;
|
|
|
|
}
|
|
|
|
for (auto tweaker : addTweakers)
|
|
|
|
{
|
|
|
|
version->tweakers += tweaker;
|
|
|
|
}
|
2014-04-23 01:27:40 +01:00
|
|
|
version->jarMods.append(jarMods);
|
2014-05-04 23:10:59 +01:00
|
|
|
version->traits.unite(traits);
|
2014-03-01 22:06:47 +00:00
|
|
|
if (shouldOverwriteLibs)
|
|
|
|
{
|
2016-03-07 01:01:28 +00:00
|
|
|
QList<LibraryPtr> libs;
|
2014-03-01 22:06:47 +00:00
|
|
|
for (auto lib : overwriteLibs)
|
|
|
|
{
|
2016-03-07 01:01:28 +00:00
|
|
|
libs.append(Library::limitedCopy(lib));
|
2014-03-01 22:06:47 +00:00
|
|
|
}
|
2014-05-11 11:37:21 +01:00
|
|
|
if (isMinecraftVersion())
|
|
|
|
{
|
2014-04-23 01:27:40 +01:00
|
|
|
version->vanillaLibraries = libs;
|
2014-05-11 11:37:21 +01:00
|
|
|
}
|
2014-04-23 01:27:40 +01:00
|
|
|
version->libraries = libs;
|
2014-03-01 22:06:47 +00:00
|
|
|
}
|
2014-07-26 22:00:35 +01:00
|
|
|
for (auto addedLibrary : addLibs)
|
2014-03-01 22:06:47 +00:00
|
|
|
{
|
2016-02-24 23:29:35 +00:00
|
|
|
// find the library by name.
|
|
|
|
const int index = findLibraryByName(version->libraries, addedLibrary->rawName());
|
|
|
|
// library not found? just add it.
|
|
|
|
if (index < 0)
|
2014-03-01 22:06:47 +00:00
|
|
|
{
|
2016-03-07 01:01:28 +00:00
|
|
|
version->libraries.append(Library::limitedCopy(addedLibrary));
|
2016-02-24 23:29:35 +00:00
|
|
|
continue;
|
2014-03-01 22:06:47 +00:00
|
|
|
}
|
2016-02-24 23:29:35 +00:00
|
|
|
auto existingLibrary = version->libraries.at(index);
|
|
|
|
// if we are higher it means we should update
|
|
|
|
if (Version(addedLibrary->version()) > Version(existingLibrary->version()))
|
2014-03-01 22:06:47 +00:00
|
|
|
{
|
2016-03-07 01:01:28 +00:00
|
|
|
auto library = Library::limitedCopy(addedLibrary);
|
2016-02-24 23:29:35 +00:00
|
|
|
version->libraries.replace(index, library);
|
2014-03-01 22:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|