Skip to content

Commit

Permalink
use "config/custom_configs/" for custom configs (backwards compatible)
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse authored and AniLeo committed Jan 31, 2019
1 parent 09a8f7a commit 27f6f49
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 102 deletions.
62 changes: 48 additions & 14 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ void Emulator::LimitCacheSize()
LOG_SUCCESS(GENERAL, "Cleaned disk cache, removed %.2f MB", size / 1024.0 / 1024.0);
}

bool Emulator::BootGame(const std::string& path, bool direct, bool add_only)
bool Emulator::BootGame(const std::string& path, bool direct, bool add_only, bool force_global_config)
{
if (g_cfg.vfs.limit_cache_size)
LimitCacheSize();
Expand All @@ -603,7 +603,7 @@ bool Emulator::BootGame(const std::string& path, bool direct, bool add_only)
if (direct && fs::exists(path))
{
m_path = path;
Load(add_only);
Load(add_only, force_global_config);
return true;
}

Expand All @@ -614,7 +614,7 @@ bool Emulator::BootGame(const std::string& path, bool direct, bool add_only)
if (fs::is_file(elf))
{
m_path = elf;
Load(add_only);
Load(add_only, force_global_config);
return true;
}
}
Expand Down Expand Up @@ -697,12 +697,33 @@ std::string Emulator::GetSfoDirFromGamePath(const std::string& game_path, const
return game_path;
}

std::string Emulator::GetCustomConfigDir()
{
#ifdef _WIN32
return fs::get_config_dir() + "config/custom_configs/";
#else
return fs::get_config_dir() + "custom_configs/";
#endif
}

std::string Emulator::GetCustomConfigPath(const std::string& title_id, bool get_deprecated_path)
{
std::string path;

if (get_deprecated_path)
path = fs::get_config_dir() + "data/" + title_id + "/config.yml";
else
path = GetCustomConfigDir() + "config_" + title_id + ".yml";

return path;
}

void Emulator::SetForceBoot(bool force_boot)
{
m_force_boot = force_boot;
}

void Emulator::Load(bool add_only)
void Emulator::Load(bool add_only, bool force_global_config)
{
if (!IsStopped())
{
Expand Down Expand Up @@ -784,18 +805,31 @@ void Emulator::Load(bool add_only)
LOG_NOTICE(LOADER, "Serial: %s", GetTitleID());
LOG_NOTICE(LOADER, "Category: %s", GetCat());

// Load custom config-1
if (fs::file cfg_file{fs::get_config_dir() + "data/" + m_title_id + "/config.yml"})
if (!force_global_config)
{
LOG_NOTICE(LOADER, "Applying custom config: data/%s/config.yml", m_title_id);
g_cfg.from_string(cfg_file.to_string());
}
const std::string config_path_new = GetCustomConfigPath(m_title_id);
const std::string config_path_old = GetCustomConfigPath(m_title_id, true);

// Load custom config-2
if (fs::file cfg_file{m_path + ".yml"})
{
LOG_NOTICE(LOADER, "Applying custom config: %s.yml", m_path);
g_cfg.from_string(cfg_file.to_string());
// Load custom config-1
if (fs::file cfg_file{ config_path_old })
{
LOG_NOTICE(LOADER, "Applying custom config: %s", config_path_old);
g_cfg.from_string(cfg_file.to_string());
}

// Load custom config-2
if (fs::file cfg_file{ config_path_new })
{
LOG_NOTICE(LOADER, "Applying custom config: %s", config_path_new);
g_cfg.from_string(cfg_file.to_string());
}

// Load custom config-3
if (fs::file cfg_file{ m_path + ".yml" })
{
LOG_NOTICE(LOADER, "Applying custom config: %s.yml", m_path);
g_cfg.from_string(cfg_file.to_string());
}
}

#if defined(_WIN32) || defined(HAVE_VULKAN)
Expand Down
7 changes: 5 additions & 2 deletions rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class Emulator final

std::string PPUCache() const;

bool BootGame(const std::string& path, bool direct = false, bool add_only = false);
bool BootGame(const std::string& path, bool direct = false, bool add_only = false, bool force_global_config = false);
bool BootRsxCapture(const std::string& path);
bool InstallPkg(const std::string& path);

Expand All @@ -322,9 +322,12 @@ class Emulator final
static std::string GetHddDir();
static std::string GetSfoDirFromGamePath(const std::string& game_path, const std::string& user);

static std::string GetCustomConfigDir();
static std::string GetCustomConfigPath(const std::string& title_id, bool get_deprecated_path = false);

void SetForceBoot(bool force_boot);

void Load(bool add_only = false);
void Load(bool add_only = false, bool force_global_config = false);
void Run();
bool Pause();
void Resume();
Expand Down
30 changes: 21 additions & 9 deletions rpcs3/rpcs3qt/emu_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ emu_settings::~emu_settings()
{
}

void emu_settings::LoadSettings(const std::string& path)
void emu_settings::LoadSettings(const std::string& title_id)
{
m_path = path;
m_title_id = title_id;

// Create config path if necessary
fs::create_path(fs::get_config_dir() + path);
fs::create_path(title_id.empty() ? fs::get_config_dir() : Emu.GetCustomConfigDir());

// Load default config
m_defaultSettings = YAML::Load(g_cfg_defaults);
Expand All @@ -202,11 +202,23 @@ void emu_settings::LoadSettings(const std::string& path)
config.close();

// Add game config
if (!path.empty() && fs::is_file(fs::get_config_dir() + path + "/config.yml"))
if (!title_id.empty())
{
config = fs::file(fs::get_config_dir() + path + "/config.yml", fs::read + fs::write);
m_currentSettings += YAML::Load(config.to_string());
config.close();
const std::string config_path_new = Emu.GetCustomConfigPath(m_title_id);
const std::string config_path_old = Emu.GetCustomConfigPath(m_title_id, true);

if (fs::is_file(config_path_new))
{
config = fs::file(config_path_new, fs::read + fs::write);
m_currentSettings += YAML::Load(config.to_string());
config.close();
}
else if (fs::is_file(config_path_old))
{
config = fs::file(config_path_old, fs::read + fs::write);
m_currentSettings += YAML::Load(config.to_string());
config.close();
}
}
}

Expand All @@ -216,9 +228,9 @@ void emu_settings::SaveSettings()
YAML::Emitter out;
emitData(out, m_currentSettings);

if (!m_path.empty())
if (!m_title_id.empty())
{
config = fs::file(fs::get_config_dir() + m_path + "/config.yml", fs::read + fs::write + fs::create);
config = fs::file(Emu.GetCustomConfigPath(m_title_id), fs::read + fs::write + fs::create);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/rpcs3qt/emu_settings.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "Utilities/File.h"
#include "Utilities/Log.h"
Expand Down Expand Up @@ -223,7 +223,7 @@ class emu_settings : public QObject
Render_Creator m_render_creator;

/** Loads the settings from path.*/
void LoadSettings(const std::string& path = "");
void LoadSettings(const std::string& title_id = "");

/** Fixes all registered invalid settings after asking the user for permission.*/
void OpenCorrectionDialog(QWidget* parent = Q_NULLPTR);
Expand Down Expand Up @@ -355,5 +355,5 @@ public Q_SLOTS:

YAML::Node m_defaultSettings; // The default settings as a YAML node.
YAML::Node m_currentSettings; // The current settings as a YAML node.
std::string m_path;
std::string m_title_id;
};
Loading

0 comments on commit 27f6f49

Please sign in to comment.