Merge branch 'develop'

This commit is contained in:
Sky 2013-10-26 11:13:14 +01:00
commit 1f28a3b8af
12 changed files with 114 additions and 29 deletions

View File

@ -37,6 +37,9 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
initTranslations(); initTranslations();
// Don't quit on hiding the last window
this->setQuitOnLastWindowClosed(false);
// Print app header // Print app header
std::cout << "MultiMC 5" << std::endl; std::cout << "MultiMC 5" << std::endl;
std::cout << "(c) 2013 MultiMC Contributors" << std::endl << std::endl; std::cout << "(c) 2013 MultiMC Contributors" << std::endl << std::endl;
@ -158,6 +161,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
m_status = MultiMC::Failed; m_status = MultiMC::Failed;
return; return;
} }
m_status = MultiMC::Initialized; m_status = MultiMC::Initialized;
} }

View File

@ -14,7 +14,7 @@ ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent) :
{ {
MultiMCPlatform::fixWM_CLASS(this); MultiMCPlatform::fixWM_CLASS(this);
ui->setupUi(this); ui->setupUi(this);
connect(mcproc, SIGNAL(ended()), this, SLOT(onEnded())); connect(mcproc, SIGNAL(ended(BaseInstance*)), this, SLOT(onEnded(BaseInstance*)));
} }
ConsoleWindow::~ConsoleWindow() ConsoleWindow::~ConsoleWindow()
@ -109,9 +109,14 @@ void ConsoleWindow::on_btnKillMinecraft_clicked()
r_u_sure.close(); r_u_sure.close();
} }
void ConsoleWindow::onEnded() void ConsoleWindow::onEnded(BaseInstance *instance)
{ {
ui->btnKillMinecraft->setEnabled(false); ui->btnKillMinecraft->setEnabled(false);
// TODO: Might need an option to forcefully close, even on an error
if(instance->settings().get("AutoCloseConsole").toBool())
{
// TODO: Check why this doesn't work // TODO: Check why this doesn't work
if (!proc->exitCode()) this->close(); if (!proc->exitCode()) this->close();
} }
}

View File

@ -49,7 +49,7 @@ public slots:
private slots: private slots:
void on_closeButton_clicked(); void on_closeButton_clicked();
void on_btnKillMinecraft_clicked(); void on_btnKillMinecraft_clicked();
void onEnded(); void onEnded(BaseInstance *instance);
protected: protected:
void closeEvent(QCloseEvent *); void closeEvent(QCloseEvent *);

View File

