From d7ebed2d66c5ba4cf7922a43adf17abc398492a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 17 Feb 2025 15:45:12 -0600 Subject: [PATCH] AutoDNS load fix in some situations --- Core/Dialog/PSPNetconfDialog.cpp | 8 +++++++- Core/HLE/sceNet.cpp | 16 +++++++++------- Core/HLE/sceNet.h | 2 ++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Core/Dialog/PSPNetconfDialog.cpp b/Core/Dialog/PSPNetconfDialog.cpp index ae3e159996..1ce052693c 100644 --- a/Core/Dialog/PSPNetconfDialog.cpp +++ b/Core/Dialog/PSPNetconfDialog.cpp @@ -112,7 +112,13 @@ int PSPNetconfDialog::Update(int animSpeed) { std::string json; if (!jsonReady_ && PollInfraJsonDownload(&json)) { if (!json.empty()) { - INFO_LOG(Log::sceNet, "Got and processed the json."); + if (!LoadAutoDNS(json)) { + // If the JSON parse fails, throw away the cache file at least. + ERROR_LOG(Log::sceNet, "Failed to parse bad json. Deleting cache file."); + DeleteAutoDNSCacheFile(); + } else { + INFO_LOG(Log::sceNet, "Got and processed the AutoDNS json."); + } } else { // TODO: Show a notice? WARN_LOG(Log::sceNet, "Failed to get json file. Autoconfig will not work."); diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index 7ccdce15d6..acc15288d6 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -18,6 +18,7 @@ #include #include #include + #include "Common/Net/Resolve.h" #include "Common/Net/SocketCompat.h" #include "Common/Data/Text/Parsers.h" @@ -272,7 +273,7 @@ bool LoadDNSForGameID(std::string_view gameID, std::string_view jsonStr, InfraDN return true; } -static bool LoadAutoDNS(std::string_view json) { +bool LoadAutoDNS(std::string_view json) { if (!g_Config.bInfrastructureAutoDNS) { return true; } @@ -325,14 +326,19 @@ std::shared_ptr g_infraDL; static const std::string_view jsonUrl = "http://metadata.ppsspp.org/infra-dns.json"; +void DeleteAutoDNSCacheFile() { + File::Delete(g_DownloadManager.UrlToCachePath(jsonUrl)); +} + void StartInfraJsonDownload() { if (!g_Config.bInfrastructureAutoDNS) { return; } if (g_infraDL) { - INFO_LOG(Log::sceNet, "json is already being downloaded"); + WARN_LOG(Log::sceNet, "json is already being downloaded. Still, starting a new download."); } + const char *acceptMime = "application/json, text/*; q=0.9, */*; q=0.8"; g_infraDL = g_DownloadManager.StartDownload(jsonUrl, Path(), http::RequestFlags::Cached24H, acceptMime); } @@ -371,6 +377,7 @@ bool PollInfraJsonDownload(std::string *jsonOutput) { if (File::ReadBinaryFileToString(g_DownloadManager.UrlToCachePath(jsonUrl), &json) && !json.empty()) { WARN_LOG(Log::sceNet, "Failed to download infra-dns.json, falling back to cached file"); *jsonOutput = json; + LoadAutoDNS(*jsonOutput); return true; } @@ -391,11 +398,6 @@ bool PollInfraJsonDownload(std::string *jsonOutput) { _dbg_assert_msg_(false, "Json output is empty!"); ERROR_LOG(Log::sceNet, "JSON output is empty! Something went wrong."); } - - if (!LoadAutoDNS(*jsonOutput)) { - // If the JSON parse fails, throw away the cache file at least. - File::Delete(g_DownloadManager.UrlToCachePath(jsonUrl)); - } return true; } diff --git a/Core/HLE/sceNet.h b/Core/HLE/sceNet.h index 994b372d85..c3410cc283 100644 --- a/Core/HLE/sceNet.h +++ b/Core/HLE/sceNet.h @@ -125,6 +125,8 @@ bool IsNetworkConnected(); void StartInfraJsonDownload(); // Polls the fetch, if returns true, jsonOutput should be looked at. If it's empty, something went very wrong as we fallback on the asset file. bool PollInfraJsonDownload(std::string *jsonOutput); +bool LoadAutoDNS(std::string_view json); +void DeleteAutoDNSCacheFile(); // These return false if allowed to be consistent with the similar function for achievements. bool NetworkWarnUserIfOnlineAndCantSavestate();