mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
don't accumulate installer (#27908)
This commit is contained in:
committed by
GitHub
parent
00dc4981d1
commit
bcb0942b73
@@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include <common/utils/HttpClient.h>
|
||||
#include <common/utils/string_utils.h>
|
||||
#include <common/version/version.h>
|
||||
#include <common/version/helper.h>
|
||||
|
||||
@@ -185,4 +186,48 @@ namespace updating
|
||||
co_return download_success ? installer_download_path : std::nullopt;
|
||||
}
|
||||
|
||||
void cleanup_updates()
|
||||
{
|
||||
auto update_dir = updating::get_pending_updates_path();
|
||||
if (std::filesystem::exists(update_dir))
|
||||
{
|
||||
// Msi and exe files
|
||||
for (const auto& entry : std::filesystem::directory_iterator(update_dir))
|
||||
{
|
||||
auto entryPath = entry.path().wstring();
|
||||
std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);
|
||||
|
||||
if (entryPath.ends_with(L".msi") || entryPath.ends_with(L".exe"))
|
||||
{
|
||||
std::error_code err;
|
||||
std::filesystem::remove(entry, err);
|
||||
if (err.value())
|
||||
{
|
||||
Logger::warn("Failed to delete installer file {}. {}", entry.path().string(), err.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Log files
|
||||
auto rootPath{ PTSettingsHelper::get_root_save_folder_location() };
|
||||
auto currentVersion = left_trim<wchar_t>(get_product_version(), L"v");
|
||||
if (std::filesystem::exists(rootPath))
|
||||
{
|
||||
for (const auto& entry : std::filesystem::directory_iterator(rootPath))
|
||||
{
|
||||
auto entryPath = entry.path().wstring();
|
||||
std::transform(entryPath.begin(), entryPath.end(), entryPath.begin(), ::towlower);
|
||||
if (entry.is_regular_file() && entryPath.ends_with(L".log") && entryPath.find(currentVersion) == std::string::npos)
|
||||
{
|
||||
std::error_code err;
|
||||
std::filesystem::remove(entry, err);
|
||||
if (err.value())
|
||||
{
|
||||
Logger::warn("Failed to delete log file {}. {}", entry.path().string(), err.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user