@ -155,6 +155,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
// FIXME: stop using POINTERS everywhere // FIXME: stop using POINTERS everywhere
connect(MMC->instances().get(), SIGNAL(dataIsInvalid()), SLOT(selectionBad())); connect(MMC->instances().get(), SIGNAL(dataIsInvalid()), SLOT(selectionBad()));
m_statusLeft = new QLabel(tr("Instance type"), this);
m_statusRight = new QLabel(tr("Assets information"), this);
m_statusRight->setAlignment(Qt::AlignRight);
statusBar()->addPermanentWidget(m_statusLeft, 1);
statusBar()->addPermanentWidget(m_statusRight, 0);
// run the things that load and download other things... FIXME: this is NOT the place // run the things that load and download other things... FIXME: this is NOT the place
// FIXME: invisible actions in the background = NOPE. // FIXME: invisible actions in the background = NOPE.
{ {
@ -168,6 +174,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
MMC->lwjgllist()->loadList(); MMC->lwjgllist()->loadList();
} }
assets_downloader = new OneSixAssets(); assets_downloader = new OneSixAssets();
connect(assets_downloader, SIGNAL(indexStarted()), SLOT(assetsIndexStarted()));
connect(assets_downloader, SIGNAL(filesStarted()), SLOT(assetsFilesStarted()));
connect(assets_downloader, SIGNAL(filesProgress(int, int, int)), SLOT(assetsFilesProgress(int, int, int)));
connect(assets_downloader, SIGNAL(failed()), SLOT(assetsFailed()));
connect(assets_downloader, SIGNAL(finished()), SLOT(assetsFinished()));
assets_downloader->start(); assets_downloader->start();
} }
} }
@ -433,6 +444,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
// settings->getConfig().setValue("MainWindowGeometry", saveGeometry()); // settings->getConfig().setValue("MainWindowGeometry", saveGeometry());
// settings->getConfig().setValue("MainWindowState", saveState()); // settings->getConfig().setValue("MainWindowState", saveState());
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
QApplication::exit();
} }
/* /*
void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos) void MainWindow::on_instanceView_customContextMenuRequested(const QPoint &pos)
@ -630,11 +642,18 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
this->hide(); this->hide();
} }
console = new ConsoleWindow(proc); console = new ConsoleWindow(proc);
console->show();
connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console, connect(proc, SIGNAL(log(QString, MessageLevel::Enum)), console,
SLOT(write(QString, MessageLevel::Enum))); SLOT(write(QString, MessageLevel::Enum)));
connect(proc, SIGNAL(ended()), this, SLOT(instanceEnded())); connect(proc, SIGNAL(ended(BaseInstance*)), this, SLOT(instanceEnded(BaseInstance*)));
if (instance->settings().get("ShowConsole").toBool())
{
console->show();
}
proc->setLogin(response.username, response.session_id); proc->setLogin(response.username, response.session_id);
proc->launch(); proc->launch();
} }
@ -747,8 +766,7 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
m_selectedInstance->menuActionEnabled("actionEditInstMods")); m_selectedInstance->menuActionEnabled("actionEditInstMods"));
ui->actionChangeInstMCVersion->setEnabled( ui->actionChangeInstMCVersion->setEnabled(
m_selectedInstance->menuActionEnabled("actionChangeInstMCVersion")); m_selectedInstance->menuActionEnabled("actionChangeInstMCVersion"));
statusBar()->clearMessage(); m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
statusBar()->showMessage(m_selectedInstance->getStatusbarDescription());
auto ico = MMC->icons()->getIcon(iconKey); auto ico = MMC->icons()->getIcon(iconKey);
ui->actionChangeInstIcon->setIcon(ico); ui->actionChangeInstIcon->setIcon(ico);
} }
@ -784,10 +802,15 @@ void MainWindow::on_actionEditInstNotes_triggered()
} }
} }
void MainWindow::instanceEnded() void MainWindow::instanceEnded(BaseInstance *instance)
{ {
this->show(); this->show();
ui->actionLaunchInstance->setEnabled(m_selectedInstance); ui->actionLaunchInstance->setEnabled(m_selectedInstance);
if (instance->settings().get("AutoCloseConsole").toBool())
{
console->close();
}
} }
void MainWindow::checkSetDefaultJava() void MainWindow::checkSetDefaultJava()
@ -822,18 +845,48 @@ void MainWindow::checkSetDefaultJava()
vselect.setResizeOn(2); vselect.setResizeOn(2);
vselect.exec(); vselect.exec();
if (!vselect.selectedVersion()) if (vselect.selectedVersion())
java = std::dynamic_pointer_cast<JavaVersion>(vselect.selectedVersion());
else
{ {
QMessageBox::warning(this, tr("Invalid version selected"), QMessageBox::warning(this, tr("Invalid version selected"),
tr("You didn't select a valid Java version, so MultiMC will " tr("You didn't select a valid Java version, so MultiMC will "
"select the default. " "select the default. "
"You can change this in the settings dialog.")); "You can change this in the settings dialog."));
JavaUtils ju; JavaUtils ju;
java = ju.GetDefaultJava(); java = ju.GetDefaultJava();
} }
if(java)
java = std::dynamic_pointer_cast<JavaVersion>(vselect.selectedVersion());
MMC->settings()->set("JavaPath", java->path); MMC->settings()->set("JavaPath", java->path);
else
MMC->settings()->set("JavaPath", QString("java"));
} }
} }
void MainWindow::assetsIndexStarted()
{
m_statusRight->setText(tr("Checking assets..."));
}
void MainWindow::assetsFilesStarted()
{
m_statusRight->setText(tr("Downloading assets..."));
}
void MainWindow::assetsFilesProgress(int succeeded, int failed, int total)
{
QString status = tr("Downloading assets: %1 / %2").arg(succeeded + failed).arg(total);
if(failed > 0) status += tr(" (%1 failed)").arg(failed);
status += tr("...");
m_statusRight->setText(status);
}
void MainWindow::assetsFailed()
{
m_statusRight->setText(tr("Failed to update assets."));
}
void MainWindow::assetsFinished()
{
m_statusRight->setText(tr("Assets up to date."));
}

View File

@ -112,10 +112,16 @@ private slots:
void on_actionChangeInstLWJGLVersion_triggered(); void on_actionChangeInstLWJGLVersion_triggered();
void instanceEnded(); void instanceEnded(BaseInstance *instance);
void on_actionInstanceSettings_triggered(); void on_actionInstanceSettings_triggered();
void assetsIndexStarted();
void assetsFilesStarted();
void assetsFilesProgress(int, int, int);
void assetsFailed();
void assetsFinished();
public slots: public slots:
void instanceActivated(QModelIndex); void instanceActivated(QModelIndex);
@ -150,6 +156,9 @@ private:
LoginResponse m_activeLogin; LoginResponse m_activeLogin;
Task *m_versionLoadTask; Task *m_versionLoadTask;
QLabel *m_statusLeft;
QLabel *m_statusRight;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -138,7 +138,7 @@ void MinecraftProcess::finish(int code, ExitStatus status)
} }
} }
m_instance->cleanupAfterRun(); m_instance->cleanupAfterRun();
emit ended(); emit ended(m_instance);
} }
void MinecraftProcess::killMinecraft() void MinecraftProcess::killMinecraft()

View File

@ -67,7 +67,7 @@ signals:
/** /**
* @brief emitted when mc has finished and the PostLaunchCommand was run * @brief emitted when mc has finished and the PostLaunchCommand was run
*/ */
void ended(); void ended(BaseInstance*);
/** /**
* @brief emitted when we want to log something * @brief emitted when we want to log something

View File

@ -67,6 +67,8 @@ void OneSixAssets::fetchXMLFinished()
QString fprefix ( "assets/" ); QString fprefix ( "assets/" );
nuke_whitelist.clear(); nuke_whitelist.clear();
emit filesStarted();
auto firstJob = index_job->first(); auto firstJob = index_job->first();
QByteArray ba = std::dynamic_pointer_cast<ByteArrayDownload>(firstJob)->m_data; QByteArray ba = std::dynamic_pointer_cast<ByteArrayDownload>(firstJob)->m_data;
@ -84,6 +86,7 @@ void OneSixAssets::fetchXMLFinished()
DownloadJob *job = new DownloadJob("Assets"); DownloadJob *job = new DownloadJob("Assets");
connect ( job, SIGNAL(succeeded()), SLOT(downloadFinished()) ); connect ( job, SIGNAL(succeeded()), SLOT(downloadFinished()) );
connect ( job, SIGNAL(failed()), SIGNAL(failed()) ); connect ( job, SIGNAL(failed()), SIGNAL(failed()) );
connect ( job, SIGNAL(filesProgress(int, int, int)), SIGNAL(filesProgress(int, int, int)) );
auto metacache = MMC->metacache(); auto metacache = MMC->metacache();
@ -130,14 +133,15 @@ void OneSixAssets::fetchXMLFinished()
emit finished(); emit finished();
} }
} }
void OneSixAssets::start() void OneSixAssets::start()
{ {
auto job = new DownloadJob("Assets index"); auto job = new DownloadJob("Assets index");
job->addByteArrayDownload(QUrl ( "http://s3.amazonaws.com/Minecraft.Resources/" )); job->addByteArrayDownload(QUrl ( "http://s3.amazonaws.com/Minecraft.Resources/" ));
connect ( job, SIGNAL(succeeded()), SLOT ( fetchXMLFinished() ) ); connect ( job, SIGNAL(succeeded()), SLOT ( fetchXMLFinished() ) );
emit indexStarted();
index_job.reset ( job ); index_job.reset ( job );
job->start(); job->start();
} }
#include "OneSixAssets.moc" #include "OneSixAssets.moc"

View File

@ -10,6 +10,9 @@ class OneSixAssets : public QObject
signals: signals:
void failed(); void failed();
void finished(); void finished();
void indexStarted();
void filesStarted();
void filesProgress(int, int, int);
public slots: public slots:
void fetchXMLFinished(); void fetchXMLFinished();

View File

@ -56,6 +56,8 @@ void DownloadJob::partSucceeded(int index)
num_succeeded++; num_succeeded++;
QLOG_INFO() << m_job_name.toLocal8Bit() << "progress:" << num_succeeded << "/" QLOG_INFO() << m_job_name.toLocal8Bit() << "progress:" << num_succeeded << "/"
<< downloads.size(); << downloads.size();
emit filesProgress(num_succeeded, num_failed, downloads.size());
if (num_failed + num_succeeded == downloads.size()) if (num_failed + num_succeeded == downloads.size())
{ {
if (num_failed) if (num_failed)
@ -78,6 +80,7 @@ void DownloadJob::partFailed(int index)
{ {
QLOG_ERROR() << "Part" << index << "failed 3 times (" << downloads[index]->m_url << ")"; QLOG_ERROR() << "Part" << index << "failed 3 times (" << downloads[index]->m_url << ")";
num_failed++; num_failed++;
emit filesProgress(num_succeeded, num_failed, downloads.size());
if (num_failed + num_succeeded == downloads.size()) if (num_failed + num_succeeded == downloads.size())
{ {
QLOG_ERROR() << m_job_name.toLocal8Bit() << "failed."; QLOG_ERROR() << m_job_name.toLocal8Bit() << "failed.";

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <QtNetwork> #include <QtNetwork>
#include <QLabel>
#include "Download.h" #include "Download.h"
#include "ByteArrayDownload.h" #include "ByteArrayDownload.h"
#include "FileDownload.h" #include "FileDownload.h"
@ -57,12 +58,13 @@ public:
signals: signals:
void started(); void started();
void progress(qint64 current, qint64 total); void progress(qint64 current, qint64 total);
void filesProgress(int, int, int);
void succeeded(); void succeeded();
void failed(); void failed();
public slots: public slots:
virtual void start(); virtual void start();
private slots: private slots:
void partProgress(int index, qint64 bytesReceived, qint64 bytesTotal);; void partProgress(int index, qint64 bytesReceived, qint64 bytesTotal);
void partSucceeded(int index); void partSucceeded(int index);
void partFailed(int index); void partFailed(int index);
private: private:

View File

@ -213,14 +213,16 @@ void LoginTask::yggdrasilLogin()
clientToken.remove('{'); clientToken.remove('{');
clientToken.remove('}'); clientToken.remove('}');
// create the request // create the request
QString requestConstent; QJsonObject root;
requestConstent += "{"; QJsonObject agent;
requestConstent += " \"agent\":{\"name\":\"Minecraft\",\"version\":1},\n"; agent.insert("name", QString("Minecraft"));
requestConstent += " \"username\":\"" + uInfo.username + "\",\n"; agent.insert("version", QJsonValue(1));
requestConstent += " \"password\":\"" + uInfo.password + "\",\n"; root.insert("agent", agent);
requestConstent += " \"clientToken\":\"" + clientToken + "\"\n"; root.insert("username", uInfo.username);
requestConstent += "}"; root.insert("password", uInfo.password);
netReply = worker->post(netRequest, requestConstent.toUtf8()); root.insert("clientToken", clientToken);
QJsonDocument requestDoc(root);
netReply = worker->post(netRequest, requestDoc.toJson());
} }
/* /*