diff options
Diffstat (limited to 'logic')
-rw-r--r-- | logic/BaseInstance.cpp | 3 | ||||
-rw-r--r-- | logic/InstanceLauncher.cpp | 74 | ||||
-rw-r--r-- | logic/InstanceLauncher.h | 28 | ||||
-rw-r--r-- | logic/LegacyInstance.cpp | 8 | ||||
-rw-r--r-- | logic/LegacyUpdate.cpp | 14 | ||||
-rw-r--r-- | logic/lists/IconList.cpp (renamed from logic/IconListModel.cpp) | 27 | ||||
-rw-r--r-- | logic/lists/IconList.h (renamed from logic/IconListModel.h) | 9 | ||||
-rw-r--r-- | logic/lists/InstanceList.cpp | 11 | ||||
-rw-r--r-- | logic/lists/LwjglVersionList.cpp | 6 | ||||
-rw-r--r-- | logic/lists/MinecraftVersionList.cpp | 6 | ||||
-rw-r--r-- | logic/net/DownloadJob.cpp | 6 | ||||
-rw-r--r-- | logic/net/NetWorker.cpp | 30 | ||||
-rw-r--r-- | logic/net/NetWorker.h | 31 | ||||
-rw-r--r-- | logic/tasks/LoginTask.cpp | 8 |
14 files changed, 138 insertions, 123 deletions
diff --git a/logic/BaseInstance.cpp b/logic/BaseInstance.cpp index bd3229c8..e166449f 100644 --- a/logic/BaseInstance.cpp +++ b/logic/BaseInstance.cpp @@ -18,6 +18,7 @@ #include <QFileInfo> #include <QDir> +#include <MultiMC.h> #include "inisettingsobject.h" #include "setting.h" @@ -52,6 +53,8 @@ BaseInstance::BaseInstance( BaseInstancePrivate* d_in, settings().registerSetting(new Setting("UseCustomBaseJar", true)); settings().registerSetting(new Setting("CustomBaseJar", "")); + auto globalSettings = MMC->settings(); + // Java Settings settings().registerSetting(new Setting("OverrideJava", false)); settings().registerSetting(new OverrideSetting("JavaPath", globalSettings->getSetting("JavaPath"))); diff --git a/logic/InstanceLauncher.cpp b/logic/InstanceLauncher.cpp new file mode 100644 index 00000000..312f4c69 --- /dev/null +++ b/logic/InstanceLauncher.cpp @@ -0,0 +1,74 @@ +#include "InstanceLauncher.h" +#include "MultiMC.h" + +#include <iostream> +#include "gui/logindialog.h" +#include "gui/taskdialog.h" +#include "gui/consolewindow.h" +#include "logic/tasks/LoginTask.h" +#include "logic/MinecraftProcess.h" +#include "lists/InstanceList.h" + + +InstanceLauncher::InstanceLauncher ( QString instId ) + :QObject(), instId ( instId ) +{} + +void InstanceLauncher::onTerminated() +{ + std::cout << "Minecraft exited" << std::endl; + MMC->quit(); +} + +void InstanceLauncher::onLoginComplete() +{ + LoginTask * task = ( LoginTask * ) QObject::sender(); + auto result = task->getResult(); + auto instance = MMC->instances()->getInstanceById(instId); + proc = instance->prepareForLaunch ( result.username, result.sessionID ); + if ( !proc ) + { + //FIXME: report error + return; + } + console = new ConsoleWindow(); + console->show(); + + connect ( proc, SIGNAL ( ended() ), SLOT ( onTerminated() ) ); + connect ( proc, SIGNAL ( log ( QString,MessageLevel::Enum ) ), console, SLOT ( write ( QString,MessageLevel::Enum ) ) ); + + proc->launch(); +} + +void InstanceLauncher::doLogin ( const QString& errorMsg ) +{ + LoginDialog* loginDlg = new LoginDialog ( nullptr, errorMsg ); + loginDlg->exec(); + if ( loginDlg->result() == QDialog::Accepted ) + { + UserInfo uInfo {loginDlg->getUsername(), loginDlg->getPassword() }; + + TaskDialog* tDialog = new TaskDialog ( nullptr ); + LoginTask* loginTask = new LoginTask ( uInfo, tDialog ); + connect ( loginTask, SIGNAL ( succeeded() ),SLOT ( onLoginComplete() ), Qt::QueuedConnection ); + connect ( loginTask, SIGNAL ( failed ( QString ) ),SLOT ( doLogin ( QString ) ), Qt::QueuedConnection ); + tDialog->exec ( loginTask ); + } + //onLoginComplete(LoginResponse("Offline","Offline", 1)); +} + +int InstanceLauncher::launch() +{ + std::cout << "Launching Instance '" << qPrintable ( instId ) << "'" << std::endl; + auto instance = MMC->instances()->getInstanceById(instId); + if ( instance.isNull() ) + { + std::cout << "Could not find instance requested. note that you have to specify the ID, not the NAME" << std::endl; + return 1; + } + + std::cout << "Logging in..." << std::endl; + doLogin ( "" ); + + return MMC->exec(); +} diff --git a/logic/InstanceLauncher.h b/logic/InstanceLauncher.h new file mode 100644 index 00000000..de93e3d7 --- /dev/null +++ b/logic/InstanceLauncher.h @@ -0,0 +1,28 @@ +#pragma once + +#include <QObject> + +class MinecraftProcess; +class ConsoleWindow; + +// Commandline instance launcher +class InstanceLauncher : public QObject +{ + Q_OBJECT + +private: + QString instId; + MinecraftProcess *proc; + ConsoleWindow *console; + +public: + InstanceLauncher(QString instId); + +private slots: + void onTerminated(); + void onLoginComplete(); + void doLogin(const QString &errorMsg); + +public: + int launch(); +}; diff --git a/logic/LegacyInstance.cpp b/logic/LegacyInstance.cpp index 124cdfcb..0672d2c8 100644 --- a/logic/LegacyInstance.cpp +++ b/logic/LegacyInstance.cpp @@ -2,7 +2,7 @@ #include "LegacyInstance_p.h" #include "MinecraftProcess.h" #include "LegacyUpdate.h" -#include "IconListModel.h" +#include "lists/IconList.h" #include <setting.h> #include <pathutils.h> #include <cmdutils.h> @@ -10,6 +10,7 @@ #include <QFileInfo> #include <QDir> #include <QImage> +#include <MultiMC.h> #define LAUNCHER_FILE "MultiMCLauncher.jar" @@ -32,8 +33,7 @@ MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session { MinecraftProcess * proc = new MinecraftProcess(this); - IconList * list = IconList::instance(); - QIcon icon = list->getIcon(iconKey()); + QIcon icon = MMC->icons()->getIcon(iconKey()); auto pixmap = icon.pixmap(128,128); pixmap.save(PathCombine(minecraftRoot(), "icon.png"),"PNG"); @@ -66,7 +66,7 @@ MinecraftProcess* LegacyInstance::prepareForLaunch(QString user, QString session args << QString("-Xdock:name=\"%1\"").arg(windowTitle); #endif - QString lwjgl = QDir(globalSettings->get("LWJGLDir").toString() + "/" + lwjglVersion()).absolutePath(); + QString lwjgl = QDir(MMC->settings()->get("LWJGLDir").toString() + "/" + lwjglVersion()).absolutePath(); // launcher arguments args << QString("-Xms%1m").arg(settings().get("MinMemAlloc").toInt()); diff --git a/logic/LegacyUpdate.cpp b/logic/LegacyUpdate.cpp index 3d286373..626ad1e0 100644 --- a/logic/LegacyUpdate.cpp +++ b/logic/LegacyUpdate.cpp @@ -3,7 +3,7 @@ #include "lists/MinecraftVersionList.h" #include "BaseInstance.h" #include "LegacyInstance.h" -#include "net/NetWorker.h" +#include "MultiMC.h" #include "ModList.h" #include <pathutils.h> #include <quazip.h> @@ -52,15 +52,15 @@ void LegacyUpdate::lwjglStart() QString url = version->url(); QUrl realUrl(url); QString hostname = realUrl.host(); - auto &worker = NetWorker::qnam(); + auto worker = MMC->qnam(); QNetworkRequest req(realUrl); req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); - QNetworkReply * rep = worker.get ( req ); + QNetworkReply * rep = worker->get ( req ); m_reply = QSharedPointer<QNetworkReply> (rep, &QObject::deleteLater); connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); - connect(&worker, SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*))); + connect(worker, SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*))); //connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError))); } @@ -77,13 +77,13 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply) "\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV"); return; } - auto &worker = NetWorker::qnam(); + auto *worker = MMC->qnam(); //Here i check if there is a cookie for me in the reply and extract it QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie>>(reply->header(QNetworkRequest::SetCookieHeader)); if(cookies.count() != 0) { //you must tell which cookie goes with which url - worker.cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net")); + worker->cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net")); } //here you can check for the 302 or whatever other header i need @@ -96,7 +96,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply) QNetworkRequest req(redirectedTo); req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)"); - QNetworkReply * rep = worker.get(req); + QNetworkReply * rep = worker->get(req); connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64))); m_reply = QSharedPointer<QNetworkReply> (rep, &QObject::deleteLater); return; diff --git a/logic/IconListModel.cpp b/logic/lists/IconList.cpp index 4a5795d6..6988d02f 100644 --- a/logic/IconListModel.cpp +++ b/logic/lists/IconList.cpp @@ -1,4 +1,4 @@ -#include "IconListModel.h" +#include "IconList.h" #include <pathutils.h> #include <QMap> #include <QEventLoop> @@ -6,8 +6,6 @@ #include <QMimeData> #include <QUrl> #define MAX_SIZE 1024 -IconList* IconList::m_Instance = 0; -QMutex IconList::mutex; struct entry { @@ -256,25 +254,4 @@ int IconList::getIconIndex ( QString key ) return -1; } - -void IconList::drop() -{ - mutex.lock(); - delete m_Instance; - m_Instance = 0; - mutex.unlock(); -} - -IconList* IconList::instance() -{ - if ( !m_Instance ) - { - mutex.lock(); - if ( !m_Instance ) - m_Instance = new IconList; - mutex.unlock(); - } - return m_Instance; -} - -#include "IconListModel.moc"
\ No newline at end of file +#include "IconList.moc"
\ No newline at end of file diff --git a/logic/IconListModel.h b/logic/lists/IconList.h index 907dfd81..cad80cdf 100644 --- a/logic/IconListModel.h +++ b/logic/lists/IconList.h @@ -9,8 +9,9 @@ class Private; class IconList : public QAbstractListModel { public: - static IconList* instance(); - static void drop(); + IconList(); + virtual ~IconList(); + QIcon getIcon ( QString key ); int getIconIndex ( QString key ); @@ -28,14 +29,10 @@ public: void installIcons ( QStringList iconFiles ); private: - virtual ~IconList(); - IconList(); // hide copy constructor IconList ( const IconList & ) = delete; // hide assign op IconList& operator= ( const IconList & ) = delete; void reindex(); - static IconList* m_Instance; - static QMutex mutex; Private* d; }; diff --git a/logic/lists/InstanceList.cpp b/logic/lists/InstanceList.cpp index 1d13e3f2..b930f781 100644 --- a/logic/lists/InstanceList.cpp +++ b/logic/lists/InstanceList.cpp @@ -22,13 +22,13 @@ #include <QJsonDocument> #include <QJsonObject> #include <QJsonArray> +#include <pathutils.h> +#include "MultiMC.h" #include "logic/lists/InstanceList.h" +#include "logic/lists/IconList.h" #include "logic/BaseInstance.h" #include "logic/InstanceFactory.h" -#include <logic/IconListModel.h> - -#include "pathutils.h" const static int GROUP_FILE_FORMAT_VERSION = 1; @@ -81,9 +81,8 @@ QVariant InstanceList::data ( const QModelIndex& index, int role ) const } case Qt::DecorationRole: { - IconList * ic = IconList::instance(); QString key = pdata->iconKey(); - return ic->getIcon(key); + return MMC->icons()->getIcon(key); } // for now. case KCategorizedSortFilterProxyModel::CategorySortRole: @@ -413,5 +412,3 @@ bool InstanceProxyModel::subSortLessThan (const QModelIndex& left, const QModelI return QString::localeAwareCompare(pdataLeft->name(), pdataRight->name()) < 0; //return pdataLeft->name() < pdataRight->name(); } - -#include "InstanceList.moc"
\ No newline at end of file diff --git a/logic/lists/LwjglVersionList.cpp b/logic/lists/LwjglVersionList.cpp index c0854628..d7826a82 100644 --- a/logic/lists/LwjglVersionList.cpp +++ b/logic/lists/LwjglVersionList.cpp @@ -14,7 +14,7 @@ */ #include "LwjglVersionList.h" -#include "logic/net/NetWorker.h" +#include "MultiMC.h" #include <QtNetwork> @@ -91,8 +91,8 @@ void LWJGLVersionList::loadList() Q_ASSERT_X(!m_loading, "loadList", "list is already loading (m_loading is true)"); setLoading(true); - auto & worker = NetWorker::qnam(); - reply = worker.get(QNetworkRequest(QUrl(RSS_URL))); + auto worker = MMC->qnam(); + reply = worker->get(QNetworkRequest(QUrl(RSS_URL))); connect(reply, SIGNAL(finished()), SLOT(netRequestComplete())); } diff --git a/logic/lists/MinecraftVersionList.cpp b/logic/lists/MinecraftVersionList.cpp index 4444f5b0..42fb1b50 100644 --- a/logic/lists/MinecraftVersionList.cpp +++ b/logic/lists/MinecraftVersionList.cpp @@ -14,7 +14,7 @@ */ #include "MinecraftVersionList.h" -#include <logic/net/NetWorker.h> +#include <MultiMC.h> #include <QDebug> @@ -151,8 +151,8 @@ MCVListLoadTask::~MCVListLoadTask() void MCVListLoadTask::executeTask() { setStatus("Loading instance version list..."); - auto & worker = NetWorker::qnam(); - vlistReply = worker.get(QNetworkRequest(QUrl(QString(MCVLIST_URLBASE) + "versions.json"))); + auto worker = MMC->qnam(); + vlistReply = worker->get(QNetworkRequest(QUrl(QString(MCVLIST_URLBASE) + "versions.json"))); connect(vlistReply, SIGNAL(finished()), this, SLOT(list_downloaded())); } diff --git a/logic/net/DownloadJob.cpp b/logic/net/DownloadJob.cpp index b87d3dc9..cad9ae72 100644 --- a/logic/net/DownloadJob.cpp +++ b/logic/net/DownloadJob.cpp @@ -1,6 +1,6 @@ #include "DownloadJob.h" #include "pathutils.h" -#include "NetWorker.h" +#include "MultiMC.h" Download::Download (QUrl url, QString target_path, QString expected_md5 ) :Job() @@ -49,8 +49,8 @@ void Download::start() QNetworkRequest request ( m_url ); request.setRawHeader(QString("If-None-Match").toLatin1(), m_expected_md5.toLatin1()); - auto &worker = NetWorker::qnam(); - QNetworkReply * rep = worker.get ( request ); + auto worker = MMC->qnam(); + QNetworkReply * rep = worker->get ( request ); m_reply = QSharedPointer<QNetworkReply> ( rep, &QObject::deleteLater ); connect ( rep, SIGNAL ( downloadProgress ( qint64,qint64 ) ), SLOT ( downloadProgress ( qint64,qint64 ) ) ); diff --git a/logic/net/NetWorker.cpp b/logic/net/NetWorker.cpp deleted file mode 100644 index c5943348..00000000 --- a/logic/net/NetWorker.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "NetWorker.h" -#include <QThreadStorage> - -class NetWorker::Private -{ -public: - QNetworkAccessManager manager; -}; - -NetWorker::NetWorker ( QObject* parent ) : QObject ( parent ) -{ - d = new Private(); -} - -QNetworkAccessManager& NetWorker::qnam() -{ - auto & w = worker(); - return w.d->manager; -} - - -NetWorker& NetWorker::worker() -{ - static QThreadStorage<NetWorker *> storage; - if (!storage.hasLocalData()) - { - storage.setLocalData(new NetWorker()); - } - return *storage.localData(); -} diff --git a/logic/net/NetWorker.h b/logic/net/NetWorker.h deleted file mode 100644 index cf7e72e1..00000000 --- a/logic/net/NetWorker.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - _.ooo-._ - .OOOP _ '. - dOOOO (_) \ - OOOOOb | - OOOOOOb. | - OOOOOOOOb | - YOO(_)OOO / - 'OOOOOY _.' - '""""'' -*/ -#pragma once - -#include <QNetworkAccessManager> -#include <QUrl> - -class NetWorker : public QObject -{ - Q_OBJECT -public: - // for high level access to the sevices (preferred) - static NetWorker &worker(); - // for low-level access to the network manager object - static QNetworkAccessManager &qnam(); -public: - -private: - explicit NetWorker ( QObject* parent = 0 ); - class Private; - Private * d; -};
\ No newline at end of file diff --git a/logic/tasks/LoginTask.cpp b/logic/tasks/LoginTask.cpp index 4e2f0fb7..ad9de7f5 100644 --- a/logic/tasks/LoginTask.cpp +++ b/logic/tasks/LoginTask.cpp @@ -14,7 +14,7 @@ */ #include "LoginTask.h" -#include "logic/net/NetWorker.h" +#include "MultiMC.h" #include <QStringList> @@ -29,8 +29,8 @@ LoginTask::LoginTask( const UserInfo& uInfo, QObject* parent ) : Task(parent), u void LoginTask::executeTask() { setStatus("Logging in..."); - auto & worker = NetWorker::qnam(); - connect(&worker, SIGNAL(finished(QNetworkReply*)), this, SLOT(processNetReply(QNetworkReply*))); + auto worker = MMC->qnam(); + connect(worker, SIGNAL(finished(QNetworkReply*)), this, SLOT(processNetReply(QNetworkReply*))); QUrl loginURL("https://login.minecraft.net/"); QNetworkRequest netRequest(loginURL); @@ -41,7 +41,7 @@ void LoginTask::executeTask() params.addQueryItem("password", uInfo.password); params.addQueryItem("version", "13"); - netReply = worker.post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8()); + netReply = worker->post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8()); } void LoginTask::processNetReply(QNetworkReply *reply) |