diff options
| -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 @@ | |||
| 15 | 15 | ||
| 16 | namespace FS = Common::FS; | 16 | namespace FS = Common::FS; |
| 17 | 17 | ||
| 18 | Config::Config(const std::string& config_file, ConfigType config_type) : type(config_type) { | 18 | Config::Config(const std::string& config_name, ConfigType config_type) : type(config_type) { |
| 19 | global = config_type == ConfigType::GlobalConfig; | 19 | global = config_type == ConfigType::GlobalConfig; |
| 20 | 20 | ||
| 21 | switch (config_type) { | 21 | Initialize(config_name); |
| 22 | case ConfigType::GlobalConfig: | ||
| 23 | case ConfigType::PerGameConfig: | ||
| 24 | qt_config_loc = fmt::format("{}" DIR_SEP "{}.ini", FS::GetUserPath(FS::UserPath::ConfigDir), | ||
| 25 | config_file); | ||
| 26 | FS::CreateFullPath(qt_config_loc); | ||
| 27 | qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), | ||
| 28 | QSettings::IniFormat); | ||
| 29 | Reload(); | ||
| 30 | break; | ||
| 31 | case ConfigType::InputProfile: | ||
| 32 | qt_config_loc = fmt::format("{}input" DIR_SEP "{}.ini", | ||
| 33 | FS::GetUserPath(FS::UserPath::ConfigDir), config_file); | ||
| 34 | FS::CreateFullPath(qt_config_loc); | ||
| 35 | qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), | ||
| 36 | QSettings::IniFormat); | ||
| 37 | break; | ||
| 38 | } | ||
| 39 | } | 22 | } |
| 40 | 23 | ||
| 41 | Config::~Config() { | 24 | Config::~Config() { |
| @@ -256,6 +239,34 @@ const std::array<UISettings::Shortcut, 16> Config::default_hotkeys{{ | |||
| 256 | }}; | 239 | }}; |
| 257 | // clang-format on | 240 | // clang-format on |
| 258 | 241 | ||
| 242 | void Config::Initialize(const std::string& config_name) { | ||
| 243 | switch (type) { | ||
| 244 | case ConfigType::GlobalConfig: | ||
| 245 | qt_config_loc = fmt::format("{}" DIR_SEP "{}.ini", FS::GetUserPath(FS::UserPath::ConfigDir), | ||
| 246 | config_name); | ||
| 247 | FS::CreateFullPath(qt_config_loc); | ||
| 248 | qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), | ||
| 249 | QSettings::IniFormat); | ||
| 250 | Reload(); | ||
| 251 | break; | ||
| 252 | case ConfigType::PerGameConfig: | ||
| 253 | qt_config_loc = fmt::format("{}custom" DIR_SEP "{}.ini", | ||
| 254 | FS::GetUserPath(FS::UserPath::ConfigDir), config_name); | ||
| 255 | FS::CreateFullPath(qt_config_loc); | ||
| 256 | qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), | ||
| 257 | QSettings::IniFormat); | ||
| 258 | Reload(); | ||
| 259 | break; | ||
| 260 | case ConfigType::InputProfile: | ||
| 261 | qt_config_loc = fmt::format("{}input" DIR_SEP "{}.ini", | ||
| 262 | FS::GetUserPath(FS::UserPath::ConfigDir), config_name); | ||
| 263 | FS::CreateFullPath(qt_config_loc); | ||
| 264 | qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), | ||
| 265 | QSettings::IniFormat); | ||
| 266 | break; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 259 | void Config::ReadPlayerValue(std::size_t player_index) { | 270 | void Config::ReadPlayerValue(std::size_t player_index) { |
| 260 | const QString player_prefix = [this, player_index] { | 271 | const QString player_prefix = [this, player_index] { |
| 261 | if (type == ConfigType::InputProfile) { | 272 | 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: | |||
| 22 | InputProfile, | 22 | InputProfile, |
| 23 | }; | 23 | }; |
| 24 | 24 | ||
| 25 | explicit Config(const std::string& config_loc = "qt-config", | 25 | explicit Config(const std::string& config_name = "qt-config", |
| 26 | ConfigType config_type = ConfigType::GlobalConfig); | 26 | ConfigType config_type = ConfigType::GlobalConfig); |
| 27 | ~Config(); | 27 | ~Config(); |
| 28 | 28 | ||
| @@ -45,6 +45,8 @@ public: | |||
| 45 | static const std::array<UISettings::Shortcut, 16> default_hotkeys; | 45 | static const std::array<UISettings::Shortcut, 16> default_hotkeys; |
| 46 | 46 | ||
| 47 | private: | 47 | private: |
| 48 | void Initialize(const std::string& config_name); | ||
| 49 | |||
| 48 | void ReadValues(); | 50 | void ReadValues(); |
| 49 | void ReadPlayerValue(std::size_t player_index); | 51 | void ReadPlayerValue(std::size_t player_index); |
| 50 | void ReadDebugValues(); | 52 | 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 | |||
| 50 | #include <QDesktopServices> | 50 | #include <QDesktopServices> |
| 51 | #include <QDesktopWidget> | 51 | #include <QDesktopWidget> |
| 52 | #include <QDialogButtonBox> | 52 | #include <QDialogButtonBox> |
| 53 | #include <QDir> | ||
| 53 | #include <QFile> | 54 | #include <QFile> |
| 54 | #include <QFileDialog> | 55 | #include <QFileDialog> |
| 55 | #include <QInputDialog> | 56 | #include <QInputDialog> |
| @@ -277,6 +278,8 @@ GMainWindow::GMainWindow() | |||
| 277 | if (args.length() >= 2) { | 278 | if (args.length() >= 2) { |
| 278 | BootGame(args[1]); | 279 | BootGame(args[1]); |
| 279 | } | 280 | } |
| 281 | |||
| 282 | MigrateConfigFiles(); | ||
| 280 | } | 283 | } |
| 281 | 284 | ||
| 282 | GMainWindow::~GMainWindow() { | 285 | GMainWindow::~GMainWindow() { |
| @@ -1578,7 +1581,8 @@ void GMainWindow::RemoveCustomConfiguration(u64 program_id) { | |||
| 1578 | const QString config_dir = | 1581 | const QString config_dir = |
| 1579 | QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir)); | 1582 | QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir)); |
| 1580 | const QString custom_config_file_path = | 1583 | const QString custom_config_file_path = |
| 1581 | config_dir + QString::fromStdString(fmt::format("{:016X}.ini", program_id)); | 1584 | config_dir + QStringLiteral("custom") + QDir::separator() + |
| 1585 | QString::fromStdString(fmt::format("{:016X}.ini", program_id)); | ||
| 1582 | 1586 | ||
| 1583 | if (!QFile::exists(custom_config_file_path)) { | 1587 | if (!QFile::exists(custom_config_file_path)) { |
| 1584 | QMessageBox::warning(this, tr("Error Removing Custom Configuration"), | 1588 | QMessageBox::warning(this, tr("Error Removing Custom Configuration"), |
| @@ -2394,6 +2398,28 @@ void GMainWindow::OnCaptureScreenshot() { | |||
| 2394 | OnStartGame(); | 2398 | OnStartGame(); |
| 2395 | } | 2399 | } |
| 2396 | 2400 | ||
| 2401 | // TODO: Written 2020-10-01: Remove per-game config migration code when it is irrelevant | ||
| 2402 | void GMainWindow::MigrateConfigFiles() { | ||
| 2403 | const std::string& config_dir_str = Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir); | ||
| 2404 | const QDir config_dir = QDir(QString::fromStdString(config_dir_str)); | ||
| 2405 | const QStringList config_dir_list = config_dir.entryList(QStringList(QStringLiteral("*.ini"))); | ||
| 2406 | |||
| 2407 | Common::FS::CreateFullPath(fmt::format("{}custom" DIR_SEP, config_dir_str)); | ||
| 2408 | for (QStringList::const_iterator it = config_dir_list.constBegin(); it != config_dir_list.constEnd(); ++it) { | ||
| 2409 | const auto filename = it->toStdString(); | ||
| 2410 | if (filename.find_first_not_of("0123456789abcdefACBDEF", 0) < 16) { | ||
| 2411 | continue; | ||
| 2412 | } | ||
| 2413 | const auto origin = fmt::format("{}{}", config_dir_str, filename); | ||
| 2414 | const auto destination = fmt::format("{}custom" DIR_SEP "{}", config_dir_str, filename); | ||
| 2415 | LOG_INFO(Frontend, "Migrating config file from {} to {}", origin, destination); | ||
| 2416 | if (!Common::FS::Rename(origin, destination)) { | ||
| 2417 | // Delete the old config file if one already exists in the new location. | ||
| 2418 | Common::FS::Delete(origin); | ||
| 2419 | } | ||
| 2420 | } | ||
| 2421 | } | ||
| 2422 | |||
| 2397 | void GMainWindow::UpdateWindowTitle(const std::string& title_name, | 2423 | void GMainWindow::UpdateWindowTitle(const std::string& title_name, |
| 2398 | const std::string& title_version) { | 2424 | const std::string& title_version) { |
| 2399 | const auto full_name = std::string(Common::g_build_fullname); | 2425 | 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: | |||
| 251 | std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); | 251 | std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); |
| 252 | InstallResult InstallNSPXCI(const QString& filename); | 252 | InstallResult InstallNSPXCI(const QString& filename); |
| 253 | InstallResult InstallNCA(const QString& filename); | 253 | InstallResult InstallNCA(const QString& filename); |
| 254 | void MigrateConfigFiles(); | ||
| 254 | void UpdateWindowTitle(const std::string& title_name = {}, | 255 | void UpdateWindowTitle(const std::string& title_name = {}, |
| 255 | const std::string& title_version = {}); | 256 | const std::string& title_version = {}); |
| 256 | void UpdateStatusBar(); | 257 | void UpdateStatusBar(); |