Skip to content

Commit

Permalink
Fix game path on windows and linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro-Beirao committed Jun 6, 2024
1 parent 15eea7f commit 864a22f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const QChar FOLDER_SEPARATOR = '/';
const QString dotfolder = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.dsda-doom";
#endif

static QString launcherFolderPath = "";
static QString launcherfolder = "";

const QStringList exmxIWADS = {"doom", "doom1", "doomu", "freedoom", "freedoom1", "bfgdoom", "bfgdoom1",

Expand Down
8 changes: 4 additions & 4 deletions src/funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void openIWADsFolder() // CTRL+O runs this function to open the folder where the
#elif Q_OS_LINUX
QProcess::startDetached("xdg-open", {dotfolder});
#else
QProcess::startDetached("explorer.exe", {gameName});
QProcess::startDetached("explorer.exe", {launcherfolder});
#endif
}

Expand All @@ -26,7 +26,7 @@ QFileInfoList getFilePath_possibleFiles()

// Find file in dsda folder
#ifdef Q_OS_WIN
QDir dsda_folder(gameName);
QDir dsda_folder(launcherfolder);
#else
QDir dsda_folder(dotfolder);
#endif
Expand Down Expand Up @@ -80,7 +80,7 @@ QString getFilePath(QString fileName)
// Find file in dsda folder
QString dsda_folder;
#ifdef Q_OS_WIN
dsda_folder = gameName;
dsda_folder = launcherfolder;
#else
dsda_folder = dotfolder;
#endif
Expand Down Expand Up @@ -171,7 +171,7 @@ QFileInfoList findIwads_possibleFiles()
doomwaddirstr = doomwaddirstr.split(":")[0];

#elif defined(Q_OS_WIN)
QDir directory(gameName);
QDir directory(launcherfolder);

doomwaddirstr = doomwaddirstr.split(";")[0];
#endif
Expand Down
44 changes: 22 additions & 22 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
QSettings *settings;
MainWindow *MainWindow::pMainWindow = nullptr;

void MainWindow::changeExeName(QString newName) { gameName = newName; }
void MainWindow::changeGameName(QString newName) { gameName = newName; }

