NOISSUE continue version file format refactors

This commit is contained in:
Petr Mrázek 2016-03-13 00:23:45 +01:00
parent 1854e05e1b
commit 02c1df2c3c
23 changed files with 425 additions and 492 deletions

View file

@ -12,22 +12,6 @@
#include "VersionBuildError.h"
#include <Version.h>
int findLibraryByName(QList<LibraryPtr> haystack, const GradleSpecifier &needle)
{
int retval = -1;
for (int i = 0; i < haystack.size(); ++i)
{
if (haystack.at(i)->rawName().matchName(needle))
{
// only one is allowed.
if (retval != -1)
return -1;
retval = i;
}
}
return retval;
}
bool VersionFile::isMinecraftVersion()
{
return fileId == "net.minecraft";
@ -40,105 +24,31 @@ bool VersionFile::hasJarMods()
void VersionFile::applyTo(MinecraftProfile *version)
{
if (!version->id.isNull() && !mcVersion.isNull())
auto theirVersion = version->getMinecraftVersion();
if (!theirVersion.isNull() && !mcVersion.isNull())
{
if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(version->id) ==
-1)
if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(theirVersion) == -1)
{
throw MinecraftVersionMismatch(fileId, mcVersion, version->id);
throw MinecraftVersionMismatch(fileId, mcVersion, theirVersion);
}
}
bool is_minecraft = isMinecraftVersion();
version->applyMinecraftVersion(id);
version->applyMainClass(mainClass);
version->applyAppletClass(appletClass);
version->applyMinecraftArguments(minecraftArguments, is_minecraft);
if (is_minecraft)
{
version->applyMinecraftVersionType(type);
}
version->applyMinecraftAssets(assets);
version->applyTweakers(addTweakers);
version->applyJarMods(jarMods);
version->applyTraits(traits);
if (!id.isNull())
{
version->id = id;
}
if (!mainClass.isNull())
{
version->mainClass = mainClass;
}
if (!appletClass.isNull())
{
version->appletClass = appletClass;
}
if (!processArguments.isNull())
{
if (isMinecraftVersion())
{
version->vanillaProcessArguments = processArguments;
}
version->processArguments = processArguments;
}
if (isMinecraftVersion())
{
if (!type.isNull())
{
version->type = type;
}
if (!m_releaseTime.isNull())
{
version->m_releaseTime = m_releaseTime;
}
if (!m_updateTime.isNull())
{
version->m_updateTime = m_updateTime;
}
}
if (!assets.isNull())
{
version->assets = assets;
}
if (!overwriteMinecraftArguments.isNull())
{
if (isMinecraftVersion())
{
version->vanillaMinecraftArguments = overwriteMinecraftArguments;
}
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);
version->traits.unite(traits);
if (shouldOverwriteLibs)
{
QList<LibraryPtr> libs;
for (auto lib : overwriteLibs)
{
libs.append(Library::limitedCopy(lib));
}
if (isMinecraftVersion())
{
version->vanillaLibraries = libs;
}
version->libraries = libs;
}
for (auto addedLibrary : addLibs)
{
// find the library by name.
const int index = findLibraryByName(version->libraries, addedLibrary->rawName());
// library not found? just add it.
if (index < 0)
{
version->libraries.append(Library::limitedCopy(addedLibrary));
continue;
}
auto existingLibrary = version->libraries.at(index);
// if we are higher it means we should update
if (Version(addedLibrary->version()) > Version(existingLibrary->version()))
{
auto library = Library::limitedCopy(addedLibrary);
version->libraries.replace(index, library);
}
version->applyLibrary(addedLibrary, isMinecraftVersion());
}
}