diff --git a/mainwindow.cpp b/mainwindow.cpp index 063683c..5c35218 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,10 +2,12 @@ #include "ui_mainwindow.h" #include "firstdialog.h" +#include "QDir" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow), - settings(new QSettings) + settings(new QSettings), + ui(new Ui::MainWindow) { // Check if this first run if (! settings->value("internal/isConfigured").toBool()) { @@ -27,6 +29,16 @@ MainWindow::MainWindow(QWidget *parent) : // Disable context menu ui->webView->setContextMenuPolicy(Qt::CustomContextMenu); + foreach(QString key, settings->allKeys()) + { + if (key.right(4) == ".mod") + { + QDir dir(settings->value("userOptions/pathConfig").toString() + "mod/"); + if(!dir.exists(key)) + settings->remove(key); + } + } + foreach(QString modName, listFiles(settings->value("userOptions/pathConfig").toString() + "mod/", "*.mod")) { QString modIniName = extractName(settings->value("userOptions/pathConfig").toString() + "/mod/", modName); @@ -92,9 +104,11 @@ void MainWindow::loadStyles() icon.addFile(launcherPath+"logo.ico", QSize(), QIcon::Normal, QIcon::Off); setWindowIcon(icon); - ui->widget->setStyleSheet("background-image: url("+launcherPath+"background.jpg);"); - ui->buttonRegister->setStyleSheet("background-image: url("+launcherPath+"button_small.jpg);border-width: 1px;"); - ui->buttonRun->setStyleSheet("background-image: url("+launcherPath+"button_big.jpg);border-width: 1px;"); + ui->widget->setStyleSheet( + "#widget { background-image: url("+launcherPath+"background.jpg); }" + "#buttonRegister { background-image: url("+launcherPath+"button_small.jpg);border-width: 1px; }" + "#buttonRun { background-image: url("+launcherPath+"button_big.jpg);border-width: 1px; }" + ); } @@ -129,8 +143,11 @@ void MainWindow::buttonClickedRegister() void MainWindow::buttonClickedRun() { + execPath = settings->value("userOptions/pathGame").toString()+settings->value("internal/executableName").toString(); + QStringList arguments; QStringList keysList = settings->allKeys(); + foreach(QString key, keysList) { if (key.right(4) == ".mod" && settings->value(key) == Qt::Checked) { arguments << "-mod=mod/" + key; @@ -141,11 +158,32 @@ void MainWindow::buttonClickedRun() } QProcess *gameProcess = new QProcess(); - gameProcess->start( - settings->value("userOptions/pathGame").toString()+settings->value("internal/executableName").toString(), - arguments); + connect(gameProcess, SIGNAL(started()), SLOT(gameStarted())); + connect(gameProcess, SIGNAL(error(QProcess::ProcessError)), SLOT(gameError())); + gameProcess->start(execPath, arguments); gameProcess->closeWriteChannel(); +} + +void MainWindow::gameError() +{ + QProcess *gameProcess = qobject_cast(sender()); + QMessageBox error(this); + QPushButton *configure = error.addButton(tr("Configure..."), QMessageBox::RejectRole); + QPushButton *ok = error.addButton(tr("OK"), QMessageBox::AcceptRole); + error.setDefaultButton(ok); + error.setEscapeButton(ok); + error.setWindowTitle(tr("Crusader Kings 2")); + error.setText(tr("Failed to start %1: %2").arg(execPath, gameProcess->errorString())); + error.setIcon(QMessageBox::Critical); + error.exec(); + if (error.clickedButton() == configure) { + FirstDialog dialog(this); + dialog.exec(); + } +} +void MainWindow::gameStarted() +{ // Quit after CK2 running QApplication::quit(); } diff --git a/mainwindow.h b/mainwindow.h index 237f743..d79f260 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -41,6 +41,7 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; + QString execPath; QStringList listFiles(QString directory, QString extension); QString extractName(QString iniDir, QString iniName); void loadStyles(); @@ -50,6 +51,8 @@ private slots: void buttonClickedRegister(); void buttonClickedRun(); void webviewLoadFinished(bool status); + void gameStarted(); + void gameError(); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 95df98b..0b5d7b8 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -135,10 +135,7 @@ - false - - - selection-background-color: rgb(255, 255, 255); + true