From 411e971ba72c90a3aa8fa97f782555fadc76fd11 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 9 Aug 2025 14:28:48 +0200 Subject: [PATCH] impr: Properly delete old update files --- lib/libimhex/include/hex/helpers/default_paths.hpp | 1 + main/gui/source/init/tasks.cpp | 9 ++++++++- main/updater/source/main.cpp | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/libimhex/include/hex/helpers/default_paths.hpp b/lib/libimhex/include/hex/helpers/default_paths.hpp index 042884f0f..2054d2ae7 100644 --- a/lib/libimhex/include/hex/helpers/default_paths.hpp +++ b/lib/libimhex/include/hex/helpers/default_paths.hpp @@ -63,6 +63,7 @@ namespace hex::paths { const static inline impl::ConfigPath Config("config"); const static inline impl::ConfigPath Recent("recent"); + const static inline impl::ConfigPath Updates("updates"); const static inline impl::PluginPath Libraries("lib"); const static inline impl::PluginPath Plugins("plugins"); diff --git a/main/gui/source/init/tasks.cpp b/main/gui/source/init/tasks.cpp index 1c5f2797a..3617bc578 100644 --- a/main/gui/source/init/tasks.cpp +++ b/main/gui/source/init/tasks.cpp @@ -210,7 +210,7 @@ namespace hex::init { if (files.size() <= count) return; - std::sort(files.begin(), files.end(), [](const auto& a, const auto& b) { + std::ranges::sort(files, [](const auto& a, const auto& b) { return std::filesystem::last_write_time(a) > std::filesystem::last_write_time(b); }); @@ -226,6 +226,13 @@ namespace hex::init { keepNewest(10, paths::Logs); keepNewest(25, paths::Backups); + // Remove all old update files + for (const auto &path : paths::Updates.all()) { + for (const auto &entry : std::filesystem::directory_iterator(path)) { + wolv::io::fs::removeAll(entry.path()); + } + } + return result; } diff --git a/main/updater/source/main.cpp b/main/updater/source/main.cpp index 085ff706c..3cb554a40 100644 --- a/main/updater/source/main.cpp +++ b/main/updater/source/main.cpp @@ -75,7 +75,7 @@ std::optional downloadUpdate(const std::string &url) { { // Loop over all available paths wolv::io::File file; - for (const auto &path : hex::paths::Config.write()) { + for (const auto &path : hex::paths::Updates.write()) { // Remove any existing update files wolv::io::fs::remove(path / updateFileName);