From ac1fd7f0cfd2f7dea62669248297149605156e7c Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 4 Feb 2024 17:40:19 +1000 Subject: [PATCH] Qt: Remove update.zip after updating --- src/duckstation-qt/autoupdaterdialog.cpp | 3 --- src/updater/cocoa_main.mm | 1 + src/updater/updater.cpp | 25 ++++++++++++++++++++++-- src/updater/updater.h | 3 +++ src/updater/win32_main.cpp | 1 + 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/duckstation-qt/autoupdaterdialog.cpp b/src/duckstation-qt/autoupdaterdialog.cpp index f4b544542..e1f288d5e 100644 --- a/src/duckstation-qt/autoupdaterdialog.cpp +++ b/src/duckstation-qt/autoupdaterdialog.cpp @@ -707,9 +707,6 @@ bool AutoUpdaterDialog::processUpdate(const std::vector& update_data) void AutoUpdaterDialog::cleanupAfterUpdate() { - const QString zip_path = QString::fromStdString(Path::Combine(EmuFolders::DataRoot, "update.zip")); - if (QFile::exists(zip_path)) - QFile::remove(zip_path); } #elif defined(__linux__) diff --git a/src/updater/cocoa_main.mm b/src/updater/cocoa_main.mm index 928e389d6..bd5aa1bab 100644 --- a/src/updater/cocoa_main.mm +++ b/src/updater/cocoa_main.mm @@ -113,6 +113,7 @@ int main(int argc, char* argv[]) } updater.CleanupStagingDirectory(); + updater.RemoveUpdateZip(); result = EXIT_SUCCESS; }); diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index ccb054ad9..62cbf7fbd 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -37,8 +37,7 @@ Updater::Updater(ProgressCallback* progress) : m_progress(progress) Updater::~Updater() { - if (m_zf) - unzClose(m_zf); + CloseUpdateZip(); } bool Updater::Initialize(std::string staging_directory, std::string destination_directory) @@ -56,10 +55,32 @@ bool Updater::OpenUpdateZip(const char* path) if (!m_zf) return false; + m_zip_path = path; + m_progress->SetStatusText("Parsing update zip..."); return ParseZip(); } +void Updater::CloseUpdateZip() +{ + if (m_zf) + { + unzClose(m_zf); + m_zf = nullptr; + } +} + +void Updater::RemoveUpdateZip() +{ + if (m_zip_path.empty()) + return; + + CloseUpdateZip(); + + if (!FileSystem::DeleteFile(m_zip_path.c_str())) + m_progress->DisplayFormattedError("Failed to remove update zip '%s'", m_zip_path.c_str()); +} + bool Updater::RecursiveDeleteDirectory(const char* path, bool remove_dir) { #ifdef _WIN32 diff --git a/src/updater/updater.h b/src/updater/updater.h index 3aed0ac55..6cf39d9d9 100644 --- a/src/updater/updater.h +++ b/src/updater/updater.h @@ -16,6 +16,7 @@ public: bool Initialize(std::string staging_directory, std::string destination_directory); bool OpenUpdateZip(const char* path); + void RemoveUpdateZip(); bool PrepareStagingDirectory(); bool StageUpdate(); bool CommitUpdate(); @@ -33,7 +34,9 @@ private: }; bool ParseZip(); + void CloseUpdateZip(); + std::string m_zip_path; std::string m_staging_directory; std::string m_destination_directory; diff --git a/src/updater/win32_main.cpp b/src/updater/win32_main.cpp index b64fe9dae..ebe2e694a 100644 --- a/src/updater/win32_main.cpp +++ b/src/updater/win32_main.cpp @@ -93,6 +93,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi } updater.CleanupStagingDirectory(); + updater.RemoveUpdateZip(); progress.DisplayFormattedInformation("Launching '%s'...", StringUtil::WideStringToUTF8String(program_to_launch).c_str());