summaryrefslogtreecommitdiffstats
path: root/libmultimc
diff options
context:
space:
mode:
authorTakSuyu <taksuyu@gmail.com>2013-07-27 12:55:51 -0700
committerTakSuyu <taksuyu@gmail.com>2013-07-27 12:55:51 -0700
commitdc39d093396c9a0ed4f03d81f95fcc8fa5705b65 (patch)
treeb88bf5fa692de82ce3418bdf5c55e9cd9eff37bc /libmultimc
parent44498f98945b7501486da35c5fdc32f94a2be080 (diff)
parenta7a84d4dbb58565f108cb0886da6cb786e34d10d (diff)
downloadMultiMC-dc39d093396c9a0ed4f03d81f95fcc8fa5705b65.tar
MultiMC-dc39d093396c9a0ed4f03d81f95fcc8fa5705b65.tar.gz
MultiMC-dc39d093396c9a0ed4f03d81f95fcc8fa5705b65.tar.lz
MultiMC-dc39d093396c9a0ed4f03d81f95fcc8fa5705b65.tar.xz
MultiMC-dc39d093396c9a0ed4f03d81f95fcc8fa5705b65.zip
Merge remote-tracking branch 'upstream/master'
Conflicts: gui/mainwindow.cpp
Diffstat (limited to 'libmultimc')
-rw-r--r--libmultimc/CMakeLists.txt6
-rw-r--r--libmultimc/include/fullversion.h69
-rw-r--r--libmultimc/include/fullversionfactory.h25
-rw-r--r--libmultimc/include/gameupdatetask.h75
-rw-r--r--libmultimc/include/instance.h46
-rw-r--r--libmultimc/include/library.h219
-rw-r--r--libmultimc/src/fullversion.cpp5
-rw-r--r--libmultimc/src/fullversionfactory.cpp206
-rw-r--r--libmultimc/src/gameupdatetask.cpp235
-rw-r--r--libmultimc/src/instance.cpp15
-rw-r--r--libmultimc/src/library.cpp37
11 files changed, 766 insertions, 172 deletions
diff --git a/libmultimc/CMakeLists.txt b/libmultimc/CMakeLists.txt
index 0209f8a4..8adee1ec 100644
--- a/libmultimc/CMakeLists.txt
+++ b/libmultimc/CMakeLists.txt
@@ -32,6 +32,9 @@ include/instversionlist.h
include/minecraftversion.h
include/minecraftversionlist.h
+include/library.h
+include/fullversion.h
+include/fullversionfactory.h
# Tasks
include/task.h
@@ -63,6 +66,9 @@ src/instversionlist.cpp
src/minecraftversion.cpp
src/minecraftversionlist.cpp
+src/library.cpp
+src/fullversion.cpp
+src/fullversionfactory.cpp
# Tasks
src/task.cpp
diff --git a/libmultimc/include/fullversion.h b/libmultimc/include/fullversion.h
new file mode 100644
index 00000000..523ac87c
--- /dev/null
+++ b/libmultimc/include/fullversion.h
@@ -0,0 +1,69 @@
+#pragma once
+#include <QString>
+
+class Library;
+
+class FullVersion
+{
+public:
+ FullVersion()
+ {
+ minimumLauncherVersion = 0xDEADBEEF;
+ isLegacy = false;
+ }
+ // the ID - determines which jar to use! ACTUALLY IMPORTANT!
+ QString id;
+ // do we actually care about parsing this?
+ QString time;
+ // I don't think we do.
+ QString releaseTime;
+ // eh, not caring - "release" or "snapshot"
+ QString type;
+ /*
+ * DEPRECATED: Old versions of the new vanilla launcher used this
+ * ex: "username_session_version"
+ */
+ QString processArguments;
+ /*
+ * arguments that should be used for launching minecraft
+ *
+ * ex: "--username ${auth_player_name} --session ${auth_session}
+ * --version ${version_name} --gameDir ${game_directory} --assetsDir ${game_assets}"
+ */
+ QString minecraftArguments;
+ /*
+ * the minimum launcher version required by this version ... current is 4 (at point of writing)
+ */
+ int minimumLauncherVersion;
+ /*
+ * The main class to load first
+ */
+ QString mainClass;
+
+ // the list of libs. just the names for now. expand to full-blown strutures!
+ QList<QSharedPointer<Library> > libraries;
+
+ // is this actually a legacy version? if so, none of the other stuff here will be ever used.
+ // added by FullVersionFactory
+ bool isLegacy;
+
+/*
+FIXME: add support for those rules here? Looks like a pile of quick hacks to me though.
+
+ "rules": [
+ {
+ "action": "allow"
+ },
+ {
+ "action": "disallow",
+ "os": {
+ "name": "osx",
+ "version": "^10\\.5\\.\\d$"
+ }
+ }
+ ],
+ "incompatibilityReason": "There is a bug in LWJGL which makes it incompatible with OSX 10.5.8. Please go to New Profile and use 1.5.2 for now. Sorry!"
+}
+*/
+ // QList<Rule> rules;
+}; \ No newline at end of file
diff --git a/libmultimc/include/fullversionfactory.h b/libmultimc/include/fullversionfactory.h
new file mode 100644
index 00000000..60e5c983
--- /dev/null
+++ b/libmultimc/include/fullversionfactory.h
@@ -0,0 +1,25 @@
+#pragma once
+#include <QtCore>
+
+struct FullVersion;
+class Rule;
+
+class FullVersionFactory
+{
+public:
+ enum Error
+ {
+ AllOK, // all parsed OK
+ ParseError, // the file was corrupted somehow
+ UnsupportedVersion // the file was meant for a launcher version we don't support (yet)
+ } m_error;
+ QString error_string;
+
+public:
+ FullVersionFactory();
+ QSharedPointer<FullVersion> parse(QByteArray data);
+private:
+ QSharedPointer<FullVersion> parse4(QJsonObject root, QSharedPointer<FullVersion> product);
+ QList<QSharedPointer<Rule> > parse4rules(QJsonObject & baseObj);
+ QStringList legacyWhitelist;
+}; \ No newline at end of file
diff --git a/libmultimc/include/gameupdatetask.h b/libmultimc/include/gameupdatetask.h
index c3f84356..b56c448b 100644
--- a/libmultimc/include/gameupdatetask.h
+++ b/libmultimc/include/gameupdatetask.h
@@ -22,47 +22,15 @@
#include <QNetworkAccessManager>
#include <QUrl>
+#include "dlqueue.h"
#include "task.h"
#include "loginresponse.h"
#include "instance.h"
#include "libmmc_config.h"
-class FileToDownload;
-typedef QSharedPointer<FileToDownload> FileToDownloadPtr;
-
-class FileToDownload : public QObject
-{
- Q_OBJECT
-
- /*!
- * The URL to download the file from.
- */
- Q_PROPERTY(QUrl url READ url WRITE setURL)
-
- /*!
- * The path to download to.
- * This path is relative to the instance's root directory.
- */
- Q_PROPERTY(QString path READ path WRITE setPath)
-
-private:
- FileToDownload(const QUrl &url, const QString &path, QObject *parent = 0);
-public:
- static FileToDownloadPtr Create(const QUrl &url, const QString &path, QObject *parent = 0);
-
- virtual QUrl url() const { return m_dlURL; }
- virtual void setURL(const QUrl &url) { m_dlURL = url; }
-
- virtual QString path() const { return m_dlPath; }
- virtual void setPath(const QString &path) { m_dlPath = path; }
-
-private:
- QUrl m_dlURL;
- QString m_dlPath;
-};
-
+class MinecraftVersion;
/*!
* The game update task is the task that handles downloading instances' files.
@@ -92,9 +60,6 @@ public:
virtual void executeTask();
- virtual bool downloadFile(const FileToDownloadPtr file);
-
-
//////////////////////
// STATE AND STATUS //
//////////////////////
@@ -110,6 +75,10 @@ public:
*/
virtual QString getStateMessage(int state);
+private:
+ void getLegacyJar();
+ void determineNewVersion();
+
public slots:
/*!
@@ -122,7 +91,15 @@ public slots:
private slots:
- virtual void updateDownloadProgress(qint64 current, qint64 total);
+ void updateDownloadProgress(qint64 current, qint64 total);
+ void legacyJarFinished();
+ void legacyJarFailed();
+
+ void versionFileFinished();
+ void versionFileFailed();
+
+ void jarlibFinished();
+ void jarlibFailed();
signals:
/*!
@@ -143,23 +120,8 @@ private:
///////////
Instance *m_inst;
-
LoginResponse m_response;
- QNetworkAccessManager *netMgr;
-
-
-
- ////////////////////////
- // FILE DOWNLOAD LIST //
- ////////////////////////
-
- // List of URLs that the game updater will need to download.
- QList<FileToDownloadPtr> m_downloadList;
- int m_currentDownload;
-
-
-
////////////////////////////
// STATE AND STATUS STUFF //
////////////////////////////
@@ -184,6 +146,13 @@ private:
// Finished
StateFinished
};
+ JobListPtr legacyDownloadJob;
+ JobListPtr specificVersionDownloadJob;
+ JobListPtr jarlibDownloadJob;
+ JobListQueue download_queue;
+
+ // target version, determined during this task
+ MinecraftVersion *targetVersion;
};
diff --git a/libmultimc/include/instance.h b/libmultimc/include/instance.h
index 717f8816..f6857cd8 100644
--- a/libmultimc/include/instance.h
+++ b/libmultimc/include/instance.h
@@ -80,16 +80,7 @@ class LIBMULTIMC_EXPORT Instance : public QObject
* This returns true if shouldForceUpdate game is true or if the intended and
* current versions don't match.
*/
- Q_PROPERTY(bool shouldUpdateGame READ shouldUpdateGame STORED false)
-
- /*!
- * Whether or not the game will be forced to update on the next launch.
- * If this is set to true, shouldUpdateGame will be true, regardless of whether or not
- * the current and intended versions match.
- * It should be noted that this is set to false automatically when game updates are run.
- */
- Q_PROPERTY(bool shouldForceUpdateGame READ shouldForceUpdateGame WRITE setShouldForceUpdateGame)
-
+ Q_PROPERTY(bool shouldUpdate READ shouldUpdate WRITE setShouldUpdate)
/*!
* The instance's current version.
@@ -125,8 +116,11 @@ class LIBMULTIMC_EXPORT Instance : public QObject
*/
Q_PROPERTY(qint64 lastCurrentVersionUpdate READ lastCurrentVersionUpdate WRITE setLastCurrentVersionUpdate)
-
-
+ /*!
+ * Is the instance a new launcher instance? Get/Set
+ */
+ Q_PROPERTY(bool isForNewLauncher READ isForNewLauncher WRITE setIsForNewLauncher)
+
// Dirs
//! Path to the instance's .minecraft folder.
Q_PROPERTY(QString minecraftDir READ minecraftDir STORED false)
@@ -236,14 +230,17 @@ public:
virtual QString intendedVersion() const { return settings().get("IntendedJarVersion").toString(); }
virtual void setIntendedVersion(QString val) { settings().set("IntendedJarVersion", val); }
- virtual bool shouldUpdateGame() const
- { return shouldForceUpdateGame() || intendedVersion() != currentVersion(); }
-
- virtual bool shouldForceUpdateGame() const { return settings().get("ShouldForceUpdate").toBool(); }
- virtual void setShouldForceUpdateGame(bool val) { settings().set("ShouldForceUpdate", val); }
-
-
-
+ virtual bool shouldUpdate() const
+ {
+ QVariant var = settings().get("ShouldUpdate");
+ if(!var.isValid() || var.toBool() == false)
+ {
+ return intendedVersion() != currentVersion();
+ }
+ return true;
+ }
+ virtual void setShouldUpdate(bool val) { settings().set("ShouldUpdate", val); }
+
//// Timestamps ////
virtual qint64 lastLaunch() const { return settings().get("lastLaunchTime").value<qint64>(); }
@@ -256,6 +253,15 @@ public:
virtual qint64 lastCurrentVersionUpdate() const { return settings().get("lastVersionUpdate").value<qint64>(); }
virtual void setLastCurrentVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); }
+ virtual bool isForNewLauncher()
+ {
+ return settings().get("IsForNewLauncher").value<bool>();
+ }
+
+ virtual void setIsForNewLauncher(bool value = true)
+ {
+ settings().set("IsForNewLauncher", value);
+ }
////// Directories //////
QString minecraftDir() const;
diff --git a/libmultimc/include/library.h b/libmultimc/include/library.h
new file mode 100644
index 00000000..8d97b4a6
--- /dev/null
+++ b/libmultimc/include/library.h
@@ -0,0 +1,219 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <QtCore>
+
+class Library;
+
+enum OpSys
+{
+ Os_Windows,
+ Os_Linux,
+ Os_OSX,
+ Os_Other
+};
+
+OpSys OpSys_fromString(QString);
+
+#ifdef Q_OS_MAC
+ #define currentSystem Os_OSX
+#endif
+
+#ifdef Q_OS_LINUX
+ #define currentSystem Os_Linux
+#endif
+
+#ifdef Q_OS_WIN32
+ #define currentSystem Os_Windows
+#endif
+
+#ifndef currentSystem
+ #define currentSystem Os_Other
+#endif
+
+
+enum RuleAction
+{
+ Allow,
+ Disallow,
+ Defer
+};
+
+RuleAction RuleAction_fromString(QString);
+
+class Rule
+{
+protected:
+ RuleAction m_result;
+ virtual bool applies(Library * parent) = 0;
+public:
+ Rule(RuleAction result)
+ :m_result(result) {}
+ virtual ~Rule(){};
+ RuleAction apply(Library * parent)
+ {
+ if(applies(parent))
+ return m_result;
+ else
+ return Defer;
+ };
+};
+
+class OsRule : public Rule
+{
+private:
+ // the OS
+ OpSys m_system;
+ // the OS version regexp
+ QString m_version_regexp;
+protected:
+ virtual bool applies ( Library* )
+ {
+ return (m_system == currentSystem);
+ }
+ OsRule(RuleAction result, OpSys system, QString version_regexp)
+ : Rule(result), m_system(system), m_version_regexp(version_regexp) {}
+public:
+ static QSharedPointer<OsRule> create(RuleAction result, OpSys system, QString version_regexp)
+ {
+ return QSharedPointer<OsRule> (new OsRule(result, system, version_regexp));
+ }
+};
+
+class ImplicitRule : public Rule
+{
+protected:
+ virtual bool applies ( Library* )
+ {
+ return true;
+ }
+ ImplicitRule(RuleAction result)
+ : Rule(result) {}
+public:
+ static QSharedPointer<ImplicitRule> create(RuleAction result)
+ {
+ return QSharedPointer<ImplicitRule> (new ImplicitRule(result));
+ }
+};
+
+class Library
+{
+private:
+ // basic values used internally (so far)
+ QString m_name;
+ QString m_base_url;
+ QList<QSharedPointer<Rule> > m_rules;
+
+ // derived values used for real things
+ /// where to store the lib locally
+ QString m_storage_path;
+ /// where to download the lib from
+ QString m_download_path;
+ /// is this lib actuall active on the current OS?
+ bool m_is_active;
+
+ // native lib?
+ bool m_is_native;
+ QMap<OpSys, QString> m_native_suffixes;
+public:
+ QStringList extract_excludes;
+
+public:
+ /// finalize the library, processing the input values into derived values and state
+ void finalize()
+ {
+ QStringList parts = m_name.split(':');
+ QString relative = parts[0];
+ relative.replace('.','/');
+ relative += '/' + parts[1] + '/' + parts[2] + '/' + parts[1] + '-' + parts[2];
+ if(!m_is_native)
+ relative += ".jar";
+ else
+ {
+ if(m_native_suffixes.contains(currentSystem))
+ {
+ relative += "-" + m_native_suffixes[currentSystem] + ".jar";
+ }
+ else
+ {
+ // really, bad.
+ relative += ".jar";
+ }
+ }
+ m_storage_path = relative;
+ m_download_path = m_base_url + relative;
+
+ if(m_rules.empty())
+ {
+ m_is_active = true;
+ }
+ else
+ {
+ RuleAction result = Disallow;
+ for(auto rule: m_rules)
+ {
+ RuleAction temp = rule->apply( this );
+ if(temp != Defer)
+ result = temp;
+ }
+ m_is_active = (result == Allow);
+ }
+ if(m_is_native)
+ {
+ m_is_active = m_is_active && m_native_suffixes.contains(currentSystem);
+ }
+ };
+
+ Library(QString name)
+ {
+ m_is_native = false;
+ m_is_native = false;
+ m_name = name;
+ m_base_url = "https://s3.amazonaws.com/Minecraft.Download/libraries/";
+ }
+
+ void setName(QString name)
+ {
+ m_name = name;
+ }
+
+ void setBaseUrl(QString base_url)
+ {
+ m_base_url = base_url;
+ }
+
+ void setIsNative()
+ {
+ m_is_native = true;
+ }
+
+ void addNative(OpSys os, QString suffix)
+ {
+ m_is_native = true;
+ m_native_suffixes[os] = suffix;
+ }
+
+ void setRules(QList<QSharedPointer<Rule> > rules)
+ {
+ m_rules = rules;
+ }
+
+ bool applies()
+ {
+ return m_is_active;
+ }
+};
diff --git a/libmultimc/src/fullversion.cpp b/libmultimc/src/fullversion.cpp
new file mode 100644
index 00000000..53664c2a
--- /dev/null
+++ b/libmultimc/src/fullversion.cpp
@@ -0,0 +1,5 @@
+#include <QtCore>
+#include "fullversion.h"
+#include <library.h>
+
+// ECHO, echo, echo, .... \ No newline at end of file
diff --git a/libmultimc/src/fullversionfactory.cpp b/libmultimc/src/fullversionfactory.cpp
new file mode 100644
index 00000000..bb55b4a9
--- /dev/null
+++ b/libmultimc/src/fullversionfactory.cpp
@@ -0,0 +1,206 @@
+#include "fullversionfactory.h"
+#include "fullversion.h"
+#include <library.h>
+
+class LibraryFinalizer
+{
+public:
+ LibraryFinalizer(QSharedPointer<Library> library)
+ {
+ m_library = library;
+ }
+
+ QSharedPointer<Library> m_library;
+};
+
+// Library rules (if any)
+QList<QSharedPointer<Rule> > FullVersionFactory::parse4rules(QJsonObject & baseObj)
+{
+ QList<QSharedPointer<Rule> > rules;
+ auto rulesVal = baseObj.value("rules");
+ if(rulesVal.isArray())
+ {
+ QJsonArray ruleList = rulesVal.toArray();
+ for(auto ruleVal : ruleList)
+ {
+ QSharedPointer<Rule> rule;
+ if(!ruleVal.isObject())
+ continue;
+ auto ruleObj = ruleVal.toObject();
+ auto actionVal = ruleObj.value("action");
+ if(!actionVal.isString())
+ continue;
+ auto action = RuleAction_fromString(actionVal.toString());
+ if(action == Defer)
+ continue;
+
+ auto osVal = ruleObj.value("os");
+ if(!osVal.isObject())
+ {
+ // add a new implicit action rule
+ rules.append(ImplicitRule::create(action));
+ }
+ else
+ {
+ auto osObj = osVal.toObject();
+ auto osNameVal = osObj.value("name");
+ if(!osNameVal.isString())
+ continue;
+ OpSys requiredOs = OpSys_fromString(osNameVal.toString());
+ QString versionRegex = osObj.value("version").toString();
+ // add a new OS rule
+ rules.append(OsRule::create(action, requiredOs, versionRegex));
+ }
+ }
+ }
+ return rules;
+}
+
+
+QSharedPointer<FullVersion> FullVersionFactory::parse4(QJsonObject root, QSharedPointer<FullVersion> fullVersion)
+{
+ fullVersion->id = root.value("id").toString();
+
+ // if it's on our legacy list, it's legacy
+ if(legacyWhitelist.contains(fullVersion->id))
+ fullVersion->isLegacy = true;
+
+ fullVersion->mainClass = root.value("mainClass").toString();
+ auto procArgsValue = root.value("processArguments");
+ if(procArgsValue.isString())
+ {
+ fullVersion->processArguments = procArgsValue.toString();
+ QString toCompare = fullVersion->processArguments.toLower();
+ if(toCompare == "legacy")
+ {
+ fullVersion->minecraftArguments = " ${auth_player_name} ${auth_session}";
+ fullVersion->isLegacy = true;
+ }
+ else if(toCompare == "username_session")
+ {
+ fullVersion->minecraftArguments = "--username ${auth_player_name} --session ${auth_session}";
+ }
+ else if(toCompare == "username_session_version")
+ {
+ fullVersion->minecraftArguments = "--username ${auth_player_name} --session ${auth_session} --version ${profile_name}";
+ }
+ }
+
+ auto minecraftArgsValue = root.value("minecraftArguments");
+ if(minecraftArgsValue.isString())
+ {
+ fullVersion->minecraftArguments = minecraftArgsValue.toString();
+ }
+
+ fullVersion->releaseTime = root.value("releaseTime").toString();
+ fullVersion->time = root.value("time").toString();
+
+ // Iterate through the list, if it's a list.
+ auto librariesValue = root.value("libraries");
+ if(!librariesValue.isArray())
+ return fullVersion;
+
+ QJsonArray libList = root.value("libraries").toArray();
+ for (auto libVal : libList)
+ {
+ if (!libVal.isObject())
+ {
+ continue;
+ }
+
+ QJsonObject libObj = libVal.toObject();
+
+ // Library name
+ auto nameVal = libObj.value("name");
+ if(!nameVal.isString())
+ continue;
+ QSharedPointer<Library> library(new Library(nameVal.toString()));
+
+ // Extract excludes (if any)
+ auto extractVal = libObj.value("extract");
+ if(extractVal.isObject())
+ {
+ QStringList excludes;
+ auto extractObj = extractVal.toObject();
+ auto excludesVal = extractObj.value("exclude");
+ if(!excludesVal.isArray())
+ goto SKIP_EXTRACTS;
+ auto excludesList = excludesVal.toArray();
+ for(auto excludeVal : excludesList)
+ {
+ if(excludeVal.isString())
+ excludes.append(excludeVal.toString());
+ }
+ library->extract_excludes = excludes;
+ }
+ SKIP_EXTRACTS:
+
+ auto nativesVal = libObj.value("natives");
+ if(nativesVal.isObject())
+ {
+ library->setIsNative();
+ auto nativesObj = nativesVal.toObject();
+ auto iter = nativesObj.begin();
+ while(iter != nativesObj.end())
+ {
+ auto osType = OpSys_fromString(iter.key());
+ if(osType == Os_Other)
+ continue;
+ if(!iter.value().isString())
+ continue;
+ library->addNative(osType, iter.value().toString());
+ iter++;
+ }
+ }
+ library->setRules(parse4rules(libObj));
+ library->finalize();
+ fullVersion->libraries.append(library);
+ }
+ return fullVersion;
+}
+
+QSharedPointer<FullVersion> FullVersionFactory::parse(QByteArray data)
+{
+ QSharedPointer<FullVersion> readVersion(new FullVersion());
+
+ QJsonParseError jsonError;
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &jsonError);
+
+ if (jsonError.error != QJsonParseError::NoError)
+ {
+ error_string = QString( "Error reading version file :") + " " + jsonError.errorString();
+ m_error = FullVersionFactory::ParseError;
+ return QSharedPointer<FullVersion>();
+ }
+
+ if(!jsonDoc.isObject())
+ {
+ error_string = "Error reading version file.";
+ m_error = FullVersionFactory::ParseError;
+ return QSharedPointer<FullVersion>();
+ }
+ QJsonObject root = jsonDoc.object();
+
+ readVersion->minimumLauncherVersion = root.value("minimumLauncherVersion").toDouble();
+ switch(readVersion->minimumLauncherVersion)
+ {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ return parse4(root, readVersion);
+ // ADD MORE HERE :D
+ default:
+ error_string = "Version file was for an unrecognized launcher version. RIP";
+ m_error = FullVersionFactory::UnsupportedVersion;
+ return QSharedPointer<FullVersion>();
+ }
+}
+
+
+FullVersionFactory::FullVersionFactory()
+{
+ m_error = FullVersionFactory::AllOK;
+ legacyWhitelist.append("1.5.1");
+ legacyWhitelist.append("1.5.2");
+}
diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp
index c718ce71..bae85c17 100644
--- a/libmultimc/src/gameupdatetask.cpp
+++ b/libmultimc/src/gameupdatetask.cpp
@@ -25,40 +25,34 @@
#include <QDebug>
#include "minecraftversionlist.h"
+#include "fullversionfactory.h"
+#include <fullversion.h>
#include "pathutils.h"
-#include "netutils.h"
+
GameUpdateTask::GameUpdateTask(const LoginResponse &response, Instance *inst, QObject *parent) :
Task(parent), m_response(response)
{
m_inst = inst;
m_updateState = StateInit;
- m_currentDownload = 0;
}
void GameUpdateTask::executeTask()
{
updateStatus();
- QNetworkAccessManager networkMgr;
- netMgr = &networkMgr;
-
// Get a pointer to the version object that corresponds to the instance's version.
- MinecraftVersion *targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().
+ targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().
findVersion(m_inst->intendedVersion());
- Q_ASSERT_X(targetVersion != NULL, "game update", "instance's intended version is not an actual version");
-
- // Make directories
- QDir binDir(m_inst->binDir());
- if (!binDir.exists() && !binDir.mkpath("."))
+ if(targetVersion == NULL)
{
- error("Failed to create bin folder.");
+ //Q_ASSERT_X(targetVersion != NULL, "game update", "instance's intended version is not an actual version");
+ setState(StateFinished);
+ emit gameUpdateComplete(m_response);
return;
}
-
-
/////////////////////////
// BUILD DOWNLOAD LIST //
/////////////////////////
@@ -66,90 +60,150 @@ void GameUpdateTask::executeTask()
setState(StateDetermineURLs);
+ if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16)
+ {
+ determineNewVersion();
+ }
+ else
+ {
+ getLegacyJar();
+ }
+ QEventLoop loop;
+ loop.exec();
+}
+
+void GameUpdateTask::determineNewVersion()
+{
+ QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
+ urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json";
+ auto dljob = DownloadJob::create(QUrl(urlstr));
+ specificVersionDownloadJob.reset(new JobList());
+ specificVersionDownloadJob->add(dljob);
+ connect(specificVersionDownloadJob.data(), SIGNAL(finished()), SLOT(versionFileFinished()));
+ connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed()));
+ connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ download_queue.enqueue(specificVersionDownloadJob);
+}
+
+void GameUpdateTask::versionFileFinished()
+{
+ JobPtr firstJob = specificVersionDownloadJob->getFirstJob();
+ auto DlJob = firstJob.dynamicCast<DownloadJob>();
+ FullVersionFactory parser;
+ auto version = parser.parse(DlJob->m_data);
- // Add the URL for minecraft.jar
+ if(!version)
+ {
+ error(parser.error_string);
+ exit(0);
+ }
+
+ if(version->isLegacy)
+ {
+ getLegacyJar();
+ return;
+ }
+ // save the version file in $instanceId/version.json and versions/$version/$version.json
+ QString version_id = targetVersion->descriptor();
+ QString mc_dir = m_inst->minecraftDir();
+ QString inst_dir = m_inst->rootDir();
+ QString version1 = PathCombine(inst_dir, "/version.json");
+ QString version2 = QString("versions/") + version_id + "/" + version_id + ".json";
+ DownloadJob::ensurePathExists(version1);
+ DownloadJob::ensurePathExists(version2);
+ QFile vfile1 (version1);
+ QFile vfile2 (version2);
+ vfile1.open(QIODevice::Truncate | QIODevice::WriteOnly );
+ vfile2.open(QIODevice::Truncate | QIODevice::WriteOnly );
+ vfile1.write(DlJob->m_data);
+ vfile2.write(DlJob->m_data);
+ vfile1.close();
+ vfile2.close();
+
+ // download the right jar, save it in versions/$version/$version.jar
+ QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
+ urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".jar";
+ QString targetstr ("versions/");
+ targetstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".jar";
+ auto dljob = DownloadJob::create(QUrl(urlstr), targetstr);
+
+ jarlibDownloadJob.reset(new JobList());
+ jarlibDownloadJob->add(dljob);
+ connect(jarlibDownloadJob.data(), SIGNAL(finished()), SLOT(jarlibFinished()));
+ connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed()));
+ connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
+ // determine and download all the libraries, save them in libraries/whatever...
+ download_queue.enqueue(jarlibDownloadJob);
+}
+
+void GameUpdateTask::jarlibFinished()
+{
+ m_inst->setCurrentVersion(targetVersion->descriptor());
+ m_inst->setShouldUpdate(false);
+ m_inst->setIsForNewLauncher(true);
+ exit(1);
+}
+
+void GameUpdateTask::jarlibFailed()
+{
+ error("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE");
+ exit(0);
+}
+
+void GameUpdateTask::versionFileFailed()
+{
+ error("Failed to download the version description. Try again.");
+ exit(0);
+}
+
+
+// this is legacy minecraft...
+void GameUpdateTask::getLegacyJar()
+{
+ // Make directories
+ QDir binDir(m_inst->binDir());
+ if (!binDir.exists() && !binDir.mkpath("."))
+ {
+ error("Failed to create bin folder.");
+ return;
+ }
+
+ // Add the URL for minecraft.jar
// This will be either 'minecraft' or the version number, depending on where
// we're downloading from.
QString jarFilename = "minecraft";
-
- // FIXME: this is NOT enough
if (targetVersion->launcherVersion() == MinecraftVersion::Launcher16)
+ {
jarFilename = targetVersion->descriptor();
+ }
QUrl mcJarURL = targetVersion->downloadURL() + jarFilename + ".jar";
qDebug() << mcJarURL.toString();
- m_downloadList.append(FileToDownload::Create(mcJarURL, PathCombine(m_inst->minecraftDir(), "bin/minecraft.jar")));
-
-
+ auto dljob = DownloadJob::create(mcJarURL, PathCombine(m_inst->minecraftDir(), "bin/minecraft.jar"));
- ////////////////////
- // DOWNLOAD FILES //
- ////////////////////
- setState(StateDownloadFiles);
- for (int i = 0; i < m_downloadList.length(); i++)
- {
- m_currentDownload = i;
- if (!downloadFile(m_downloadList[i]))
- return;
- }
-
-
-
- ///////////////////
- // INSTALL FILES //
- ///////////////////
- setState(StateInstall);
-
- // Nothing to do here yet
+ legacyDownloadJob.reset(new JobList());
+ legacyDownloadJob->add(dljob);
+ connect(legacyDownloadJob.data(), SIGNAL(finished()), SLOT(legacyJarFinished()));
+ connect(legacyDownloadJob.data(), SIGNAL(failed()), SLOT(legacyJarFailed()));
+ connect(legacyDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
-
-
- //////////////
- // FINISHED //
- //////////////
+ download_queue.enqueue(legacyDownloadJob);
+}
+
+
+void GameUpdateTask::legacyJarFinished()
+{
setState(StateFinished);
emit gameUpdateComplete(m_response);
+ m_inst->setIsForNewLauncher(true);
+ exit(1);
}
-bool GameUpdateTask::downloadFile( const FileToDownloadPtr file )
+void GameUpdateTask::legacyJarFailed()
{
- setSubStatus("Downloading " + file->url().toString());
- QNetworkReply *reply = netMgr->get(QNetworkRequest(file->url()));
-
- this->connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
- SLOT(updateDownloadProgress(qint64,qint64)));
-
- NetUtils::waitForNetRequest(reply);
-
- if (reply->error() == QNetworkReply::NoError)
- {
- QString filePath = file->path();
- QFile outFile(filePath);
- if (outFile.exists() && !outFile.remove())
- {
- error("Can't delete old file " + file->path() + ": " + outFile.errorString());
- return false;
- }
-
- if (!outFile.open(QIODevice::WriteOnly))
- {
- error("Can't write to " + file->path() + ": " + outFile.errorString());
- return false;
- }
-
- outFile.write(reply->readAll());
- outFile.close();
- }
- else
- {
- error("Can't download " + file->url().toString() + ": " + reply->errorString());
- return false;
- }
-
- // TODO: Check file integrity after downloading.
-
- return true;
+ emit gameUpdateError("failed to download the minecraft.jar");
+ exit(0);
}
int GameUpdateTask::state() const
@@ -223,22 +277,7 @@ void GameUpdateTask::error(const QString &msg)
void GameUpdateTask::updateDownloadProgress(qint64 current, qint64 total)
{
// The progress on the current file is current / total
- float currentDLProgress = (float) current / (float) total; // Cast ALL the values!
-
- // The overall progress is (current progress + files downloaded) / total files to download
- float overallDLProgress = ((currentDLProgress + m_currentDownload) / (float) m_downloadList.length());
-
- // Multiply by 100 to make it a percentage.
- setProgress((int)(overallDLProgress * 100));
-}
-
-FileToDownloadPtr FileToDownload::Create(const QUrl &url, const QString &path, QObject *parent)
-{
- return FileToDownloadPtr(new FileToDownload (url, path, parent));
+ float currentDLProgress = (float) current / (float) total;
+ setProgress((int)(currentDLProgress * 100)); // convert to percentage
}
-FileToDownload::FileToDownload(const QUrl &url, const QString &path, QObject *parent) :
- QObject(parent), m_dlURL(url), m_dlPath(path)
-{
-
-}
diff --git a/libmultimc/src/instance.cpp b/libmultimc/src/instance.cpp
index 08cd6605..5fdb5064 100644
--- a/libmultimc/src/instance.cpp
+++ b/libmultimc/src/instance.cpp
@@ -34,7 +34,8 @@ Instance::Instance(const QString &rootDir, QObject *parent) :
settings().registerSetting(new Setting("iconKey", "default"));
settings().registerSetting(new Setting("notes", ""));
settings().registerSetting(new Setting("NeedsRebuild", true));
- settings().registerSetting(new Setting("ShouldForceUpdate", false));
+ settings().registerSetting(new Setting("IsForNewLauncher", false));
+ settings().registerSetting(new Setting("ShouldUpdate", false));
settings().registerSetting(new Setting("JarVersion", "Unknown"));
settings().registerSetting(new Setting("LwjglVersion", "2.9.0"));
settings().registerSetting(new Setting("IntendedJarVersion", ""));
@@ -62,6 +63,18 @@ Instance::Instance(const QString &rootDir, QObject *parent) :
// Auto login
settings().registerSetting(new OverrideSetting("AutoLogin", globalSettings->getSetting("AutoLogin")));
+
+ // Console
+ settings().registerSetting(new OverrideSetting("ShowConsole", globalSettings->getSetting("ShowConsole")));
+ settings().registerSetting(new OverrideSetting("AutoCloseConsole", globalSettings->getSetting("AutoCloseConsole")));
+
+ // Overrides
+ settings().registerSetting(new Setting("OverrideConsole", false));
+ settings().registerSetting(new Setting("OverrideWindow", false));
+ settings().registerSetting(new Setting("OverrideLogin", false));
+ settings().registerSetting(new Setting("OverrideMemory", false));
+ settings().registerSetting(new Setting("OverrideJava", false));
+ settings().registerSetting(new Setting("OverrideCommands", false));
}
QString Instance::id() const
diff --git a/libmultimc/src/library.cpp b/libmultimc/src/library.cpp
new file mode 100644
index 00000000..9d4cc6e3
--- /dev/null
+++ b/libmultimc/src/library.cpp
@@ -0,0 +1,37 @@
+/* Copyright 2013 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "include/library.h"
+
+RuleAction RuleAction_fromString(QString name)
+{
+ if(name == "allow")
+ return Allow;
+ if(name == "disallow")
+ return Disallow;
+ return Defer;
+}
+
+OpSys OpSys_fromString(QString name)
+{
+ if(name == "linux")
+ return Os_Linux;
+ if(name == "windows")
+ return Os_Windows;
+ if(name == "osx")
+ return Os_OSX;
+ return Os_Other;
+}
+// default url for lib: