Skip to content

Commit

Permalink
Use custom configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
O1L committed Oct 24, 2015
1 parent fd628d8 commit 9d6df23
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 10 deletions.
9 changes: 6 additions & 3 deletions Utilities/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ bool fs::is_file(const std::string& file)

#ifdef _WIN32
DWORD attrs;
if ((attrs = GetFileAttributesW(to_wchar(file).get())) == INVALID_FILE_ATTRIBUTES)
const std::string path = fmt::replace_all(file, "/", "\\");
if ((attrs = GetFileAttributesW(to_wchar(path).get())) == INVALID_FILE_ATTRIBUTES)
{
return false;
}
Expand All @@ -190,7 +191,8 @@ bool fs::is_dir(const std::string& dir)

#ifdef _WIN32
DWORD attrs;
if ((attrs = GetFileAttributesW(to_wchar(dir).get())) == INVALID_FILE_ATTRIBUTES)
const std::string path = fmt::replace_all(dir, "/", "\\");
if ((attrs = GetFileAttributesW(to_wchar(path).get())) == INVALID_FILE_ATTRIBUTES)
{
return false;
}
Expand All @@ -212,7 +214,8 @@ bool fs::create_dir(const std::string& dir)
g_tls_error = fse::ok;

#ifdef _WIN32
if (!CreateDirectoryW(to_wchar(dir).get(), NULL))
const std::string path = fmt::replace_all(dir, "/", "\\");
if (!CreateDirectoryW(to_wchar(path).get(), NULL))
#else
if (mkdir(dir.c_str(), 0777))
#endif
Expand Down
38 changes: 35 additions & 3 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ void Emulator::SetTitle(const std::string& title)
m_title = title;
}

void Emulator::CreateConfig(const std::string& name)
{
const std::string& path = "data/" + name;
const std::string& ini_file = path + "/" + name + ".ini";

if (!fs::is_dir("data"))
fs::create_dir("data");

if (!fs::is_dir(path))
fs::create_dir(path);

if (!fs::is_file(ini_file))
rpcs3::config_t{ ini_file }.save();
}

bool Emulator::BootGame(const std::string& path, bool direct)
{
static const char* elf_path[6] =
Expand Down Expand Up @@ -173,12 +188,27 @@ void Emulator::Load()
}
}

//TODO: load custom config if exists
ResetInfo();
GetVFS().Init(elf_dir);

// load custom config as global
if (!Ini.UseDefaultIni.GetValue())
{
std::string& name = PSFLoader{ vfsFile{ "/app_home/../PARAM.SFO" } }.GetString("TITLE_ID");
if (name.size())
{
name = name.substr(0, 4) + "-" + name.substr(4, 5);
CreateConfig(name);
rpcs3::config.path("data/" + name + "/" + name + ".ini");
rpcs3::config.load();
}
}

// TODO: use state configuration instead of global config
rpcs3::state.config = rpcs3::config;

LOG_NOTICE(LOADER, "Loading '%s'...", m_path.c_str());
ResetInfo();
GetVFS().Init(elf_dir);
LOG_NOTICE(LOADER, "Used configuration: '%s'", rpcs3::config.path().c_str());

// /dev_bdvd/ mounting
vfsFile f("/app_home/../dev_bdvd.path");
Expand Down Expand Up @@ -447,6 +477,8 @@ void Emulator::Stop()

RSXIOMem.Clear();
vm::close();
rpcs3::config.path("rpcs3.new.ini"); // fallback to default .ini
rpcs3::config.load();

SendDbgCommand(DID_STOPPED_EMU);
}
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Emulator final
void SetPath(const std::string& path, const std::string& elf_path = "");
void SetTitleID(const std::string& id);
void SetTitle(const std::string& title);
void CreateConfig(const std::string& name);

