diff --git a/updater/Updater.cpp b/updater/Updater.cpp index 6d6288c75..1fee272ee 100644 --- a/updater/Updater.cpp +++ b/updater/Updater.cpp @@ -81,15 +81,7 @@ Updater::Updater(ProgressCallback* progress) Updater::~Updater() { -#ifdef _WIN32 - if (m_archive_opened) - SzArEx_Free(&m_archive, &g_Alloc); - - ISzAlloc_Free(&g_Alloc, m_look_stream.buf); - - if (m_file_opened) - File_Close(&m_archive_stream.file); -#endif + CloseUpdateZip(); } void Updater::SetupLogging(ProgressCallback* progress, const std::string& destination_directory) @@ -123,6 +115,8 @@ bool Updater::OpenUpdateZip(const char* path) LookToRead2_CreateVTable(&m_look_stream, False); CrcGenerateTable(); + m_zip_path = path; + m_look_stream.buf = (Byte*)ISzAlloc_Alloc(&g_Alloc, kInputBufSize); if (!m_look_stream.buf) { @@ -163,6 +157,29 @@ bool Updater::OpenUpdateZip(const char* path) #endif } +void Updater::CloseUpdateZip() +{ +#ifdef _WIN32 + if (m_archive_opened) + { + SzArEx_Free(&m_archive, &g_Alloc); + m_archive_opened = false; + } + + if (m_look_stream.buf) + { + ISzAlloc_Free(&g_Alloc, m_look_stream.buf); + m_look_stream.buf = nullptr; + } + + if (m_file_opened) + { + File_Close(&m_archive_stream.file); + m_file_opened = false; + } +#endif +} + bool Updater::RecursiveDeleteDirectory(const char* path) { #ifdef _WIN32 @@ -404,3 +421,14 @@ void Updater::CleanupStagingDirectory() if (!RecursiveDeleteDirectory(m_staging_directory.c_str())) m_progress->DisplayFormattedError("Failed to remove staging directory '%s'", m_staging_directory.c_str()); } + +void Updater::RemoveUpdateZip() +{ + if (m_zip_path.empty()) + return; + + CloseUpdateZip(); + + if (!FileSystem::DeleteFilePath(m_zip_path.c_str())) + m_progress->DisplayFormattedError("Failed to remove update zip '%s'", m_zip_path.c_str()); +} diff --git a/updater/Updater.h b/updater/Updater.h index 9503b436d..fc5bf31a6 100644 --- a/updater/Updater.h +++ b/updater/Updater.h @@ -40,10 +40,13 @@ public: bool StageUpdate(); bool CommitUpdate(); void CleanupStagingDirectory(); + void RemoveUpdateZip(); private: static bool RecursiveDeleteDirectory(const char* path); + void CloseUpdateZip(); + struct FileToUpdate { u32 file_index; @@ -52,6 +55,7 @@ private: bool ParseZip(); + std::string m_zip_path; std::string m_destination_directory; std::string m_staging_directory; diff --git a/updater/Windows/WindowsUpdater.cpp b/updater/Windows/WindowsUpdater.cpp index dbaa22b0a..36a8dd4e2 100644 --- a/updater/Windows/WindowsUpdater.cpp +++ b/updater/Windows/WindowsUpdater.cpp @@ -385,6 +385,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi } updater.CleanupStagingDirectory(); + updater.RemoveUpdateZip(); progress.ModalInformation("Update complete.");