mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 04:47:53 +00:00
config: Migrate config files into config/custom
Co-authored-by: lat9nq <lat9nq@virginia.edu>
This commit is contained in:
parent
c0c4ed0d3b
commit
64e174237e
4 changed files with 61 additions and 21 deletions
|
@ -15,27 +15,10 @@
|
|||
|
||||
namespace FS = Common::FS;
|
||||
|
||||
Config::Config(const std::string& config_file, ConfigType config_type) : type(config_type) {
|
||||
Config::Config(const std::string& config_name, ConfigType config_type) : type(config_type) {
|
||||
global = config_type == ConfigType::GlobalConfig;
|
||||
|
||||
switch (config_type) {
|
||||
case ConfigType::GlobalConfig:
|
||||
case ConfigType::PerGameConfig:
|
||||
qt_config_loc = fmt::format("{}" DIR_SEP "{}.ini", FS::GetUserPath(FS::UserPath::ConfigDir),
|
||||
config_file);
|
||||
FS::CreateFullPath(qt_config_loc);
|
||||
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
|
||||
QSettings::IniFormat);
|
||||
Reload();
|
||||
break;
|
||||
case ConfigType::InputProfile:
|
||||
qt_config_loc = fmt::format("{}input" DIR_SEP "{}.ini",
|
||||
FS::GetUserPath(FS::UserPath::ConfigDir), config_file);
|
||||
FS::CreateFullPath(qt_config_loc);
|
||||
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
|
||||
QSettings::IniFormat);
|
||||
break;
|
||||
}
|
||||
Initialize(config_name);
|
||||
}
|
||||
|
||||
Config::~Config() {
|
||||
|
@ -256,6 +239,34 @@ const std::array<UISettings::Shortcut, 16> Config::default_hotkeys{{
|
|||
}};
|
||||
// clang-format on
|
||||
|
||||
void Config::Initialize(const std::string& config_name) {
|
||||
switch (type) {
|
||||
case ConfigType::GlobalConfig:
|
||||
qt_config_loc = fmt::format("{}" DIR_SEP "{}.ini", FS::GetUserPath(FS::UserPath::ConfigDir),
|
||||
config_name);
|
||||
FS::CreateFullPath(qt_config_loc);
|
||||
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
|
||||
QSettings::IniFormat);
|
||||
Reload();
|
||||
break;
|
||||
case ConfigType::PerGameConfig:
|
||||
qt_config_loc = fmt::format("{}custom" DIR_SEP "{}.ini",
|
||||
FS::GetUserPath(FS::UserPath::ConfigDir), config_name);
|
||||
FS::CreateFullPath(qt_config_loc);
|
||||
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
|
||||
QSettings::IniFormat);
|
||||
Reload();
|
||||
break;
|
||||
case ConfigType::InputProfile:
|
||||
qt_config_loc = fmt::format("{}input" DIR_SEP "{}.ini",
|
||||
FS::GetUserPath(FS::UserPath::ConfigDir), config_name);
|
||||
FS::CreateFullPath(qt_config_loc);
|
||||
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
|
||||
QSettings::IniFormat);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Config::ReadPlayerValue(std::size_t player_index) {
|
||||
const QString player_prefix = [this, player_index] {
|
||||
if (type == ConfigType::InputProfile) {
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
InputProfile,
|
||||
};
|
||||
|
||||
explicit Config(const std::string& config_loc = "qt-config",
|
||||
explicit Config(const std::string& config_name = "qt-config",
|
||||
ConfigType config_type = ConfigType::GlobalConfig);
|
||||
~Config();
|
||||
|
||||
|
@ -45,6 +45,8 @@ public:
|
|||
static const std::array<UISettings::Shortcut, 16> default_hotkeys;
|
||||
|
||||
private:
|
||||
void Initialize(const std::string& config_name);
|
||||
|
||||
void ReadValues();
|
||||
void ReadPlayerValue(std::size_t player_index);
|
||||
void ReadDebugValues();
|
||||
|
|
|
@ -50,6 +50,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
|
|||
#include <QDesktopServices>
|
||||
#include <QDesktopWidget>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
|
@ -277,6 +278,8 @@ GMainWindow::GMainWindow()
|
|||
if (args.length() >= 2) {
|
||||
BootGame(args[1]);
|
||||
}
|
||||
|
||||
MigrateConfigFiles();
|
||||
}
|
||||
|
||||
GMainWindow::~GMainWindow() {
|
||||
|
@ -1578,7 +1581,8 @@ void GMainWindow::RemoveCustomConfiguration(u64 program_id) {
|
|||
const QString config_dir =
|
||||
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir));
|
||||
const QString custom_config_file_path =
|
||||
config_dir + QString::fromStdString(fmt::format("{:016X}.ini", program_id));
|
||||
config_dir + QStringLiteral("custom") + QDir::separator() +
|
||||
QString::fromStdString(fmt::format("{:016X}.ini", program_id));
|
||||
|
||||
if (!QFile::exists(custom_config_file_path)) {
|
||||
QMessageBox::warning(this, tr("Error Removing Custom Configuration"),
|
||||
|
@ -2394,6 +2398,28 @@ void GMainWindow::OnCaptureScreenshot() {
|
|||
OnStartGame();
|
||||
}
|
||||
|
||||
// TODO: Written 2020-10-01: Remove per-game config migration code when it is irrelevant
|
||||
void GMainWindow::MigrateConfigFiles() {
|
||||
const std::string& config_dir_str = Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir);
|
||||
const QDir config_dir = QDir(QString::fromStdString(config_dir_str));
|
||||
const QStringList config_dir_list = config_dir.entryList(QStringList(QStringLiteral("*.ini")));
|
||||
|
||||
Common::FS::CreateFullPath(fmt::format("{}custom" DIR_SEP, config_dir_str));
|
||||
for (QStringList::const_iterator it = config_dir_list.constBegin(); it != config_dir_list.constEnd(); ++it) {
|
||||
const auto filename = it->toStdString();
|
||||
if (filename.find_first_not_of("0123456789abcdefACBDEF", 0) < 16) {
|
||||
continue;
|
||||
}
|
||||
const auto origin = fmt::format("{}{}", config_dir_str, filename);
|
||||
const auto destination = fmt::format("{}custom" DIR_SEP "{}", config_dir_str, filename);
|
||||
LOG_INFO(Frontend, "Migrating config file from {} to {}", origin, destination);
|
||||
if (!Common::FS::Rename(origin, destination)) {
|
||||
// Delete the old config file if one already exists in the new location.
|
||||
Common::FS::Delete(origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GMainWindow::UpdateWindowTitle(const std::string& title_name,
|
||||
const std::string& title_version) {
|
||||
const auto full_name = std::string(Common::g_build_fullname);
|
||||
|
|
|
@ -251,6 +251,7 @@ private:
|
|||
std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
|
||||
InstallResult InstallNSPXCI(const QString& filename);
|
||||
InstallResult InstallNCA(const QString& filename);
|
||||
void MigrateConfigFiles();
|
||||
void UpdateWindowTitle(const std::string& title_name = {},
|
||||
const std::string& title_version = {});
|
||||
void UpdateStatusBar();
|
||||
|
|
Loading…
Reference in a new issue