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