From c7cc11cc9883c2c1087a7639c6c378358716939e Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Wed, 30 Apr 2025 00:40:04 +0100 Subject: [PATCH] only add etag is dst file already exists, enable curl --compressed option. curl/libcurl does not send Accept-Encoding by default. many servers support sending compressed versions of files, to speed up transfers. this is ideal for the switch as its io is shit, but the cpu is mostly idle (4% cpu usage for sphaira). github and appstore support sending gzip json files, themezer doesn't seem to. --- sphaira/source/download.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sphaira/source/download.cpp b/sphaira/source/download.cpp index e3a96b2..61c15c1 100644 --- a/sphaira/source/download.cpp +++ b/sphaira/source/download.cpp @@ -473,7 +473,8 @@ auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult { return {}; } - if (e.GetFlags() & Flag_Cache) { + // only add etag if the dst file still exists. + if ((e.GetFlags() & Flag_Cache) && fs::FileExists(&fs.m_fs, e.GetPath())) { g_cache.get(e.GetPath(), header_in); } } @@ -492,6 +493,8 @@ auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult { CURL_EASY_SETOPT_LOG(curl, CURLOPT_BUFFERSIZE, 1024*512); CURL_EASY_SETOPT_LOG(curl, CURLOPT_HEADERFUNCTION, header_callback); CURL_EASY_SETOPT_LOG(curl, CURLOPT_HEADERDATA, &header_out); + // enable all forms of compression supported by libcurl. + CURL_EASY_SETOPT_LOG(curl, CURLOPT_ACCEPT_ENCODING, ""); if (has_post) { CURL_EASY_SETOPT_LOG(curl, CURLOPT_POSTFIELDS, e.GetFields().c_str()); @@ -560,6 +563,15 @@ auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult { g_cache.set(e.GetPath(), header_out); } + // enable to log received headers. + #if 0 + log_write("\n\nLOGGING HEADER\n"); + for (auto [a, b] : header_out.m_map) { + log_write("\t%s: %s\n", a.c_str(), b.c_str()); + } + log_write("\n\n"); + #endif + fs.DeleteFile(e.GetPath()); fs.CreateDirectoryRecursivelyWithPath(e.GetPath()); if (R_FAILED(fs.RenameFile(tmp_buf, e.GetPath()))) {