Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: rename pad profiles to input config files #14579

Merged
merged 1 commit into from Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 22 additions & 22 deletions rpcs3/Emu/Io/pad_config.cpp
Expand Up @@ -4,7 +4,7 @@

LOG_CHANNEL(input_log, "Input");

extern std::string g_pad_profile_override;
extern std::string g_input_config_override;

std::vector<std::string> cfg_pad::get_buttons(const std::string& str)
{
Expand All @@ -26,16 +26,16 @@ std::string cfg_pad::get_buttons(std::vector<std::string> vec)
return fmt::merge(vec, ",");
}

bool cfg_input::load(const std::string& title_id, const std::string& profile, bool strict)
bool cfg_input::load(const std::string& title_id, const std::string& config_file, bool strict)
{
input_log.notice("Loading pad config (title_id='%s', profile='%s', strict=%d)", title_id, profile, strict);
input_log.notice("Loading pad config (title_id='%s', config_file='%s', strict=%d)", title_id, config_file, strict);

std::string cfg_name;

// Check profile override first
if (!strict && !g_pad_profile_override.empty())
// Check configuration override first
if (!strict && !g_input_config_override.empty())
{
cfg_name = rpcs3::utils::get_input_config_dir() + g_pad_profile_override + ".yml";
cfg_name = rpcs3::utils::get_input_config_dir() + g_input_config_override + ".yml";
}

// Check custom config next
Expand All @@ -44,23 +44,23 @@ bool cfg_input::load(const std::string& title_id, const std::string& profile, bo
cfg_name = rpcs3::utils::get_custom_input_config_path(title_id);
}

// Check active global profile next
if ((title_id.empty() || !strict) && !profile.empty() && !fs::is_file(cfg_name))
// Check active global configuration next
if ((title_id.empty() || !strict) && !config_file.empty() && !fs::is_file(cfg_name))
{
cfg_name = rpcs3::utils::get_input_config_dir() + profile + ".yml";
cfg_name = rpcs3::utils::get_input_config_dir() + config_file + ".yml";
}

// Fallback to default profile
// Fallback to default configuration
if (!strict && !fs::is_file(cfg_name))
{
cfg_name = rpcs3::utils::get_input_config_dir() + g_cfg_profile.default_profile + ".yml";
cfg_name = rpcs3::utils::get_input_config_dir() + g_cfg_input_configs.default_config + ".yml";
}

from_default();

if (fs::file cfg_file{ cfg_name, fs::read })
{
input_log.notice("Loading pad profile: '%s'", cfg_name);
input_log.notice("Loading input configuration: '%s'", cfg_name);

if (std::string content = cfg_file.to_string(); !content.empty())
{
Expand All @@ -69,22 +69,22 @@ bool cfg_input::load(const std::string& title_id, const std::string& profile, bo
}

// Add keyboard by default
input_log.notice("Pad profile empty. Adding default keyboard pad handler");
input_log.notice("Input configuration empty. Adding default keyboard pad handler");
player[0]->handler.from_string(fmt::format("%s", pad_handler::keyboard));
player[0]->device.from_string(pad::keyboard_device_name.data());
player[0]->buddy_device.from_string(""sv);

return false;
}

void cfg_input::save(const std::string& title_id, const std::string& profile) const
void cfg_input::save(const std::string& title_id, const std::string& config_file) const
{
std::string cfg_name;

if (title_id.empty())
{
cfg_name = rpcs3::utils::get_input_config_dir() + profile + ".yml";
input_log.notice("Saving pad config profile '%s' to '%s'", profile, cfg_name);
cfg_name = rpcs3::utils::get_input_config_dir() + config_file + ".yml";
input_log.notice("Saving input configuration '%s' to '%s'", config_file, cfg_name);
}
else
{
Expand All @@ -105,12 +105,12 @@ void cfg_input::save(const std::string& title_id, const std::string& profile) co
}
}

cfg_profile::cfg_profile()
: path(rpcs3::utils::get_input_config_root() + "/active_profiles.yml")
cfg_input_configurations::cfg_input_configurations()
: path(rpcs3::utils::get_input_config_root() + "/active_input_configurations.yml")
{
}

bool cfg_profile::load()
bool cfg_input_configurations::load()
{
if (fs::file cfg_file{ path, fs::read })
{
Expand All @@ -121,14 +121,14 @@ bool cfg_profile::load()
return false;
}

void cfg_profile::save() const
void cfg_input_configurations::save() const
{
input_log.notice("Saving pad profile config to '%s'", path);
input_log.notice("Saving input configurations config to '%s'", path);

fs::pending_file cfg_file(path);

if (!cfg_file.file || (cfg_file.file.write(to_string()), !cfg_file.commit()))
{
input_log.error("Failed to save pad profile config to '%s' (error=%s)", path, fs::g_tls_error);
input_log.error("Failed to save input configurations config to '%s' (error=%s)", path, fs::g_tls_error);
}
}
10 changes: 5 additions & 5 deletions rpcs3/Emu/Io/pad_config.h
Expand Up @@ -131,18 +131,18 @@ struct cfg_input final : cfg::node
void save(const std::string& title_id, const std::string& profile = "") const;
};

struct cfg_profile final : cfg::node
struct cfg_input_configurations final : cfg::node
{
cfg_profile();
cfg_input_configurations();
bool load();
void save() const;

const std::string path;
const std::string global_key = "global";
const std::string default_profile = "Default";
const std::string default_config = "Default";

cfg::map_entry active_profiles{ this, "Active Profiles" };
cfg::map_entry active_configs{ this, "Active Configurations" };
};

extern cfg_input g_cfg_input;
extern cfg_profile g_cfg_profile;
extern cfg_input_configurations g_cfg_input_configs;
2 changes: 1 addition & 1 deletion rpcs3/Emu/system_utils.cpp
Expand Up @@ -379,6 +379,6 @@ namespace rpcs3::utils
std::string get_custom_input_config_path(const std::string& title_id)
{
if (title_id.empty()) return "";
return get_input_config_dir(title_id) + g_cfg_profile.default_profile + ".yml";
return get_input_config_dir(title_id) + g_cfg_input_configs.default_config + ".yml";
}
}
16 changes: 8 additions & 8 deletions rpcs3/Input/pad_thread.cpp
Expand Up @@ -27,7 +27,7 @@
LOG_CHANNEL(sys_log, "SYS");

extern bool is_input_allowed();
extern std::string g_pad_profile_override;
extern std::string g_input_config_override;

namespace pad
{
Expand Down Expand Up @@ -100,19 +100,19 @@ void pad_thread::Init()

handlers.clear();

g_cfg_profile.load();
g_cfg_input_configs.load();

std::string active_profile = g_cfg_profile.active_profiles.get_value(pad::g_title_id);
std::string active_config = g_cfg_input_configs.active_configs.get_value(pad::g_title_id);

if (active_profile.empty())
if (active_config.empty())
{
active_profile = g_cfg_profile.active_profiles.get_value(g_cfg_profile.global_key);
active_config = g_cfg_input_configs.active_configs.get_value(g_cfg_input_configs.global_key);
}

input_log.notice("Using pad profile: '%s' (override='%s')", active_profile, g_pad_profile_override);
input_log.notice("Using input configuration: '%s' (override='%s')", active_config, g_input_config_override);

// Load in order to get the pad handlers
if (!g_cfg_input.load(pad::g_title_id, active_profile))
if (!g_cfg_input.load(pad::g_title_id, active_config))
{
input_log.notice("Loaded empty pad config");
}
Expand All @@ -125,7 +125,7 @@ void pad_thread::Init()
}

// Reload with proper defaults
if (!g_cfg_input.load(pad::g_title_id, active_profile))
if (!g_cfg_input.load(pad::g_title_id, active_config))
{
input_log.notice("Reloaded empty pad config");
}
Expand Down
18 changes: 9 additions & 9 deletions rpcs3/main.cpp
Expand Up @@ -88,7 +88,7 @@ static atomic_t<bool> s_headless = false;
static atomic_t<bool> s_no_gui = false;
static atomic_t<char*> s_argv0;

std::string g_pad_profile_override;
std::string g_input_config_override;

extern thread_local std::string(*g_tls_log_prefix)();
extern thread_local std::string_view g_tls_serialize_name;
Expand Down Expand Up @@ -291,7 +291,7 @@ constexpr auto arg_styles = "styles";
constexpr auto arg_style = "style";
constexpr auto arg_stylesheet = "stylesheet";
constexpr auto arg_config = "config";
constexpr auto arg_pad_profile = "pad-profile"; // only useful with no-gui
constexpr auto arg_input_config = "input-config"; // only useful with no-gui
constexpr auto arg_q_debug = "qDebug";
constexpr auto arg_error = "error";
constexpr auto arg_updating = "updating";
Expand Down Expand Up @@ -652,8 +652,8 @@ int main(int argc, char** argv)
parser.addOption(QCommandLineOption(arg_stylesheet, "Loads a custom stylesheet.", "path", ""));
const QCommandLineOption config_option(arg_config, "Forces the emulator to use this configuration file for CLI-booted game.", "path", "");
parser.addOption(config_option);
const QCommandLineOption pad_profile_option(arg_pad_profile, "Forces the emulator to use this pad profile file for CLI-booted game.", "name", "");
parser.addOption(pad_profile_option);
const QCommandLineOption input_config_option(arg_input_config, "Forces the emulator to use this input config file for CLI-booted game.", "name", "");
parser.addOption(input_config_option);
const QCommandLineOption installfw_option(arg_installfw, "Forces the emulator to install this firmware file.", "path", "");
parser.addOption(installfw_option);
const QCommandLineOption installpkg_option(arg_installpkg, "Forces the emulator to install this pkg file.", "path", "");
Expand Down Expand Up @@ -1289,18 +1289,18 @@ int main(int argc, char** argv)
}
}

