diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-07-28 08:40:15 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-07-28 08:40:15 +0200 |
commit | 9d99b539bfaabe45a43948edf37e900401288f65 (patch) | |
tree | b583a7649dfa59597f352a41ed641b373f130436 /gui | |
parent | a7a84d4dbb58565f108cb0886da6cb786e34d10d (diff) | |
download | MultiMC-9d99b539bfaabe45a43948edf37e900401288f65.tar MultiMC-9d99b539bfaabe45a43948edf37e900401288f65.tar.gz MultiMC-9d99b539bfaabe45a43948edf37e900401288f65.tar.lz MultiMC-9d99b539bfaabe45a43948edf37e900401288f65.tar.xz MultiMC-9d99b539bfaabe45a43948edf37e900401288f65.zip |
Parsing the version files, part IV
Also, start of big refactors.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/mainwindow.cpp | 69 | ||||
-rw-r--r-- | gui/newinstancedialog.cpp | 2 | ||||
-rw-r--r-- | gui/newinstancedialog.h | 1 |
3 files changed, 32 insertions, 40 deletions
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 4bf38424..901f70b3 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -56,6 +56,7 @@ #include "gameupdatetask.h" #include "instance.h" +#include "instanceloader.h" #include "minecraftprocess.h" #include "instancemodel.h" @@ -182,46 +183,40 @@ void MainWindow::on_actionAddInstance_triggered() } NewInstanceDialog *newInstDlg = new NewInstanceDialog ( this ); - if (newInstDlg->exec()) + if (!newInstDlg->exec()) + return; + + Instance *newInstance = NULL; + + QString instDirName = DirNameFromString(newInstDlg->instName()); + QString instDir = PathCombine(globalSettings->get("InstanceDir").toString(), instDirName); + + auto &loader = InstanceLoader::get(); + auto error = loader.createInstance(newInstance, instDir); + QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName); + + switch (error) { - Instance *newInstance = NULL; - - QString instDirName = DirNameFromString(newInstDlg->instName()); - QString instDir = PathCombine(globalSettings->get("InstanceDir").toString(), - instDirName); + case InstanceLoader::NoCreateError: + newInstance->setName(newInstDlg->instName()); + newInstance->setIntendedVersion(newInstDlg->selectedVersion()->descriptor()); + instList.add(InstancePtr(newInstance)); + return; + + case InstanceLoader::InstExists: + errorMsg += "An instance with the given directory name already exists."; + QMessageBox::warning(this, "Error", errorMsg); + break; - InstanceLoader::InstLoaderError error = InstanceLoader::get(). - createInstance(newInstance, instDir); + case InstanceLoader::CantCreateDir: + errorMsg += "Failed to create the instance directory."; + QMessageBox::warning(this, "Error", errorMsg); + break; - if (error == InstanceLoader::NoError) - { - newInstance->setName(newInstDlg->instName()); - newInstance->setIntendedVersion(newInstDlg->selectedVersion()->descriptor()); - instList.add(InstancePtr(newInstance)); - } - else - { - QString errorMsg = QString("Failed to create instance %1: "). - arg(instDirName); - - switch (error) - { - case InstanceLoader::InstExists: - errorMsg += "An instance with the given directory name already exists."; - break; - - case InstanceLoader::CantCreateDir: - errorMsg += "Failed to create the instance directory."; - break; - - default: - errorMsg += QString("Unknown instance loader error %1"). - arg(error); - break; - } - - QMessageBox::warning(this, "Error", errorMsg); - } + default: + errorMsg += QString("Unknown instance loader error %1").arg(error); + QMessageBox::warning(this, "Error", errorMsg); + break; } } diff --git a/gui/newinstancedialog.cpp b/gui/newinstancedialog.cpp index ccdea063..cf005429 100644 --- a/gui/newinstancedialog.cpp +++ b/gui/newinstancedialog.cpp @@ -17,7 +17,6 @@ #include "ui_newinstancedialog.h" #include "instanceloader.h" -#include "instancetypeinterface.h" #include "instversionlist.h" #include "instversion.h" @@ -36,7 +35,6 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent) : QDialog(parent), ui(new Ui::NewInstanceDialog) { - m_selectedType = NULL; m_selectedVersion = NULL; ui->setupUi(this); diff --git a/gui/newinstancedialog.h b/gui/newinstancedialog.h index 1970e37a..4ea5f944 100644 --- a/gui/newinstancedialog.h +++ b/gui/newinstancedialog.h @@ -52,7 +52,6 @@ private: Ui::NewInstanceDialog *ui; const InstVersion *m_selectedVersion; - const InstanceTypeInterface *m_selectedType; }; #endif // NEWINSTANCEDIALOG_H |