Qt: Remove backup AppImage on next launch

This commit is contained in:
Stenzek 2023-03-21 23:13:31 +10:00 committed by refractionpcsx2
parent b02af117f8
commit 7cdcfd4b1a
3 changed files with 40 additions and 0 deletions

View File

@ -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

View File

@ -37,6 +37,7 @@ public:
static std::string getDefaultTag();
static QString getCurrentVersion();
static QString getCurrentVersionDate();
static void cleanupAfterUpdate();
Q_SIGNALS:
void updateCheckCompleted();

View File

@ -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<VM
s_boot_and_debug = true;
continue;
}
else if (CHECK_ARG(QStringLiteral("-updatecleanup")))
{
if (AutoUpdaterDialog::isSupported())
AutoUpdaterDialog::cleanupAfterUpdate();
continue;
}
#ifdef ENABLE_RAINTEGRATION
else if (CHECK_ARG(QStringLiteral("-raintegration")))
{