mirror of https://git.suyu.dev/suyu/suyu
commit
a171000cbe
@ -0,0 +1,3 @@
|
||||
[submodule "externals/inih/inih"]
|
||||
path = externals/inih/inih
|
||||
url = https://github.com/svn2github/inih
|
@ -0,0 +1,11 @@
|
||||
set(SRCS
|
||||
inih/ini.c
|
||||
inih/cpp/INIReader.cpp
|
||||
)
|
||||
set(HEADERS
|
||||
inih/ini.h
|
||||
inih/cpp/INIReader.h
|
||||
)
|
||||
|
||||
create_directory_groups(${SRCS} ${HEADERS})
|
||||
add_library(inih ${SRCS} ${HEADERS})
|
@ -0,0 +1 @@
|
||||
Subproject commit 603729dec89aaca42d7bd08f08bc333165b7d5d1
|
@ -0,0 +1,65 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "citra/default_ini.h"
|
||||
#include "common/file_util.h"
|
||||
#include "core/settings.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
Config::Config() {
|
||||
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
||||
glfw_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "glfw-config.ini";
|
||||
glfw_config = new INIReader(glfw_config_loc);
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
bool Config::LoadINI(INIReader* config, const char* location, const std::string& default_contents, bool retry) {
|
||||
if (config->ParseError() < 0) {
|
||||
if (retry) {
|
||||
ERROR_LOG(CONFIG, "Failed to load %s. Creating file from defaults...", location);
|
||||
FileUtil::CreateFullPath(location);
|
||||
FileUtil::WriteStringToFile(true, default_contents, location);
|
||||
*config = INIReader(location); // Reopen file
|
||||
|
||||
return LoadINI(config, location, default_contents, false);
|
||||
}
|
||||
ERROR_LOG(CONFIG, "Failed.");
|
||||
return false;
|
||||
}
|
||||
INFO_LOG(CONFIG, "Successfully loaded %s", location);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Config::ReadControls() {
|
||||
Settings::values.pad_a_key = glfw_config->GetInteger("Controls", "pad_a", GLFW_KEY_A);
|
||||
Settings::values.pad_b_key = glfw_config->GetInteger("Controls", "pad_b", GLFW_KEY_S);
|
||||
Settings::values.pad_x_key = glfw_config->GetInteger("Controls", "pad_x", GLFW_KEY_Z);
|
||||
Settings::values.pad_y_key = glfw_config->GetInteger("Controls", "pad_y", GLFW_KEY_X);
|
||||
Settings::values.pad_l_key = glfw_config->GetInteger("Controls", "pad_l", GLFW_KEY_Q);
|
||||
Settings::values.pad_r_key = glfw_config->GetInteger("Controls", "pad_r", GLFW_KEY_W);
|
||||
Settings::values.pad_start_key = glfw_config->GetInteger("Controls", "pad_start", GLFW_KEY_M);
|
||||
Settings::values.pad_select_key = glfw_config->GetInteger("Controls", "pad_select", GLFW_KEY_N);
|
||||
Settings::values.pad_home_key = glfw_config->GetInteger("Controls", "pad_home", GLFW_KEY_B);
|
||||
Settings::values.pad_dup_key = glfw_config->GetInteger("Controls", "pad_dup", GLFW_KEY_T);
|
||||
Settings::values.pad_ddown_key = glfw_config->GetInteger("Controls", "pad_ddown", GLFW_KEY_G);
|
||||
Settings::values.pad_dleft_key = glfw_config->GetInteger("Controls", "pad_dleft", GLFW_KEY_F);
|
||||
Settings::values.pad_dright_key = glfw_config->GetInteger("Controls", "pad_dright", GLFW_KEY_H);
|
||||
Settings::values.pad_sup_key = glfw_config->GetInteger("Controls", "pad_sup", GLFW_KEY_UP);
|
||||
Settings::values.pad_sdown_key = glfw_config->GetInteger("Controls", "pad_sdown", GLFW_KEY_DOWN);
|
||||
Settings::values.pad_sleft_key = glfw_config->GetInteger("Controls", "pad_sleft", GLFW_KEY_LEFT);
|
||||
Settings::values.pad_sright_key = glfw_config->GetInteger("Controls", "pad_sright", GLFW_KEY_RIGHT);
|
||||
}
|
||||
|
||||
void Config::Reload() {
|
||||
LoadINI(glfw_config, glfw_config_loc.c_str(), DefaultINI::glfw_config_file);
|
||||
ReadControls();
|
||||
}
|
||||
|
||||
Config::~Config() {
|
||||
delete glfw_config;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <inih/cpp/INIReader.h>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
class Config {
|
||||
INIReader* glfw_config;
|
||||
std::string glfw_config_loc;
|
||||
|
||||
bool LoadINI(INIReader* config, const char* location, const std::string& default_contents="", bool retry=true);
|
||||
void ReadControls();
|
||||
public:
|
||||
Config();
|
||||
~Config();
|
||||
|
||||
void Reload();
|
||||
};
|
@ -0,0 +1,30 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace DefaultINI {
|
||||
|
||||
const char* glfw_config_file = R"(
|
||||
[Controls]
|
||||
pad_start =
|
||||
pad_select =
|
||||
pad_home =
|
||||
pad_dup =
|
||||
pad_ddown =
|
||||
pad_dleft =
|
||||
pad_dright =
|
||||
pad_a =
|
||||
pad_b =
|
||||
pad_x =
|
||||
pad_y =
|
||||
pad_r =
|
||||
pad_l =
|
||||
pad_sup =
|
||||
pad_sdown =
|
||||
pad_sleft =
|
||||
pad_sright =
|
||||
)";
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "core/settings.h"
|
||||
#include "common/file_util.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
Config::Config() {
|
||||
|
||||
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
||||
qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini";
|
||||
FileUtil::CreateFullPath(qt_config_loc);
|
||||
qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
|
||||
|
||||
Reload();
|
||||
}
|
||||
|
||||
void Config::ReadControls() {
|
||||
qt_config->beginGroup("Controls");
|
||||
Settings::values.pad_a_key = qt_config->value("pad_a", Qt::Key_A).toInt();
|
||||
Settings::values.pad_b_key = qt_config->value("pad_b", Qt::Key_S).toInt();
|
||||
Settings::values.pad_x_key = qt_config->value("pad_x", Qt::Key_Z).toInt();
|
||||
Settings::values.pad_y_key = qt_config->value("pad_y", Qt::Key_X).toInt();
|
||||
Settings::values.pad_l_key = qt_config->value("pad_l", Qt::Key_Q).toInt();
|
||||
Settings::values.pad_r_key = qt_config->value("pad_r", Qt::Key_W).toInt();
|
||||
Settings::values.pad_start_key = qt_config->value("pad_start", Qt::Key_M).toInt();
|
||||
Settings::values.pad_select_key = qt_config->value("pad_select", Qt::Key_N).toInt();
|
||||
Settings::values.pad_home_key = qt_config->value("pad_home", Qt::Key_B).toInt();
|
||||
Settings::values.pad_dup_key = qt_config->value("pad_dup", Qt::Key_T).toInt();
|
||||
Settings::values.pad_ddown_key = qt_config->value("pad_ddown", Qt::Key_G).toInt();
|
||||
Settings::values.pad_dleft_key = qt_config->value("pad_dleft", Qt::Key_F).toInt();
|
||||
Settings::values.pad_dright_key = qt_config->value("pad_dright", Qt::Key_H).toInt();
|
||||
Settings::values.pad_sup_key = qt_config->value("pad_sup", Qt::Key_Up).toInt();
|
||||
Settings::values.pad_sdown_key = qt_config->value("pad_sdown", Qt::Key_Down).toInt();
|
||||
Settings::values.pad_sleft_key = qt_config->value("pad_sleft", Qt::Key_Left).toInt();
|
||||
Settings::values.pad_sright_key = qt_config->value("pad_sright", Qt::Key_Right).toInt();
|
||||
qt_config->endGroup();
|
||||
}
|
||||
|
||||
void Config::SaveControls() {
|
||||
qt_config->beginGroup("Controls");
|
||||
qt_config->setValue("pad_a", Settings::values.pad_a_key);
|
||||
qt_config->setValue("pad_b", Settings::values.pad_b_key);
|
||||
qt_config->setValue("pad_x", Settings::values.pad_x_key);
|
||||
qt_config->setValue("pad_y", Settings::values.pad_y_key);
|
||||
qt_config->setValue("pad_l", Settings::values.pad_l_key);
|
||||
qt_config->setValue("pad_r", Settings::values.pad_r_key);
|
||||
qt_config->setValue("pad_start", Settings::values.pad_start_key);
|
||||
qt_config->setValue("pad_select", Settings::values.pad_select_key);
|
||||
qt_config->setValue("pad_home", Settings::values.pad_home_key);
|
||||
qt_config->setValue("pad_dup", Settings::values.pad_dup_key);
|
||||
qt_config->setValue("pad_ddown", Settings::values.pad_ddown_key);
|
||||
qt_config->setValue("pad_dleft", Settings::values.pad_dleft_key);
|
||||
qt_config->setValue("pad_dright", Settings::values.pad_dright_key);
|
||||
qt_config->setValue("pad_sup", Settings::values.pad_sup_key);
|
||||
qt_config->setValue("pad_sdown", Settings::values.pad_sdown_key);
|
||||
qt_config->setValue("pad_sleft", Settings::values.pad_sleft_key);
|
||||
qt_config->setValue("pad_sright", Settings::values.pad_sright_key);
|
||||
qt_config->endGroup();
|
||||
}
|
||||
|
||||
void Config::Reload() {
|
||||
ReadControls();
|
||||
}
|
||||
|
||||
void Config::Save() {
|
||||
SaveControls();
|
||||
}
|
||||
|
||||
Config::~Config() {
|
||||
Save();
|
||||
|
||||
delete qt_config;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
class Config {
|
||||
QSettings* qt_config;
|
||||
std::string qt_config_loc;
|
||||
|
||||
void ReadControls();
|
||||
void SaveControls();
|
||||
public:
|
||||
Config();
|
||||
~Config();
|
||||
|
||||
void Reload();
|
||||
void Save();
|
||||
};
|
@ -0,0 +1,11 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
Values values = {};
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Settings {
|
||||
|
||||
struct Values {
|
||||
int pad_a_key;
|
||||
int pad_b_key;
|
||||
int pad_x_key;
|
||||
int pad_y_key;
|
||||
int pad_l_key;
|
||||
int pad_r_key;
|
||||
int pad_start_key;
|
||||
int pad_select_key;
|
||||
int pad_home_key;
|
||||
int pad_dup_key;
|
||||
int pad_ddown_key;
|
||||
int pad_dleft_key;
|
||||
int pad_dright_key;
|
||||
int pad_sup_key;
|
||||
int pad_sdown_key;
|
||||
int pad_sleft_key;
|
||||
int pad_sright_key;
|
||||
} extern values;
|
||||
|
||||
}
|
Loading…
Reference in New Issue