From 21db20d0413bdf2277d129fde9ced10931744cd7 Mon Sep 17 00:00:00 2001 From: Nicholas Keane Date: Thu, 17 Jun 2021 13:14:40 -0400 Subject: [PATCH] add capability to change load and shaders directories in Citra filesystem --- src/citra/config.cpp | 4 + src/citra/default_ini.h | 8 + src/citra_qt/configuration/config.cpp | 17 +- .../configuration/configure_storage.cpp | 40 +++++ .../configuration/configure_storage.ui | 150 ++++++++++++++++-- src/common/file_util.cpp | 8 +- src/core/settings.cpp | 2 + src/core/settings.h | 2 + 8 files changed, 218 insertions(+), 13 deletions(-) diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 6f747fcf5..c5ad94f6c 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -201,10 +201,14 @@ void Config::ReadValues() { // Data Storage Settings::values.use_virtual_sd = sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true); + Settings::values.load_dir = sdl2_config->GetString( + "Data Storage", "load_directory", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)); Settings::values.nand_dir = sdl2_config->GetString( "Data Storage", "nand_directory", FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)); Settings::values.sdmc_dir = sdl2_config->GetString( "Data Storage", "sdmc_directory", FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)); + Settings::values.shaders_dir = sdl2_config->GetString( + "Data Storage", "shaders_directory", FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)); // System Settings::values.is_new_3ds = sdl2_config->GetBoolean("System", "is_new_3ds", true); diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index 55d8da8f5..51d9556ca 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h @@ -250,6 +250,10 @@ volume = # 1 (default): Yes, 0: No use_virtual_sd = +# The path of the Load directory (for mods and textures). +# empty (default) will use the user_path +load_directory = + # The path of the virtual SD card directory. # empty (default) will use the user_path sdmc_directory = @@ -258,6 +262,10 @@ sdmc_directory = # empty (default) will use the user_path nand_directory = +# The path of the Shaders directory. +# empty (default) will use the user_path +shaders_directory = + [System] # The system model that Citra will try to emulate # 0: Old 3DS, 1: New 3DS (default) diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 28612bbd0..de9511298 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -302,6 +302,11 @@ void Config::ReadDataStorageValues() { qt_config->beginGroup(QStringLiteral("Data Storage")); Settings::values.use_virtual_sd = ReadSetting(QStringLiteral("use_virtual_sd"), true).toBool(); + std::string load_dir = FileUtil::GetUserPath(FileUtil::UserPath::LoadDir); + Settings::values.load_dir = + ReadSetting(QStringLiteral("load_directory"), QString::fromStdString(load_dir)) + .toString() + .toStdString(); std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); Settings::values.nand_dir = ReadSetting(QStringLiteral("nand_directory"), QString::fromStdString(nand_dir)) @@ -312,6 +317,11 @@ void Config::ReadDataStorageValues() { ReadSetting(QStringLiteral("sdmc_directory"), QString::fromStdString(sdmc_dir)) .toString() .toStdString(); + std::string shader_dir = FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir); + Settings::values.shaders_dir = + ReadSetting(QStringLiteral("shaders_directory"), QString::fromStdString(shader_dir)) + .toString() + .toStdString(); qt_config->endGroup(); } @@ -862,13 +872,18 @@ void Config::SaveDataStorageValues() { qt_config->beginGroup(QStringLiteral("Data Storage")); WriteSetting(QStringLiteral("use_virtual_sd"), Settings::values.use_virtual_sd, true); + WriteSetting(QStringLiteral("load_directory"), + QString::fromStdString(Settings::values.load_dir), + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir))); WriteSetting(QStringLiteral("nand_directory"), QString::fromStdString(Settings::values.nand_dir), QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir))); WriteSetting(QStringLiteral("sdmc_directory"), QString::fromStdString(Settings::values.sdmc_dir), QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir))); - + WriteSetting(QStringLiteral("shaders_directory"), + QString::fromStdString(Settings::values.shaders_dir), + QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir))); qt_config->endGroup(); } diff --git a/src/citra_qt/configuration/configure_storage.cpp b/src/citra_qt/configuration/configure_storage.cpp index 62e299a90..c36066a2d 100644 --- a/src/citra_qt/configuration/configure_storage.cpp +++ b/src/citra_qt/configuration/configure_storage.cpp @@ -15,6 +15,21 @@ ConfigureStorage::ConfigureStorage(QWidget* parent) ui->setupUi(this); SetConfiguration(); + connect(ui->open_load_dir, &QPushButton::clicked, []() { + QString path = QString::fromStdString(Settings::values.load_dir); + QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + }); + + connect(ui->change_load_dir, &QPushButton::clicked, this, [this]() { + const QString dir_path = QFileDialog::getExistingDirectory( + this, tr("Select Load Directory"), QString::fromStdString(Settings::values.load_dir), + QFileDialog::ShowDirsOnly); + if (!dir_path.isEmpty()) { + Settings::values.load_dir = dir_path.toStdString(); + SetConfiguration(); + } + }); + connect(ui->open_nand_dir, &QPushButton::clicked, []() { QString path = QString::fromStdString(Settings::values.nand_dir); QDesktopServices::openUrl(QUrl::fromLocalFile(path)); @@ -45,6 +60,21 @@ ConfigureStorage::ConfigureStorage(QWidget* parent) } }); + connect(ui->open_shaders_dir, &QPushButton::clicked, []() { + QString path = QString::fromStdString(Settings::values.shaders_dir); + QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + }); + + connect(ui->change_shaders_dir, &QPushButton::clicked, this, [this]() { + const QString dir_path = QFileDialog::getExistingDirectory( + this, tr("Select Shaders Directory"), QString::fromStdString(Settings::values.shaders_dir), + QFileDialog::ShowDirsOnly); + if (!dir_path.isEmpty()) { + Settings::values.shaders_dir = dir_path.toStdString(); + SetConfiguration(); + } + }); + connect(ui->toggle_virtual_sd, &QCheckBox::clicked, this, [this]() { ApplyConfiguration(); SetConfiguration(); @@ -54,6 +84,11 @@ ConfigureStorage::ConfigureStorage(QWidget* parent) ConfigureStorage::~ConfigureStorage() = default; void ConfigureStorage::SetConfiguration() { + ui->load_group->setVisible(Settings::values.use_virtual_sd); + QString load_path = QString::fromStdString(Settings::values.load_dir); + ui->load_dir_path->setText(load_path); + ui->open_load_dir->setEnabled(!Settings::values.load_path.empty()); + ui->nand_group->setVisible(Settings::values.use_virtual_sd); QString nand_path = QString::fromStdString(Settings::values.nand_dir); ui->nand_dir_path->setText(nand_path); @@ -64,6 +99,11 @@ void ConfigureStorage::SetConfiguration() { ui->sdmc_dir_path->setText(sdmc_path); ui->open_sdmc_dir->setEnabled(!Settings::values.sdmc_dir.empty()); + ui->shaders_group->setVisible(Settings::values.use_virtual_sd); + QString shaders_path = QString::fromStdString(Settings::values.shaders_dir); + ui->shaders_dir_path->setText(shaders_path); + ui->open_shaders_dir->setEnabled(!Settings::values.shaders_path.empty()); + ui->toggle_virtual_sd->setChecked(Settings::values.use_virtual_sd); ui->storage_group->setEnabled(!Core::System::GetInstance().IsPoweredOn()); diff --git a/src/citra_qt/configuration/configure_storage.ui b/src/citra_qt/configuration/configure_storage.ui index c6f72dd5d..cb29a7956 100644 --- a/src/citra_qt/configuration/configure_storage.ui +++ b/src/citra_qt/configuration/configure_storage.ui @@ -7,7 +7,7 @@ 0 0 681 - 375 + 431 @@ -34,7 +34,7 @@ - + @@ -44,19 +44,19 @@ - NAND Directory + Load Directory - + false - + Open @@ -86,6 +86,71 @@ + + + + Change + + + + + + + + + + + + + + + + + + + + NAND Directory + + + + + + + false + + + + + + + Open + + + + + + + + + + + NOTE: this does not move the contents of the previous directory to the new one + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -103,11 +168,11 @@ - + - + - + SDMC Directory @@ -132,14 +197,14 @@ - + NOTE: this does not move the contents of the previous directory to the new one - + Qt::Horizontal @@ -163,6 +228,71 @@ + + + + + + + + + + + + Shaders Directory + + + + + + + false + + + + + + + Open + + + + + + + + + + + NOTE: this does not move the contents of the previous directory to the new one + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Change + + + + + + + + diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index b7576c208..2a71fb099 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -729,9 +729,13 @@ void SetUserPath(const std::string& path) { g_paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP); g_paths.emplace(UserPath::CheatsDir, user_path + CHEATS_DIR DIR_SEP); g_paths.emplace(UserPath::DLLDir, user_path + DLL_DIR DIR_SEP); - g_paths.emplace(UserPath::ShaderDir, user_path + SHADER_DIR DIR_SEP); + g_paths.emplace(UserPath::ShaderDir, !Settings::values.shaders_dir.empty() + ? Settings::values.shaders_dir + : user_path + SHADER_DIR DIR_SEP); g_paths.emplace(UserPath::DumpDir, user_path + DUMP_DIR DIR_SEP); - g_paths.emplace(UserPath::LoadDir, user_path + LOAD_DIR DIR_SEP); + g_paths.emplace(UserPath::LoadDir, !Settings::values.load_dir.empty() + ? Settings::values.load_dir + : user_path + LOAD_DIR DIR_SEP); g_paths.emplace(UserPath::StatesDir, user_path + STATES_DIR DIR_SEP); } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 855307ba5..ca44ce938 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -118,8 +118,10 @@ void LogSettings() { log_setting("Camera_OuterLeftConfig", values.camera_config[OuterLeftCamera]); log_setting("Camera_OuterLeftFlip", values.camera_flip[OuterLeftCamera]); log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd); + log_setting("DataStorage_LoadDir", values.load_dir); log_setting("DataStorage_SdmcDir", values.sdmc_dir); log_setting("DataStorage_NandDir", values.nand_dir); + log_setting("DataStorage_ShadersDir", values.shaders_dir); log_setting("System_IsNew3ds", values.is_new_3ds); log_setting("System_RegionValue", values.region_value); log_setting("Debugging_UseGdbstub", values.use_gdbstub); diff --git a/src/core/settings.h b/src/core/settings.h index af41b9a02..935153d61 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -140,8 +140,10 @@ struct Values { // Data Storage bool use_virtual_sd; + std::string load_dir; std::string nand_dir; std::string sdmc_dir; + std::string shaders_dir; // System int region_value;