Move the logic for loading the json file to the function. Minor cleanup.

This commit is contained in:
Henrik Rydgård 2025-01-11 23:31:20 +01:00
parent 5815c3e3be
commit ae15cba56c
3 changed files with 20 additions and 14 deletions

View file

@ -134,13 +134,23 @@ void AfterApctlMipsCall::SetData(int HandlerID, int OldState, int NewState, int
argsAddr = ArgsAddr;
}
bool LoadDNSForGameID(std::string_view jsonStr, std::string_view gameID, InfraDNSConfig *dns) {
bool LoadDNSForGameID(std::string_view gameID, InfraDNSConfig *dns) {
using namespace json;
json::JsonReader reader(jsonStr.data(), jsonStr.length());
if (!reader.ok() || !reader.root()) {
ERROR_LOG(Log::IO, "Error parsing JSON from store");
// TODO: Load from cache instead of zip (if possible), and sometimes update it.
size_t jsonSize;
std::unique_ptr<uint8_t[]> data(g_VFS.ReadFile("infra-dns.json", &jsonSize));
if (!data) {
return false;
}
std::string_view jsonStr = std::string_view((const char *)data.get(), jsonSize);
json::JsonReader reader(jsonStr.data(), jsonStr.length());
if (!reader.ok() || !reader.root()) {
ERROR_LOG(Log::IO, "Error parsing DNS JSON");
return false;
}
const JsonGet root = reader.root();
const JsonGet def = root.getDict("default");
@ -210,7 +220,6 @@ bool LoadDNSForGameID(std::string_view jsonStr, std::string_view gameID, InfraDN
}
// TODO: Check for not working platforms
break;
}
@ -637,6 +646,7 @@ u32 Net_Term() {
FreeUser(netThread2Addr);
netInited = false;
g_infraDNSConfig = {};
return 0;
}
@ -704,12 +714,7 @@ static int sceNetInit(u32 poolSize, u32 calloutPri, u32 calloutStack, u32 netini
if (g_Config.bInfrastructureAutoDNS) {
// Load the automatic DNS config.
std::string discID = g_paramSFO.GetDiscID();
size_t jsonSize;
uint8_t *data = g_VFS.ReadFile("infra-dns.json", &jsonSize);
if (data && g_Config.bInfrastructureAutoDNS) {
std::string_view json = std::string_view((const char *)data, jsonSize);
LoadDNSForGameID(json, discID, &g_infraDNSConfig);
}
LoadDNSForGameID(discID, &g_infraDNSConfig);
}
netInited = true;

View file

@ -42,6 +42,7 @@
#include "Core/ELF/ParamSFO.h"
#include "Core/HLE/sceDisplay.h"
#include "Core/HLE/sceUmd.h"
#include "Core/HLE/sceNet.h"
#include "GPU/GPUCommon.h"
#include "GPU/GPUState.h"
@ -415,8 +416,8 @@ void GamePauseScreen::CreateViews() {
rightColumnItems->Add(new Choice(pa->T("Settings")))->OnClick.Handle(this, &GamePauseScreen::OnGameSettings);
rightColumnItems->Add(new Choice(pa->T("Create Game Config")))->OnClick.Handle(this, &GamePauseScreen::OnCreateConfig);
}
UI::Choice *displayEditor_ = rightColumnItems->Add(new Choice(gr->T("Display layout & effects")));
displayEditor_->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
rightColumnItems->Add(new Choice(gr->T("Display layout & effects")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
screenManager()->push(new DisplayLayoutScreen(gamePath_));
return UI::EVENT_DONE;
});

View file

@ -1,5 +1,5 @@
{
"comment": "This file contains our built-in DNS used by the Auto mode in Infrastructure. In addition to being shipped, it'll also be hosted on ppsspp.org. Key names below are not important.",
"comment": "This file contains our built-in DNS used by the Auto mode in Infrastructure. In addition to being shipped, it'll also be hosted on ppsspp.org. Game names below are not important.",
"default": {
"dns": "67.222.156.251",
"revival_credits": {