diff options
author | Morph <39850852+Morph1984@users.noreply.github.com> | 2020-09-27 20:20:22 +0200 |
---|---|---|
committer | Morph <39850852+Morph1984@users.noreply.github.com> | 2020-11-16 05:33:19 +0100 |
commit | 64e174237e7ad9ae082e24303d321534f4e78bca (patch) | |
tree | 046e228dadac9832c1fbd811757c3d0c1d344b07 | |
parent | controllers/npad: Connect a controller on init if none are connected (diff) | |
download | yuzu-64e174237e7ad9ae082e24303d321534f4e78bca.tar yuzu-64e174237e7ad9ae082e24303d321534f4e78bca.tar.gz yuzu-64e174237e7ad9ae082e24303d321534f4e78bca.tar.bz2 yuzu-64e174237e7ad9ae082e24303d321534f4e78bca.tar.lz yuzu-64e174237e7ad9ae082e24303d321534f4e78bca.tar.xz yuzu-64e174237e7ad9ae082e24303d321534f4e78bca.tar.zst yuzu-64e174237e7ad9ae082e24303d321534f4e78bca.zip |
-rw-r--r-- | src/yuzu/configuration/config.cpp | 49 | ||||
-rw-r--r-- | src/yuzu/configuration/config.h | 4 | ||||
-rw-r--r-- | src/yuzu/main.cpp | 28 | ||||
-rw-r--r-- | src/yuzu/main.h | 1 |
4 files changed, 61 insertions, 21 deletions
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 545cafca9..618f991b0 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -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) { diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index a1ffca48f..8a600e19d 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -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(); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 5f9f416ea..4a3dea2a5 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -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); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index afcfa68a9..b380a66f3 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -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(); |