const std::string& GetPath() const
{
Expand Down
40 changes: 37 additions & 3 deletions rpcs3/Gui/GameViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Emu/FS/vfsFile.h"
#include "GameViewer.h"
#include "Loader/PSF.h"
#include "SettingsDialog.h"
#include <wx/dir.h>

static const std::string m_class_name = "GameViewer";
Expand Down Expand Up @@ -251,13 +252,46 @@ void GameViewer::DClick(wxListEvent& event)

void GameViewer::RightClick(wxListEvent& event)
{
m_popup->Destroy(m_popup->FindItemByPosition(0));
m_popup->Destroy(0);
m_popup->Destroy(1);
m_popup->Destroy(2);

wxMenuItem *pMenuItemA = m_popup->Append(event.GetIndex(), _T("Remove Game"));
Bind(wxEVT_MENU, &GameViewer::RemoveGame, this, event.GetIndex());
wxFont font = GetFont();
font.SetWeight(wxFONTWEIGHT_BOLD);
wxMenuItem* boot_item = new wxMenuItem(m_popup, 0, _T("Boot"));
boot_item->SetFont(font);

m_popup->Append(boot_item);
m_popup->Append(1, _T("Configure"));
m_popup->Append(2, _T("Remove Game"));

Bind(wxEVT_MENU, &GameViewer::BootGame, this, 0);
Bind(wxEVT_MENU, &GameViewer::ConfigureGame, this, 1);
Bind(wxEVT_MENU, &GameViewer::RemoveGame, this, 2);

PopupMenu(m_popup, event.GetPoint());
}

void GameViewer::BootGame(wxCommandEvent& WXUNUSED(event))
{
wxListEvent unused_event;
DClick(unused_event);
}

void GameViewer::ConfigureGame(wxCommandEvent& WXUNUSED(event))
{
long i = GetFirstSelected();
if (i < 0) return;

Emu.CreateConfig(m_game_data[i].serial);
rpcs3::config.path("data/" + m_game_data[i].serial + "/" + m_game_data[i].serial + ".ini");
LOG_NOTICE(LOADER, "Configure: '%s'", rpcs3::config.path().c_str());
rpcs3::config.load();
SettingsDialog(this);
rpcs3::config.path("rpcs3.new.ini");
rpcs3::config.load();
}

void GameViewer::RemoveGame(wxCommandEvent& event)
{
Emu.GetVFS().Init("/");
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/Gui/GameViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ class GameViewer : public wxListView
void LoadSettings();

void Refresh();
void BootGame(wxCommandEvent& event);
void ConfigureGame(wxCommandEvent& event);
void RemoveGame(wxCommandEvent& event);
bool RemoveFolder(std::string localPath);

private:
virtual void DClick(wxListEvent& event);
Expand Down
4 changes: 4 additions & 0 deletions rpcs3/Gui/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ SettingsDialog::SettingsDialog(wxWindow *parent, rpcs3::config_t* cfg)
wxCheckBox* chbox_hle_savetty = new wxCheckBox(p_misc, wxID_ANY, "Save TTY output to file");
wxCheckBox* chbox_hle_exitonstop = new wxCheckBox(p_misc, wxID_ANY, "Exit RPCS3 when process finishes");
wxCheckBox* chbox_hle_always_start = new wxCheckBox(p_misc, wxID_ANY, "Always start after boot");
wxCheckBox* chbox_hle_use_default_ini = new wxCheckBox(p_misc, wxID_ANY, "Use default configuration");

wxTextCtrl* txt_dbg_range_min = new wxTextCtrl(p_core, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(55, 20));
wxTextCtrl* txt_dbg_range_max = new wxTextCtrl(p_core, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(55, 20));
Expand Down Expand Up @@ -335,6 +336,7 @@ SettingsDialog::SettingsDialog(wxWindow *parent, rpcs3::config_t* cfg)
chbox_hle_savetty->SetValue(Ini.HLESaveTTY.GetValue());
chbox_hle_exitonstop->SetValue(Ini.HLEExitOnStop.GetValue());
chbox_hle_always_start->SetValue(Ini.HLEAlwaysStart.GetValue());
chbox_hle_use_default_ini->SetValue(Ini.UseDefaultIni.GetValue());
chbox_core_hook_stfunc->SetValue(Ini.HookStFunc.GetValue());
chbox_core_load_liblv2->SetValue(Ini.LoadLibLv2.GetValue());

Expand Down Expand Up @@ -449,6 +451,7 @@ SettingsDialog::SettingsDialog(wxWindow *parent, rpcs3::config_t* cfg)
s_subpanel_misc->Add(chbox_hle_savetty, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_misc->Add(chbox_hle_exitonstop, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_misc->Add(chbox_hle_always_start, wxSizerFlags().Border(wxALL, 5).Expand());
s_subpanel_misc->Add(chbox_hle_use_default_ini, wxSizerFlags().Border(wxALL, 5).Expand());

// Auto Pause
s_subpanel_misc->Add(chbox_dbg_ap_systemcall, wxSizerFlags().Border(wxALL, 5).Expand());
Expand Down Expand Up @@ -528,6 +531,7 @@ SettingsDialog::SettingsDialog(wxWindow *parent, rpcs3::config_t* cfg)
Ini.NETInterface.SetValue(cbox_net_interface->GetSelection());
Ini.SysLanguage.SetValue(cbox_sys_lang->GetSelection());
Ini.HLEAlwaysStart.SetValue(chbox_hle_always_start->GetValue());
Ini.UseDefaultIni.SetValue(chbox_hle_use_default_ini->GetValue());

//Auto Pause
Ini.DBGAutoPauseFunctionCall.SetValue(chbox_dbg_ap_functioncall->GetValue());
Expand Down
4 changes: 4 additions & 0 deletions rpcs3/Ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class Inis
IniEntry<bool> HLESaveTTY;
IniEntry<bool> HLEExitOnStop;
IniEntry<bool> HLEAlwaysStart;
IniEntry<bool> UseDefaultIni;

// Auto Pause
IniEntry<bool> DBGAutoPauseSystemCall;
Expand Down Expand Up @@ -249,6 +250,7 @@ class Inis
HLEExitOnStop.Init("HLE_HLEExitOnStop", path);
HLELogLvl.Init("HLE_HLELogLvl", path);
HLEAlwaysStart.Init("HLE_HLEAlwaysStart", path);
UseDefaultIni.Init("HLE_UseDefaultIni", path);

// Auto Pause
DBGAutoPauseFunctionCall.Init("DBG_AutoPauseFunctionCall", path);
Expand Down Expand Up @@ -333,6 +335,7 @@ class Inis
HLEExitOnStop.Load(false);
HLELogLvl.Load(3);
HLEAlwaysStart.Load(true);
UseDefaultIni.Load(false);

//Auto Pause
DBGAutoPauseFunctionCall.Load(false);
Expand Down Expand Up @@ -417,6 +420,7 @@ class Inis
HLEExitOnStop.Save();
HLELogLvl.Save();
HLEAlwaysStart.Save();
UseDefaultIni.Save();

//Auto Pause
DBGAutoPauseFunctionCall.Save();
Expand Down

0 comments on commit 9d6df23

Please sign in to comment.