mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace updating
|
||||
std::future<std::optional<std::filesystem::path>> download_new_version(const new_version_download_info& new_version);
|
||||
std::filesystem::path get_pending_updates_path();
|
||||
std::future<nonstd::expected<github_version_info, std::wstring>> get_github_version_info_async(const bool prerelease = false);
|
||||
void cleanup_updates();
|
||||
|
||||
// non-localized
|
||||
constexpr inline std::wstring_view INSTALLER_FILENAME_PATTERN = L"powertoyssetup";
|
||||
|
||||
Reference in New Issue
Block a user