summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-03 23:58:39 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-03 23:58:39 +0200
commit4f73091bb5bdbdb91329b9a4ef647fc8286d423c (patch)
tree6bc63a2d9ca2265cd7ee6dcf683219b73e25a24e
parent13b1b98f7cf8a3b3b2c15dd42f96537b02c00711 (diff)
downloadMultiMC-4f73091bb5bdbdb91329b9a4ef647fc8286d423c.tar
MultiMC-4f73091bb5bdbdb91329b9a4ef647fc8286d423c.tar.gz
MultiMC-4f73091bb5bdbdb91329b9a4ef647fc8286d423c.tar.lz
MultiMC-4f73091bb5bdbdb91329b9a4ef647fc8286d423c.tar.xz
MultiMC-4f73091bb5bdbdb91329b9a4ef647fc8286d423c.zip
Errr... I forgot.
-rw-r--r--backend/BaseInstance.h33
-rw-r--r--backend/CMakeLists.txt8
-rw-r--r--backend/InstanceFactory.cpp12
-rw-r--r--backend/InstanceFactory.h3
-rw-r--r--backend/LegacyInstance.cpp14
-rw-r--r--backend/LegacyInstance.h4
-rw-r--r--backend/OneSixAssets.cpp157
-rw-r--r--backend/OneSixAssets.h21
-rw-r--r--backend/OneSixInstance.cpp22
-rw-r--r--backend/OneSixInstance.h4
-rw-r--r--backend/tasks/GameUpdateTask.cpp90
-rw-r--r--backend/tasks/GameUpdateTask.h81
-rw-r--r--backend/tasks/LoginResponse.cpp69
-rw-r--r--backend/tasks/LoginResponse.h94
-rw-r--r--backend/tasks/LoginTask.cpp2
-rw-r--r--backend/tasks/LoginTask.h9
-rw-r--r--gui/mainwindow.cpp20
-rw-r--r--gui/mainwindow.h5
-rw-r--r--main.cpp3
19 files changed, 269 insertions, 382 deletions
diff --git a/backend/BaseInstance.h b/backend/BaseInstance.h
index 088075f2..1bb2ce17 100644
--- a/backend/BaseInstance.h
+++ b/backend/BaseInstance.h
@@ -57,42 +57,20 @@ public:
/// Path to the instance's root directory.
QString rootDir() const;
- /*!
- * \brief Gets the instance list that this instance is a part of.
- * Returns NULL if this instance is not in a list
- * (the parent is not an InstanceList).
- * \return A pointer to the InstanceList containing this instance.
- */
- InstanceList *instList() const;
-
-
- //////// INSTANCE INFO ////////
-
- /// The name of the instance that is displayed to the user.
QString name() const;
-
- /// Set the name of the instance that is displayed to the user.
void setName(QString val);
- /// The instance's icon key.
QString iconKey() const;
-
- /// Set the instance's icon key.
void setIconKey(QString val);
- //! The instance's notes.
QString notes() const;
-
- /// set the instance notes text
void setNotes(QString val);
- //! The instance's group.
QString group() const;
-
- /// set the instance group
void setGroup(QString val);
- //// Timestamps ////
+ virtual bool setIntendedVersionId(QString version) = 0;
+ virtual QString intendedVersionId() = 0;
/**
* Gets the time that the instance was last launched.
@@ -102,6 +80,13 @@ public:
/// Sets the last launched time to 'val' milliseconds since epoch
void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch());
+ /*!
+ * \brief Gets the instance list that this instance is a part of.
+ * Returns NULL if this instance is not in a list
+ * (the parent is not an InstanceList).
+ * \return A pointer to the InstanceList containing this instance.
+ */
+ InstanceList *instList() const;
/*!
* \brief Gets a pointer to this instance's version list.
diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt
index 9bd07c01..f79ef8ef 100644
--- a/backend/CMakeLists.txt
+++ b/backend/CMakeLists.txt
@@ -26,6 +26,8 @@ LegacyInstance.h
OneSixInstance.h
InstanceFactory.h
+OneSixAssets.h
+
# Versions
InstanceVersion.h
MinecraftVersion.h
@@ -41,9 +43,8 @@ lists/LwjglVersionList.h
# Tasks
tasks/Task.h
tasks/LoginTask.h
-tasks/LoginResponse.h
-tasks/UserInfo.h
tasks/GameUpdateTask.h
+tasks/UserInfo.h
MinecraftProcess.h
)
@@ -55,6 +56,8 @@ LegacyInstance.cpp
OneSixInstance.cpp
InstanceFactory.cpp
+OneSixAssets.cpp
+
# Versions
InstanceVersion.cpp
MinecraftVersion.cpp
@@ -72,7 +75,6 @@ tasks/Task.cpp
tasks/LoginTask.cpp
tasks/GameUpdateTask.cpp
tasks/UserInfo.cpp
-tasks/LoginResponse.cpp
MinecraftProcess.cpp
)
diff --git a/backend/InstanceFactory.cpp b/backend/InstanceFactory.cpp
index ee582d3f..f3636da3 100644
--- a/backend/InstanceFactory.cpp
+++ b/backend/InstanceFactory.cpp
@@ -21,6 +21,7 @@
#include "BaseInstance.h"
#include "LegacyInstance.h"
#include "OneSixInstance.h"
+#include "InstanceVersion.h"
#include "inifile.h"
#include <inisettingsobject.h>
@@ -61,7 +62,7 @@ InstanceFactory::InstLoadError InstanceFactory::loadInstance(BaseInstance *&inst
}
-InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *&inst, const QString &instDir)
+InstanceFactory::InstCreateError InstanceFactory::createInstance( BaseInstance*& inst, const InstVersion* version, const QString& instDir )
{
QDir rootDir(instDir);
@@ -70,9 +71,14 @@ InstanceFactory::InstCreateError InstanceFactory::createInstance(BaseInstance *&
{
return InstanceFactory::CantCreateDir;
}
- return InstanceFactory::UnknownCreateError;
- //inst = new BaseInstance(instDir, this);
+ auto m_settings = new INISettingsObject(PathCombine(instDir, "instance.cfg"));
+ m_settings->registerSetting(new Setting("InstanceType", "Legacy"));
+ m_settings->set("InstanceType", "OneSix");
+
+ inst = new OneSixInstance(instDir, m_settings, this);
+ inst->setIntendedVersionId(version->descriptor());
+
//FIXME: really, how do you even know?
return InstanceFactory::NoCreateError;
}
diff --git a/backend/InstanceFactory.h b/backend/InstanceFactory.h
index 26857ef9..12139e7d 100644
--- a/backend/InstanceFactory.h
+++ b/backend/InstanceFactory.h
@@ -21,6 +21,7 @@
#include "libmmc_config.h"
+class InstVersion;
class BaseInstance;
/*!
@@ -59,7 +60,7 @@ public:
* - InstExists if the given instance directory is already an instance.
* - CantCreateDir if the given instance directory cannot be created.
*/
- InstCreateError createInstance(BaseInstance *&inst, const QString &instDir);
+ InstCreateError createInstance(BaseInstance *&inst, const InstVersion * version, const QString &instDir);
/*!
* \brief Loads an instance from the given directory.
diff --git a/backend/LegacyInstance.cpp b/backend/LegacyInstance.cpp
index 001400e5..b4031eb1 100644
--- a/backend/LegacyInstance.cpp
+++ b/backend/LegacyInstance.cpp
@@ -206,28 +206,36 @@ void LegacyInstance::setLWJGLVersion ( QString val )
I_D(LegacyInstance);
d->m_settings->set ( "LwjglVersion", val );
}
-QString LegacyInstance::intendedVersion() const
+QString LegacyInstance::intendedVersionId()
{
I_D(LegacyInstance);
return d->m_settings->get ( "IntendedJarVersion" ).toString();
}
-void LegacyInstance::setIntendedVersion ( QString val )
+bool LegacyInstance::setIntendedVersionId ( QString version )
{
+ /*
I_D(LegacyInstance);
d->m_settings->set ( "IntendedJarVersion", val );
+ */
+ return false;
}
bool LegacyInstance::shouldUpdate() const
{
+ /*
I_D(LegacyInstance);
QVariant var = d->m_settings->get ( "ShouldUpdate" );
if ( !var.isValid() || var.toBool() == false )
{
- return intendedVersion() != currentVersion();
+ return intendedVersionId() != currentVersion();
}
return true;
+ */
+ return false;
}
void LegacyInstance::setShouldUpdate ( bool val )
{
+ /*
I_D(LegacyInstance);
d->m_settings->set ( "ShouldUpdate", val );
+ */
}
diff --git a/backend/LegacyInstance.h b/backend/LegacyInstance.h
index ef449b79..64b7b40a 100644
--- a/backend/LegacyInstance.h
+++ b/backend/LegacyInstance.h
@@ -84,8 +84,8 @@ public:
* If this is not the same as currentVersion, the instance's game updater
* will be run on launch.
*/
- QString intendedVersion() const;
- void setIntendedVersion(QString val);
+ virtual QString intendedVersionId();
+ virtual bool setIntendedVersionId ( QString version );
/*!
* Whether or not Minecraft should be downloaded when the instance is launched.
diff --git a/backend/OneSixAssets.cpp b/backend/OneSixAssets.cpp
new file mode 100644
index 00000000..e2894bdd
--- /dev/null
+++ b/backend/OneSixAssets.cpp
@@ -0,0 +1,157 @@
+#include <QString>
+#include <QDebug>
+#include <QtXml/QtXml>
+#include "OneSixAssets.h"
+#include "dlqueue.h"
+
+inline QDomElement getDomElementByTagName(QDomElement parent, QString tagname)
+{
+ QDomNodeList elementList = parent.elementsByTagName(tagname);
+ if (elementList.count())
+ return elementList.at(0).toElement();
+ else
+ return QDomElement();
+}
+
+class ThreadedDeleter : public QThread
+{
+ Q_OBJECT
+public:
+ void run()
+ {
+ QDirIterator iter(m_base, QDirIterator::Subdirectories);
+ QStringList nuke_list;
+ int base_length = m_base.length();
+ while (iter.hasNext())
+ {
+ QString filename = iter.next();
+ QFileInfo current(filename);
+ // we keep the dirs... whatever
+ if(current.isDir())
+ continue;
+ QString trimmedf = filename;
+ trimmedf.remove(0, base_length + 1);
+ if(m_whitelist.contains(trimmedf))
+ {
+ //qDebug() << trimmedf << " gets to live";
+ }
+ else
+ {
+ // DO NOT TOLERATE JUNK
+ //qDebug() << trimmedf << " dies";
+ QFile f (filename);
+ f.remove();
+ }
+ }
+ };
+ QString m_base;
+ QStringList m_whitelist;
+};
+
+class NukeAndPaveJob: public Job
+{
+ Q_OBJECT
+public:
+
+ explicit NukeAndPaveJob(QString base, QStringList whitelist)
+ :Job()
+ {
+ QDir dir(base);
+ deleterThread.m_base = dir.absolutePath();
+ deleterThread.m_whitelist = whitelist;
+ };
+public slots:
+ virtual void start()
+ {
+ connect(&deleterThread, SIGNAL(finished()), SLOT(threadFinished()));
+ deleterThread.start();
+ };
+ void threadFinished()
+ {
+ emit finish();
+ }
+private:
+ ThreadedDeleter deleterThread;
+};
+
+class Private
+{
+public:
+ JobListQueue dl;
+ JobListPtr index_job;
+ JobListPtr files_job;
+};
+
+OneSixAssets::OneSixAssets(QObject* parent):QObject(parent), d(new Private) {}
+
+void OneSixAssets::fetchFinished()
+{
+ QString prefix ( "http://s3.amazonaws.com/Minecraft.Resources/" );
+ QString fprefix ( "assets/" );
+ QStringList nuke_whitelist;
+
+ JobPtr firstJob = d->index_job->getFirstJob();
+ auto DlJob = firstJob.dynamicCast<DownloadJob>();
+ QByteArray ba = DlJob->m_data;
+
+ QString xmlErrorMsg;
+ QDomDocument doc;
+ if ( !doc.setContent ( ba, false, &xmlErrorMsg ) )
+ {
+ qDebug() << "Failed to process s3.amazonaws.com/Minecraft.Resources. XML error:" <<
+ xmlErrorMsg << ba;
+ }
+ //QRegExp etag_match(".*([a-f0-9]{32}).*");
+ QDomNodeList contents = doc.elementsByTagName ( "Contents" );
+
+ JobList *job = new JobList();
+ connect ( job, SIGNAL ( finished() ), SIGNAL(finished()) );
+ connect ( job, SIGNAL ( failed() ), SIGNAL(failed()) );
+
+ for ( int i = 0; i < contents.length(); i++ )
+ {
+ QDomElement element = contents.at ( i ).toElement();
+
+ if ( element.isNull() )
+ continue;
+
+ QDomElement keyElement = getDomElementByTagName ( element, "Key" );
+ QDomElement lastmodElement = getDomElementByTagName ( element, "LastModified" );
+ QDomElement etagElement = getDomElementByTagName ( element, "ETag" );
+ QDomElement sizeElement = getDomElementByTagName ( element, "Size" );
+
+ if ( keyElement.isNull() || lastmodElement.isNull() || etagElement.isNull() || sizeElement.isNull() )
+ continue;
+
+ QString keyStr = keyElement.text();
+ QString lastModStr = lastmodElement.text();
+ QString etagStr = etagElement.text();
+ QString sizeStr = sizeElement.text();
+
+ //Filter folder keys
+ if ( sizeStr == "0" )
+ continue;
+
+ QString trimmedEtag = etagStr.remove ( '"' );
+ job->add ( DownloadJob::create ( QUrl ( prefix + keyStr ),fprefix + keyStr, trimmedEtag ) );
+ nuke_whitelist.append ( keyStr );
+ }
+ job->add ( JobPtr ( new NukeAndPaveJob ( fprefix, nuke_whitelist ) ) );
+ d->files_job.reset ( job );
+ d->dl.enqueue ( d->files_job );
+}
+void OneSixAssets::fetchStarted()
+{
+ qDebug() << "Started downloading!";
+}
+void OneSixAssets::start()
+{
+ JobList *job = new JobList();
+ job->add ( DownloadJob::create ( QUrl ( "http://s3.amazonaws.com/Minecraft.Resources/" ) ) );
+ connect ( job, SIGNAL ( finished() ), SLOT ( fetchFinished() ) );
+ connect ( job, SIGNAL ( started() ), SLOT ( fetchStarted() ) );
+ d->index_job.reset ( job );
+ d->dl.enqueue ( d->index_job );
+}
+
+#include "OneSixAssets.moc" \ No newline at end of file
diff --git a/backend/OneSixAssets.h b/backend/OneSixAssets.h
new file mode 100644
index 00000000..caf67c93
--- /dev/null
+++ b/backend/OneSixAssets.h
@@ -0,0 +1,21 @@
+#pragma once
+#include <QObject>
+#include <QSharedPointer>
+
+class Private;
+
+class OneSixAssets : public QObject
+{
+ Q_OBJECT
+signals:
+ void failed();
+ void finished();
+
+public slots:
+ void fetchFinished();
+ void fetchStarted();
+public:
+ explicit OneSixAssets ( QObject* parent = 0 );
+ void start();
+ QSharedPointer<Private> d;
+};
diff --git a/backend/OneSixInstance.cpp b/backend/OneSixInstance.cpp
index 1932651c..d81ed3b1 100644
--- a/backend/OneSixInstance.cpp
+++ b/backend/OneSixInstance.cpp
@@ -1,18 +1,32 @@
#include "OneSixInstance.h"
#include "OneSixInstance_p.h"
+#include "tasks/GameUpdateTask.h"
+#include "MinecraftProcess.h"
+#include <setting.h>
-OneSixInstance::OneSixInstance ( const QString& rootDir, SettingsObject* settings, QObject* parent )
-: BaseInstance ( new OneSixInstancePrivate(), rootDir, settings, parent )
+OneSixInstance::OneSixInstance ( const QString& rootDir, SettingsObject* setting_obj, QObject* parent )
+: BaseInstance ( new OneSixInstancePrivate(), rootDir, setting_obj, parent )
{
-
+ I_D(OneSixInstance);
+ d->m_settings->registerSetting(new Setting("IntendedVersion", ""));
}
GameUpdateTask* OneSixInstance::doUpdate()
{
- return nullptr;
+ return new GameUpdateTask(this);
}
MinecraftProcess* OneSixInstance::prepareForLaunch ( QString user, QString session )
{
return nullptr;
}
+
+bool OneSixInstance::setIntendedVersionId ( QString version )
+{
+ settings().set("IntendedVersion", version);
+}
+
+QString OneSixInstance::intendedVersionId()
+{
+ return settings().get("IntendedVersion").toString();
+}
diff --git a/backend/OneSixInstance.h b/backend/OneSixInstance.h
index 2abf5b49..5b4b2d8f 100644
--- a/backend/OneSixInstance.h
+++ b/backend/OneSixInstance.h
@@ -8,4 +8,8 @@ public:
explicit OneSixInstance(const QString &rootDir, SettingsObject * settings, QObject *parent = 0);
virtual GameUpdateTask* doUpdate();
virtual MinecraftProcess* prepareForLaunch ( QString user, QString session );
+
+ virtual bool setIntendedVersionId ( QString version );
+ virtual QString intendedVersionId();
+
}; \ No newline at end of file
diff --git a/backend/tasks/GameUpdateTask.cpp b/backend/tasks/GameUpdateTask.cpp
index 2b1acf26..f49b551c 100644
--- a/backend/tasks/GameUpdateTask.cpp
+++ b/backend/tasks/GameUpdateTask.cpp
@@ -24,6 +24,7 @@
#include <QDebug>
+#include "BaseInstance.h"
#include "lists/MinecraftVersionList.h"
#include "VersionFactory.h"
#include "OneSixVersion.h"
@@ -31,34 +32,23 @@
#include "pathutils.h"
-GameUpdateTask::GameUpdateTask(const LoginResponse &response, BaseInstance *inst, QObject *parent) :
- Task(parent), m_response(response)
+GameUpdateTask::GameUpdateTask(BaseInstance *inst, QObject *parent) :
+ Task(parent)
{
m_inst = inst;
- m_updateState = StateInit;
}
void GameUpdateTask::executeTask()
{
- updateStatus();
-
// Get a pointer to the version object that corresponds to the instance's version.
- //FIXME: HACKERY
- // targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().findVersion(m_inst->intendedVersion());
+ targetVersion = (MinecraftVersion *)MinecraftVersionList::getMainList().findVersion(m_inst->intendedVersionId());
if(targetVersion == NULL)
{
- //Q_ASSERT_X(targetVersion != NULL, "game update", "instance's intended version is not an actual version");
- setState(StateFinished);
- emit gameUpdateComplete(m_response);
+ emit gameUpdateComplete();
return;
}
- /////////////////////////
- // BUILD DOWNLOAD LIST //
- /////////////////////////
- // Build a list of URLs that will need to be downloaded.
-
- setState(StateDetermineURLs);
+ setStatus("Getting the version files from Mojang.");
QString urlstr("http://s3.amazonaws.com/Minecraft.Download/versions/");
urlstr += targetVersion->descriptor() + "/" + targetVersion->descriptor() + ".json";
@@ -121,10 +111,6 @@ void GameUpdateTask::versionFileFinished()
void GameUpdateTask::jarlibFinished()
{
- //FIXME: HACKERY
- // m_inst->setCurrentVersion(targetVersion->descriptor());
- // m_inst->setShouldUpdate(false);
- // m_inst->setIsForNewLauncher(true);
exit(1);
}
@@ -140,70 +126,6 @@ void GameUpdateTask::versionFileFailed()
exit(0);
}
-
-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);
diff --git a/backend/tasks/GameUpdateTask.h b/backend/tasks/GameUpdateTask.h
index ea0cf658..f13f42d1 100644
--- a/backend/tasks/GameUpdateTask.h
+++ b/backend/tasks/GameUpdateTask.h
@@ -24,12 +24,10 @@
#include "dlqueue.h"
#include "Task.h"
-#include "tasks/LoginResponse.h"
-#include "BaseInstance.h"
-
#include "libmmc_config.h"
class MinecraftVersion;
+class BaseInstance;
/*!
* The game update task is the task that handles downloading instances' files.
@@ -37,58 +35,14 @@ class MinecraftVersion;
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, BaseInstance *inst, QObject *parent = 0);
-
-
- /////////////////////////
- // EXECUTION FUNCTIONS //
- /////////////////////////
+ explicit GameUpdateTask(BaseInstance *inst, QObject *parent = 0);
virtual void executeTask();
- //////////////////////
- // 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);
-
-private:
- void getLegacyJar();
- void determineNewVersion();
-
public slots:
-
- /*!
- * Updates the status message based on the state and substatus message.
- */
- virtual void updateStatus();
-
-
virtual void error(const QString &msg);
-
private slots:
void updateDownloadProgress(qint64 current, qint64 total);
@@ -103,7 +57,7 @@ signals:
* \brief Signal emitted when the game update is complete.
* \param response The login response received from login task.
*/
- void gameUpdateComplete(const LoginResponse &response);
+ void gameUpdateComplete();
/*!
* \brief Signal emitted if an error occurrs during the update.
@@ -112,37 +66,10 @@ signals:
void gameUpdateError(const QString &errorMsg);
private:
- ///////////
- // STUFF //
- ///////////
-
BaseInstance *m_inst;
- LoginResponse m_response;
-
- ////////////////////////////
- // 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
- };
JobListPtr legacyDownloadJob;
JobListPtr specificVersionDownloadJob;
JobListPtr jarlibDownloadJob;
diff --git a/backend/tasks/LoginResponse.cpp b/backend/tasks/LoginResponse.cpp
deleted file mode 100644
index 218f51c1..00000000
--- a/backend/tasks/LoginResponse.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/* 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 "tasks/LoginResponse.h"
-
-LoginResponse::LoginResponse(const QString& username, const QString& sessionID,
- qint64 latestVersion, QObject *parent) :
- QObject(parent)
-{
- this->m_username = username;
- this->m_sessionID = sessionID;
- this->m_latestVersion = latestVersion;
-}
-
-LoginResponse::LoginResponse()
-{
- this->m_username = "";
- this->m_sessionID = "";
- this->m_latestVersion = 0;
-}
-
-LoginResponse::LoginResponse(const LoginResponse &other)
-{
- this->m_username = other.username();
- this->m_sessionID = other.sessionID();
- this->m_latestVersion = other.latestVersion();
-}
-
-QString LoginResponse::username() const
-{
- return m_username;
-}
-
-void LoginResponse::setUsername(const QString& username)
-{
- this->m_username = username;
-}
-
-QString LoginResponse::sessionID() const
-{
- return m_sessionID;
-}
-
-void LoginResponse::setSessionID(const QString& sessionID)
-{
- this->m_sessionID = sessionID;
-}
-
-qint64 LoginResponse::latestVersion() const
-{
- return m_latestVersion;
-}
-
-void LoginResponse::setLatestVersion(qint64 v)
-{
- this->m_latestVersion = v;
-}
diff --git a/backend/tasks/LoginResponse.h b/backend/tasks/LoginResponse.h
deleted file mode 100644
index 60875619..00000000
--- a/backend/tasks/LoginResponse.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/* 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 <QObject>
-
-#include "libmmc_config.h"
-
-/*!
- * \brief The LoginResponse class represents a response received from Minecraft's login servers.
- */
-class LIBMULTIMC_EXPORT LoginResponse : public QObject
-{
- Q_OBJECT
-public:
- /*!
- * \brief Creates a new instance of the LoginResponse class.
- * \param username The user's username.
- * \param sessionID The user's session ID.
- * \param latestVersion The latest version of Minecraft.
- * \param parent The parent object.
- */
- explicit LoginResponse(const QString &username, const QString &sessionID,
- qint64 latestVersion, QObject *parent = 0);
- LoginResponse();
- LoginResponse(const LoginResponse& other);
-
- /*!
- * \brief Gets the username.
- * This one should go without saying.
- * \return The username.
- * \sa setUsername()
- */
- QString username() const;
-
- /*!
- * \brief setUsername Sets the username.
- * \param username The new username.
- * \sa username()
- */
- void setUsername(const QString& username);
-
-
- /*!
- * \brief Gets the session ID.
- * \return The session ID.
- * \sa setSessionID()
- */
- QString sessionID() const;
-
- /*!
- * \brief Sets the session ID.
- * \param sessionID The new session ID.
- * \sa sessionID()
- */
- void setSessionID(const QString& sessionID);
-
-
- /*!
- * \brief Gets the latest version.
- * This is a value returned by the login servers when a user logs in.
- * \return The latest version.
- * \sa setLatestVersion()
- */
- qint64 latestVersion() const;
-
- /*!
- * \brief Sets the latest version.
- * \param v The new latest version.
- * \sa latestVersion()
- */
- void setLatestVersion(qint64 v);
-
-private:
- QString m_username;
- QString m_sessionID;
- qint64 m_latestVersion;
-};
-
-Q_DECLARE_METATYPE(LoginResponse)
-
diff --git a/backend/tasks/LoginTask.cpp b/backend/tasks/LoginTask.cpp
index 11f58f28..999a718e 100644
--- a/backend/tasks/LoginTask.cpp
+++ b/backend/tasks/LoginTask.cpp
@@ -77,7 +77,7 @@ void LoginTask::processNetReply(QNetworkReply *reply)
QString username = strings[2];
QString sessionID = strings[3];
- LoginResponse response(username, sessionID, latestVersion);
+ LoginResponse response{username, sessionID, latestVersion};
emit loginComplete(response);
}
else
diff --git a/backend/tasks/LoginTask.h b/backend/tasks/LoginTask.h
index e23ea9e9..cb606204 100644
--- a/backend/tasks/LoginTask.h
+++ b/backend/tasks/LoginTask.h
@@ -19,10 +19,15 @@
#include "Task.h"
#include "UserInfo.h"
-#include "tasks/LoginResponse.h"
-
#include "libmmc_config.h"
+struct LoginResponse
+{
+ QString username;
+ QString sessionID;
+ qint64 latestVersion;
+};
+
//class QNetworkAccessManager;
class QNetworkReply;
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index db3a2828..50d301ed 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -192,15 +192,13 @@ void MainWindow::on_actionAddInstance_triggered()
QString instDir = PathCombine(globalSettings->get("InstanceDir").toString(), instDirName);
auto &loader = InstanceFactory::get();
- auto error = loader.createInstance(newInstance, instDir);
- QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName);
+ auto error = loader.createInstance(newInstance, newInstDlg->selectedVersion(), instDir);
+ QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName);
switch (error)
{
case InstanceFactory::NoCreateError:
newInstance->setName(newInstDlg->instName());
- // FIXME:HACKERY
- // newInstance->setIntendedVersion(newInstDlg->selectedVersion()->descriptor());
instList.add(InstancePtr(newInstance));
return;
@@ -417,24 +415,25 @@ void MainWindow::onLoginComplete(LoginResponse response)
{
if(!m_activeInst)
return;
+ m_activeLogin = LoginResponse(response);
GameUpdateTask *updateTask = m_activeInst->doUpdate();
if(!updateTask)
{
- launchInstance(m_activeInst, response);
+ launchInstance(m_activeInst, m_activeLogin);
}
else
{
TaskDialog *tDialog = new TaskDialog(this);
- connect(updateTask, SIGNAL(gameUpdateComplete(LoginResponse)),SLOT(onGameUpdateComplete(LoginResponse)));
+ connect(updateTask, SIGNAL(gameUpdateComplete()),SLOT(onGameUpdateComplete()));
connect(updateTask, SIGNAL(gameUpdateError(QString)), SLOT(onGameUpdateError(QString)));
tDialog->exec(updateTask);
}
}
-void MainWindow::onGameUpdateComplete(LoginResponse response)
+void MainWindow::onGameUpdateComplete()
{
- launchInstance(m_activeInst, response);
+ launchInstance(m_activeInst, m_activeLogin);
}
void MainWindow::onGameUpdateError(QString error)
@@ -446,7 +445,7 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
{
Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
- proc = instance->prepareForLaunch(response.username(), response.sessionID());
+ proc = instance->prepareForLaunch(response.username, response.sessionID);
if(!proc)
return;
@@ -524,8 +523,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered()
VersionSelectDialog *vselect = new VersionSelectDialog(inst->versionList(), this);
if (vselect->exec() && vselect->selectedVersion())
{
- // FIXME:HACKERY
- // inst->setIntendedVersion(vselect->selectedVersion()->descriptor());
+ inst->setIntendedVersionId(vselect->selectedVersion()->descriptor());
}
}
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index 738dac0c..8ab90cc6 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -19,7 +19,7 @@
#include <QMainWindow>
#include "lists/InstanceList.h"
-#include "tasks/LoginResponse.h"
+#include "tasks/LoginTask.h"
#include "BaseInstance.h"
class InstanceModel;
@@ -100,7 +100,7 @@ private slots:
void onLoginComplete(LoginResponse response);
- void onGameUpdateComplete(LoginResponse response);
+ void onGameUpdateComplete();
void onGameUpdateError(QString error);
void taskStart(Task *task);
@@ -133,6 +133,7 @@ private:
// This is set when the user launches an instance and is used to refer to that
// instance throughout the launching process.
BaseInstance *m_activeInst;
+ LoginResponse m_activeLogin;
Task *m_versionLoadTask;
};
diff --git a/main.cpp b/main.cpp
index 51cdde3f..468cf438 100644
--- a/main.cpp
+++ b/main.cpp
@@ -28,7 +28,6 @@
#include "AppSettings.h"
#include "lists/InstanceList.h"
-#include "tasks/LoginResponse.h"
#include "tasks/LoginTask.h"
#include "MinecraftProcess.h"
@@ -64,7 +63,7 @@ private slots:
void onLoginComplete(QString instId, LoginResponse response)
{
- proc = instance->prepareForLaunch(response.username(), response.sessionID());
+ proc = instance->prepareForLaunch(response.username, response.sessionID);
if(!proc)
{
//FIXME: report error