From 4b4c874c8d6a5a65d3e61e791fdb64fc1ec51675 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Thu, 9 May 2024 11:17:45 +0200 Subject: [PATCH] update gwca, respect cache_duration --- Dependencies/GWCA | 2 +- GWToolboxdll/Modules/Resources.cpp | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Dependencies/GWCA b/Dependencies/GWCA index 6c1f53661..2bd7cb304 160000 --- a/Dependencies/GWCA +++ b/Dependencies/GWCA @@ -1 +1 @@ -Subproject commit 6c1f5366141633e9961ae92d2a9dc4328300b6e5 +Subproject commit 2bd7cb304683236b981a4203eabffd00057517fa diff --git a/GWToolboxdll/Modules/Resources.cpp b/GWToolboxdll/Modules/Resources.cpp index 9bbe880cd..fcd0520f7 100644 --- a/GWToolboxdll/Modules/Resources.cpp +++ b/GWToolboxdll/Modules/Resources.cpp @@ -553,7 +553,7 @@ void Resources::Download(const std::string& url, AsyncLoadMbCallback callback, v return hash_file; }; - const auto get_cache_modified_time = [&hash_name](const std::filesystem::path& file_name) -> std::optional { + const auto get_cache_modified_time = [](const std::filesystem::path& file_name) -> std::optional { if (!std::filesystem::exists(file_name)) { return std::optional(); } @@ -565,7 +565,7 @@ void Resources::Download(const std::string& url, AsyncLoadMbCallback callback, v const auto load_from_cache = [](const std::filesystem::path& file_name) -> std::optional { std::ifstream cache_file(file_name); if (!cache_file.is_open()) { - return std::optional(); + return {}; } std::string contents((std::istreambuf_iterator(cache_file)), std::istreambuf_iterator()); @@ -591,19 +591,18 @@ void Resources::Download(const std::string& url, AsyncLoadMbCallback callback, v if (url.substr(0, http.size()) == http) { return url.substr(http.size()); } - else if (url.substr(0, https.size()) == https) { + if (url.substr(0, https.size()) == https) { return url.substr(https.size()); } return url; // Return the original if no match is found }; - EnqueueWorkerTask([url, callback, context, cache_duration, &get_cache_modified_time, &load_from_cache, &save_to_cache, &remove_protocol, &hash_name] { - const auto computer_path = Resources::GetComputerFolderPath(); - const auto cache_path = (computer_path / "cache" / remove_protocol(url)); + EnqueueWorkerTask([url, callback, context, &cache_duration, &get_cache_modified_time, &load_from_cache, &save_to_cache, &remove_protocol, &hash_name] { + const auto cache_path = Resources::GetPath("cache") / remove_protocol(url); const auto hashed_path = hash_name(cache_path); const auto expiration = get_cache_modified_time(cache_path); if (expiration.has_value() && - expiration.value() - std::chrono::file_clock::now() < std::chrono::days(30)) { + expiration.value() - std::chrono::file_clock::now() < cache_duration) { const auto response = load_from_cache(cache_path); if (response.has_value()) { EnqueueMainTask([callback, context, response] {