diff options
author | Petr Mrázek <peterix@gmail.com> | 2016-03-13 00:23:45 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2016-03-26 17:05:27 +0100 |
commit | 02c1df2c3c260fe625b9c3314e9eed2885a97456 (patch) | |
tree | 1ca64f44fc609ba47a6a1fde4b9e93fe15b1e618 /logic/minecraft/VersionFile.cpp | |
parent | 1854e05e1bb14d8f2bbc4676f44024a83e972f6f (diff) | |
download | PrismLauncher-02c1df2c3c260fe625b9c3314e9eed2885a97456.tar.gz PrismLauncher-02c1df2c3c260fe625b9c3314e9eed2885a97456.tar.bz2 PrismLauncher-02c1df2c3c260fe625b9c3314e9eed2885a97456.zip |
NOISSUE continue version file format refactors
Diffstat (limited to 'logic/minecraft/VersionFile.cpp')
-rw-r--r-- | logic/minecraft/VersionFile.cpp | 126 |
1 files changed, 18 insertions, 108 deletions
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 <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()) - { - 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<LibraryPtr> 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()); } } |