Qt: Remove update.zip after updating

This commit is contained in:
Stenzek 2024-02-04 17:40:19 +10:00
parent 885addcfce
commit ac1fd7f0cf
No known key found for this signature in database
5 changed files with 28 additions and 5 deletions

View file

@ -707,9 +707,6 @@ bool AutoUpdaterDialog::processUpdate(const std::vector<u8>& update_data)
void AutoUpdaterDialog::cleanupAfterUpdate() 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__) #elif defined(__linux__)

View file

@ -113,6 +113,7 @@ int main(int argc, char* argv[])
} }
updater.CleanupStagingDirectory(); updater.CleanupStagingDirectory();
updater.RemoveUpdateZip();
result = EXIT_SUCCESS; result = EXIT_SUCCESS;
}); });

View file

@ -37,8 +37,7 @@ Updater::Updater(ProgressCallback* progress) : m_progress(progress)
Updater::~Updater() Updater::~Updater()
{ {
if (m_zf) CloseUpdateZip();
unzClose(m_zf);
} }
bool Updater::Initialize(std::string staging_directory, std::string destination_directory) bool Updater::Initialize(std::string staging_directory, std::string destination_directory)
@ -56,10 +55,32 @@ bool Updater::OpenUpdateZip(const char* path)
if (!m_zf) if (!m_zf)
return false; return false;
m_zip_path = path;
m_progress->SetStatusText("Parsing update zip..."); m_progress->SetStatusText("Parsing update zip...");
return ParseZip(); 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) bool Updater::RecursiveDeleteDirectory(const char* path, bool remove_dir)
{ {
#ifdef _WIN32 #ifdef _WIN32

View file

@ -16,6 +16,7 @@ public:
bool Initialize(std::string staging_directory, std::string destination_directory); bool Initialize(std::string staging_directory, std::string destination_directory);
bool OpenUpdateZip(const char* path); bool OpenUpdateZip(const char* path);
void RemoveUpdateZip();
bool PrepareStagingDirectory(); bool PrepareStagingDirectory();
bool StageUpdate(); bool StageUpdate();
bool CommitUpdate(); bool CommitUpdate();
@ -33,7 +34,9 @@ private:
}; };
bool ParseZip(); bool ParseZip();
void CloseUpdateZip();
std::string m_zip_path;
std::string m_staging_directory; std::string m_staging_directory;
std::string m_destination_directory; std::string m_destination_directory;

View file

@ -93,6 +93,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
} }
updater.CleanupStagingDirectory(); updater.CleanupStagingDirectory();
updater.RemoveUpdateZip();
progress.DisplayFormattedInformation("Launching '%s'...", progress.DisplayFormattedInformation("Launching '%s'...",
StringUtil::WideStringToUTF8String(program_to_launch).c_str()); StringUtil::WideStringToUTF8String(program_to_launch).c_str());