Remove temporary installer files on application startup

This commit is contained in:
Dan Paulat 2024-03-26 23:46:56 -05:00
parent b2e441dc2e
commit d598631a77
3 changed files with 38 additions and 3 deletions

View file

@ -627,9 +627,13 @@ void MainWindowImpl::AsyncSetup()
// Check for updates // Check for updates
if (generalSettings.update_notifications_enabled().GetValue()) if (generalSettings.update_notifications_enabled().GetValue())
{ {
boost::asio::post( boost::asio::post(threadPool_,
threadPool_, [this]()
[this]() { updateManager_->CheckForUpdates(main::kVersionString_); }); {
manager::UpdateManager::RemoveTemporaryReleases();
updateManager_->CheckForUpdates(
main::kVersionString_);
});
} }
} }

View file

@ -6,6 +6,7 @@
#include <boost/json.hpp> #include <boost/json.hpp>
#include <cpr/cpr.h> #include <cpr/cpr.h>
#include <re2/re2.h> #include <re2/re2.h>
#include <QStandardPaths>
namespace scwx namespace scwx
{ {
@ -230,6 +231,34 @@ UpdateManager::Impl::FindLatestRelease()
return {latestRelease, latestReleaseVersion}; return {latestRelease, latestReleaseVersion};
} }
void UpdateManager::RemoveTemporaryReleases()
{
#if defined(_WIN32)
const std::string destination {
QStandardPaths::writableLocation(QStandardPaths::TempLocation)
.toStdString()};
const std::filesystem::path destinationPath {destination};
std::filesystem::directory_iterator it {destinationPath};
for (auto& file : it)
{
if (file.is_regular_file() && file.path().string().ends_with(".msi") &&
file.path().stem().string().starts_with("supercell-wx-"))
{
logger_->info("Removing temporary installer: {}",
file.path().string());
std::error_code error;
if (!std::filesystem::remove(file.path(), error))
{
logger_->warn("Error removing temporary installer: {}",
error.message());
}
}
}
#endif
}
std::shared_ptr<UpdateManager> UpdateManager::Instance() std::shared_ptr<UpdateManager> UpdateManager::Instance()
{ {
static std::weak_ptr<UpdateManager> updateManagerReference_ {}; static std::weak_ptr<UpdateManager> updateManagerReference_ {};

View file

@ -27,6 +27,8 @@ public:
bool CheckForUpdates(const std::string& currentVersion = {}); bool CheckForUpdates(const std::string& currentVersion = {});
static void RemoveTemporaryReleases();
static std::shared_ptr<UpdateManager> Instance(); static std::shared_ptr<UpdateManager> Instance();
signals: signals: