windows: move config.yml and games.yml to /config/

This commit is contained in:
Megamouse 2025-01-02 12:24:25 +01:00
parent 5c2c4a6649
commit 451e953d26
20 changed files with 76 additions and 94 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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()

View File

@ -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

View File

@ -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")
{
}

View File

@ -235,7 +235,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();
@ -272,7 +272,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)))

View File

@ -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")
{
}

View File

@ -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")
{
}

View File

@ -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")
{
}

View File

@ -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<std::string, player_history> 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);

View File

@ -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()

View File

@ -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";
}

View File

@ -374,7 +374,22 @@ 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";
// Move 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::rename(old_path, cfg_path, false))
{
sys_log.error("Failed to move '%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)
@ -4466,7 +4481,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
{

View File

@ -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,24 @@ 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";
// Move 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::rename(old_path, path, false))
{
cfg_log.error("Failed to move '%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());

View File

@ -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)

View File

@ -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";
}

View File

@ -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")
{
}

View File

@ -96,7 +96,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();
@ -123,7 +123,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)))

View File

@ -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() : "");

View File

@ -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()