aboutsummaryrefslogtreecommitdiff
path: root/logic/minecraft
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-03-13 00:23:45 +0100
committerPetr Mrázek <peterix@gmail.com>2016-03-26 17:05:27 +0100
commit02c1df2c3c260fe625b9c3314e9eed2885a97456 (patch)
tree1ca64f44fc609ba47a6a1fde4b9e93fe15b1e618 /logic/minecraft
parent1854e05e1bb14d8f2bbc4676f44024a83e972f6f (diff)
downloadPrismLauncher-02c1df2c3c260fe625b9c3314e9eed2885a97456.tar.gz
PrismLauncher-02c1df2c3c260fe625b9c3314e9eed2885a97456.tar.bz2
PrismLauncher-02c1df2c3c260fe625b9c3314e9eed2885a97456.zip
NOISSUE continue version file format refactors
Diffstat (limited to 'logic/minecraft')
-rw-r--r--logic/minecraft/Library.h2
-rw-r--r--logic/minecraft/MinecraftProfile.cpp228
-rw-r--r--logic/minecraft/MinecraftProfile.h66
-rw-r--r--logic/minecraft/MinecraftVersion.cpp67
-rw-r--r--logic/minecraft/MinecraftVersion.h20
-rw-r--r--logic/minecraft/MinecraftVersionList.cpp3
-rw-r--r--logic/minecraft/MojangVersionFormat.cpp9
-rw-r--r--logic/minecraft/ProfilePatch.h20
-rw-r--r--logic/minecraft/ProfileUtils.cpp1
-rw-r--r--logic/minecraft/VersionFile.cpp126
-rw-r--r--logic/minecraft/VersionFile.h39
-rw-r--r--logic/minecraft/VersionSource.h9
-rw-r--r--logic/minecraft/forge/ForgeInstaller.cpp38
-rw-r--r--logic/minecraft/ftb/FTBProfileStrategy.cpp5
-rw-r--r--logic/minecraft/onesix/OneSixInstance.cpp44
-rw-r--r--logic/minecraft/onesix/OneSixProfileStrategy.cpp8
-rw-r--r--logic/minecraft/onesix/OneSixUpdate.cpp11
-rw-r--r--logic/minecraft/onesix/OneSixVersionFormat.cpp97
18 files changed, 401 insertions, 392 deletions
diff --git a/logic/minecraft/Library.h b/logic/minecraft/Library.h
index 891601be..35b5cb99 100644
--- a/logic/minecraft/Library.h
+++ b/logic/minecraft/Library.h
@@ -13,7 +13,7 @@
#include "GradleSpecifier.h"
#include "net/URLConstants.h"
-class MojangLibraryDownloadInfo;
+struct MojangLibraryDownloadInfo;
class Library;
typedef std::shared_ptr<Library> LibraryPtr;
diff --git a/logic/minecraft/MinecraftProfile.cpp b/logic/minecraft/MinecraftProfile.cpp
index 0cf8b548..7586c156 100644
--- a/logic/minecraft/MinecraftProfile.cpp
+++ b/logic/minecraft/MinecraftProfile.cpp
@@ -14,6 +14,7 @@
*/
#include <QFile>
+#include <Version.h>
#include <QDir>
#include <QJsonDocument>
#include <QJsonArray>
@@ -60,11 +61,8 @@ void MinecraftProfile::reload()
void MinecraftProfile::clear()
{
id.clear();
- m_updateTime = QDateTime();
- m_releaseTime = QDateTime();
type.clear();
assets.clear();
- processArguments.clear();
minecraftArguments.clear();
mainClass.clear();
appletClass.clear();
@@ -94,13 +92,13 @@ bool MinecraftProfile::remove(const int index)
auto patch = versionPatch(index);
if (!patch->isRemovable())
{
- qDebug() << "Patch" << patch->getPatchID() << "is non-removable";
+ qDebug() << "Patch" << patch->getID() << "is non-removable";
return false;
}
if(!m_strategy->removePatch(patch))
{
- qCritical() << "Patch" << patch->getPatchID() << "could not be removed";
+ qCritical() << "Patch" << patch->getID() << "could not be removed";
return false;
}
@@ -117,7 +115,7 @@ bool MinecraftProfile::remove(const QString id)
int i = 0;
for (auto patch : VersionPatches)
{
- if (patch->getPatchID() == id)
+ if (patch->getID() == id)
{
return remove(i);
}
@@ -131,12 +129,12 @@ bool MinecraftProfile::customize(int index)
auto patch = versionPatch(index);
if (!patch->isCustomizable())
{
- qDebug() << "Patch" << patch->getPatchID() << "is not customizable";
+ qDebug() << "Patch" << patch->getID() << "is not customizable";
return false;
}
if(!m_strategy->customizePatch(patch))
{
- qCritical() << "Patch" << patch->getPatchID() << "could not be customized";
+ qCritical() << "Patch" << patch->getID() << "could not be customized";
return false;
}
reapplySafe();
@@ -151,12 +149,12 @@ bool MinecraftProfile::revertToBase(int index)
auto patch = versionPatch(index);
if (!patch->isRevertible())
{
- qDebug() << "Patch" << patch->getPatchID() << "is not revertible";
+ qDebug() << "Patch" << patch->getID() << "is not revertible";
return false;
}
if(!m_strategy->revertPatch(patch))
{
- qCritical() << "Patch" << patch->getPatchID() << "could not be reverted";
+ qCritical() << "Patch" << patch->getID() << "could not be reverted";
return false;
}
reapplySafe();
@@ -172,14 +170,14 @@ QString MinecraftProfile::versionFileId(const int index) const
{
return QString();
}
- return VersionPatches.at(index)->getPatchID();
+ return VersionPatches.at(index)->getID();
}
ProfilePatchPtr MinecraftProfile::versionPatch(const QString &id)
{
for (auto file : VersionPatches)
{
- if (file->getPatchID() == id)
+ if (file->getID() == id)
{
return file;
}
@@ -216,9 +214,9 @@ bool MinecraftProfile::revertToVanilla()
}
if(it->isRevertible() || it->isRemovable())
{
- if(!remove(it->getPatchID()))
+ if(!remove(it->getID()))
{
- qWarning() << "Couldn't remove" << it->getPatchID() << "from profile!";
+ qWarning() << "Couldn't remove" << it->getID() << "from profile!";
reapplySafe();
saveCurrentOrder();
return false;
@@ -230,7 +228,7 @@ bool MinecraftProfile::revertToVanilla()
return true;
}
-QList<std::shared_ptr<Library> > MinecraftProfile::getActiveNormalLibs()
+QList<std::shared_ptr<Library> > MinecraftProfile::getActiveNormalLibs() const
{
QList<std::shared_ptr<Library> > output;
for (auto lib : libraries)
@@ -251,7 +249,7 @@ QList<std::shared_ptr<Library> > MinecraftProfile::getActiveNormalLibs()
return output;
}
-QList<std::shared_ptr<Library> > MinecraftProfile::getActiveNativeLibs()
+QList<std::shared_ptr<Library> > MinecraftProfile::getActiveNativeLibs() const
{
QList<std::shared_ptr<Library> > output;
for (auto lib : libraries)
@@ -282,16 +280,16 @@ QVariant MinecraftProfile::data(const QModelIndex &index, int role) const
switch (column)
{
case 0:
- return VersionPatches.at(row)->getPatchName();
+ return VersionPatches.at(row)->getName();
case 1:
{
if(patch->isCustom())
{
- return QString("%1 (Custom)").arg(patch->getPatchVersion());
+ return QString("%1 (Custom)").arg(patch->getVersion());
}
else
{
- return patch->getPatchVersion();
+ return patch->getVersion();
}
}
default:
@@ -366,7 +364,7 @@ void MinecraftProfile::saveCurrentOrder() const
{
if(!item->isMoveable())
continue;
- order.append(item->getPatchID());
+ order.append(item->getID());
}
m_strategy->saveOrder(order);
}
@@ -419,7 +417,6 @@ void MinecraftProfile::reapply()
{
file->applyTo(this);
}
- finalize();
}
bool MinecraftProfile::reapplySafe()
@@ -437,41 +434,186 @@ bool MinecraftProfile::reapplySafe()
return true;
}
-void MinecraftProfile::finalize()
+static void applyString(const QString & from, QString & to)
{
- // HACK: deny april fools. my head hurts enough already.
- QDate now = QDate::currentDate();
- bool isAprilFools = now.month() == 4 && now.day() == 1;
- if (assets.endsWith("_af") && !isAprilFools)
+ if(from.isEmpty())
+ return;
+ to = from;
+}
+
+void MinecraftProfile::applyMinecraftVersion(const QString& id)
+{
+ applyString(id, this->id);
+}
+
+void MinecraftProfile::applyAppletClass(const QString& appletClass)
+{
+ applyString(appletClass, this->appletClass);
+}
+
+void MinecraftProfile::applyMainClass(const QString& mainClass)
+{
+ applyString(mainClass, this->mainClass);
+}
+
+void MinecraftProfile::applyMinecraftArguments(const QString& minecraftArguments, bool isMinecraft)
+{
+ applyString(minecraftArguments, this->minecraftArguments);
+ if(isMinecraft)
{
- assets = assets.left(assets.length() - 3);
+ applyString(minecraftArguments, this->vanillaMinecraftArguments);
}
- if (assets.isEmpty())
+}
+
+void MinecraftProfile::applyMinecraftVersionType(const QString& type)
+{
+ applyString(type, this->type);
+}
+
+void MinecraftProfile::applyMinecraftAssets(const QString& assets)
+{
+ applyString(assets, this->assets);
+}
+
+void MinecraftProfile::applyTraits(const QSet<QString>& traits)
+{
+ this->traits.unite(traits);
+}
+
+void MinecraftProfile::applyTweakers(const QStringList& tweakers)
+{
+ // FIXME: check for dupes?
+ // FIXME: does order matter?
+ for (auto tweaker : tweakers)
{
- assets = "legacy";
+ this->tweakers += tweaker;
}
- auto finalizeArguments = [&]( QString & minecraftArguments, const QString & processArguments ) -> void
+}
+
+void MinecraftProfile::applyJarMods(const QList<JarmodPtr>& jarMods)
+{
+ this->jarMods.append(jarMods);
+}
+
+static int findLibraryByName(QList<LibraryPtr> haystack, const GradleSpecifier &needle)
+{
+ int retval = -1;
+ for (int i = 0; i < haystack.size(); ++i)
{
- if (!minecraftArguments.isEmpty())
- return;
- QString toCompare = processArguments.toLower();
- if (toCompare == "legacy")
+ if (haystack.at(i)->rawName().matchName(needle))
{
- minecraftArguments = " ${auth_player_name} ${auth_session}";
+ // only one is allowed.
+ if (retval != -1)
+ return -1;
+ retval = i;
}
- else if (toCompare == "username_session")
+ }
+ return retval;
+}
+
+void MinecraftProfile::applyLibrary(LibraryPtr library, bool isMinecraft)
+{
+ auto insert = [&](QList<LibraryPtr> & into)
+ {
+ // find the library by name.
+ const int index = findLibraryByName(into, library->rawName());
+ // library not found? just add it.
+ if (index < 0)
{
- minecraftArguments = "--username ${auth_player_name} --session ${auth_session}";
+ into.append(Library::limitedCopy(library));
+ return;
}
- else if (toCompare == "username_session_version")
+ auto existingLibrary = into.at(index);
+ // if we are higher it means we should update
+ if (Version(library->version()) > Version(existingLibrary->version()))
{
- minecraftArguments = "--username ${auth_player_name} "
- "--session ${auth_session} "
- "--version ${profile_name}";
+ auto libraryCopy = Library::limitedCopy(library);
+ into.replace(index, libraryCopy);
}
};
- finalizeArguments(vanillaMinecraftArguments, vanillaProcessArguments);
- finalizeArguments(minecraftArguments, processArguments);
+ insert(libraries);
+ if(isMinecraft)
+ {
+ insert(vanillaLibraries);
+ }
+}
+
+
+QString MinecraftProfile::getMinecraftVersion() const
+{
+ return id;
+}
+
+QString MinecraftProfile::getAppletClass() const
+{
+ return appletClass;
+}
+
+QString MinecraftProfile::getMainClass() const
+{
+ return mainClass;
+}
+
+const QSet<QString> &MinecraftProfile::getTraits() const
+{
+ return traits;
+}
+
+const QStringList & MinecraftProfile::getTweakers() const
+{
+ return tweakers;
+}
+
+bool MinecraftProfile::hasTrait(const QString& trait) const
+{
+ return traits.contains(trait);
+}
+
+
+QString MinecraftProfile::getMinecraftVersionType() const
+{
+ return type;
+}
+
+QString MinecraftProfile::getMinecraftAssets() const
+{
+ // HACK: deny april fools. my head hurts enough already.
+ QDate now = QDate::currentDate();
+ bool isAprilFools = now.month() == 4 && now.day() == 1;
+ if (assets.endsWith("_af") && !isAprilFools)
+ {
+ return assets.left(assets.length() - 3);
+ }
+ if (assets.isEmpty())
+ {
+ return QLatin1Literal("legacy");
+ }
+ return assets;
+}
+
+QString MinecraftProfile::getMinecraftArguments() const
+{
+ return minecraftArguments;
+}
+
+QString MinecraftProfile::getVanillaMinecraftArguments() const
+{
+ return vanillaMinecraftArguments;
+}
+
+const QList<JarmodPtr> & MinecraftProfile::getJarMods() const
+{
+ return jarMods;
+}
+
+const QList<LibraryPtr> & MinecraftProfile::getLibraries() const
+{
+ return libraries;
+}
+
+const QList<LibraryPtr> & MinecraftProfile::getVanillaLibraries() const
+{
+ return vanillaLibraries;
}
void MinecraftProfile::installJarMods(QStringList selectedFiles)
diff --git a/logic/minecraft/MinecraftProfile.h b/logic/minecraft/MinecraftProfile.h
index 84d3ce3b..24d13609 100644
--- a/logic/minecraft/MinecraftProfile.h
+++ b/logic/minecraft/MinecraftProfile.h
@@ -88,16 +88,40 @@ public:
/// apply the patches. Catches all the errors and returns true/false for success/failure
bool reapplySafe();
- /// do a finalization step (should always be done after applying all patches to profile)
- void finalize();
+public:
+ void applyMinecraftVersion(const QString& id);
+ void applyMainClass(const QString& mainClass);
+ void applyAppletClass(const QString& appletClass);
+ void applyMinecraftArguments(const QString& minecraftArguments, bool isMinecraft);
+ void applyMinecraftVersionType(const QString& type);
+ void applyMinecraftAssets(const QString& assets);
+ void applyTraits(const QSet<QString> &traits);
+ void applyTweakers(const QStringList &tweakers);
+ void applyJarMods(const QList<JarmodPtr>&jarMods);
+ void applyLibrary(LibraryPtr library, bool isMinecraft);
public:
/// get all java libraries that belong to the classpath
- QList<LibraryPtr> getActiveNormalLibs();
+ QList<LibraryPtr> getActiveNormalLibs() const;
/// get all native libraries that need to be available to the process
- QList<LibraryPtr> getActiveNativeLibs();
+ QList<LibraryPtr> getActiveNativeLibs() const;
+
+ QString getMinecraftVersion() const;
+ QString getMainClass() const;
+ QString getAppletClass() const;
+ QString getMinecraftVersionType() const;
+ QString getMinecraftAssets() const;
+ QString getMinecraftArguments() const;
+ QString getVanillaMinecraftArguments() const;
+ const QSet<QString> & getTraits() const;
+ const QStringList & getTweakers() const;
+ const QList<JarmodPtr> & getJarMods() const;
+ const QList<LibraryPtr> & getLibraries() const;
+ const QList<LibraryPtr> & getVanillaLibraries() const;
+ bool hasTrait(const QString & trait) const;
+public:
/// get file ID of the patch file at #
QString versionFileId(const int index) const;
@@ -110,34 +134,22 @@ public:
/// save the current patch order
void saveCurrentOrder() const;
-public: /* only use in ProfileStrategy */
/// Remove all the patches
void clearPatches();
/// Add the patch object to the internal list of patches
void appendPatch(ProfilePatchPtr patch);
-public: /* data */
+protected: /* data */
/// the ID - determines which jar to use! ACTUALLY IMPORTANT!
QString id;
- /// the time this version was actually released by Mojang
- QDateTime m_releaseTime;
-
- /// the time this version was last updated by Mojang
- QDateTime m_updateTime;
-
/// Release type - "release" or "snapshot"
QString type;
+
/// Assets type - "legacy" or a version ID
QString assets;
- /**
- * DEPRECATED: Old versions of the new vanilla launcher used this
- * ex: "username_session_version"
- */
- QString processArguments;
- /// Same as above, but only for vanilla
- QString vanillaProcessArguments;
+
/**
* arguments that should be used for launching minecraft
*
@@ -145,19 +157,17 @@ public: /* data */
* --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}"
*/
QString minecraftArguments;
+
/// Same as above, but only for vanilla
QString vanillaMinecraftArguments;
- /**
- * A list of all tweaker classes
- */
+
+ /// A list of all tweaker classes
QStringList tweakers;
- /**
- * The main class to load first
- */
+
+ /// The main class to load first
QString mainClass;
- /**
- * The applet class, for some very old minecraft releases
- */
+
+ /// The applet class, for some very old minecraft releases
QString appletClass;
/// the list of libs - both active and inactive, native and java
diff --git a/logic/minecraft/MinecraftVersion.cpp b/logic/minecraft/MinecraftVersion.cpp
index 8a1ac501..3224de4c 100644
--- a/logic/minecraft/MinecraftVersion.cpp
+++ b/logic/minecraft/MinecraftVersion.cpp
@@ -43,6 +43,11 @@ QString MinecraftVersion::typeString() const
}
}
+VersionSource MinecraftVersion::getVersionSource()
+{
+ return m_versionSource;
+}
+
bool MinecraftVersion::hasJarMods()
{
return false;
@@ -64,19 +69,6 @@ void MinecraftVersion::applyFileTo(MinecraftProfile *version)
throw VersionIncomplete(QObject::tr("Can't apply incomplete/builtin Minecraft version %1").arg(m_name));
}
}
-/*
-QJsonDocument MinecraftVersion::toJson(bool saveOrder)
-{
- if(m_versionSource == Local && getVersionFile())
- {
- return getVersionFile()->toJson(saveOrder);
- }
- else
- {
- throw VersionIncomplete(QObject::tr("Can't write incomplete/builtin Minecraft version %1").arg(m_name));
- }
-}
-*/
QString MinecraftVersion::getUrl() const
{
@@ -171,36 +163,12 @@ void MinecraftVersion::applyTo(MinecraftProfile *version)
throw VersionIncomplete(QObject::tr(
"Minecraft version %1 could not be applied: version files are missing.").arg(m_descriptor));
}
- if (!m_descriptor.isNull())
- {
- version->id = m_descriptor;
- }
- if (!m_mainClass.isNull())
- {
- version->mainClass = m_mainClass;
- }
- if (!m_appletClass.isNull())
- {
- version->appletClass = m_appletClass;
- }
- if (!m_processArguments.isNull())
- {
- version->vanillaProcessArguments = m_processArguments;
- version->processArguments = m_processArguments;
- }
- if (!m_type.isNull())
- {
- version->type = m_type;
- }
- if (!m_releaseTime.isNull())
- {
- version->m_releaseTime = m_releaseTime;
- }
- if (!m_updateTime.isNull())
- {
- version->m_updateTime = m_updateTime;
- }
- version->traits.unite(m_traits);
+ version->applyMinecraftVersion(m_descriptor);
+ version->applyMainClass(m_mainClass);
+ version->applyAppletClass(m_appletClass);
+ version->applyMinecraftArguments(" ${auth_player_name} ${auth_session}", true); // all builtin versions are legacy
+ version->applyMinecraftVersionType(m_type);
+ version->applyTraits(m_traits);
}
int MinecraftVersion::getOrder()
@@ -218,22 +186,27 @@ QList<JarmodPtr> MinecraftVersion::getJarMods()
return QList<JarmodPtr>();
}
-QString MinecraftVersion::getPatchName()
+QString MinecraftVersion::getName()
{
return "Minecraft";
}
-QString MinecraftVersion::getPatchVersion()
+QString MinecraftVersion::getVersion()
{
return m_descriptor;
}
-QString MinecraftVersion::getPatchID()
+QString MinecraftVersion::getID()
{
return "net.minecraft";
}
-QString MinecraftVersion::getPatchFilename()
+QString MinecraftVersion::getFilename()
{
return QString();
}
+QDateTime MinecraftVersion::getReleaseDateTime()
+{
+ return m_releaseTime;
+}
+
bool MinecraftVersion::needsUpdate()
{
diff --git a/logic/minecraft/MinecraftVersion.h b/logic/minecraft/MinecraftVersion.h
index 33ca2899..aca9c08d 100644
--- a/logic/minecraft/MinecraftVersion.h
+++ b/logic/minecraft/MinecraftVersion.h
@@ -22,7 +22,6 @@
#include "BaseVersion.h"
#include "ProfilePatch.h"
#include "VersionFile.h"
-#include "VersionSource.h"
#include "multimc_logic_export.h"
@@ -32,6 +31,8 @@ typedef std::shared_ptr<MinecraftVersion> MinecraftVersionPtr;
class MULTIMC_LOGIC_EXPORT MinecraftVersion : public BaseVersion, public ProfilePatch
{
+friend class MinecraftVersionList;
+
public: /* methods */
bool usesLegacyLauncher();
virtual QString descriptor() override;
@@ -43,10 +44,13 @@ public: /* methods */
virtual int getOrder() override;
virtual void setOrder(int order) override;
virtual QList<JarmodPtr> getJarMods() override;
- virtual QString getPatchID() override;
- virtual QString getPatchVersion() override;
- virtual QString getPatchName() override;
- virtual QString getPatchFilename() override;
+ virtual QString getID() override;
+ virtual QString getVersion() override;
+ virtual QString getName() override;
+ virtual QString getFilename() override;
+ QDateTime getReleaseDateTime() override;
+ VersionSource getVersionSource() override;
+
bool needsUpdate();
bool hasUpdate();
virtual bool isCustom() override;
@@ -84,7 +88,7 @@ public: /* methods */
private: /* methods */
void applyFileTo(MinecraftProfile *version);
-public: /* data */
+protected: /* data */
VersionSource m_versionSource = Builtin;
/// The URL that this version will be downloaded from.
@@ -105,9 +109,6 @@ public: /* data */
/// The applet class this version uses (if any, can be empty).
QString m_appletClass;
- /// The process arguments used by this version
- QString m_processArguments;
-
/// The type of this release
QString m_type;
@@ -126,7 +127,6 @@ public: /* data */
/// an update available from Mojang
MinecraftVersionPtr upstreamUpdate;
-private: /* data */
QDateTime m_loadedVersionFileTimestamp;
mutable VersionFilePtr m_loadedVersionFile;
};
diff --git a/logic/minecraft/MinecraftVersionList.cpp b/logic/minecraft/MinecraftVersionList.cpp
index 507d8254..f219c782 100644
--- a/logic/minecraft/MinecraftVersionList.cpp
+++ b/logic/minecraft/MinecraftVersionList.cpp
@@ -111,7 +111,7 @@ static bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second)
{
auto left = std::dynamic_pointer_cast<MinecraftVersion>(first);
auto right = std::dynamic_pointer_cast<MinecraftVersion>(second);
- return left->m_releaseTime > right->m_releaseTime;
+ return left->getReleaseDateTime() > right->getReleaseDateTime();
}
void MinecraftVersionList::sortInternal()
@@ -191,7 +191,6 @@ void MinecraftVersionList::loadBuiltinList()
mcVersion->m_appletClass = versionObj.value("appletClass").toString("");
mcVersion->m_mainClass = versionObj.value("mainClass").toString("");
mcVersion->m_jarChecksum = versionObj.value("checksum").toString("");
- mcVersion->m_processArguments = versionObj.value("processArguments").toString("legacy");
if (versionObj.contains("+traits"))
{
for (auto traitVal : Json::requireArray(versionObj.value("+traits")))
diff --git a/logic/minecraft/MojangVersionFormat.cpp b/logic/minecraft/MojangVersionFormat.cpp
index def388bf..2d4f26c5 100644
--- a/logic/minecraft/MojangVersionFormat.cpp
+++ b/logic/minecraft/MojangVersionFormat.cpp
@@ -150,7 +150,7 @@ VersionFilePtr MojangVersionFormat::versionFileFromJson(const QJsonDocument &doc
Bits::readString(root, "id", out->id);
Bits::readString(root, "mainClass", out->mainClass);
- Bits::readString(root, "minecraftArguments", out->overwriteMinecraftArguments);
+ Bits::readString(root, "minecraftArguments", out->minecraftArguments);
Bits::readString(root, "type", out->type);
if(root.contains("assetIndex"))
@@ -203,8 +203,7 @@ QJsonDocument versionFileToJson(VersionFilePtr patch)
QJsonObject root;
writeString(root, "id", patch->id);
writeString(root, "mainClass", patch->mainClass);
- writeString(root, "processArguments", patch->processArguments);
- writeString(root, "minecraftArguments", patch->overwriteMinecraftArguments);
+ writeString(root, "minecraftArguments", patch->minecraftArguments);
writeString(root, "type", patch->type);
writeString(root, "assets", patch->assets);
writeString(root, "releaseTime", timeToS3Time(patch->m_releaseTime));
@@ -246,7 +245,7 @@ QJsonDocument versionFileToJson(VersionFilePtr patch)
static QJsonDocument minecraftVersionToJson(MinecraftVersionPtr patch)
{
- if(patch->m_versionSource == Local && patch->getVersionFile())
+ if(patch->getVersionSource() == Local && patch->getVersionFile())
{
return MojangVersionFormat::profilePatchToJson(patch->getVersionFile());
}
@@ -268,7 +267,7 @@ QJsonDocument MojangVersionFormat::profilePatchToJson(const ProfilePatchPtr &pat
{
return minecraftVersionToJson(mversion);
}
- throw VersionIncomplete(QObject::tr("Unhandled object type while processing %1").arg(patch->getPatchName()));
+ throw VersionIncomplete(QObject::tr("Unhandled object type while processing %1").arg(patch->getName()));
}
LibraryPtr MojangVersionFormat::libraryFromJson(const QJsonObject &libObj, const QString &filename)
diff --git a/logic/minecraft/ProfilePatch.h b/logic/minecraft/ProfilePatch.h
index cf7a1904..0d01ba87 100644
--- a/logic/minecraft/ProfilePatch.h
+++ b/logic/minecraft/ProfilePatch.h
@@ -14,6 +14,14 @@ enum ProblemSeverity
PROBLEM_ERROR
};
+/// where is a version from?
+enum VersionSource
+{
+ Builtin, //!< version loaded from the internal resources.
+ Local, //!< version loaded from a file in the cache.
+ Remote, //!< incomplete version on a remote server.
+};
+
class PatchProblem
{
public:
@@ -56,10 +64,14 @@ public:
virtual void setOrder(int order) = 0;
virtual int getOrder() = 0;
- virtual QString getPatchID() = 0;
- virtual QString getPatchName() = 0;
- virtual QString getPatchVersion() = 0;
- virtual QString getPatchFilename() = 0;
+ virtual QString getID() = 0;
+ virtual QString getName() = 0;
+ virtual QString getVersion() = 0;
+ virtual QDateTime getReleaseDateTime() = 0;
+
+ virtual QString getFilename() = 0;
+
+ virtual VersionSource getVersionSource() = 0;
virtual const QList<PatchProblem>& getProblems()
{
diff --git a/logic/minecraft/ProfileUtils.cpp b/logic/minecraft/ProfileUtils.cpp
index 30e83a1f..dfff7956 100644
--- a/logic/minecraft/ProfileUtils.cpp
+++ b/logic/minecraft/ProfileUtils.cpp
@@ -166,6 +166,5 @@ void removeLwjglFromPatch(VersionFilePtr patch)
libs = filteredLibs;
};
filter(patch->addLibs);
- filter(patch->overwriteLibs);
}
}
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