if (parser.isSet(arg_pad_profile))
if (parser.isSet(arg_input_config))
{
if (!s_no_gui)
{
report_fatal_error(fmt::format("The option '%s' can only be used in combination with '%s'.", arg_pad_profile, arg_no_gui));
report_fatal_error(fmt::format("The option '%s' can only be used in combination with '%s'.", arg_input_config, arg_no_gui));
}

g_pad_profile_override = parser.value(pad_profile_option).toStdString();
g_input_config_override = parser.value(input_config_option).toStdString();

if (g_pad_profile_override.empty())
if (g_input_config_override.empty())
{
report_fatal_error(fmt::format("Pad profile name is empty"));
report_fatal_error(fmt::format("Input config file name is empty"));
}
}

Expand Down
8 changes: 4 additions & 4 deletions rpcs3/rpcs3qt/game_list_frame.cpp
Expand Up @@ -1684,10 +1684,10 @@ bool game_list_frame::RemoveCustomPadConfiguration(const std::string& title_id,
: tr("Remove custom pad configuration?")) != QMessageBox::Yes)
return true;

g_cfg_profile.load();
g_cfg_profile.active_profiles.erase(title_id);
g_cfg_profile.save();
game_list_log.notice("Removed active pad profile entry for key '%s'", title_id);
g_cfg_input_configs.load();
g_cfg_input_configs.active_configs.erase(title_id);
g_cfg_input_configs.save();
game_list_log.notice("Removed active input configuration entry for key '%s'", title_id);

if (QDir(qstr(config_dir)).removeRecursively())
{
Expand Down