mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:30:06 +00:00
Remove temporary installer files on application startup
This commit is contained in:
parent
b2e441dc2e
commit
d598631a77
3 changed files with 38 additions and 3 deletions
|
|
@ -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_);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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_ {};
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue