summaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-09 00:26:35 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-09 00:26:35 +0200
commitbf5f5091ef6daeaf7067f4fc8973eb068ddc52fc (patch)
tree647f77c1d7f8c8e0e7bdf90fb7f3b0eac9aa5f6c /backend
parentc8925e0f667b0c94028345586d99008066358200 (diff)
downloadMultiMC-bf5f5091ef6daeaf7067f4fc8973eb068ddc52fc.tar
MultiMC-bf5f5091ef6daeaf7067f4fc8973eb068ddc52fc.tar.gz
MultiMC-bf5f5091ef6daeaf7067f4fc8973eb068ddc52fc.tar.lz
MultiMC-bf5f5091ef6daeaf7067f4fc8973eb068ddc52fc.tar.xz
MultiMC-bf5f5091ef6daeaf7067f4fc8973eb068ddc52fc.zip
Various task related improvements.
* Errors are reported back to task users via Failure signals. * Lwjgl doesn't download on each legacy instance start anymore. * Tasks were unified when it comes to success/failure. * Task dialogs don't get spawned after short tasks finish anymore.
Diffstat (limited to 'backend')
-rw-r--r--backend/BaseUpdate.cpp5
-rw-r--r--backend/BaseUpdate.h14
-rw-r--r--backend/LegacyUpdate.cpp59
-rw-r--r--backend/LegacyUpdate.h3
-rw-r--r--backend/OneSixUpdate.cpp14
-rw-r--r--backend/lists/LwjglVersionList.cpp3
-rw-r--r--backend/lists/MinecraftVersionList.cpp23
-rw-r--r--backend/tasks/LoginTask.cpp23
-rw-r--r--backend/tasks/LoginTask.h11
-rw-r--r--backend/tasks/Task.cpp18
-rw-r--r--backend/tasks/Task.h23
11 files changed, 84 insertions, 112 deletions
diff --git a/backend/BaseUpdate.cpp b/backend/BaseUpdate.cpp
index 8a4aced3..b086ab14 100644
--- a/backend/BaseUpdate.cpp
+++ b/backend/BaseUpdate.cpp
@@ -5,11 +5,6 @@ BaseUpdate::BaseUpdate ( BaseInstance* inst, QObject* parent ) : Task ( parent )
m_inst = inst;
}
-void BaseUpdate::error ( const QString& msg )
-{
- emit gameUpdateError(msg);
-}
-
void BaseUpdate::updateDownloadProgress(qint64 current, qint64 total)
{
// The progress on the current file is current / total
diff --git a/backend/BaseUpdate.h b/backend/BaseUpdate.h
index 83eb0089..b7d2017e 100644
--- a/backend/BaseUpdate.h
+++ b/backend/BaseUpdate.h
@@ -38,20 +38,8 @@ public:
virtual void executeTask() = 0;
-signals:
- /*!
- * \brief Signal emitted when the game update is complete.
- */
- void gameUpdateComplete();
-
- /*!
- * \brief Signal emitted if an error occurrs during the update.
- * \param errorMsg An error message to be displayed to the user.
- */
- void gameUpdateError(const QString &errorMsg);
-
protected slots:
- virtual void error(const QString &msg);
+ //virtual void error(const QString &msg);
void updateDownloadProgress(qint64 current, qint64 total);
protected:
diff --git a/backend/LegacyUpdate.cpp b/backend/LegacyUpdate.cpp
index ff42e52d..630f7f29 100644
--- a/backend/LegacyUpdate.cpp
+++ b/backend/LegacyUpdate.cpp
@@ -18,21 +18,33 @@ void LegacyUpdate::executeTask()
void LegacyUpdate::lwjglStart()
{
LegacyInstance * inst = (LegacyInstance *) m_inst;
+
+ lwjglVersion = inst->lwjglVersion();
+ lwjglTargetPath = PathCombine("lwjgl", lwjglVersion );
+ lwjglNativesPath = PathCombine( lwjglTargetPath, "natives/");
+
+ // if the 'done' file exists, we don't have to download this again
+ QFileInfo doneFile(PathCombine(lwjglTargetPath, "done"));
+ if(doneFile.exists())
+ {
+ emitSucceeded();
+ return;
+ }
+
auto &list = LWJGLVersionList::get();
if(!list.isLoaded())
{
- error("Too soon! Let the LWJGL list load :)");
- emitEnded();
+ emitFailed("Too soon! Let the LWJGL list load :)");
return;
}
- QString lwjglVer = inst->lwjglVersion();
- auto version = list.getVersion(lwjglVer);
+
+ auto version = list.getVersion(lwjglVersion);
if(!version)
{
- error("Game update failed: the selected LWJGL version is invalid.");
- emitEnded();
+ emitFailed("Game update failed: the selected LWJGL version is invalid.");
+ return;
}
- lwjglVersion = version->name();
+
QString url = version->url();
QUrl realUrl(url);
QString hostname = realUrl.host();
@@ -56,8 +68,9 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
}
if(reply->error() != QNetworkReply::NoError)
{
- error("Failed to download: " + reply->errorString() + "\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV");
- emitEnded();
+ emitFailed( "Failed to download: "+
+ reply->errorString()+
+ "\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV");
return;
}
auto &worker = NetWorker::spawn();
@@ -95,22 +108,19 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
void LegacyUpdate::extractLwjgl()
{
// make sure the directories are there
- QString lwjgl_base = PathCombine("lwjgl", lwjglVersion );
- QString nativesPath = PathCombine( lwjgl_base, "natives/");
- bool success = ensurePathExists(nativesPath);
+
+ bool success = ensurePathExists(lwjglNativesPath);
if(!success)
{
- error("Failed to extract the lwjgl libs - error when creating required folders.");
- emitEnded();
+ emitFailed("Failed to extract the lwjgl libs - error when creating required folders.");
return;
}
QuaZip zip("lwjgl.zip");
if(!zip.open(QuaZip::mdUnzip))
{
- error("Failed to extract the lwjgl libs - not a valid archive.");
- emitEnded();
+ emitFailed("Failed to extract the lwjgl libs - not a valid archive.");
return;
}
@@ -122,8 +132,7 @@ void LegacyUpdate::extractLwjgl()
if(!file.open(QIODevice::ReadOnly))
{
zip.close();
- error("Failed to extract the lwjgl libs - error while reading archive.");
- emitEnded();
+ emitFailed("Failed to extract the lwjgl libs - error while reading archive.");
return;
}
QuaZipFileInfo info;
@@ -139,7 +148,7 @@ void LegacyUpdate::extractLwjgl()
{
if (name.endsWith(jarNames[i]))
{
- destFileName = PathCombine(lwjgl_base, jarNames[i]);
+ destFileName = PathCombine(lwjglTargetPath, jarNames[i]);
}
}
// Not found? look for the natives
@@ -160,7 +169,7 @@ void LegacyUpdate::extractLwjgl()
name = name.mid(lastSlash+1);
else if(lastBackSlash != -1)
name = name.mid(lastBackSlash+1);
- destFileName = PathCombine(nativesPath, name);
+ destFileName = PathCombine(lwjglNativesPath, name);
}
}
// Now if destFileName is still empty, go to the next file.
@@ -176,13 +185,15 @@ void LegacyUpdate::extractLwjgl()
}
zip.close();
m_reply.clear();
- emit gameUpdateComplete();
- emitEnded();
+ QFile doneFile(PathCombine(lwjglTargetPath, "done"));
+ doneFile.open(QIODevice::WriteOnly);
+ doneFile.write("done.");
+ doneFile.close();
+ emitSucceeded();
}
void LegacyUpdate::lwjglFailed()
{
- error("Bad stuff happened while trying to get the lwjgl libs...");
- emitEnded();
+ emitFailed("Bad stuff happened while trying to get the lwjgl libs...");
}
diff --git a/backend/LegacyUpdate.h b/backend/LegacyUpdate.h
index de5608d0..cc1f5efd 100644
--- a/backend/LegacyUpdate.h
+++ b/backend/LegacyUpdate.h
@@ -47,6 +47,9 @@ private:
// MinecraftVersion *targetVersion;
QString lwjglURL;
QString lwjglVersion;
+
+ QString lwjglTargetPath;
+ QString lwjglNativesPath;
};
diff --git a/backend/OneSixUpdate.cpp b/backend/OneSixUpdate.cpp
index 84d8dfae..db15c923 100644
--- a/backend/OneSixUpdate.cpp
+++ b/backend/OneSixUpdate.cpp
@@ -43,7 +43,7 @@ void OneSixUpdate::executeTask()
if(targetVersion == nullptr)
{
// don't do anything if it was invalid
- emit gameUpdateComplete();
+ emitSucceeded();
return;
}
@@ -104,8 +104,7 @@ void OneSixUpdate::versionFileFinished()
void OneSixUpdate::versionFileFailed()
{
- error("Failed to download the version description. Try again.");
- emitEnded();
+ emitFailed("Failed to download the version description. Try again.");
}
void OneSixUpdate::jarlibStart()
@@ -114,8 +113,7 @@ void OneSixUpdate::jarlibStart()
bool successful = inst->reloadFullVersion();
if(!successful)
{
- error("Failed to load the version description file (version.json). It might be corrupted, missing or simply too new.");
- emitEnded();
+ emitFailed("Failed to load the version description file (version.json). It might be corrupted, missing or simply too new.");
return;
}
@@ -149,13 +147,11 @@ void OneSixUpdate::jarlibStart()
void OneSixUpdate::jarlibFinished()
{
- emit gameUpdateComplete();
- emitEnded();
+ emitSucceeded();
}
void OneSixUpdate::jarlibFailed()
{
- error("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE");
- emitEnded();
+ emitFailed("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE");
}
diff --git a/backend/lists/LwjglVersionList.cpp b/backend/lists/LwjglVersionList.cpp
index 73a27a58..068394e8 100644
--- a/backend/lists/LwjglVersionList.cpp
+++ b/backend/lists/LwjglVersionList.cpp
@@ -119,8 +119,7 @@ void LWJGLVersionList::netRequestComplete()
int errorLine;
if (!doc.setContent(reply->readAll(), false, &xmlErrorMsg, &errorLine))
{
- failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg +
- " at line " + QString::number(errorLine));
+ failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " + QString::number(errorLine));
setLoading(false);
return;
}
diff --git a/backend/lists/MinecraftVersionList.cpp b/backend/lists/MinecraftVersionList.cpp
index e14d7a25..ae28c46d 100644
--- a/backend/lists/MinecraftVersionList.cpp
+++ b/backend/lists/MinecraftVersionList.cpp
@@ -179,9 +179,8 @@ void MCVListLoadTask::list_downloaded()
{
if(vlistReply->error() != QNetworkReply::QNetworkReply::NoError)
{
- qDebug() << "Failed to load Minecraft main version list" << vlistReply->errorString();
vlistReply->deleteLater();
- emitEnded();
+ emitFailed("Failed to load Minecraft main version list" + vlistReply->errorString());
return;
}
@@ -191,15 +190,13 @@ void MCVListLoadTask::list_downloaded()
if (jsonError.error != QJsonParseError::NoError)
{
- qDebug() << "Error parsing version list JSON:" << jsonError.errorString();
- emitEnded();
+ emitFailed("Error parsing version list JSON:" + jsonError.errorString());
return;
}
if(!jsonDoc.isObject())
{
- qDebug() << "Error parsing version list JSON: " << "jsonDoc is not an object";
- emitEnded();
+ emitFailed("Error parsing version list JSON: jsonDoc is not an object");
return;
}
@@ -208,8 +205,7 @@ void MCVListLoadTask::list_downloaded()
// Get the ID of the latest release and the latest snapshot.
if(!root.value("latest").isObject())
{
- qDebug() << "Error parsing version list JSON: " << "version list is missing 'latest' object";
- emitEnded();
+ emitFailed("Error parsing version list JSON: version list is missing 'latest' object");
return;
}
@@ -219,22 +215,19 @@ void MCVListLoadTask::list_downloaded()
QString latestSnapshotID = latest.value("snapshot").toString("");
if(latestReleaseID.isEmpty())
{
- qDebug() << "Error parsing version list JSON: " << "latest release field is missing";
- emitEnded();
+ emitFailed("Error parsing version list JSON: latest release field is missing");
return;
}
if(latestSnapshotID.isEmpty())
{
- qDebug() << "Error parsing version list JSON: " << "latest snapshot field is missing";
- emitEnded();
+ emitFailed("Error parsing version list JSON: latest snapshot field is missing");
return;
}
// Now, get the array of versions.
if(!root.value("versions").isArray())
{
- qDebug() << "Error parsing version list JSON: " << "version list object is missing 'versions' array";
- emitEnded();
+ emitFailed("Error parsing version list JSON: version list object is missing 'versions' array");
return;
}
QJsonArray versions = root.value("versions").toArray();
@@ -308,7 +301,7 @@ void MCVListLoadTask::list_downloaded()
#ifdef PRINT_VERSIONS
m_list->printToStdOut();
#endif
- emitEnded();
+ emitSucceeded();
return;
}
diff --git a/backend/tasks/LoginTask.cpp b/backend/tasks/LoginTask.cpp
index 7a1d5262..48202044 100644
--- a/backend/tasks/LoginTask.cpp
+++ b/backend/tasks/LoginTask.cpp
@@ -71,44 +71,41 @@ void LoginTask::processNetReply(QNetworkReply *reply)
QString username = strings[2];
QString sessionID = strings[3];
- LoginResponse response{username, sessionID, latestVersion};
- emit loginComplete(response);
+ result = {username, sessionID, latestVersion};
+ emitSucceeded();
}
else
{
- emit loginFailed("Failed to parse Minecraft version string.");
+ emitFailed("Failed to parse Minecraft version string.");
}
}
else
{
if (responseStr.toLower() == "bad login")
- emit loginFailed("Invalid username or password.");
+ emitFailed("Invalid username or password.");
else if (responseStr.toLower() == "old version")
- emit loginFailed("Launcher outdated, please update.");
+ emitFailed("Launcher outdated, please update.");
else
- emit loginFailed("Login failed: " + responseStr);
+ emitFailed("Login failed: " + responseStr);
}
}
else if (responseCode == 503)
{
- emit loginFailed("The login servers are currently unavailable. "
- "Check http://help.mojang.com/ for more info.");
+ emitFailed("The login servers are currently unavailable. Check http://help.mojang.com/ for more info.");
}
else
{
- emit loginFailed(QString("Login failed: Unknown HTTP error %1 occurred.").
- arg(QString::number(responseCode)));
+ emitFailed(QString("Login failed: Unknown HTTP error %1 occurred.").arg(QString::number(responseCode)));
}
break;
}
case QNetworkReply::OperationCanceledError:
- emit loginFailed("Login canceled.");
+ emitFailed("Login canceled.");
break;
default:
- emit loginFailed("Login failed: " + reply->errorString());
+ emitFailed("Login failed: " + reply->errorString());
break;
}
- emitEnded();
}
diff --git a/backend/tasks/LoginTask.h b/backend/tasks/LoginTask.h
index 81d1b6cc..77d65255 100644
--- a/backend/tasks/LoginTask.h
+++ b/backend/tasks/LoginTask.h
@@ -40,17 +40,18 @@ class LIBMULTIMC_EXPORT LoginTask : public Task
Q_OBJECT
public:
explicit LoginTask(const UserInfo& uInfo, QObject *parent = 0);
+ LoginResponse getResult()
+ {
+ return result;
+ };
-public slots:
+protected slots:
void processNetReply(QNetworkReply* reply);
-signals:
- void loginComplete(LoginResponse loginResponse);
- void loginFailed(const QString& errorMsg);
-
protected:
void executeTask();
+ LoginResponse result;
QNetworkReply* netReply;
UserInfo uInfo;
};
diff --git a/backend/tasks/Task.cpp b/backend/tasks/Task.cpp
index 30dd2d10..7c148591 100644
--- a/backend/tasks/Task.cpp
+++ b/backend/tasks/Task.cpp
@@ -37,11 +37,6 @@ int Task::getProgress() const
return progress;
}
-void Task::calcProgress(int parts, int whole)
-{
- setProgress((int)((((float)parts) / ((float)whole))*100)); // Not sure if C++ or LISP...
-}
-
void Task::setProgress(int progress)
{
this->progress = progress;
@@ -58,16 +53,21 @@ void Task::emitStarted()
{
running = true;
emit started();
- emit started(this);
}
-void Task::emitEnded()
+void Task::emitFailed(QString reason)
+{
+ running = false;
+ emit failed(reason);
+}
+
+void Task::emitSucceeded()
{
running = false;
- emit ended();
- emit ended(this);
+ emit succeeded();
}
+
bool Task::isRunning() const
{
return running;
diff --git a/backend/tasks/Task.h b/backend/tasks/Task.h
index bbe27ae1..15219931 100644
--- a/backend/tasks/Task.h
+++ b/backend/tasks/Task.h
@@ -27,33 +27,21 @@ class LIBMULTIMC_EXPORT Task : public QObject
public:
explicit Task(QObject *parent = 0);
- // Starts the task.
- void startTask();
-
QString getStatus() const;
int getProgress() const;
-
bool isRunning() const;
- /*!
- * \brief Calculates and sets the task's progress based on the number of parts completed out of the total number to complete.
- * This is essentially just shorthand for setProgress((parts / whole) * 100);
- * \param parts The parts out of the whole completed. This parameter should
- * be less than whole. If it is greater than whole, progress is set to 100.
- * \param whole The total number of things that need to be completed.
- */
- void calcProgress(int parts, int whole);
+public slots:
+ void startTask();
protected slots:
void setStatus(const QString& status);
void setProgress(int progress);
signals:
- void started(Task* task);
- void ended(Task* task);
-
void started();
- void ended();
+ void failed(QString reason);
+ void succeeded();
void statusChanged(Task* task, const QString& status);
void progressChanged(Task* task, int progress);
@@ -65,7 +53,8 @@ protected:
virtual void executeTask() = 0;
virtual void emitStarted();
- virtual void emitEnded();
+ virtual void emitFailed(QString reason);
+ virtual void emitSucceeded();
virtual void emitStatusChange(const QString &status);
virtual void emitProgressChange(int progress);