summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-05-05 00:10:59 +0200
committerPetr Mrázek <peterix@gmail.com>2014-06-09 01:38:29 +0200
commit4c3bd416c65ec887209fa06b0a5634099b77f322 (patch)
treef656031d147aba8f8dd621de2bd452ea1bfd86b4 /logic
parentaade36860c373268857ca821c14a13f38c880b1a (diff)
downloadMultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.tar
MultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.tar.gz
MultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.tar.lz
MultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.tar.xz
MultiMC-4c3bd416c65ec887209fa06b0a5634099b77f322.zip
Much change, very jarmod.
Diffstat (limited to 'logic')
-rw-r--r--logic/BaseInstance.h2
-rw-r--r--logic/LegacyUpdate.cpp2
-rw-r--r--logic/LegacyUpdate.h2
-rw-r--r--logic/OneSixInstance.cpp70
-rw-r--r--logic/OneSixInstance.h5
-rw-r--r--logic/OneSixUpdate.cpp214
-rw-r--r--logic/OneSixUpdate.h11
-rw-r--r--logic/URNResolver.cpp98
-rw-r--r--logic/URNResolver.h18
-rw-r--r--logic/VersionFile.cpp1
-rw-r--r--logic/VersionFilterData.cpp (renamed from logic/forge/ForgeData.cpp)16
-rw-r--r--logic/VersionFilterData.h (renamed from logic/forge/ForgeData.h)8
-rw-r--r--logic/VersionFinal.cpp69
-rw-r--r--logic/VersionFinal.h3
-rw-r--r--logic/forge/ForgeInstaller.cpp24
-rw-r--r--logic/forge/ForgeVersion.cpp4
-rw-r--r--logic/forge/ForgeVersionList.cpp1
-rw-r--r--logic/forge/ForgeVersionList.h2
-rw-r--r--logic/lists/MinecraftVersionList.cpp26
-rw-r--r--logic/lists/MinecraftVersionList.h1
20 files changed, 494 insertions, 83 deletions
diff --git a/logic/BaseInstance.h b/logic/BaseInstance.h
index 16791592..41ceda39 100644
--- a/logic/BaseInstance.h
+++ b/logic/BaseInstance.h
@@ -89,7 +89,7 @@ public:
void setGroupInitial(QString val);
void setGroupPost(QString val);
- QStringList extraArguments() const;
+ virtual QStringList extraArguments() const;
virtual QString intendedVersionId() const = 0;
virtual bool setIntendedVersionId(QString version) = 0;
diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp
index 6816df40..aea88c95 100644
--- a/logic/LegacyUpdate.cpp
+++ b/logic/LegacyUpdate.cpp
@@ -64,7 +64,7 @@ void LegacyUpdate::fmllibsStart()
bool forge_present = false;
QString version = inst->intendedVersionId();
- auto & fmlLibsMapping = g_forgeData.fmlLibsMapping;
+ auto & fmlLibsMapping = g_VersionFilterData.fmlLibsMapping;
if (!fmlLibsMapping.contains(version))
{
lwjglStart();
diff --git a/logic/LegacyUpdate.h b/logic/LegacyUpdate.h
index 1550ec34..140ee1e3 100644
--- a/logic/LegacyUpdate.h
+++ b/logic/LegacyUpdate.h
@@ -21,7 +21,7 @@
#include "logic/net/NetJob.h"
#include "logic/tasks/Task.h"
-#include "logic/forge/ForgeData.h"
+#include "logic/VersionFilterData.h"
class MinecraftVersion;
class BaseInstance;
diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp
index dc452188..9057a6e3 100644
--- a/logic/OneSixInstance.cpp
+++ b/logic/OneSixInstance.cpp
@@ -29,7 +29,8 @@
#include "gui/dialogs/InstanceEditDialog.h"
#include <MMCError.h>
-OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings, QObject *parent)
+OneSixInstance::OneSixInstance(const QString &rootDir, SettingsObject *settings,
+ QObject *parent)
: BaseInstance(new OneSixInstancePrivate(), rootDir, settings, parent)
{
I_D(OneSixInstance);
@@ -47,7 +48,7 @@ void OneSixInstance::init()
{
reloadVersion();
}
- catch(MMCError & e)
+ catch (MMCError &e)
{
// QLOG_ERROR() << "Caught exception on instance init: " << e.cause();
}
@@ -125,7 +126,7 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr<VersionFinal> version)
QString original_path =
PathCombine(PathCombine(objectDir.path(), tlk), asset_object.hash);
QFile original(original_path);
- if(!original.exists())
+ if (!original.exists())
continue;
if (!target.exists())
{
@@ -137,7 +138,7 @@ QDir OneSixInstance::reconstructAssets(std::shared_ptr<VersionFinal> version)
bool couldCopy = original.copy(target_path);
QLOG_DEBUG() << " Copying" << original_path << "to" << target_path
- << QString::number(couldCopy); // << original.errorString();
+ << QString::number(couldCopy); // << original.errorString();
}
}
@@ -205,8 +206,20 @@ bool OneSixInstance::prepareForLaunch(AuthSessionPtr account, QString &launchScr
{
launchScript += "cp " + librariesPath().absoluteFilePath(lib->storagePath()) + "\n";
}
- QString targetstr = version->id + "/" + version->id + ".jar";
- launchScript += "cp " + versionsPath().absoluteFilePath(targetstr) + "\n";
+ QString minecraftjarpath;
+ if (version->hasJarMods())
+ {
+ for (auto jarmod : version->jarMods)
+ {
+ launchScript += "cp " + jarmodsPath().absoluteFilePath(jarmod->name) + "\n";
+ }
+ minecraftjarpath = version->id + "/" + version->id + "-stripped.jar";
+ }
+ else
+ {
+ minecraftjarpath = version->id + "/" + version->id + ".jar";
+ }
+ launchScript += "cp " + versionsPath().absoluteFilePath(minecraftjarpath) + "\n";
}
launchScript += "mainClass " + version->mainClass + "\n";
@@ -231,12 +244,16 @@ bool OneSixInstance::prepareForLaunch(AuthSessionPtr account, QString &launchScr
}
QDir natives_dir(PathCombine(instanceRoot(), "natives/"));
launchScript += "windowTitle " + windowTitle() + "\n";
- for(auto native: version->getActiveNativeLibs())
+ for (auto native : version->getActiveNativeLibs())
{
QFileInfo finfo(PathCombine("libraries", native->storagePath()));
launchScript += "ext " + finfo.absoluteFilePath() + "\n";
}
launchScript += "natives " + natives_dir.absolutePath() + "\n";
+ for (auto trait : version->traits)
+ {
+ launchScript += "trait " + trait + "\n";
+ }
launchScript += "launcher onesix\n";
return true;
}
@@ -319,7 +336,7 @@ bool OneSixInstance::versionIsCustom()
{
I_D(const OneSixInstance);
auto ver = d->version;
- if(ver)
+ if (ver)
{
return !ver->isVanilla();
}
@@ -330,7 +347,7 @@ bool OneSixInstance::versionIsFTBPack()
{
I_D(const OneSixInstance);
auto ver = d->version;
- if(ver)
+ if (ver)
{
return ver->hasFtbPack();
}
@@ -352,11 +369,11 @@ void OneSixInstance::reloadVersion()
d->m_flags.remove(VersionBrokenFlag);
emit versionReloaded();
}
- catch(MMCError & error)
+ catch (MMCError &error)
{
d->version->clear();
d->m_flags.insert(VersionBrokenFlag);
- //TODO: rethrow to show some error message(s)?
+ // TODO: rethrow to show some error message(s)?
emit versionReloaded();
throw;
}
@@ -409,8 +426,8 @@ QString OneSixInstance::getStatusbarDescription()
{
traits.append(tr("broken"));
}
-
- if(traits.size())
+
+ if (traits.size())
{
return tr("Minecraft %1 (%2)").arg(intendedVersionId()).arg(traits.join(", "));
}
@@ -424,6 +441,12 @@ QDir OneSixInstance::librariesPath() const
{
return QDir::current().absoluteFilePath("libraries");
}
+
+QDir OneSixInstance::jarmodsPath() const
+{
+ return QDir(jarModsDir());
+}
+
QDir OneSixInstance::versionsPath() const
{
return QDir::current().absoluteFilePath("versions");
@@ -441,7 +464,7 @@ bool OneSixInstance::providesVersionFile() const
bool OneSixInstance::reload()
{
- if(BaseInstance::reload())
+ if (BaseInstance::reload())
{
try
{
@@ -480,3 +503,22 @@ QString OneSixInstance::jarModsDir() const
{
return PathCombine(instanceRoot(), "jarmods");
}
+
+QString OneSixInstance::libDir() const
+{
+ return PathCombine(minecraftRoot(), "lib");
+}
+
+QStringList OneSixInstance::extraArguments() const
+{
+ auto list = BaseInstance::extraArguments();
+ auto version = getFullVersion();
+ if (!version)
+ return list;
+ if (version->hasJarMods())
+ {
+ list.append({"-Dfml.ignoreInvalidMinecraftCertificates=true",
+ "-Dfml.ignorePatchDiscrepancies=true"});
+ }
+ return list;
+}
diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h
index b26ff752..80b197c4 100644
--- a/logic/OneSixInstance.h
+++ b/logic/OneSixInstance.h
@@ -40,6 +40,7 @@ public:
QString resourcePacksDir() const;
QString loaderModsDir() const;
QString coreModsDir() const;
+ QString libDir() const;
virtual QString instanceConfigFolder() const override;
virtual std::shared_ptr<Task> doUpdate() override;
@@ -82,13 +83,15 @@ public:
virtual bool menuActionEnabled(QString action_name) const override;
virtual QString getStatusbarDescription() override;
+ virtual QDir jarmodsPath() const;
virtual QDir librariesPath() const;
virtual QDir versionsPath() const;
virtual QStringList externalPatches() const;
virtual bool providesVersionFile() const;
bool reload() override;
-
+ virtual QStringList extraArguments() const override;
+
signals:
void versionReloaded();
diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp
index da2fd29c..230ef9a9 100644
--- a/logic/OneSixUpdate.cpp
+++ b/logic/OneSixUpdate.cpp
@@ -259,7 +259,7 @@ void OneSixUpdate::jarlibStart()
auto metacache = MMC->metacache();
auto entry = metacache->resolveEntry("versions", localPath);
job->addNetAction(CacheDownload::make(QUrl(urlstr), entry));
-
+ jarHashOnEntry = entry->md5sum;
jarlibDownloadJob.reset(job);
}
@@ -341,7 +341,36 @@ void OneSixUpdate::jarlibStart()
void OneSixUpdate::jarlibFinished()
{
- assetIndexStart();
+ OneSixInstance *inst = (OneSixInstance *)m_inst;
+ std::shared_ptr<VersionFinal> version = inst->getFullVersion();
+
+ // create stripped jar, if needed
+ if(version->hasJarMods())
+ {
+ //FIXME: good candidate for moving elsewhere (jar location resolving/version caching).
+ QString version_id = version->id;
+ QString localPath = version_id + "/" + version_id + ".jar";
+ QString strippedPath = version_id + "/" + version_id + "-stripped.jar";
+ auto metacache = MMC->metacache();
+ auto entry = metacache->resolveEntry("versions", localPath);
+ auto entryStripped = metacache->resolveEntry("versions", strippedPath);
+
+ QString fullJarPath = entry->getFullPath();
+ QString fullStrippedJarPath = entryStripped->getFullPath();
+
+ if(entry->md5sum != jarHashOnEntry || !QFileInfo::exists(fullStrippedJarPath))
+ {
+ stripJar(fullJarPath, fullStrippedJarPath);
+ }
+ }
+ if(version->traits.contains("legacyFML"))
+ {
+ fmllibsStart();
+ }
+ else
+ {
+ assetIndexStart();
+ }
}
void OneSixUpdate::jarlibFailed()
@@ -350,3 +379,184 @@ void OneSixUpdate::jarlibFailed()
QString failed_all = failed.join("\n");
emitFailed(tr("Failed to download the following files:\n%1\n\nPlease try again.").arg(failed_all));
}
+
+void OneSixUpdate::stripJar(QString origPath, QString newPath)
+{
+ QFileInfo runnableJar(newPath);
+ if (runnableJar.exists() && !QFile::remove(runnableJar.filePath()))
+ {
+ emitFailed("Failed to delete old minecraft.jar");
+ return;
+ }
+
+ // TaskStep(); // STEP 1
+ setStatus(tr("Creating stripped jar: Opening minecraft.jar ..."));
+
+ QuaZip zipOut(runnableJar.filePath());
+ if (!zipOut.open(QuaZip::mdCreate))
+ {
+ QFile::remove(runnableJar.filePath());
+ emitFailed("Failed to open the minecraft.jar for stripping");
+ return;
+ }
+ // Modify the jar
+ setStatus(tr("Creating stripped jar: Adding files..."));
+ if (!MergeZipFiles(&zipOut, origPath))
+ {
+ zipOut.close();
+ QFile::remove(runnableJar.filePath());
+ emitFailed("Failed to add " + origPath + " to the jar.");
+ return;
+ }
+}
+
+bool OneSixUpdate::MergeZipFiles(QuaZip *into, QString from)
+{
+ setStatus(tr("Installing mods: Adding ") + from + " ...");
+
+ QuaZip modZip(from);
+ modZip.open(QuaZip::mdUnzip);
+
+ QuaZipFile fileInsideMod(&modZip);
+ QuaZipFile zipOutFile(into);
+ for (bool more = modZip.goToFirstFile(); more; more = modZip.goToNextFile())
+ {
+ QString filename = modZip.getCurrentFileName();
+ if (filename.contains("META-INF"))
+ {
+ QLOG_INFO() << "Skipping META-INF " << filename << " from " << from;
+ continue;
+ }
+ QLOG_INFO() << "Adding file " << filename << " from " << from;
+
+ if (!fileInsideMod.open(QIODevice::ReadOnly))
+ {
+ QLOG_ERROR() << "Failed to open " << filename << " from " << from;
+ return false;
+ }
+ /*
+ QuaZipFileInfo old_info;
+ fileInsideMod.getFileInfo(&old_info);
+ */
+ QuaZipNewInfo info_out(fileInsideMod.getActualFileName());
+ /*
+ info_out.externalAttr = old_info.externalAttr;
+ */
+ if (!zipOutFile.open(QIODevice::WriteOnly, info_out))
+ {
+ QLOG_ERROR() << "Failed to open " << filename << " in the jar";
+ fileInsideMod.close();
+ return false;
+ }
+ if (!JlCompress::copyData(fileInsideMod, zipOutFile))
+ {
+ zipOutFile.close();
+ fileInsideMod.close();
+ QLOG_ERROR() << "Failed to copy data of " << filename << " into the jar";
+ return false;
+ }
+ zipOutFile.close();
+ fileInsideMod.close();
+ }
+ return true;
+}
+
+
+void OneSixUpdate::fmllibsStart()
+{
+ // Get the mod list
+ OneSixInstance *inst = (OneSixInstance *)m_inst;
+ std::shared_ptr<VersionFinal> fullversion = inst->getFullVersion();
+ bool forge_present = false;
+
+ QString version = inst->intendedVersionId();
+ auto & fmlLibsMapping = g_VersionFilterData.fmlLibsMapping;
+ if (!fmlLibsMapping.contains(version))
+ {
+ assetIndexStart();
+ return;
+ }
+
+ auto &libList = fmlLibsMapping[version];
+
+ // determine if we need some libs for FML or forge
+ setStatus(tr("Checking for FML libraries..."));
+ forge_present = (fullversion->versionFile("net.minecraftforge") != nullptr);
+ // we don't...
+ if (!forge_present)
+ {
+ assetIndexStart();
+ return;
+ }
+
+ // now check the lib folder inside the instance for files.
+ for (auto &lib : libList)
+ {
+ QFileInfo libInfo(PathCombine(inst->libDir(), lib.filename));
+ if (libInfo.exists())
+ continue;
+ fmlLibsToProcess.append(lib);
+ }
+
+ // if everything is in place, there's nothing to do here...
+ if (fmlLibsToProcess.isEmpty())
+ {
+ assetIndexStart();
+ return;
+ }
+
+ // download missing libs to our place
+ setStatus(tr("Dowloading FML libraries..."));
+ auto dljob = new NetJob("FML libraries");
+ auto metacache = MMC->metacache();
+ for (auto &lib : fmlLibsToProcess)
+ {
+ auto entry = metacache->resolveEntry("fmllibs", lib.filename);
+ QString urlString = lib.ours ? URLConstants::FMLLIBS_OUR_BASE_URL + lib.filename
+ : URLConstants::FMLLIBS_FORGE_BASE_URL + lib.filename;
+ dljob->addNetAction(CacheDownload::make(QUrl(urlString), entry));
+ }
+
+ connect(dljob, SIGNAL(succeeded()), SLOT(fmllibsFinished()));
+ connect(dljob, SIGNAL(failed()), SLOT(fmllibsFailed()));
+ connect(dljob, SIGNAL(progress(qint64, qint64)), SIGNAL(progress(qint64, qint64)));
+ legacyDownloadJob.reset(dljob);
+ legacyDownloadJob->start();
+}
+
+void OneSixUpdate::fmllibsFinished()
+{
+ legacyDownloadJob.reset();
+ if(!fmlLibsToProcess.isEmpty())
+ {
+ setStatus(tr("Copying FML libraries into the instance..."));
+ OneSixInstance *inst = (OneSixInstance *)m_inst;
+ auto metacache = MMC->metacache();
+ int index = 0;
+ for (auto &lib : fmlLibsToProcess)
+ {
+ progress(index, fmlLibsToProcess.size());
+ auto entry = metacache->resolveEntry("fmllibs", lib.filename);
+ auto path = PathCombine(inst->libDir(), lib.filename);
+ if(!ensureFilePathExists(path))
+ {
+ emitFailed(tr("Failed creating FML library folder inside the instance."));
+ return;
+ }
+ if (!QFile::copy(entry->getFullPath(), PathCombine(inst->libDir(), lib.filename)))
+ {
+ emitFailed(tr("Failed copying Forge/FML library: %1.").arg(lib.filename));
+ return;
+ }
+ index++;
+ }
+ progress(index, fmlLibsToProcess.size());
+ }
+ assetIndexStart();
+}
+
+void OneSixUpdate::fmllibsFailed()
+{
+ emitFailed("Game update failed: it was impossible to fetch the required FML libraries.");
+ return;
+} \ No newline at end of file
diff --git a/logic/OneSixUpdate.h b/logic/OneSixUpdate.h
index eac882b5..00f7c135 100644
--- a/logic/OneSixUpdate.h
+++ b/logic/OneSixUpdate.h
@@ -21,6 +21,8 @@
#include "logic/net/NetJob.h"
#include "logic/tasks/Task.h"
+#include "logic/VersionFilterData.h"
+#include <quazip.h>
class MinecraftVersion;
class OneSixInstance;
@@ -42,6 +44,10 @@ slots:
void jarlibFinished();
void jarlibFailed();
+ void fmllibsStart();
+ void fmllibsFinished();
+ void fmllibsFailed();
+
void assetIndexStart();
void assetIndexFinished();
void assetIndexFailed();
@@ -49,11 +55,16 @@ slots:
void assetsFinished();
void assetsFailed();
+ void stripJar(QString origPath, QString newPath);
+ bool MergeZipFiles(QuaZip *into, QString from);
private:
NetJobPtr specificVersionDownloadJob;
NetJobPtr jarlibDownloadJob;
+ NetJobPtr legacyDownloadJob;
// target version, determined during this task
std::shared_ptr<MinecraftVersion> targetVersion;
OneSixInstance *m_inst = nullptr;
+ QString jarHashOnEntry;
+ QList<FMLlib> fmlLibsToProcess;
};
diff --git a/logic/URNResolver.cpp b/logic/URNResolver.cpp
new file mode 100644
index 00000000..b6bdcf41
--- /dev/null
+++ b/logic/URNResolver.cpp
@@ -0,0 +1,98 @@
+#include "URNResolver.h"
+#include <logger/QsLog.h>
+#include "MultiMC.h"
+#include "logic/forge/ForgeVersionList.h"
+#include "logic/forge/ForgeVersion.h"
+
+QString unescapeNSS(QString RawNSS)
+{
+ QString NSS;
+ NSS.reserve(RawNSS.size());
+ enum
+ {
+ Normal,
+ FirstHex,
+ SecondHex
+ } ParseState = Normal;
+
+ QByteArray translator(" ");
+
+ for (auto ch : RawNSS)
+ {
+ if(ParseState == Normal)
+ {
+ if(ch == '%')
+ {
+ ParseState = FirstHex;
+ continue;
+ }
+ else
+ {
+ NSS.append(ch);
+ }
+ }
+ if(ParseState == FirstHex)
+ {
+ translator[0] = ch.toLower().unicode();
+ ParseState = SecondHex;
+ }
+ else if(ParseState == SecondHex)
+ {
+ translator[1] = ch.toLower().unicode();
+ auto result = QByteArray::fromHex(translator);
+ if (result[0] == '\0')
+ return NSS;
+ NSS.append(result);
+ ParseState = Normal;
+ }
+ }
+ return NSS;
+}
+
+bool URNResolver::parse(const QString &URN, QString &NID, QString &NSS)
+{
+ QRegExp URNPattern(
+ "^urn:([a-z0-9][a-z0-9-]{0,31}):(([a-z0-9()+,\\-.:=@;$_!*']|%[0-9a-f]{2})+).*",
+ Qt::CaseInsensitive);
+ if (URNPattern.indexIn(URN) == -1)
+ return false;
+ auto captures = URNPattern.capturedTexts();
+ QString RawNID = captures[1];
+ QString RawNSS = captures[2];
+
+ NID = RawNID.toLower();
+ NSS = unescapeNSS(RawNSS);
+ return true;
+}
+
+URNResolver::URNResolver()
+{
+}
+
+QVariant URNResolver::resolve(QString URN)
+{
+ QString NID, NSS;
+ parse(URN, NID, NSS);
+
+ if(NID != "x-mmc")
+ return QVariant();
+ auto parts = NSS.split(":");
+ if(parts.size() < 1)
+ return QVariant();
+ unsigned int version = parts[0].toUInt();
+ switch(version)
+ {
+ case 1:
+ return resolveV1(parts.mid(1));
+ default:
+ return QVariant();
+ }
+}
+
+/**
+ * TODO: implement.
+ */
+QVariant URNResolver::resolveV1(QStringList parts)
+{
+ return QVariant();
+}
diff --git a/logic/URNResolver.h b/logic/URNResolver.h
new file mode 100644
index 00000000..dfc7f5eb
--- /dev/null
+++ b/logic/URNResolver.h
@@ -0,0 +1,18 @@
+#pragma once
+#include <QString>
+#include <QMap>
+#include <memory>
+#include <QVariant>
+
+class URNResolver;
+typedef std::shared_ptr<URNResolver> URNResolverPtr;
+
+class URNResolver
+{
+public:
+ URNResolver();
+ QVariant resolve (QString URN);
+ static bool parse (const QString &URN, QString &NID, QString &NSS);
+private:
+ QVariant resolveV1 (QStringList parts);
+};
diff --git a/logic/VersionFile.cpp b/logic/VersionFile.cpp
index 4a850f97..222750d4 100644
--- a/logic/VersionFile.cpp
+++ b/logic/VersionFile.cpp
@@ -461,6 +461,7 @@ void VersionFile::applyTo(VersionFinal *version)
version->tweakers.removeAll(tweaker);
}
version->jarMods.append(jarMods);
+ version->traits.unite(traits);
if (shouldOverwriteLibs)
{
QList<OneSixLibraryPtr> libs;
diff --git a/logic/forge/ForgeData.cpp b/logic/VersionFilterData.cpp
index 700b847b..8322dad4 100644
--- a/logic/forge/ForgeData.cpp
+++ b/logic/VersionFilterData.cpp
@@ -1,8 +1,8 @@
-#include "ForgeData.h"
+#include "VersionFilterData.h"
-extern ForgeData g_forgeData = ForgeData();
+extern VersionFilterData g_VersionFilterData = VersionFilterData();
-ForgeData::ForgeData()
+VersionFilterData::VersionFilterData()
{
// 1.3.*
auto libs13 =
@@ -54,9 +54,11 @@ ForgeData::ForgeData()
{"bcprov-jdk15on-148.jar", "960dea7c9181ba0b17e8bab0c06a43f0a5f04e65", true},
{"deobfuscation_data_1.5.2.zip", "446e55cd986582c70fcf12cb27bc00114c5adfd9", false},
{"scala-library.jar", "458d046151ad179c85429ed7420ffb1eaf6ddf85", true}};
-
+
// don't use installers for those.
- forgeInstallerBlacklist = QSet<QString>({
- "1.5.2"
- });
+ forgeInstallerBlacklist = QSet<QString>({"1.5.2"});
+ legacyLaunchWhitelist =
+ QSet<QString>({"1.5.2", "1.5.1", "1.5", "1.4.7", "1.4.6", "1.4.5", "1.4.4", "1.4.3",
+ "1.4.2", "1.4.1", "1.4", "1.3.2", "1.3.1", "1.3", "1.2.5", "1.2.4",
+ "1.2.3", "1.2.2", "1.2.1", "1.1", "1.0.1", "1.0"});
}
diff --git a/logic/forge/ForgeData.h b/logic/VersionFilterData.h
index 27749778..562654a9 100644
--- a/logic/forge/ForgeData.h
+++ b/logic/VersionFilterData.h
@@ -10,12 +10,14 @@ struct FMLlib
bool ours;
};
-struct ForgeData
+struct VersionFilterData
{
- ForgeData();
+ VersionFilterData();
// mapping between minecraft versions and FML libraries required
QMap<QString, QList<FMLlib>> fmlLibsMapping;
// set of minecraft versions for which using forge installers is blacklisted
QSet<QString> forgeInstallerBlacklist;
+ // set of 'legacy' versions (ones that use the legacy launch)
+ QSet<QString> legacyLaunchWhitelist;
};
-extern ForgeData g_forgeData;
+extern VersionFilterData g_VersionFilterData;
diff --git a/logic/VersionFinal.cpp b/logic/VersionFinal.cpp
index 18bd360b..5bac4bcf 100644
--- a/logic/VersionFinal.cpp
+++ b/logic/VersionFinal.cpp
@@ -21,6 +21,7 @@
#include "OneSixVersionBuilder.h"
#include "OneSixInstance.h"
+#include "VersionFilterData.h"
#include <pathutils.h>
VersionFinal::VersionFinal(OneSixInstance *instance, QObject *parent)
@@ -63,17 +64,34 @@ bool VersionFinal::canRemove(const int index) const
return false;
}
+bool VersionFinal::preremove(VersionFilePtr versionfile)
+{
+ bool ok = true;
+ for(auto & jarmod: versionfile->jarMods)
+ {
+ QString fullpath =PathCombine(m_instance->jarModsDir(), jarmod->name);
+ QFileInfo finfo (fullpath);
+ if(finfo.exists(fullpath))
+ ok &= QFile::remove(fullpath);
+ }
+ return ok;
+}
+
bool VersionFinal::remove(const int index)
{
- if (canRemove(index) && QFile::remove(versionFiles.at(index)->filename))
+ if (!canRemove(index))
+ return false;
+ if(!preremove(versionFiles[index]))
{
- beginResetModel();
- versionFiles.removeAt(index);
- reapply(true);
- endResetModel();
- return true;
+ return false;
}
- return false;
+ if(!QFile::remove(versionFiles.at(index)->filename))
+ return false;
+ beginResetModel();
+ versionFiles.removeAt(index);
+ reapply(true);
+ endResetModel();
+ return true;
}
bool VersionFinal::remove(const QString id)
@@ -129,7 +147,11 @@ bool VersionFinal::removeFtbPack()
bool VersionFinal::isVanilla()
{
QDir patches(PathCombine(m_instance->instanceRoot(), "patches/"));
- return versionFiles.size() > 1 || QFile::exists(PathCombine(m_instance->instanceRoot(), "custom.json"));
+ if(versionFiles.size() > 1)
+ return false;
+ if(QFile::exists(PathCombine(m_instance->instanceRoot(), "custom.json")))
+ return false;
+ return true;
}
bool VersionFinal::revertToVanilla()
@@ -140,7 +162,16 @@ bool VersionFinal::revertToVanilla()
{
if ((*it)->fileId != "org.multimc.version.json")
{
- QFile::remove((*it)->filename);
+ if(!preremove(*it))
+ {
+ endResetModel();
+ return false;
+ }
+ if(!QFile::remove((*it)->filename))
+ {
+ endResetModel();
+ return false;
+ }
it = versionFiles.erase(it);
}
else
@@ -303,16 +334,15 @@ void VersionFinal::move(const int index, const MoveDirection direction)
{
return;
}
-
- VersionFilePtr we = versionFiles[index];
- VersionFilePtr them = versionFiles[theirIndex];
- if (!we || !them)
+ if(direction == MoveDown)
{
- return;
+ beginMoveRows(QModelIndex(), index, index, QModelIndex(), theirIndex+1);
+ }
+ else
+ {
+ beginMoveRows(QModelIndex(), index, index, QModelIndex(), theirIndex);
}
- beginMoveRows(QModelIndex(), index, index, QModelIndex(), theirIndex);
- versionFiles.replace(theirIndex, we);
- versionFiles.replace(index, them);
+ versionFiles.swap(index, theirIndex);
endMoveRows();
auto order = getExistingOrder();
@@ -396,5 +426,10 @@ void VersionFinal::finalize()
};
finalizeArguments(vanillaMinecraftArguments, vanillaProcessArguments);
finalizeArguments(minecraftArguments, processArguments);
+ // use legacy launch for this version if the version id is legacy
+ if(g_VersionFilterData.legacyLaunchWhitelist.contains(id))
+ {
+ traits.insert("legacyLaunch");
+ }
}
diff --git a/logic/VersionFinal.h b/logic/VersionFinal.h
index 71e43399..f3bf9771 100644
--- a/logic/VersionFinal.h
+++ b/logic/VersionFinal.h
@@ -81,6 +81,9 @@ public:
static std::shared_ptr<VersionFinal> fromJson(const QJsonObject &obj);
+private:
+ bool preremove(VersionFilePtr);
+
// data members
public:
/// the ID - determines which jar to use! ACTUALLY IMPORTANT!
diff --git a/logic/forge/ForgeInstaller.cpp b/logic/forge/ForgeInstaller.cpp
index 1204b855..3b13a7cd 100644
--- a/logic/forge/ForgeInstaller.cpp
+++ b/logic/forge/ForgeInstaller.cpp
@@ -20,7 +20,7 @@
#include "logic/tasks/Task.h"
#include "logic/OneSixInstance.h"
#include "logic/forge/ForgeVersionList.h"
-#include "ForgeData.h"
+#include "logic/VersionFilterData.h"
#include "gui/dialogs/ProgressDialog.h"
#include <quazip.h>
@@ -239,7 +239,16 @@ bool ForgeInstaller::addLegacy(OneSixInstance *to)
{
return false;
}
-
+ auto entry = MMC->metacache()->resolveEntry("minecraftforge", m_forge_version->filename());
+ finalPath = PathCombine(to->jarModsDir(), m_forge_version->filename());
+ if (!ensureFilePathExists(finalPath))
+ {
+ return false;
+ }
+ if (!QFile::copy(entry->getFullPath(),finalPath))
+ {
+ return false;
+ }
QJsonObject obj;
obj.insert("order", 5);
{
@@ -256,13 +265,15 @@ bool ForgeInstaller::addLegacy(OneSixInstance *to)
obj.insert("fileId", id());
obj.insert("version", m_forge_version->jobbuildver);
obj.insert("mcVersion", to->intendedVersionId());
- if (g_forgeData.fmlLibsMapping.contains(m_forge_version->mcver))
+ if (g_VersionFilterData.fmlLibsMapping.contains(m_forge_version->mcver))
{
QJsonArray traitsPlus;
traitsPlus.append(QString("legacyFML"));
obj.insert("+traits", traitsPlus);
}
-
+ auto fullversion = to->getFullVersion();
+ fullversion->remove("net.minecraftforge");
+
QFile file(filename(to->instanceRoot()));
if (!file.open(QFile::WriteOnly))
{
@@ -299,8 +310,7 @@ protected:
}
void prepare(ForgeVersionPtr forgeVersion)
{
- auto entry =
- MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename());
+ auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename());
auto installFunction = [this, entry, forgeVersion]()
{
if (!install(entry, forgeVersion))
@@ -313,7 +323,7 @@ protected:
reload();
}
};
-
+
if (entry->stale)
{
NetJob *fjob = new NetJob("Forge download");
diff --git a/logic/forge/ForgeVersion.cpp b/logic/forge/ForgeVersion.cpp
index fd4efc4b..3131ec39 100644
--- a/logic/forge/ForgeVersion.cpp
+++ b/logic/forge/ForgeVersion.cpp
@@ -1,5 +1,5 @@
#include "ForgeVersion.h"
-#include "ForgeData.h"
+#include "logic/VersionFilterData.h"
#include <QObject>
QString ForgeVersion::name()
@@ -39,7 +39,7 @@ bool ForgeVersion::usesInstaller()
{
if(installer_url.isEmpty())
return false;
- if(g_forgeData.forgeInstallerBlacklist.contains(mcver))
+ if(g_VersionFilterData.forgeInstallerBlacklist.contains(mcver))
return false;
return true;
}
diff --git a/logic/forge/ForgeVersionList.cpp b/logic/forge/ForgeVersionList.cpp
index c873bab7..545fff42 100644
--- a/logic/forge/ForgeVersionList.cpp
+++ b/logic/forge/ForgeVersionList.cpp
@@ -421,6 +421,7 @@ void ForgeListLoadTask::listFailed()
QLOG_ERROR() << "Getting forge version list failed for reasons unknown.";
}
}
+
void ForgeListLoadTask::gradleListFailed()
{
auto reply = gradleListDownload->m_reply;
diff --git a/logic/forge/ForgeVersionList.h b/logic/forge/ForgeVersionList.h
index c848e9b8..2c020b0f 100644
--- a/logic/forge/ForgeVersionList.h
+++ b/logic/forge/ForgeVersionList.h
@@ -41,6 +41,8 @@ public:
virtual BaseVersionPtr getLatestStable() const;
+ ForgeVersionPtr findVersionByVersionNr(QString version);
+
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual int columnCount(const QModelIndex &parent) const;
diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp
index ec2f2d21..fb6daae8 100644
--- a/logic/lists/MinecraftVersionList.cpp
+++ b/logic/lists/MinecraftVersionList.cpp
@@ -113,28 +113,6 @@ MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
m_list = vlist;
m_currentStable = NULL;
vlistReply = nullptr;
- legacyWhitelist.insert("1.5.2");
- legacyWhitelist.insert("1.5.1");
- legacyWhitelist.insert("1.5");
- legacyWhitelist.insert("1.4.7");
- legacyWhitelist.insert("1.4.6");
- legacyWhitelist.insert("1.4.5");
- legacyWhitelist.insert("1.4.4");
- legacyWhitelist.insert("1.4.3");
- legacyWhitelist.insert("1.4.2");
- legacyWhitelist.insert("1.4.1");
- legacyWhitelist.insert("1.4");
- legacyWhitelist.insert("1.3.2");
- legacyWhitelist.insert("1.3.1");
- legacyWhitelist.insert("1.3");
- legacyWhitelist.insert("1.2.5");
- legacyWhitelist.insert("1.2.4");
- legacyWhitelist.insert("1.2.3");
- legacyWhitelist.insert("1.2.2");
- legacyWhitelist.insert("1.2.1");
- legacyWhitelist.insert("1.1");
- legacyWhitelist.insert("1.0.1");
- legacyWhitelist.insert("1.0");
}
MCVListLoadTask::~MCVListLoadTask()
@@ -240,25 +218,21 @@ void MCVListLoadTask::list_downloaded()
// OneSix or Legacy. use filter to determine type
if (versionTypeStr == "release")
{
- legacyLaunch = legacyWhitelist.contains(versionID);
is_latest = (versionID == latestReleaseID);
is_snapshot = false;
}
else if (versionTypeStr == "snapshot") // It's a snapshot... yay
{
- legacyLaunch = legacyWhitelist.contains(versionID);
is_latest = (versionID == latestSnapshotID);
is_snapshot = true;
}
else if (versionTypeStr == "old_alpha")
{
- legacyLaunch = false;
is_latest = false;
is_snapshot = false;
}
else if (versionTypeStr == "old_beta")
{
- legacyLaunch = true;
is_latest = false;
is_snapshot = false;
}
diff --git a/logic/lists/MinecraftVersionList.h b/logic/lists/MinecraftVersionList.h
index 167f4d11..8f748d34 100644
--- a/logic/lists/MinecraftVersionList.h
+++ b/logic/lists/MinecraftVersionList.h
@@ -72,5 +72,4 @@ protected:
QNetworkReply *vlistReply;
MinecraftVersionList *m_list;
MinecraftVersion *m_currentStable;
- QSet<QString> legacyWhitelist;
};