Loader: try to retrieve database config if not booted through the UI

This commit is contained in:
Megamouse 2026-04-18 16:09:01 +02:00
parent 36cd81fb5f
commit d3804de243
3 changed files with 42 additions and 8 deletions

View File

@ -933,7 +933,7 @@ game_boot_result Emulator::GetElfPathFromDir(std::string& elf_path, const std::s
return game_boot_result::invalid_file_or_folder;
}
game_boot_result Emulator::BootGame(const std::string& path, const std::string& title_id, bool direct, cfg_mode config_mode, const std::string& config_path, const std::string& db_config)
game_boot_result Emulator::BootGame(const std::string& path, const std::string& title_id, bool direct, cfg_mode config_mode, const std::string& config_path, const std::optional<std::string>& db_config)
{
if (m_restrict_emu_state_change)
{
@ -1565,8 +1565,15 @@ game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch,
sys_log.notice("Version: APP_VER=%s VERSION=%s", version_app, version_disc);
{
if (!m_db_config && (m_config_mode == cfg_mode::database_config || m_config_mode == cfg_mode::custom))
{
// Get database config if possible. This only happens if the database config hasn't been set by the UI (e.g. if booted with no-gui).
// We only know the title_id for sure at this point, so it doesn't make sense to retrieve it earlier.
m_db_config = Emu.GetCallbacks().get_database_config(m_title_id);
}
// We add the database configuration if it is set, unless we are using a mode that specifically selects a different configuration.
bool add_database_config = !m_db_config.empty() && (m_config_mode == cfg_mode::database_config || m_config_mode == cfg_mode::custom || m_config_mode == cfg_mode::continuous);
bool add_database_config = m_db_config && !m_db_config->empty() && (m_config_mode == cfg_mode::database_config || m_config_mode == cfg_mode::custom || m_config_mode == cfg_mode::continuous);
if (m_config_mode == cfg_mode::custom_selection || (m_config_mode == cfg_mode::continuous && !m_config_path.empty()))
{
@ -1619,12 +1626,12 @@ game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch,
}
}
if (add_database_config)
if (add_database_config && m_db_config && !m_db_config->empty())
{
// Add database config
sys_log.notice("Applying database config");
if (g_cfg.from_string(m_db_config))
if (g_cfg.from_string(*m_db_config))
{
g_cfg.name = "database_config";
}
@ -3373,7 +3380,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate, savestate_stage* save_s
klic.clear();
hdd1.clear();
init_mem_containers = nullptr;
m_db_config.clear();
m_db_config = std::nullopt;
m_config_path.clear();
m_config_mode = cfg_mode::custom;
read_used_savestate_versions();

View File

@ -115,6 +115,7 @@ struct EmuCallbacks
std::function<void()> check_microphone_permissions;
std::function<std::unique_ptr<class video_source>()> make_video_source;
std::function<void(bool)> enable_gamemode;
std::function<std::string(const std::string&)> get_database_config;
};
namespace utils
@ -146,7 +147,7 @@ class Emulator final
cfg_mode m_config_mode = cfg_mode::custom;
std::string m_config_path;
std::string m_db_config;
std::optional<std::string> m_db_config; // std::nullopt means it has not been retrieved yet
std::string m_path;
std::string m_path_old;
std::string m_path_original;
@ -370,7 +371,8 @@ public:
const std::string& GetUsedDatabaseConfig() const
{
return m_db_config;
static std::string empty_db_config;
return m_db_config ? *m_db_config : empty_db_config;
}
bool IsChildProcess() const
@ -422,7 +424,7 @@ public:
return emulation_state_guard_t{this};
}
game_boot_result BootGame(const std::string& path, const std::string& title_id = "", bool direct = false, cfg_mode config_mode = cfg_mode::custom, const std::string& config_path = "", const std::string& db_config = "");
game_boot_result BootGame(const std::string& path, const std::string& title_id = "", bool direct = false, cfg_mode config_mode = cfg_mode::custom, const std::string& config_path = "", const std::optional<std::string>& db_config = std::nullopt);
bool BootRsxCapture(const std::string& path);
void SetForceBoot(bool force_boot);

View File

@ -2,6 +2,8 @@
#include "main_application.h"
#include "display_sleep_control.h"
#include "gamemode_control.h"
#include "rpcs3qt/gui_settings.h"
#include "rpcs3qt/config_database.h"
#include "util/types.hpp"
#include "util/logs.hpp"
@ -409,5 +411,28 @@ EmuCallbacks main_application::CreateCallbacks()
return path + suffix;
};
callbacks.get_database_config = [](const std::string& title_id)
{
if (title_id.empty())
return std::string();
sys_log.notice("Trying to retrieve database config for: '%s'", title_id);
const auto settings = std::make_shared<gui_settings>();
config_database config_db(settings, nullptr);
config_db.request_config_database(false);
if (!config_db.has_config(title_id))
return std::string();
if (const auto config = config_db.get_config(title_id))
{
sys_log.notice("Found database config for: '%s'", title_id);
return config.value();
}
return std::string();
};
return callbacks;
}