pollymc/logic/minecraft/VersionFile.cpp

145 lines
3.0 KiB
C++
Raw Normal View History

2014-03-02 03:36:47 +05:30
#include <QJsonArray>
#include <QJsonDocument>
#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
{
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
{
// only one is allowed.
2014-05-10 05:23:32 +05:30
if (retval != -1)
return -1;
retval = i;
2014-03-02 03:36:47 +05:30
}
}
return retval;
2014-03-02 03:36:47 +05:30
}
bool VersionFile::isMinecraftVersion()
{
2015-01-28 03:01:07 +05:30
return fileId == "net.minecraft";
}
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)
{
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;
}
if (!appletClass.isNull())
{
version->appletClass = appletClass;
}
2014-03-02 03:36:47 +05:30
if (!processArguments.isNull())
{
if (isMinecraftVersion())
{
version->vanillaProcessArguments = processArguments;
}
2014-03-02 03:36:47 +05:30
version->processArguments = processArguments;
}
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())
{
if (isMinecraftVersion())
{
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;
}
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
}
if (isMinecraftVersion())
{
version->vanillaLibraries = libs;
}
version->libraries = libs;
2014-03-02 03:36:47 +05:30
}
for (auto addedLibrary : addLibs)
2014-03-02 03:36:47 +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));
continue;
2014-03-02 03:36:47 +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);
version->libraries.replace(index, library);
2014-03-02 03:36:47 +05:30
}
}
}