FileUtil, Frontends: Fix updating custom NAND/SDMC path

This commit is contained in:
SachinVin 2022-04-30 14:45:15 +05:30
parent 1382035d4d
commit b6ff58a9d6
8 changed files with 63 additions and 39 deletions

View file

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

View file

@ -16,31 +16,33 @@ ConfigureStorage::ConfigureStorage(QWidget* parent)
SetConfiguration();
connect(ui->open_nand_dir, &QPushButton::clicked, []() {
QString path = QString::fromStdString(Settings::values.nand_dir);
QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
});
connect(ui->change_nand_dir, &QPushButton::clicked, this, [this]() {
const QString dir_path = QFileDialog::getExistingDirectory(
this, tr("Select NAND Directory"), QString::fromStdString(Settings::values.nand_dir),
this, tr("Select NAND Directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)),
QFileDialog::ShowDirsOnly);
if (!dir_path.isEmpty()) {
Settings::values.nand_dir = dir_path.toStdString();
FileUtil::UpdateUserPath(FileUtil::UserPath::NANDDir, dir_path.toStdString());
SetConfiguration();
}
});
connect(ui->open_sdmc_dir, &QPushButton::clicked, []() {
QString path = QString::fromStdString(Settings::values.sdmc_dir);
QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
});
connect(ui->change_sdmc_dir, &QPushButton::clicked, this, [this]() {
const QString dir_path = QFileDialog::getExistingDirectory(
this, tr("Select SDMC Directory"), QString::fromStdString(Settings::values.sdmc_dir),
this, tr("Select SDMC Directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)),
QFileDialog::ShowDirsOnly);
if (!dir_path.isEmpty()) {
Settings::values.sdmc_dir = dir_path.toStdString();
FileUtil::UpdateUserPath(FileUtil::UserPath::SDMCDir, dir_path.toStdString());
SetConfiguration();
}
});
@ -55,14 +57,14 @@ ConfigureStorage::~ConfigureStorage() = default;
void ConfigureStorage::SetConfiguration() {
ui->nand_group->setVisible(Settings::values.use_virtual_sd);
QString nand_path = QString::fromStdString(Settings::values.nand_dir);
QString nand_path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
ui->nand_dir_path->setText(nand_path);
ui->open_nand_dir->setEnabled(!Settings::values.nand_dir.empty());
ui->open_nand_dir->setEnabled(!nand_path.isEmpty());
ui->sdmc_group->setVisible(Settings::values.use_virtual_sd);
QString sdmc_path = QString::fromStdString(Settings::values.sdmc_dir);
QString sdmc_path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
ui->sdmc_dir_path->setText(sdmc_path);
ui->open_sdmc_dir->setEnabled(!Settings::values.sdmc_dir.empty());
ui->open_sdmc_dir->setEnabled(!sdmc_path.isEmpty());
ui->toggle_virtual_sd->setChecked(Settings::values.use_virtual_sd);

View file

@ -69,7 +69,7 @@
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>NOTE: this does not move the contents of the previous directory to the new one</string>
<string>NOTE: This does not move the contents of the previous directory to the new one.</string>
</property>
</widget>
</item>
@ -134,7 +134,7 @@
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>NOTE: this does not move the contents of the previous directory to the new one</string>
<string>NOTE: This does not move the contents of the previous directory to the new one.</string>
</property>
</widget>
</item>