rpcsx/rpcs3/Emu/Io/mouse_config.cpp

63 lines
1.3 KiB
C++
Raw Normal View History

2020-12-24 13:48:22 +01:00
#include "stdafx.h"
#include "mouse_config.h"
#include "MouseHandler.h"
#include "Utilities/File.h"
mouse_config::mouse_config()
2024-06-06 02:06:39 +02:00
#ifdef _WIN32
: cfg_name(fs::get_config_dir() + "config/config_mouse.yml")
#else
: cfg_name(fs::get_config_dir() + "config_mouse.yml")
#endif
2020-12-24 13:48:22 +01:00
{
}
bool mouse_config::exist() const
{
return fs::is_file(cfg_name);
}
bool mouse_config::load()
{
2024-08-08 05:35:23 +02:00
g_cfg_mouse.from_default();
2020-12-24 13:48:22 +01:00
if (fs::file cfg_file{cfg_name, fs::read})
{
2024-08-08 05:35:23 +02:00
if (const std::string content = cfg_file.to_string(); !content.empty())
{
return from_string(content);
}
2020-12-24 13:48:22 +01:00
}
return false;
}
void mouse_config::save()
2020-12-24 13:48:22 +01:00
{
fs::pending_file file(cfg_name);
if (file.file)
{
file.file.write(to_string());
file.commit();
}
reload_requested = true;
2020-12-24 13:48:22 +01:00
}
cfg::string& mouse_config::get_button(int code)
{
switch (code)
{
case CELL_MOUSE_BUTTON_1: return mouse_button_1;
case CELL_MOUSE_BUTTON_2: return mouse_button_2;
case CELL_MOUSE_BUTTON_3: return mouse_button_3;
case CELL_MOUSE_BUTTON_4: return mouse_button_4;
case CELL_MOUSE_BUTTON_5: return mouse_button_5;
case CELL_MOUSE_BUTTON_6: return mouse_button_6;
case CELL_MOUSE_BUTTON_7: return mouse_button_7;
case CELL_MOUSE_BUTTON_8: return mouse_button_8;
default: fmt::throw_exception("Invalid code %d", code);
}
}