mirror of https://github.com/WerWolv/ImHex.git
feat: Keep only 10 latest logs on exit (#1079)
Co-authored-by: Nik <werwolv98@gmail.com>
This commit is contained in:
parent
a5b0a8614a
commit
e1620966e5
|
@ -442,6 +442,27 @@ namespace hex::init {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool clearOldLogs() {
|
||||
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Logs, true)) {
|
||||
std::vector<std::filesystem::directory_entry> files;
|
||||
|
||||
for (const auto& file : std::filesystem::directory_iterator(path))
|
||||
files.push_back(file);
|
||||
|
||||
if (files.size() <= 10)
|
||||
return true;
|
||||
|
||||
std::sort(files.begin(), files.end(), [](const auto& a, const auto& b) {
|
||||
return std::filesystem::last_write_time(a) > std::filesystem::last_write_time(b);
|
||||
});
|
||||
|
||||
for (auto it = files.begin() + 10; it != files.end(); it++)
|
||||
std::filesystem::remove(it->path());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool unloadPlugins() {
|
||||
PluginManager::unload();
|
||||
|
||||
|
@ -497,6 +518,7 @@ namespace hex::init {
|
|||
{ "Saving settings...", storeSettings, false },
|
||||
{ "Cleaning up shared data...", deleteSharedData, false },
|
||||
{ "Unloading plugins...", unloadPlugins, false },
|
||||
{ "Clearing old logs...", clearOldLogs, false },
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue