Updater: Remove update zip after committing

This commit is contained in:
Connor McLaughlin 2022-05-23 20:16:03 +10:00 committed by refractionpcsx2
parent c3ee97103f
commit 680a3802d7
3 changed files with 42 additions and 9 deletions

View File

@ -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());
}

View File

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

View File

@ -385,6 +385,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
}
updater.CleanupStagingDirectory();
updater.RemoveUpdateZip();
progress.ModalInformation("Update complete.");