From 252d1a1a6350bb7cec7c6c9774b04f772bf93713 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Thu, 2 Jan 2025 12:24:25 +0100 Subject: [PATCH] windows: move config.yml and games.yml to /config/ --- Utilities/File.cpp | 10 ++++++++- Utilities/File.h | 4 ++-- Utilities/bin_patch.cpp | 10 +++------ rpcs3/Emu/IPC_config.cpp | 8 ++------ rpcs3/Emu/Io/camera_config.cpp | 6 +----- rpcs3/Emu/Io/emulated_pad_config.h | 4 ++-- rpcs3/Emu/Io/mouse_config.cpp | 6 +----- rpcs3/Emu/Io/rb3drums_config.cpp | 8 +------- rpcs3/Emu/Io/recording_config.cpp | 6 +----- rpcs3/Emu/NP/np_handler.cpp | 8 ++------ rpcs3/Emu/NP/rpcn_config.cpp | 8 ++------ rpcs3/Emu/NP/upnp_config.cpp | 8 ++------ rpcs3/Emu/System.cpp | 31 ++++++++++++++++++++++++++-- rpcs3/Emu/games_config.cpp | 33 ++++++++++++++++++++++++++++-- rpcs3/Emu/system_utils.cpp | 12 ++--------- rpcs3/Emu/vfs_config.cpp | 8 ++------ rpcs3/Input/ps_move_config.cpp | 6 +----- rpcs3/Input/raw_mouse_config.cpp | 4 ++-- rpcs3/rpcs3qt/emu_settings.cpp | 4 ++-- rpcs3/rpcs3qt/uuid.cpp | 10 +++------ 20 files changed, 100 insertions(+), 94 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 3c4a8c769db7..dc565817eb07 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -2021,7 +2021,7 @@ std::string fs::get_executable_dir() return s_exe_dir; } -const std::string& fs::get_config_dir() +const std::string& fs::get_config_dir([[maybe_unused]] bool get_config_subdirectory) { // Use magic static static const std::string s_dir = [] @@ -2103,6 +2103,14 @@ const std::string& fs::get_config_dir() return dir; }(); +#ifdef _WIN32 + if (get_config_subdirectory) + { + static const std::string subdir = s_dir + "config/"; + return subdir; + } +#endif + return s_dir; } diff --git a/Utilities/File.h b/Utilities/File.h index 4768b24ac028..649df58cdc24 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -599,8 +599,8 @@ namespace fs // Get executable containing directory std::string get_executable_dir(); - // Get configuration directory - const std::string& get_config_dir(); + // Get configuration directory. set get_config_subdirectory to true to get the nested config dir on windows. + const std::string& get_config_dir(bool get_config_subdirectory = false); // Get common cache directory const std::string& get_cache_dir(); diff --git a/Utilities/bin_patch.cpp b/Utilities/bin_patch.cpp index 49b19f5bda91..95b8ec4c604a 100644 --- a/Utilities/bin_patch.cpp +++ b/Utilities/bin_patch.cpp @@ -125,19 +125,15 @@ patch_engine::patch_engine() std::string patch_engine::get_patch_config_path() { -#ifdef _WIN32 - const std::string config_dir = fs::get_config_dir() + "config/"; + const std::string config_dir = fs::get_config_dir(true); const std::string patch_path = config_dir + "patch_config.yml"; - +#ifdef _WIN32 if (!fs::create_path(config_dir)) { patch_log.error("Could not create path: %s (%s)", patch_path, fs::g_tls_error); } - - return patch_path; -#else - return fs::get_config_dir() + "patch_config.yml"; #endif + return patch_path; } std::string patch_engine::get_patches_path() diff --git a/rpcs3/Emu/IPC_config.cpp b/rpcs3/Emu/IPC_config.cpp index 5aa95f4c34e5..6a51e803246f 100644 --- a/rpcs3/Emu/IPC_config.cpp +++ b/rpcs3/Emu/IPC_config.cpp @@ -25,7 +25,7 @@ void cfg_ipc::load() void cfg_ipc::save() const { #ifdef _WIN32 - const std::string path_to_cfg = fs::get_config_dir() + "config/"; + const std::string path_to_cfg = fs::get_config_dir(true); if (!fs::create_path(path_to_cfg)) { IPC.error("Could not create path: %s", path_to_cfg); @@ -42,11 +42,7 @@ void cfg_ipc::save() const std::string cfg_ipc::get_path() { -#ifdef _WIN32 - return fs::get_config_dir() + "config/ipc.yml"; -#else - return fs::get_config_dir() + "ipc.yml"; -#endif + return fs::get_config_dir(true) + "ipc.yml"; } bool cfg_ipc::get_server_enabled() const diff --git a/rpcs3/Emu/Io/camera_config.cpp b/rpcs3/Emu/Io/camera_config.cpp index 9767405646e1..d7071b05c3ae 100644 --- a/rpcs3/Emu/Io/camera_config.cpp +++ b/rpcs3/Emu/Io/camera_config.cpp @@ -8,11 +8,7 @@ cfg_camera g_cfg_camera; cfg_camera::cfg_camera() : cfg::node() -#ifdef _WIN32 - , path(fs::get_config_dir() + "config/camera.yml") -#else - , path(fs::get_config_dir() + "camera.yml") -#endif + , path(fs::get_config_dir(true) + "camera.yml") { } diff --git a/rpcs3/Emu/Io/emulated_pad_config.h b/rpcs3/Emu/Io/emulated_pad_config.h index b6703b01ddd1..4dff6c6e9c0c 100644 --- a/rpcs3/Emu/Io/emulated_pad_config.h +++ b/rpcs3/Emu/Io/emulated_pad_config.h @@ -221,7 +221,7 @@ struct emulated_pads_config : cfg::node m_mutex.lock(); bool result = false; - const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id); + const std::string cfg_name = fmt::format("%s%s.yml", fs::get_config_dir(true), cfg_id); cfg_log.notice("Loading %s config: %s", cfg_id, cfg_name); from_default(); @@ -258,7 +258,7 @@ struct emulated_pads_config : cfg::node { std::lock_guard lock(m_mutex); - const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id); + const std::string cfg_name = fmt::format("%s%s.yml", fs::get_config_dir(true), cfg_id); cfg_log.notice("Saving %s config to '%s'", cfg_id, cfg_name); if (!fs::create_path(fs::get_parent_dir(cfg_name))) diff --git a/rpcs3/Emu/Io/mouse_config.cpp b/rpcs3/Emu/Io/mouse_config.cpp index b7dcec7e59d4..07ec4b525a32 100644 --- a/rpcs3/Emu/Io/mouse_config.cpp +++ b/rpcs3/Emu/Io/mouse_config.cpp @@ -4,11 +4,7 @@ #include "Utilities/File.h" mouse_config::mouse_config() -#ifdef _WIN32 - : cfg_name(fs::get_config_dir() + "config/config_mouse.yml") -#else - : cfg_name(fs::get_config_dir() + "config_mouse.yml") -#endif + : cfg_name(fs::get_config_dir(true) + "config_mouse.yml") { } diff --git a/rpcs3/Emu/Io/rb3drums_config.cpp b/rpcs3/Emu/Io/rb3drums_config.cpp index 1e308d8b70b8..34c289818c8a 100644 --- a/rpcs3/Emu/Io/rb3drums_config.cpp +++ b/rpcs3/Emu/Io/rb3drums_config.cpp @@ -8,13 +8,7 @@ cfg_rb3drums g_cfg_rb3drums; cfg_rb3drums::cfg_rb3drums() : cfg::node() -#ifdef _WIN32 - , - path(fs::get_config_dir() + "config/rb3drums.yml") -#else - , - path(fs::get_config_dir() + "rb3drums.yml") -#endif + , path(fs::get_config_dir(true) + "rb3drums.yml") { } diff --git a/rpcs3/Emu/Io/recording_config.cpp b/rpcs3/Emu/Io/recording_config.cpp index 0457317d8038..357106e074a6 100644 --- a/rpcs3/Emu/Io/recording_config.cpp +++ b/rpcs3/Emu/Io/recording_config.cpp @@ -8,11 +8,7 @@ cfg_recording g_cfg_recording; cfg_recording::cfg_recording() : cfg::node() -#ifdef _WIN32 - , path(fs::get_config_dir() + "config/recording.yml") -#else - , path(fs::get_config_dir() + "recording.yml") -#endif + , path(fs::get_config_dir(true) + "recording.yml") { } diff --git a/rpcs3/Emu/NP/np_handler.cpp b/rpcs3/Emu/NP/np_handler.cpp index 3bcff2f9603b..7c9723a25fa2 100644 --- a/rpcs3/Emu/NP/np_handler.cpp +++ b/rpcs3/Emu/NP/np_handler.cpp @@ -59,11 +59,7 @@ namespace np { std::string get_players_history_path() { -#ifdef _WIN32 - return fs::get_config_dir() + "config/players_history.yml"; -#else - return fs::get_config_dir() + "players_history.yml"; -#endif + return fs::get_config_dir(true) + "players_history.yml"; } std::map load_players_history() @@ -1440,7 +1436,7 @@ namespace np void np_handler::save_players_history() { #ifdef _WIN32 - const std::string path_to_cfg = fs::get_config_dir() + "config/"; + const std::string path_to_cfg = fs::get_config_dir(true); if (!fs::create_path(path_to_cfg)) { nph_log.error("Could not create path: %s", path_to_cfg); diff --git a/rpcs3/Emu/NP/rpcn_config.cpp b/rpcs3/Emu/NP/rpcn_config.cpp index ff802e554e2c..1f52d60a05e7 100644 --- a/rpcs3/Emu/NP/rpcn_config.cpp +++ b/rpcs3/Emu/NP/rpcn_config.cpp @@ -34,7 +34,7 @@ void cfg_rpcn::load() void cfg_rpcn::save() const { #ifdef _WIN32 - const std::string path_to_cfg = fs::get_config_dir() + "config/"; + const std::string path_to_cfg = fs::get_config_dir(true); if (!fs::create_path(path_to_cfg)) { rpcn_log.error("Could not create path: %s", path_to_cfg); @@ -51,11 +51,7 @@ void cfg_rpcn::save() const std::string cfg_rpcn::get_path() { -#ifdef _WIN32 - return fs::get_config_dir() + "config/rpcn.yml"; -#else - return fs::get_config_dir() + "rpcn.yml"; -#endif + return fs::get_config_dir(true) + "rpcn.yml"; } std::string cfg_rpcn::generate_npid() diff --git a/rpcs3/Emu/NP/upnp_config.cpp b/rpcs3/Emu/NP/upnp_config.cpp index 13a4f7269854..bf43b8e55b07 100644 --- a/rpcs3/Emu/NP/upnp_config.cpp +++ b/rpcs3/Emu/NP/upnp_config.cpp @@ -24,7 +24,7 @@ void cfg_upnp::load() void cfg_upnp::save() const { #ifdef _WIN32 - const std::string path_to_cfg = fs::get_config_dir() + "config/"; + const std::string path_to_cfg = fs::get_config_dir(true); if (!fs::create_path(path_to_cfg)) { upnp_cfg_log.error("Could not create path: %s", path_to_cfg); @@ -51,9 +51,5 @@ void cfg_upnp::set_device_url(std::string_view url) std::string cfg_upnp::get_path() { -#ifdef _WIN32 - return fs::get_config_dir() + "config/upnp.yml"; -#else - return fs::get_config_dir() + "upnp.yml"; -#endif + return fs::get_config_dir(true) + "upnp.yml"; } diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 551e7de36d47..619fece496ef 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -374,7 +374,34 @@ void Emulator::Init() g_cfg_defaults = g_cfg.to_string(); - const std::string cfg_path = fs::get_config_dir() + "/config.yml"; + const std::string cfg_path = fs::get_config_dir(true) + "config.yml"; + + // Copy file from deprecated location to new location +#ifdef _WIN32 + const std::string old_path = fs::get_config_dir(false) + "config.yml"; + + if (fs::is_file(old_path)) + { + sys_log.notice("Found deprecated config.yml file: '%s'", old_path); + + if (!fs::is_file(cfg_path)) + { + sys_log.warning("Moving '%s' to '%s'", old_path, cfg_path); + + if (fs::copy_file(old_path, cfg_path, true)) + { + if (!fs::remove_file(old_path)) + { + sys_log.error("Failed to remove '%s' (error='%s')", old_path, fs::g_tls_error); + } + } + else + { + sys_log.error("Failed to copy '%s' to '%s' (error='%s')", old_path, cfg_path, fs::g_tls_error); + } + } + } +#endif // Save new global config if it doesn't exist or is empty if (fs::stat_t info{}; !fs::get_stat(cfg_path, info) || info.size == 0) @@ -4508,7 +4535,7 @@ void Emulator::SaveSettings(const std::string& settings, const std::string& titl if (title_id.empty()) { - config_name = fs::get_config_dir() + "/config.yml"; + config_name = fs::get_config_dir(true) + "config.yml"; } else { diff --git a/rpcs3/Emu/games_config.cpp b/rpcs3/Emu/games_config.cpp index 0979a015850f..5930fafe9f2d 100644 --- a/rpcs3/Emu/games_config.cpp +++ b/rpcs3/Emu/games_config.cpp @@ -123,7 +123,7 @@ bool games_config::save_nl() YAML::Emitter out; out << m_games; - fs::pending_file temp(fs::get_config_dir() + "/games.yml"); + fs::pending_file temp(fs::get_config_dir(true) + "games.yml"); if (temp.file && temp.file.write(out.c_str(), out.size()) >= out.size() && temp.commit()) { @@ -147,7 +147,36 @@ void games_config::load() m_games.clear(); - if (fs::file f{fs::get_config_dir() + "/games.yml", fs::read + fs::create}) + const std::string path = fs::get_config_dir(true) + "games.yml"; + + // Copy file from deprecated location to new location +#ifdef _WIN32 + const std::string old_path = fs::get_config_dir(false) + "games.yml"; + + if (fs::is_file(old_path)) + { + cfg_log.notice("Found deprecated games.yml file: '%s'", old_path); + + if (!fs::is_file(path)) + { + cfg_log.warning("Moving '%s' to '%s'", old_path, path); + + if (fs::copy_file(old_path, path, true)) + { + if (!fs::remove_file(old_path)) + { + cfg_log.error("Failed to remove '%s' (error='%s')", old_path, fs::g_tls_error); + } + } + else + { + cfg_log.error("Failed to copy '%s' to '%s' (error='%s')", old_path, path, fs::g_tls_error); + } + } + } +#endif + + if (fs::file f{path, fs::read + fs::create}) { auto [result, error] = yaml_load(f.to_string()); diff --git a/rpcs3/Emu/system_utils.cpp b/rpcs3/Emu/system_utils.cpp index 050f0839c259..49439dc3fc5d 100644 --- a/rpcs3/Emu/system_utils.cpp +++ b/rpcs3/Emu/system_utils.cpp @@ -311,11 +311,7 @@ namespace rpcs3::utils std::string get_custom_config_dir() { -#ifdef _WIN32 - return fs::get_config_dir() + "config/custom_configs/"; -#else - return fs::get_config_dir() + "custom_configs/"; -#endif + return fs::get_config_dir(true) + "custom_configs/"; } std::string get_custom_config_path(const std::string& identifier) @@ -330,11 +326,7 @@ namespace rpcs3::utils std::string get_input_config_root() { -#ifdef _WIN32 - return fs::get_config_dir() + "config/input_configs/"; -#else - return fs::get_config_dir() + "input_configs/"; -#endif + return fs::get_config_dir(true) + "input_configs/"; } std::string get_input_config_dir(const std::string& title_id) diff --git a/rpcs3/Emu/vfs_config.cpp b/rpcs3/Emu/vfs_config.cpp index c650bfaeeb4c..0d7508a28426 100644 --- a/rpcs3/Emu/vfs_config.cpp +++ b/rpcs3/Emu/vfs_config.cpp @@ -115,7 +115,7 @@ void cfg_vfs::load() void cfg_vfs::save() const { #ifdef _WIN32 - const std::string path_to_cfg = fs::get_config_dir() + "config/"; + const std::string path_to_cfg = fs::get_config_dir(true); if (!fs::create_path(path_to_cfg)) { vfs_log.error("Could not create path: %s", path_to_cfg); @@ -140,9 +140,5 @@ void cfg_vfs::save() const std::string cfg_vfs::get_path() { -#ifdef _WIN32 - return fs::get_config_dir() + "config/vfs.yml"; -#else - return fs::get_config_dir() + "vfs.yml"; -#endif + return fs::get_config_dir(true) + "vfs.yml"; } diff --git a/rpcs3/Input/ps_move_config.cpp b/rpcs3/Input/ps_move_config.cpp index 14f9d081fe96..bb9daa528ac0 100644 --- a/rpcs3/Input/ps_move_config.cpp +++ b/rpcs3/Input/ps_move_config.cpp @@ -7,11 +7,7 @@ cfg_ps_moves g_cfg_move; cfg_ps_moves::cfg_ps_moves() : cfg::node() -#ifdef _WIN32 - , path(fs::get_config_dir() + "config/ps_move.yml") -#else - , path(fs::get_config_dir() + "ps_move.yml") -#endif + , path(fs::get_config_dir(true) + "ps_move.yml") { } diff --git a/rpcs3/Input/raw_mouse_config.cpp b/rpcs3/Input/raw_mouse_config.cpp index b02f349dac87..bd870b12908b 100644 --- a/rpcs3/Input/raw_mouse_config.cpp +++ b/rpcs3/Input/raw_mouse_config.cpp @@ -63,7 +63,7 @@ bool raw_mice_config::load() m_mutex.lock(); bool result = false; - const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id); + const std::string cfg_name = fmt::format("%s%s.yml", fs::get_config_dir(true), cfg_id); cfg_log.notice("Loading %s config: %s", cfg_id, cfg_name); from_default(); @@ -90,7 +90,7 @@ void raw_mice_config::save() { std::lock_guard lock(m_mutex); - const std::string cfg_name = fmt::format("%sconfig/%s.yml", fs::get_config_dir(), cfg_id); + const std::string cfg_name = fmt::format("%s%s.yml", fs::get_config_dir(true), cfg_id); cfg_log.notice("Saving %s config to '%s'", cfg_id, cfg_name); if (!fs::create_path(fs::get_parent_dir(cfg_name))) diff --git a/rpcs3/rpcs3qt/emu_settings.cpp b/rpcs3/rpcs3qt/emu_settings.cpp index 2b4d4a0b87c8..eb6439243aa1 100644 --- a/rpcs3/rpcs3qt/emu_settings.cpp +++ b/rpcs3/rpcs3qt/emu_settings.cpp @@ -93,7 +93,7 @@ void emu_settings::LoadSettings(const std::string& title_id, bool create_config_ m_title_id = title_id; // Create config path if necessary - fs::create_path(title_id.empty() ? fs::get_config_dir() : rpcs3::utils::get_custom_config_dir()); + fs::create_path(title_id.empty() ? fs::get_config_dir(true) : rpcs3::utils::get_custom_config_dir()); // Load default config auto [default_config, default_error] = yaml_load(g_cfg_defaults); @@ -113,7 +113,7 @@ void emu_settings::LoadSettings(const std::string& title_id, bool create_config_ if (create_config_from_global) { // Add global config - const std::string global_config_path = fs::get_config_dir() + "config.yml"; + const std::string global_config_path = fs::get_config_dir(true) + "config.yml"; fs::g_tls_error = fs::error::ok; fs::file config(global_config_path, fs::read + fs::create); auto [global_config, global_error] = yaml_load(config ? config.to_string() : ""); diff --git a/rpcs3/rpcs3qt/uuid.cpp b/rpcs3/rpcs3qt/uuid.cpp index 0ade0218d397..d3f3f58b7760 100644 --- a/rpcs3/rpcs3qt/uuid.cpp +++ b/rpcs3/rpcs3qt/uuid.cpp @@ -13,19 +13,15 @@ namespace gui { std::string get_uuid_path() { -#ifdef _WIN32 - const std::string config_dir = fs::get_config_dir() + "config/"; + const std::string config_dir = fs::get_config_dir(true); const std::string uuid_path = config_dir + "uuid"; - +#ifdef _WIN32 if (!fs::create_path(config_dir)) { uuid_log.error("Could not create path: %s (%s)", uuid_path, fs::g_tls_error); } - - return uuid_path; -#else - return fs::get_config_dir() + "uuid"; #endif + return uuid_path; } std::string make_uuid()