Skip to content

Commit

Permalink
Add game updater for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro-Beirao committed Oct 31, 2024
1 parent 7d469eb commit a38aec8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
11 changes: 5 additions & 6 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

const QString version = "v1.3.1";

const QString UPDATER_URL = "https://raw.githubusercontent.com/Pedro-Beirao/dsda-launcher/refs/heads/master/updater.json";
const QString LAUNCHER_REPO = "https://github.com/Pedro-Beirao/dsda-launcher";
const QString LAUNCHER_UPDATER = "https://raw.githubusercontent.com/Pedro-Beirao/dsda-launcher/refs/heads/master/updater/updater.json";

const QString DSDALAUNCHER_URL = "https://github.com/Pedro-Beirao/dsda-launcher";

const QString DSDADOOM_URL = "https://github.com/kraflab/dsda-doom";
const QString DSDADOOM_API_URL = "https://api.github.com/repos/kraflab/dsda-doom/releases/latest";
const QString DSDADOOM_DOWNLOAD_URL = "https://github.com/kraflab/dsda-doom/";
const QString GAME_REPO = "https://github.com/kraflab/dsda-doom";
const QString GAME_API = "https://api.github.com/repos/kraflab/dsda-doom/releases/latest";
const QString GAME_UPDATER_MACOS = "https://raw.githubusercontent.com/Pedro-Beirao/dsda-launcher/refs/heads/master/updater/dsda-updater-macos.sh";

#if defined Q_OS_WIN
const QChar FOLDER_SEPARATOR = '\\';
Expand Down
8 changes: 4 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ void MainWindow::showSSLDialog()

void MainWindow::CheckForUpdates(bool manualReq)
{
QSimpleUpdater::getInstance()->setModuleVersion(UPDATER_URL, version);
QSimpleUpdater::getInstance()->setNotifyOnUpdate(UPDATER_URL, true);
QSimpleUpdater::getInstance()->setNotifyOnFinish(UPDATER_URL, manualReq);
QSimpleUpdater::getInstance()->checkForUpdates(UPDATER_URL);
QSimpleUpdater::getInstance()->setModuleVersion(LAUNCHER_UPDATER, version);
QSimpleUpdater::getInstance()->setNotifyOnUpdate(LAUNCHER_UPDATER, true);
QSimpleUpdater::getInstance()->setNotifyOnFinish(LAUNCHER_UPDATER, manualReq);
QSimpleUpdater::getInstance()->checkForUpdates(LAUNCHER_UPDATER);
}

// Prevents launching the game twice if the button "Launch" is pressed twice quickly
Expand Down
22 changes: 17 additions & 5 deletions src/mainwindow_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void MainWindow::on_actionAbout_triggered()
QMessageBox msgBox;
// msgBox.setOption(QMessageBox::Option::DontUseNativeDialog);
msgBox.setText(APP_NAME " " + version);
msgBox.setInformativeText("<a href='" + DSDALAUNCHER_URL + "'>" + DSDALAUNCHER_URL + "</a>");
msgBox.setInformativeText("<a href='" + LAUNCHER_REPO + "'>" + LAUNCHER_REPO + "</a>");
msgBox.addButton(tr("Ok"), QMessageBox::NoRole);
msgBox.exec();
}
Expand All @@ -32,9 +32,9 @@ void MainWindow::on_actionSaveState_triggered()
}
}

void MainWindow::on_actionGithubDsdalauncher_triggered() { QDesktopServices::openUrl(QUrl(DSDALAUNCHER_URL)); }
void MainWindow::on_actionGithubDsdalauncher_triggered() { QDesktopServices::openUrl(QUrl(LAUNCHER_REPO)); }

void MainWindow::on_actionGithubDsdadoom_triggered() { QDesktopServices::openUrl(QUrl(DSDADOOM_URL)); }
void MainWindow::on_actionGithubDsdadoom_triggered() { QDesktopServices::openUrl(QUrl(GAME_REPO)); }

void MainWindow::on_actionCheckForUpdatesDsdalauncher_triggered()
{
Expand Down Expand Up @@ -72,7 +72,7 @@ void MainWindow::on_actionCheckForUpdatesDsdadoom_triggered()
if (output.size() >= 2) portversion = output[1];
}

QNetworkRequest req0((QUrl(DSDADOOM_API_URL)));
QNetworkRequest req0((QUrl(GAME_API)));
req0.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QJsonObject json0;
QNetworkAccessManager nam0;
Expand Down Expand Up @@ -101,7 +101,19 @@ void MainWindow::on_actionCheckForUpdatesDsdadoom_triggered()
msgBox.exec();
if (msgBox.clickedButton() == pButtonYes)
{
QDesktopServices::openUrl(QUrl(DSDADOOM_DOWNLOAD_URL));
#if defined(Q_OS_MAC)
QProcess *process = new QProcess;
// clang-format off
process->startDetached("sh", {"-c", "rm /tmp/dsda-updater-macos.sh;"
"curl -L -o /tmp/dsda-updater-macos.sh " + GAME_UPDATER_MACOS + ";"
"p2=" + launcherfolder + "/../Resources;"
"p2=${p2//\\//\\\\/};"
"sed -i -e s/'$1'/$p2/g /tmp/dsda-updater-macos.sh;"
"chmod +x /tmp/dsda-updater-macos.sh;"
"open -a Terminal --args /tmp/dsda-updater-macos.sh"});
// clang-format on
process->deleteLater();
#endif
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow_bottom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void MainWindow::on_additionalArguments_pushButton_clicked()
{
#if defined Q_OS_MACOS
QProcess *process = new QProcess;
process->startDetached("sh", {"-c", "echo \"" + path + " --help ; rm /tmp/dsda-doom-params.sh\" > /tmp/dsda-doom-params.sh ; chmod +x /tmp/dsda-doom-params.sh ; open -a Terminal /tmp/dsda-doom-params.sh"});
process->startDetached("sh", {"-c", "rm /tmp/dsda-doom-params.sh; echo \"" + path + " --help\" > /tmp/dsda-doom-params.sh ; chmod +x /tmp/dsda-doom-params.sh ; open -a Terminal /tmp/dsda-doom-params.sh"});
process->deleteLater();
#elif defined Q_OS_WIN
system(("start cmd.exe /k \"" + path.toStdString() + "\" --help").c_str());
Expand Down

0 comments on commit a38aec8

Please sign in to comment.