Skip to content

Commit

Permalink
windows: move config.yml and games.yml to /config/
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Jan 2, 2025
1 parent fb237dd commit 252d1a1
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 94 deletions.
10 changes: 9 additions & 1 deletion Utilities/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions Utilities/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 3 additions & 7 deletions Utilities/bin_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions rpcs3/Emu/IPC_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions rpcs3/Emu/Io/camera_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Io/emulated_pad_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)))
Expand Down
6 changes: 1 addition & 5 deletions rpcs3/Emu/Io/mouse_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
8 changes: 1 addition & 7 deletions rpcs3/Emu/Io/rb3drums_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
6 changes: 1 addition & 5 deletions rpcs3/Emu/Io/recording_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
8 changes: 2 additions & 6 deletions rpcs3/Emu/NP/np_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions rpcs3/Emu/NP/rpcn_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions rpcs3/Emu/NP/upnp_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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";
}
31 changes: 29 additions & 2 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand Down
33 changes: 31 additions & 2 deletions rpcs3/Emu/games_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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());

Expand Down
12 changes: 2 additions & 10 deletions rpcs3/Emu/system_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions rpcs3/Emu/vfs_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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";
}
6 changes: 1 addition & 5 deletions rpcs3/Input/ps_move_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Input/raw_mouse_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)))
Expand Down
Loading

0 comments on commit 252d1a1

Please sign in to comment.