summaryrefslogtreecommitdiffstats
path: root/libmultimc
diff options
context:
space:
mode:
Diffstat (limited to 'libmultimc')
-rw-r--r--libmultimc/include/gameupdatetask.h144
-rw-r--r--libmultimc/include/instance.h35
-rw-r--r--libmultimc/include/logintask.h7
-rw-r--r--libmultimc/include/minecraftprocess.h8
-rw-r--r--libmultimc/include/minecraftversion.h10
-rw-r--r--libmultimc/src/gameupdatetask.cpp227
-rw-r--r--libmultimc/src/instance.cpp5
-rw-r--r--libmultimc/src/logintask.cpp22
-rw-r--r--libmultimc/src/minecraftprocess.cpp11
-rw-r--r--libmultimc/src/minecraftversion.cpp12
-rw-r--r--libmultimc/src/minecraftversionlist.cpp17
11 files changed, 446 insertions, 52 deletions
diff --git a/libmultimc/include/gameupdatetask.h b/libmultimc/include/gameupdatetask.h
index eabfbd1f..47f6c007 100644
--- a/libmultimc/include/gameupdatetask.h
+++ b/libmultimc/include/gameupdatetask.h
@@ -18,19 +18,105 @@
#include <QObject>
+#include <QList>
+
+#include <QNetworkAccessManager>
+#include <QUrl>
+
+#include "task.h"
#include "loginresponse.h"
+#include "instance.h"
#include "libmmc_config.h"
+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)
+public:
+ FileToDownload(const QUrl &url, const QString &path, QObject *parent = 0);
+ FileToDownload(const FileToDownload &other);
+
+ 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;
+};
+
/*!
- * \brief The game update task is the task that handles downloading instances.
- * Each instance type has its own class inheriting from this base game update task.
+ * The game update task is the task that handles downloading instances' files.
*/
-class LIBMULTIMC_EXPORT GameUpdateTask : public QObject
+class LIBMULTIMC_EXPORT GameUpdateTask : public Task
{
Q_OBJECT
+
+ /*!
+ * The task's state.
+ * A certain state message will be shown depending on what this is set to.
+ */
+ Q_PROPERTY(int state READ state WRITE setState)
+
+ /*!
+ * The substatus message.
+ * This will be next to the the state message in the task's status.
+ */
+ Q_PROPERTY(QString subStatus READ subStatus WRITE setSubStatus)
public:
- explicit GameUpdateTask(const LoginResponse &response, QObject *parent = 0);
+ explicit GameUpdateTask(const LoginResponse &response, Instance *inst, QObject *parent = 0);
+
+
+ /////////////////////////
+ // EXECUTION FUNCTIONS //
+ /////////////////////////
+
+ virtual void executeTask();
+
+ virtual bool downloadFile(const FileToDownload &file);
+
+
+ //////////////////////
+ // STATE AND STATUS //
+ //////////////////////
+
+ virtual int state() const;
+ virtual void setState(int state, bool resetSubStatus = true);
+
+ virtual QString subStatus() const;
+ virtual void setSubStatus(const QString &msg);
+
+ /*!
+ * Gets the message that will be displated for the given state.
+ */
+ virtual QString getStateMessage(int state);
+
+public slots:
+
+ /*!
+ * Updates the status message based on the state and substatus message.
+ */
+ virtual void updateStatus();
+
+
+ virtual void error(const QString &msg);
+
+
+private slots:
+ virtual void updateDownloadProgress(qint64 current, qint64 total);
signals:
/*!
@@ -40,13 +126,59 @@ signals:
void gameUpdateComplete(const LoginResponse &response);
/*!
- * \brief Signal emitted if the game update fails.
+ * \brief Signal emitted if an error occurrs during the update.
* \param errorMsg An error message to be displayed to the user.
*/
- void gameUpdateFailed(const QString &errorMsg);
+ void gameUpdateError(const QString &errorMsg);
private:
+ ///////////
+ // STUFF //
+ ///////////
+
+ Instance *m_inst;
+
LoginResponse m_response;
+
+ QNetworkAccessManager *netMgr;
+
+
+
+ ////////////////////////
+ // FILE DOWNLOAD LIST //
+ ////////////////////////
+
+ // List of URLs that the game updater will need to download.
+ QList<FileToDownload> m_downloadList;
+ int m_currentDownload;
+
+
+
+ ////////////////////////////
+ // STATE AND STATUS STUFF //
+ ////////////////////////////
+
+ int m_updateState;
+ QString m_subStatusMsg;
+
+ enum UpdateState
+ {
+ // Initializing
+ StateInit = 0,
+
+ // Determining files to download
+ StateDetermineURLs,
+
+ // Downloading files
+ StateDownloadFiles,
+
+ // Installing files
+ StateInstall,
+
+ // Finished
+ StateFinished
+ };
};
+
#endif // GAMEUPDATETASK_H
diff --git a/libmultimc/include/instance.h b/libmultimc/include/instance.h
index e72a0be3..717f8816 100644
--- a/libmultimc/include/instance.h
+++ b/libmultimc/include/instance.h
@@ -75,6 +75,21 @@ class LIBMULTIMC_EXPORT Instance : public QObject
*/
Q_PROPERTY(bool shouldRebuild READ shouldRebuild WRITE setShouldRebuild)
+ /*!
+ * Whether or not Minecraft should be downloaded when the instance is launched.
+ * 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)
+
/*!
* The instance's current version.
@@ -182,7 +197,7 @@ public:
//////// INSTANCE INFO ////////
//// General Info ////
- virtual QString name() { return settings().get("name").toString(); }
+ virtual QString name() const { return settings().get("name").toString(); }
virtual void setName(QString val)
{
settings().set("name", val);
@@ -212,27 +227,33 @@ public:
//// Version Stuff ////
- virtual QString currentVersion() { return settings().get("JarVersion").toString(); }
+ virtual QString currentVersion() const { return settings().get("JarVersion").toString(); }
virtual void setCurrentVersion(QString val) { settings().set("JarVersion", val); }
- virtual QString lwjglVersion() { return settings().get("LwjglVersion").toString(); }
+ virtual QString lwjglVersion() const { return settings().get("LwjglVersion").toString(); }
virtual void setLWJGLVersion(QString val) { settings().set("LwjglVersion", val); }
- virtual QString intendedVersion() { return settings().get("IntendedJarVersion").toString(); }
+ 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); }
+
//// Timestamps ////
- virtual qint64 lastLaunch() { return settings().get("lastLaunchTime").value<qint64>(); }
+ virtual qint64 lastLaunch() const { return settings().get("lastLaunchTime").value<qint64>(); }
virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch())
{
settings().set("lastLaunchTime", val);
emit propertiesChanged(this);
}
- virtual qint64 lastCurrentVersionUpdate() { return settings().get("lastVersionUpdate").value<qint64>(); }
+ virtual qint64 lastCurrentVersionUpdate() const { return settings().get("lastVersionUpdate").value<qint64>(); }
virtual void setLastCurrentVersionUpdate(qint64 val) { settings().set("lastVersionUpdate", val); }
@@ -274,7 +295,7 @@ public:
* stored in the instance config file against the last modified time of Minecraft.jar.
* \return True if updateCurrentVersion() should be called.
*/
- virtual bool shouldUpdateCurrentVersion();
+ virtual bool shouldUpdateCurrentVersion() const;
/*!
* \brief Updates the current version.
diff --git a/libmultimc/include/logintask.h b/libmultimc/include/logintask.h
index e00609ec..15d715bd 100644
--- a/libmultimc/include/logintask.h
+++ b/libmultimc/include/logintask.h
@@ -30,20 +30,19 @@ class LIBMULTIMC_EXPORT LoginTask : public Task
{
Q_OBJECT
public:
- explicit LoginTask(const UserInfo& uInfo, QString inst, QObject *parent = 0);
+ explicit LoginTask(const UserInfo& uInfo, QObject *parent = 0);
public slots:
void processNetReply(QNetworkReply* reply);
signals:
- void loginComplete(QString inst, LoginResponse loginResponse);
- void loginFailed(QString inst, const QString& errorMsg);
+ void loginComplete(LoginResponse loginResponse);
+ void loginFailed(const QString& errorMsg);
protected:
void executeTask();
QNetworkReply* netReply;
- QString inst;
UserInfo uInfo;
};
diff --git a/libmultimc/include/minecraftprocess.h b/libmultimc/include/minecraftprocess.h
index ac4d6be2..eb861236 100644
--- a/libmultimc/include/minecraftprocess.h
+++ b/libmultimc/include/minecraftprocess.h
@@ -54,7 +54,7 @@ public:
* @param session the minecraft session id
* @param console the instance console window
*/
- MinecraftProcess(InstancePtr inst, QString user, QString session);
+ MinecraftProcess(Instance *inst, QString user, QString session);
/**
* @brief launch minecraft
@@ -66,7 +66,7 @@ public:
* @param inst the instance
* @param destination the destination path
*/
- static inline void extractIcon(InstancePtr inst, QString destination);
+ static inline void extractIcon(Instance *inst, QString destination);
/**
* @brief extract the MultiMC launcher.jar
@@ -78,7 +78,7 @@ public:
* @brief prepare the launch by extracting icon and launcher
* @param inst the instance
*/
- static void prepare(InstancePtr inst);
+ static void prepare(Instance *inst);
/**
* @brief split a string into argv items like a shell would do
@@ -101,7 +101,7 @@ signals:
void log(QString text, MessageLevel::Enum level=MessageLevel::MultiMC);
protected:
- InstancePtr m_instance;
+ Instance *m_instance;
QString m_user;
QString m_session;
QString m_err_leftover;
diff --git a/libmultimc/include/minecraftversion.h b/libmultimc/include/minecraftversion.h
index e30582ac..fd11b316 100644
--- a/libmultimc/include/minecraftversion.h
+++ b/libmultimc/include/minecraftversion.h
@@ -39,6 +39,11 @@ class LIBMULTIMC_EXPORT MinecraftVersion : public InstVersion
*/
Q_PROPERTY(QString etag READ etag)
+ /*!
+ * True if this is a version from the new Minecraft launcher's version list.
+ */
+ Q_PROPERTY(bool isForNewLauncher READ isForNewLauncher WRITE setIsForNewLauncher)
+
public:
explicit MinecraftVersion(QString descriptor,
QString name,
@@ -75,6 +80,9 @@ public:
virtual QString typeName() const;
virtual qint64 timestamp() const;
+ virtual bool isForNewLauncher() const;
+ virtual void setIsForNewLauncher(bool val);
+
virtual VersionType versionType() const;
virtual void setVersionType(VersionType typeName);
@@ -90,6 +98,8 @@ private:
QString m_dlUrl;
QString m_etag;
VersionType m_type;
+
+ bool m_isNewLauncherVersion;
};
#endif // MINECRAFTVERSION_H
diff --git a/libmultimc/src/gameupdatetask.cpp b/libmultimc/src/gameupdatetask.cpp
index c152147e..34c8f670 100644
--- a/libmultimc/src/gameupdatetask.cpp
+++ b/libmultimc/src/gameupdatetask.cpp
@@ -15,8 +15,231 @@
#include "gameupdatetask.h"
-GameUpdateTask::GameUpdateTask(const LoginResponse &response, QObject *parent) :
- QObject(parent), m_response(response)
+#include <QtNetwork>
+
+#include <QFile>
+#include <QFileInfo>
+#include <QTextStream>
+#include <QDataStream>
+
+#include <QDebug>
+
+#include "minecraftversionlist.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().
+ 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("."))
+ {
+ error("Failed to create bin folder.");
+ return;
+ }
+
+
+
+ /////////////////////////
+ // BUILD DOWNLOAD LIST //
+ /////////////////////////
+ // Build a list of URLs that will need to be downloaded.
+
+ setState(StateDetermineURLs);
+
+
+ // 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";
+
+ if (targetVersion->isForNewLauncher())
+ jarFilename = targetVersion->descriptor();
+
+ QUrl mcJarURL = targetVersion->downloadURL() + jarFilename + ".jar";
+ qDebug() << mcJarURL.toString();
+ m_downloadList.append(FileToDownload(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
+
+
+
+ //////////////
+ // FINISHED //
+ //////////////
+ setState(StateFinished);
+ emit gameUpdateComplete(m_response);
+}
+
+bool GameUpdateTask::downloadFile(const FileToDownload &file)
+{
+ 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)
+ {
+ QFile outFile = file.path();
+ 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;
+}
+
+int GameUpdateTask::state() const
+{
+ return m_updateState;
+}
+
+void GameUpdateTask::setState(int state, bool resetSubStatus)
+{
+ m_updateState = state;
+ if (resetSubStatus)
+ setSubStatus("");
+ else // We only need to update if we're not resetting substatus becasue setSubStatus updates status for us.
+ updateStatus();
+}
+
+QString GameUpdateTask::subStatus() const
+{
+ return m_subStatusMsg;
+}
+
+void GameUpdateTask::setSubStatus(const QString &msg)
+{
+ m_subStatusMsg = msg;
+ updateStatus();
+}
+
+QString GameUpdateTask::getStateMessage(int state)
+{
+ switch (state)
+ {
+ case StateInit:
+ return "Initializing";
+
+ case StateDetermineURLs:
+ return "Determining files to download";
+
+ case StateDownloadFiles:
+ return "Downloading files";
+
+ case StateInstall:
+ return "Installing";
+
+ case StateFinished:
+ return "Finished";
+
+ default:
+ return "Downloading instance files";
+ }
+}
+
+void GameUpdateTask::updateStatus()
+{
+ QString newStatus;
+
+ newStatus = getStateMessage(state());
+ if (!subStatus().isEmpty())
+ newStatus += ": " + subStatus();
+ else
+ newStatus += "...";
+
+ setStatus(newStatus);
+}
+
+
+void GameUpdateTask::error(const QString &msg)
+{
+ emit gameUpdateError(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));
+}
+
+
+
+FileToDownload::FileToDownload(const QUrl &url, const QString &path, QObject *parent) :
+ QObject(parent), m_dlURL(url), m_dlPath(path)
+{
+
+}
+
+FileToDownload::FileToDownload(const FileToDownload &other) :
+ QObject(other.parent()), m_dlURL(other.m_dlURL), m_dlPath(other.m_dlPath)
{
}
diff --git a/libmultimc/src/instance.cpp b/libmultimc/src/instance.cpp
index f4a6a3c9..08cd6605 100644
--- a/libmultimc/src/instance.cpp
+++ b/libmultimc/src/instance.cpp
@@ -34,8 +34,9 @@ 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("JarVersion", "Unknown"));
- settings().registerSetting(new Setting("LwjglVersion", "Mojang"));
+ settings().registerSetting(new Setting("LwjglVersion", "2.9.0"));
settings().registerSetting(new Setting("IntendedJarVersion", ""));
settings().registerSetting(new Setting("lastLaunchTime", 0));
@@ -157,7 +158,7 @@ InstVersionList *Instance::versionList() const
return &MinecraftVersionList::getMainList();
}
-bool Instance::shouldUpdateCurrentVersion()
+bool Instance::shouldUpdateCurrentVersion() const
{
QFileInfo jar(mcJar());
return jar.lastModified().toUTC().toMSecsSinceEpoch() != lastCurrentVersionUpdate();
diff --git a/libmultimc/src/logintask.cpp b/libmultimc/src/logintask.cpp
index e042a93f..4a55037c 100644
--- a/libmultimc/src/logintask.cpp
+++ b/libmultimc/src/logintask.cpp
@@ -24,8 +24,8 @@
#include <QUrl>
#include <QUrlQuery>
-LoginTask::LoginTask( const UserInfo& uInfo, QString inst, QObject* parent ) :
- Task(parent), uInfo(uInfo), inst(inst)
+LoginTask::LoginTask( const UserInfo& uInfo, QObject* parent ) :
+ Task(parent), uInfo(uInfo)
{
}
@@ -78,42 +78,42 @@ void LoginTask::processNetReply(QNetworkReply *reply)
QString sessionID = strings[3];
LoginResponse response(username, sessionID, latestVersion);
- emit loginComplete(inst, response);
+ emit loginComplete(response);
}
else
{
- emit loginFailed(inst, "Failed to parse Minecraft version string.");
+ emit loginFailed("Failed to parse Minecraft version string.");
}
}
else
{
if (responseStr.toLower() == "bad login")
- emit loginFailed(inst, "Invalid username or password.");
+ emit loginFailed("Invalid username or password.");
else if (responseStr.toLower() == "old version")
- emit loginFailed(inst, "Launcher outdated, please update.");
+ emit loginFailed("Launcher outdated, please update.");
else
- emit loginFailed(inst, "Login failed: " + responseStr);
+ emit loginFailed("Login failed: " + responseStr);
}
}
else if (responseCode == 503)
{
- emit loginFailed(inst, "The login servers are currently unavailable. "
+ emit loginFailed("The login servers are currently unavailable. "
"Check http://help.mojang.com/ for more info.");
}
else
{
- emit loginFailed(inst, QString("Login failed: Unknown HTTP error %1 occurred.").
+ emit loginFailed(QString("Login failed: Unknown HTTP error %1 occurred.").
arg(QString::number(responseCode)));
}
break;
}
case QNetworkReply::OperationCanceledError:
- emit loginFailed(inst, "Login canceled.");
+ emit loginFailed("Login canceled.");
break;
default:
- emit loginFailed(inst, "Login failed: " + reply->errorString());
+ emit loginFailed("Login failed: " + reply->errorString());
break;
}
diff --git a/libmultimc/src/minecraftprocess.cpp b/libmultimc/src/minecraftprocess.cpp
index f1b63e3d..e8b9959e 100644
--- a/libmultimc/src/minecraftprocess.cpp
+++ b/libmultimc/src/minecraftprocess.cpp
@@ -73,7 +73,7 @@ QStringList MinecraftProcess::splitArgs(QString args)
}
// prepare tools
-inline void MinecraftProcess::extractIcon(InstancePtr inst, QString destination)
+inline void MinecraftProcess::extractIcon(Instance *inst, QString destination)
{
// QImage(":/icons/instances/" + inst->iconKey()).save(destination);
}
@@ -83,14 +83,14 @@ inline void MinecraftProcess::extractLauncher(QString destination)
QFile(":/launcher/launcher.jar").copy(destination);
}
-void MinecraftProcess::prepare(InstancePtr inst)
+void MinecraftProcess::prepare(Instance *inst)
{
extractLauncher(PathCombine(inst->minecraftDir(), LAUNCHER_FILE));
extractIcon(inst, PathCombine(inst->minecraftDir(), "icon.png"));
}
// constructor
-MinecraftProcess::MinecraftProcess(InstancePtr inst, QString user, QString session) :
+MinecraftProcess::MinecraftProcess(Instance *inst, QString user, QString session) :
m_instance(inst), m_user(user), m_session(session)
{
connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(finish(int, QProcess::ExitStatus)));
@@ -254,9 +254,8 @@ void MinecraftProcess::genArgs()
#endif
// lwjgl
- QString lwjgl = m_instance->lwjglVersion();
- if (lwjgl != "Mojang")
- lwjgl = QDir(globalSettings->get("LWJGLDir").toString() + "/" + lwjgl).absolutePath();
+ QString lwjgl = QDir(globalSettings->get("LWJGLDir").toString() + "/" +
+ m_instance->lwjglVersion()).absolutePath();
// launcher arguments
m_arguments << QString("-Xms%1m").arg(m_instance->settings().get("MinMemAlloc").toInt());
diff --git a/libmultimc/src/minecraftversion.cpp b/libmultimc/src/minecraftversion.cpp
index 2e8b4a9b..7dee802f 100644
--- a/libmultimc/src/minecraftversion.cpp
+++ b/libmultimc/src/minecraftversion.cpp
@@ -24,6 +24,7 @@ MinecraftVersion::MinecraftVersion(QString descriptor,
InstVersion(descriptor, name, timestamp, parent), m_dlUrl(dlUrl), m_etag(etag)
{
m_linkedVersion = NULL;
+ m_isNewLauncherVersion = false;
}
MinecraftVersion::MinecraftVersion(const MinecraftVersion *linkedVersion) :
@@ -98,6 +99,16 @@ qint64 MinecraftVersion::timestamp() const
return m_timestamp;
}
+bool MinecraftVersion::isForNewLauncher() const
+{
+ return m_isNewLauncherVersion;
+}
+
+void MinecraftVersion::setIsForNewLauncher(bool val)
+{
+ m_isNewLauncherVersion = val;
+}
+
MinecraftVersion::VersionType MinecraftVersion::versionType() const
{
return m_type;
@@ -137,6 +148,7 @@ InstVersion *MinecraftVersion::copyVersion(InstVersionList *newParent) const
MinecraftVersion *version = new MinecraftVersion(
descriptor(), name(), timestamp(), downloadURL(), etag(), newParent);
version->setVersionType(versionType());
+ version->setIsForNewLauncher(isForNewLauncher());
return version;
}
}
diff --git a/libmultimc/src/minecraftversionlist.cpp b/libmultimc/src/minecraftversionlist.cpp
index bb8b0f7a..8b40069e 100644
--- a/libmultimc/src/minecraftversionlist.cpp
+++ b/libmultimc/src/minecraftversionlist.cpp
@@ -29,6 +29,8 @@
#include <QtNetwork>
+#include "netutils.h"
+
#define MCVLIST_URLBASE "http://s3.amazonaws.com/Minecraft.Download/versions/"
#define ASSETS_URLBASE "http://assets.minecraft.net/"
#define MCN_URLBASE "http://sonicrules.org/mcnweb.py"
@@ -101,6 +103,7 @@ InstVersion *MinecraftVersionList::getLatestStable() const
return m_vlist.at(i);
}
}
+ return NULL;
}
MinecraftVersionList &MinecraftVersionList::getMainList()
@@ -169,13 +172,6 @@ inline QDateTime timeFromMCVListTime(QString str)
}
-inline void waitForNetRequest(QNetworkReply *netReply)
-{
- QEventLoop loop;
- loop.connect(netReply, SIGNAL(finished()), SLOT(quit()));
- loop.exec();
-}
-
MCVListLoadTask::MCVListLoadTask(MinecraftVersionList *vlist)
{
@@ -222,7 +218,7 @@ bool MCVListLoadTask::loadFromVList()
{
QNetworkReply *vlistReply = netMgr->get(QNetworkRequest(QUrl(QString(MCVLIST_URLBASE) +
"versions.json")));
- waitForNetRequest(vlistReply);
+ NetUtils::waitForNetRequest(vlistReply);
switch (vlistReply->error())
{
@@ -307,6 +303,7 @@ bool MCVListLoadTask::loadFromVList()
MinecraftVersion *mcVersion = new MinecraftVersion(
versionID, versionID, versionTime.toMSecsSinceEpoch(),
dlUrl, "");
+ mcVersion->setIsForNewLauncher(true);
mcVersion->setVersionType(versionType);
tempList.append(mcVersion);
}
@@ -335,7 +332,7 @@ bool MCVListLoadTask::loadFromAssets()
bool succeeded = false;
QNetworkReply *assetsReply = netMgr->get(QNetworkRequest(QUrl(ASSETS_URLBASE)));
- waitForNetRequest(assetsReply);
+ NetUtils::waitForNetRequest(assetsReply);
switch (assetsReply->error())
{
@@ -459,7 +456,7 @@ bool MCVListLoadTask::loadFromAssets()
bool MCVListLoadTask::loadMCNostalgia()
{
QNetworkReply *mcnReply = netMgr->get(QNetworkRequest(QUrl(QString(MCN_URLBASE) + "?pversion=1&list=True")));
- waitForNetRequest(mcnReply);
+ NetUtils::waitForNetRequest(mcnReply);
return true;
}