diff --git a/src/constants.cpp b/src/constants.cpp index 819cd82..557d346 100644 --- a/src/constants.cpp +++ b/src/constants.cpp @@ -1,4 +1,5 @@ #include "constants.h" +QString gameName = ""; QString datafolder = ""; QString launcherfolder = ""; diff --git a/src/constants.h b/src/constants.h index 3d29305..7204b8d 100644 --- a/src/constants.h +++ b/src/constants.h @@ -6,8 +6,6 @@ const QString version = "v1.3.1"; -static QString gameName = ""; - const QString DSDALAUNCHER_URL = "https://github.com/Pedro-Beirao/dsda-launcher"; const QString DSDALAUNCHER_API_URL = "https://api.github.com/repos/Pedro-Beirao/dsda-launcher/releases/latest"; const QString DSDALAUNCHER_DOWNLOAD_URL = "https://github.com/Pedro-Beirao/dsda-launcher/releases/latest"; @@ -22,6 +20,7 @@ const QChar FOLDER_SEPARATOR = '\\'; const QChar FOLDER_SEPARATOR = '/'; #endif +extern QString gameName; extern QString datafolder; extern QString launcherfolder; diff --git a/src/funcs.cpp b/src/funcs.cpp index 08bd8b4..e2740be 100644 --- a/src/funcs.cpp +++ b/src/funcs.cpp @@ -1,6 +1,27 @@ #include "funcs.h" #include +QString getGamePath() +{ +#if defined(Q_OS_WIN) + return launcherfolder + "\\" + gameName + ".exe"; +#elif defined(Q_OS_LINUX) + QProcess whichProcess; + whichProcess.start("which", QStringList(gameName)); + whichProcess.waitForFinished(); + if (whichProcess.readAllStandardOutput() != "") + { + return gameName; + } + else + { + return launcherfolder + "/" + gameName; + } +#elif defined(Q_OS_MACOS) + return launcherfolder + "/../Resources/" + gameName; +#endif +} + void openIWADsFolder() // CTRL+O runs this function to open the folder where the IWADs should be placed in { #if defined Q_OS_MACOS diff --git a/src/funcs.h b/src/funcs.h index 811c690..85d36fe 100644 --- a/src/funcs.h +++ b/src/funcs.h @@ -11,6 +11,7 @@ extern QSettings *settings; +QString getGamePath(); void openIWADsFolder(); QString getFileName(QString filePath); QFileInfoList getFilePath_possibleFiles(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e933a9c..2e7c79e 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -59,7 +59,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi #if defined(Q_OS_WIN) datafolder = launcherfolder; - #else QString dotfolder = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.dsda-doom"; if (QDir(dotfolder).exists()) @@ -621,12 +620,12 @@ void MainWindow::on_launchGame_pushButton_clicked(bool returnTooltip, QString ex QTextStream out(&file); #if defined Q_OS_MACOS - out << "\"" + launcherfolder + "/../Resources/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete; + out << "\"" + getGamePath() + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete; #elif defined Q_OS_LINUX - out << "\"" + launcherfolder + "/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete; + out << "\"" + getGamePath() + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete; #else std::replace(launcherfolder.begin(), launcherfolder.end(), '/', '\\'); - out << "\"" + launcherfolder + "\\" + gameName + ".exe\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete; + out << "\"" + getGamePath() + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete; #endif file.close(); @@ -644,12 +643,12 @@ void MainWindow::on_launchGame_pushButton_clicked(bool returnTooltip, QString ex { QClipboard *clip = QApplication::clipboard(); #if defined Q_OS_MACOS - clip->setText("\"" + launcherfolder + "/../Resources/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete); + clip->setText("\"" + getGamePath() + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete); #elif defined Q_OS_LINUX - clip->setText("\"" + launcherfolder + "/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete); + clip->setText("\"" + getGamePath() + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete); #else std::replace(launcherfolder.begin(), launcherfolder.end(), '/', '\\'); - clip->setText("\"" + launcherfolder + "\\" + gameName + ".exe\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete); + clip->setText("\"" + getGamePath() + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete); #endif } @@ -680,13 +679,15 @@ void MainWindow::Launch(QStringList arguments) } #if defined Q_OS_MACOS - QFile port = QFile(launcherfolder + "/../Resources/" + gameName + ""); + QString gamePath = getGamePath(); + QFile port = QFile(getGamePath()); + qDebug() << gamePath; if (port.exists()) { QString homePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); QProcess *process = new QProcess; process->setWorkingDirectory(homePath); - process->start(launcherfolder + "/../Resources/" + gameName, arguments); + process->start(gamePath, arguments); connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus))); connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput())); connect(process, SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError())); @@ -697,37 +698,34 @@ void MainWindow::Launch(QStringList arguments) QMessageBox::warning(this, "dsda-launcher", gameName + " was not found in dsda-launcher.app/Contents/Resources/" + gameName); } #elif defined Q_OS_LINUX - QFile port = QFile(launcherfolder + "/" + gameName); - QString homePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); - // Run "which" command to check if dsda-doom exists. if it does then no need to specify a path, just run a process with gameName. - QStringList apar; - apar << gameName; - QProcess whichProcess; - whichProcess.start("which", apar); - whichProcess.waitForFinished(); - QString processPath; - // If it finds an executable in the dsda-launcher folder, it will prioritize it over the one installed in a bin folder. - if (port.exists()) processPath = launcherfolder + "/" + gameName; - else processPath = gameName; - if (whichProcess.readAllStandardOutput() != "") + QString gamePath = getGamePath(); + QFile port = QFile(getGamePath()); + if (port.exists()) { + QString homePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); QProcess *process = new QProcess; process->setWorkingDirectory(homePath); - process->start(processPath, arguments); + process->start(gamePath, arguments); connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus))); connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput())); + connect(process, SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError())); connect(process, SIGNAL(started()), this, SLOT(started())); } - else QMessageBox::warning(this, "dsda-launcher", ("Failed to launch the application executable.\nMake sure that " + gameName + " is installed correctly through your package manager or installed with the original build instructions.\n\nIf you are sure " + gameName + " exists, symlink it to dsda-launcher's folder.")); + else + { + QMessageBox::warning(this, "dsda-launcher", ("Failed to launch the application executable.\nMake sure that " + gameName + " is installed correctly through your package manager or installed with the original build instructions.\n\nIf you are sure " + gameName + " exists, symlink it to dsda-launcher's folder.")); + } #else - QFile port = QFile(launcherfolder + "/" + gameName + ".exe"); + QString gamePath = getGamePath(); + QFile port = QFile(getGamePath()); if (port.exists()) { QProcess *process = new QProcess; process->setWorkingDirectory(launcherfolder); - process->start(launcherfolder + "/" + gameName + ".exe", arguments); + process->start(gamePath, arguments); connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus))); connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput())); + connect(process, SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError())); connect(process, SIGNAL(started()), this, SLOT(started())); } else diff --git a/src/mainwindow_actions.cpp b/src/mainwindow_actions.cpp index 4d8f773..77cc20e 100644 --- a/src/mainwindow_actions.cpp +++ b/src/mainwindow_actions.cpp @@ -87,15 +87,8 @@ void MainWindow::on_actionCheckForUpdatesDsdadoom_triggered() QString portversion; - QString path; - -#if defined Q_OS_MACOS - path = launcherfolder + "/../Resources/" + gameName; -#elif defined Q_OS_LINUX - path = launcherfolder + "/" + gameName; -#else - path = launcherfolder + "\\" + gameName + ".exe"; -#endif + QString path = getGamePath(); + QFile port = QFile(path); if (port.exists()) { diff --git a/src/mainwindow_bottom.cpp b/src/mainwindow_bottom.cpp index 8f3e9d6..6b223e7 100644 --- a/src/mainwindow_bottom.cpp +++ b/src/mainwindow_bottom.cpp @@ -12,15 +12,7 @@ void MainWindow::on_additionalArguments_pushButton_clicked() { if (!canLaunch) return; - QString path; - -#if defined Q_OS_MACOS - path = launcherfolder + "/../Resources/" + gameName; -#elif defined Q_OS_LINUX - path = launcherfolder + "/" + gameName; -#else - path = launcherfolder + "\\" + gameName + ".exe"; -#endif + QString path = getGamePath(); QFile port = QFile(path); if (port.exists())