1
0
Fork 0

Gate use of custom directories behind a variable (#6157)

previous changes had forced every single user to use custom
directories for NAND and SDMC. Those paths were saved to the
config file and would interact badly with portable builds.
This commit is contained in:
Vitor K 2022-10-22 10:39:47 -03:00 committed by GitHub
parent 67c4b87184
commit 9626bdf385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 183 additions and 144 deletions

View File

@ -203,14 +203,15 @@ void Config::ReadValues() {
Settings::values.use_virtual_sd =
sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true);
const std::string default_nand_dir = FileUtil::GetDefaultUserPath(FileUtil::UserPath::NANDDir);
FileUtil::UpdateUserPath(
FileUtil::UserPath::NANDDir,
sdl2_config->GetString("Data Storage", "nand_directory", default_nand_dir));
const std::string default_sdmc_dir = FileUtil::GetDefaultUserPath(FileUtil::UserPath::SDMCDir);
FileUtil::UpdateUserPath(
FileUtil::UserPath::SDMCDir,
sdl2_config->GetString("Data Storage", "sdmc_directory", default_sdmc_dir));
Settings::values.use_custom_storage =
sdl2_config->GetBoolean("Data Storage", "use_custom_storage", false);
if (Settings::values.use_custom_storage) {
FileUtil::UpdateUserPath(FileUtil::UserPath::NANDDir,
sdl2_config->GetString("Data Storage", "nand_directory", ""));
FileUtil::UpdateUserPath(FileUtil::UserPath::SDMCDir,
sdl2_config->GetString("Data Storage", "sdmc_directory", ""));
}
// System
Settings::values.is_new_3ds = sdl2_config->GetBoolean("System", "is_new_3ds", true);

View File

@ -250,6 +250,10 @@ volume =
# 1 (default): Yes, 0: No
use_virtual_sd =
# Whether to use custom storage locations
# 1: Yes, 0 (default): No
use_custom_storage =
# The path of the virtual SD card directory.
# empty (default) will use the user_path
sdmc_directory =

View File

@ -304,21 +304,17 @@ void Config::ReadDataStorageValues() {
Settings::values.use_virtual_sd = ReadSetting(QStringLiteral("use_virtual_sd"), true).toBool();
Settings::values.use_custom_storage =
ReadSetting(QStringLiteral("use_custom_storage"), false).toBool();
const std::string nand_dir =
ReadSetting(
QStringLiteral("nand_directory"),
QString::fromStdString(FileUtil::GetDefaultUserPath(FileUtil::UserPath::NANDDir)))
.toString()
.toStdString();
ReadSetting(QStringLiteral("nand_directory"), QStringLiteral("")).toString().toStdString();
const std::string sdmc_dir =
ReadSetting(
QStringLiteral("sdmc_directory"),
QString::fromStdString(FileUtil::GetDefaultUserPath(FileUtil::UserPath::SDMCDir)))
.toString()
.toStdString();
ReadSetting(QStringLiteral("sdmc_directory"), QStringLiteral("")).toString().toStdString();
if (Settings::values.use_custom_storage) {
FileUtil::UpdateUserPath(FileUtil::UserPath::NANDDir, nand_dir);
FileUtil::UpdateUserPath(FileUtil::UserPath::SDMCDir, sdmc_dir);
}
qt_config->endGroup();
}
@ -869,12 +865,13 @@ void Config::SaveDataStorageValues() {
qt_config->beginGroup(QStringLiteral("Data Storage"));
WriteSetting(QStringLiteral("use_virtual_sd"), Settings::values.use_virtual_sd, true);
WriteSetting(QStringLiteral("use_custom_storage"), Settings::values.use_custom_storage, false);
WriteSetting(QStringLiteral("nand_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)),
QString::fromStdString(FileUtil::GetDefaultUserPath(FileUtil::UserPath::NANDDir)));
QStringLiteral(""));
WriteSetting(QStringLiteral("sdmc_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)),
QString::fromStdString(FileUtil::GetDefaultUserPath(FileUtil::UserPath::SDMCDir)));
QStringLiteral(""));
qt_config->endGroup();
}

View File

@ -51,28 +51,42 @@ ConfigureStorage::ConfigureStorage(QWidget* parent)
ApplyConfiguration();
SetConfiguration();
});
connect(ui->toggle_custom_storage, &QCheckBox::clicked, this, [this]() {
ApplyConfiguration();
SetConfiguration();
});
}
ConfigureStorage::~ConfigureStorage() = default;
void ConfigureStorage::SetConfiguration() {
ui->nand_group->setVisible(Settings::values.use_virtual_sd);
ui->nand_group->setVisible(Settings::values.use_custom_storage);
QString nand_path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
ui->nand_dir_path->setText(nand_path);
ui->open_nand_dir->setEnabled(!nand_path.isEmpty());
ui->sdmc_group->setVisible(Settings::values.use_virtual_sd);
ui->sdmc_group->setVisible(Settings::values.use_virtual_sd &&
Settings::values.use_custom_storage);
QString sdmc_path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
ui->sdmc_dir_path->setText(sdmc_path);
ui->open_sdmc_dir->setEnabled(!sdmc_path.isEmpty());
ui->toggle_virtual_sd->setChecked(Settings::values.use_virtual_sd);
ui->toggle_custom_storage->setChecked(Settings::values.use_custom_storage);
ui->storage_group->setEnabled(!Core::System::GetInstance().IsPoweredOn());
}
void ConfigureStorage::ApplyConfiguration() {
Settings::values.use_virtual_sd = ui->toggle_virtual_sd->isChecked();
Settings::values.use_custom_storage = ui->toggle_custom_storage->isChecked();
if (!Settings::values.use_custom_storage) {
FileUtil::UpdateUserPath(FileUtil::UserPath::NANDDir,
GetDefaultUserPath(FileUtil::UserPath::NANDDir));
FileUtil::UpdateUserPath(FileUtil::UserPath::SDMCDir,
GetDefaultUserPath(FileUtil::UserPath::SDMCDir));
}
}
void ConfigureStorage::RetranslateUI() {

View File

@ -33,6 +33,19 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="custom_storage_group">
<property name="title">
<string>Custom Storage</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QCheckBox" name="toggle_custom_storage">
<property name="text">
<string>Use Custom Storage</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="nand_group">
<property name="title">
@ -167,6 +180,9 @@
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">

View File

@ -774,6 +774,9 @@ const std::string& GetDefaultUserPath(UserPath path) {
}
const void UpdateUserPath(UserPath path, const std::string& filename) {
if (filename.empty()) {
return;
}
if (!FileUtil::IsDirectory(filename)) {
LOG_ERROR(Common_Filesystem, "Path is not a directory. UserPath: {} filename: {}", path,
filename);

View File

@ -120,8 +120,11 @@ 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_UseCustomStorage", values.use_custom_storage);
if (values.use_custom_storage) {
log_setting("DataStorage_SdmcDir", FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
log_setting("DataStorage_NandDir", FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
}
log_setting("System_IsNew3ds", values.is_new_3ds);
log_setting("System_RegionValue", values.region_value);
log_setting("Debugging_UseGdbstub", values.use_gdbstub);

View File

@ -155,6 +155,7 @@ struct Values {
// Data Storage
bool use_virtual_sd;
bool use_custom_storage;
// System
int region_value;