void MainWindow::showSSLDialog()
{
Expand Down Expand Up @@ -55,7 +55,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->setupUi(this);
MainWindow::pMainWindow = this;

launcherFolderPath = QCoreApplication::applicationDirPath();
launcherfolder = QCoreApplication::applicationDirPath();

// Allow files to be droped in the launcher (*.wad *.lmp *.deh *.bex)
setAcceptDrops(true);
Expand Down Expand Up @@ -589,12 +589,12 @@ void MainWindow::on_launchGame_pushButton_clicked(bool returnTooltip, QString ex
QTextStream out(&file);

#ifdef Q_OS_MACOS
out << "\"" + launcherFolderPath + "/../Resources/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete;
out << "\"" + launcherfolder + "/../Resources/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete;
#elif Q_OS_LINUX
out << "\"" + gameName + "/" + exeName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete;
out << "\"" + launcherfolder + "/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete;
#else
std::replace(gameName.begin(), gameName.end(), '/', '\\');
out << "\"" + gameName + "\\" + exeName + ".exe\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete;
std::replace(launcherfolder.begin(), launcherfolder.end(), '/', '\\');
out << "\"" + launcherfolder + "\\" + gameName + ".exe\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete;
#endif
file.close();

Expand All @@ -612,12 +612,12 @@ void MainWindow::on_launchGame_pushButton_clicked(bool returnTooltip, QString ex
{
QClipboard *clip = QApplication::clipboard();
#ifdef Q_OS_MACOS
clip->setText("\"" + launcherFolderPath + "/../Resources/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete);
clip->setText("\"" + launcherfolder + "/../Resources/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete);
#elif Q_OS_LINUX
clip->setText("\"" + gameName + "/" + exeName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete);
clip->setText("\"" + launcherfolder + "/" + gameName + "\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete);
#else
std::replace(gameName.begin(), gameName.end(), '/', '\\');
clip->setText("\"" + gameName + "\\" + exeName + ".exe\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete);
std::replace(launcherfolder.begin(), launcherfolder.end(), '/', '\\');
clip->setText("\"" + launcherfolder + "\\" + gameName + ".exe\" -iwad \"" + ui->iwad_comboBox->itemData(ui->iwad_comboBox->currentIndex(), Qt::ToolTipRole).toString() + "\" " + argStrComplete);
#endif
}

Expand Down Expand Up @@ -648,13 +648,13 @@ void MainWindow::Launch(QStringList arguments)
}

#ifdef Q_OS_MACOS
QFile port = QFile(launcherFolderPath + "/../Resources/" + gameName + "");
QFile port = QFile(launcherfolder + "/../Resources/" + gameName + "");
if (port.exists())
{
QString homePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QProcess *process = new QProcess;
process->setWorkingDirectory(homePath);
process->start(launcherFolderPath + "/../Resources/" + gameName, arguments);
process->start(launcherfolder + "/../Resources/" + gameName, 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()));
Expand All @@ -665,18 +665,18 @@ void MainWindow::Launch(QStringList arguments)
QMessageBox::warning(this, "dsda-launcher", gameName + " was not found in dsda-launcher.app/Contents/Resources/" + gameName);
}
#elif Q_OS_LINUX
QFile port = QFile(gameName + "/" + exeName);
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 exeName.
// 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 << exeName;
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 = gameName + "/" + exeName;
else processPath = exeName;
if (port.exists()) processPath = launcherfolder + "/" + gameName;
else processPath = gameName;
if (whichProcess.readAllStandardOutput() != "")
{
QProcess *process = new QProcess;
Expand All @@ -686,21 +686,21 @@ void MainWindow::Launch(QStringList arguments)
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
connect(process, SIGNAL(started()), this, SLOT(started()));
}
else QMessageBox::warning(this, "dsda-launcher", ("Failed to launch the application executable.\nMake sure that " + exeName + " is installed correctly through your package manager or installed with the original build instructions.\n\nIf you are sure " + exeName + " 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(gameName + "/" + exeName + ".exe");
QFile port = QFile(launcherfolder + "/" + gameName + ".exe");
if (port.exists())
{
QProcess *process = new QProcess;
process->setWorkingDirectory(gameName);
process->start(gameName + "/" + exeName + ".exe", arguments);
process->setWorkingDirectory(launcherfolder);
process->start(launcherfolder + "/" + gameName + ".exe", arguments);
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus)));
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
connect(process, SIGNAL(started()), this, SLOT(started()));
}
else
{
QMessageBox::warning(this, "dsda-launcher", "Failed to launch the application executable.\nMake sure that the launcher is in the same folder as " + exeName + ".exe");
QMessageBox::warning(this, "dsda-launcher", "Failed to launch the application executable.\nMake sure that the launcher is in the same folder as " + gameName + ".exe");
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public slots:
void setResolutionsList(QListWidget *list);
void dropFile(QString fileName);
void dropLmp(QString filePath);
void changeExeName(QString newName);
void changeGameName(QString newName);
void setToggles(QString t1, QString a1, QString t2, QString a2, QString t3, QString a3, QString t4, QString a4);
void whenAnimationFinishNext();
void whenAnimationFinishPrevious();
Expand Down
6 changes: 3 additions & 3 deletions src/mainwindow_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ void MainWindow::on_actionCheckForUpdatesDsdadoom_triggered()
QString path;

#ifdef Q_OS_MACOS
path = launcherFolderPath + "/../Resources/" + gameName;
path = launcherfolder + "/../Resources/" + gameName;
#elif Q_OS_LINUX
path = gameName + "/" + gameName;
path = launcherfolder + "/" + gameName;
#else
path = gameName + "\\" + gameName + ".exe";
path = launcherfolder + "\\" + gameName + ".exe";
#endif
QFile port = QFile(path);
if (port.exists())
Expand Down
6 changes: 3 additions & 3 deletions src/mainwindow_bottom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ void MainWindow::on_additionalArguments_pushButton_clicked()
QString path;

#ifdef Q_OS_MACOS
path = launcherFolderPath + "/../Resources/" + gameName;
path = launcherfolder + "/../Resources/" + gameName;
#elif Q_OS_LINUX
path = gameName + "/" + gameName;
path = launcherfolder + "/" + gameName;
#else
path = gameName + "\\" + gameName + ".exe";
path = launcherfolder + "\\" + gameName + ".exe";
#endif

QFile port = QFile(path);
Expand Down
6 changes: 3 additions & 3 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Settings::Settings(QWidget *parent) : QWidget(parent), ui(new Ui::Settings)
{
ui->executable_lineEdit->setText(settings->value("exeName").toString());
}
MainWindow::pMainWindow->changeExeName(ui->executable_lineEdit->text());
MainWindow::pMainWindow->changeGameName(ui->executable_lineEdit->text());

ui->maxHistory_lineEdit->setValidator(new QRegularExpressionValidator (QRegularExpression("[0-9]{2}"), this));

Expand Down Expand Up @@ -394,11 +394,11 @@ void Settings::on_save_pushButton_clicked()

if (ui->executable_lineEdit->text().isEmpty())
{
MainWindow::pMainWindow->changeExeName("dsda-doom");
MainWindow::pMainWindow->changeGameName("dsda-doom");
}
else
{
MainWindow::pMainWindow->changeExeName(ui->executable_lineEdit->text());
MainWindow::pMainWindow->changeGameName(ui->executable_lineEdit->text());
}

settings->setValue("exeName", ui->executable_lineEdit->text());
Expand Down

0 comments on commit 864a22f

Please sign in to comment.