From 7cdcfd4b1ae55d05e5740eb30bf67bc059037f6a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 21 Mar 2023 23:13:31 +1000 Subject: [PATCH] Qt: Remove backup AppImage on next launch --- pcsx2-qt/AutoUpdaterDialog.cpp | 31 +++++++++++++++++++++++++++++++ pcsx2-qt/AutoUpdaterDialog.h | 1 + pcsx2-qt/QtHost.cpp | 8 ++++++++ 3 files changed, 40 insertions(+) diff --git a/pcsx2-qt/AutoUpdaterDialog.cpp b/pcsx2-qt/AutoUpdaterDialog.cpp index 6e3a8d0d9d..eb853587a9 100644 --- a/pcsx2-qt/AutoUpdaterDialog.cpp +++ b/pcsx2-qt/AutoUpdaterDialog.cpp @@ -595,6 +595,11 @@ bool AutoUpdaterDialog::doUpdate(const QString& zip_path, const QString& updater return true; } +void AutoUpdaterDialog::cleanupAfterUpdate() +{ + // Nothing to do on Windows for now, the updater stub cleans everything up. +} + #elif defined(__linux__) bool AutoUpdaterDialog::processUpdate(const QByteArray& update_data, QProgressDialog&) @@ -663,6 +668,7 @@ bool AutoUpdaterDialog::processUpdate(const QByteArray& update_data, QProgressDi // Execute new appimage. QProcess* new_process = new QProcess(); new_process->setProgram(qappimage_path); + new_process->setArguments(QStringList{QStringLiteral("-updatecleanup")}); if (!new_process->startDetached()) { reportError("Failed to execute new AppImage."); @@ -673,6 +679,23 @@ bool AutoUpdaterDialog::processUpdate(const QByteArray& update_data, QProgressDi return true; } +void AutoUpdaterDialog::cleanupAfterUpdate() +{ + // Remove old/backup AppImage. + const char* appimage_path = std::getenv("APPIMAGE"); + if (!appimage_path) + return; + + const QString qappimage_path(QString::fromUtf8(appimage_path)); + const QString backup_appimage_path(qappimage_path + QStringLiteral(".backup")); + if (!QFile::exists(backup_appimage_path)) + return; + + Console.WriteLn(Color_StrongOrange, QStringLiteral("Removing backup AppImage %1").arg(backup_appimage_path).toStdString()); + if (!QFile::remove(backup_appimage_path)) + Console.Error(QStringLiteral("Failed to remove backup AppImage %1").arg(backup_appimage_path).toStdString()); +} + #elif defined(__APPLE__) static QString UpdateVersionNumberInName(QString name, QStringView new_version) @@ -789,6 +812,10 @@ bool AutoUpdaterDialog::processUpdate(const QByteArray& update_data, QProgressDi return true; } +void AutoUpdaterDialog::cleanupAfterUpdate() +{ +} + #else bool AutoUpdaterDialog::processUpdate(const QByteArray& update_data, QProgressDialog& progress) @@ -796,4 +823,8 @@ bool AutoUpdaterDialog::processUpdate(const QByteArray& update_data, QProgressDi return false; } +void AutoUpdaterDialog::cleanupAfterUpdate() +{ +} + #endif diff --git a/pcsx2-qt/AutoUpdaterDialog.h b/pcsx2-qt/AutoUpdaterDialog.h index 65fe4291b6..da3654f552 100644 --- a/pcsx2-qt/AutoUpdaterDialog.h +++ b/pcsx2-qt/AutoUpdaterDialog.h @@ -37,6 +37,7 @@ public: static std::string getDefaultTag(); static QString getCurrentVersion(); static QString getCurrentVersionDate(); + static void cleanupAfterUpdate(); Q_SIGNALS: void updateCheckCompleted(); diff --git a/pcsx2-qt/QtHost.cpp b/pcsx2-qt/QtHost.cpp index 97a542b2a3..72fcdd619e 100644 --- a/pcsx2-qt/QtHost.cpp +++ b/pcsx2-qt/QtHost.cpp @@ -56,6 +56,7 @@ #include "fmt/core.h" +#include "AutoUpdaterDialog.h" #include "DisplayWidget.h" #include "GameList/GameListWidget.h" #include "MainWindow.h" @@ -1755,6 +1756,13 @@ bool QtHost::ParseCommandLineOptions(const QStringList& args, std::shared_ptr