From 02c1df2c3c260fe625b9c3314e9eed2885a97456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 13 Mar 2016 00:23:45 +0100 Subject: NOISSUE continue version file format refactors --- logic/minecraft/VersionFile.cpp | 126 ++++++---------------------------------- 1 file changed, 18 insertions(+), 108 deletions(-) (limited to 'logic/minecraft/VersionFile.cpp') diff --git a/logic/minecraft/VersionFile.cpp b/logic/minecraft/VersionFile.cpp index 410f6659..9cd8dd5e 100644 --- a/logic/minecraft/VersionFile.cpp +++ b/logic/minecraft/VersionFile.cpp @@ -12,22 +12,6 @@ #include "VersionBuildError.h" #include -int findLibraryByName(QList 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()) - { - if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(version->id) == - -1) - { - throw MinecraftVersionMismatch(fileId, mcVersion, version->id); - } - } - - 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()) + auto theirVersion = version->getMinecraftVersion(); + if (!theirVersion.isNull() && !mcVersion.isNull()) { - version->assets = assets; - } - if (!overwriteMinecraftArguments.isNull()) - { - if (isMinecraftVersion()) + if (QRegExp(mcVersion, Qt::CaseInsensitive, QRegExp::Wildcard).indexIn(theirVersion) == -1) { - version->vanillaMinecraftArguments = overwriteMinecraftArguments; + throw MinecraftVersionMismatch(fileId, mcVersion, theirVersion); } - version->minecraftArguments = overwriteMinecraftArguments; - } - if (!addMinecraftArguments.isNull()) - { - version->minecraftArguments += addMinecraftArguments; - } - if (shouldOverwriteTweakers) - { - version->tweakers = overwriteTweakers; } - for (auto tweaker : addTweakers) + bool is_minecraft = isMinecraftVersion(); + version->applyMinecraftVersion(id); + version->applyMainClass(mainClass); + version->applyAppletClass(appletClass); + version->applyMinecraftArguments(minecraftArguments, is_minecraft); + if (is_minecraft) { - version->tweakers += tweaker; - } - version->jarMods.append(jarMods); - version->traits.unite(traits); - if (shouldOverwriteLibs) - { - QList libs; - for (auto lib : overwriteLibs) - { - libs.append(Library::limitedCopy(lib)); - } - if (isMinecraftVersion()) - { - version->vanillaLibraries = libs; - } - version->libraries = libs; + version->applyMinecraftVersionType(type); } + version->applyMinecraftAssets(assets); + version->applyTweakers(addTweakers); + + version->applyJarMods(jarMods); + version->applyTraits(traits); + 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()); } } -- cgit v1.2.3