2021-04-18 11:57:20 +01:00
|
|
|
// Copyright 2021 Citra Emulator Project
|
2021-04-17 14:16:48 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QUrl>
|
|
|
|
#include "citra_qt/configuration/configure_storage.h"
|
2022-12-08 11:27:25 +00:00
|
|
|
#include "common/settings.h"
|
2021-04-17 14:16:48 +01:00
|
|
|
#include "core/core.h"
|
|
|
|
#include "ui_configure_storage.h"
|
|
|
|
|
|
|
|
ConfigureStorage::ConfigureStorage(QWidget* parent)
|
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::ConfigureStorage>()) {
|
|
|
|
ui->setupUi(this);
|
|
|
|
SetConfiguration();
|
|
|
|
|
|
|
|
connect(ui->open_nand_dir, &QPushButton::clicked, []() {
|
2022-04-30 10:15:15 +01:00
|
|
|
QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
|
2021-04-17 14:16:48 +01:00
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->change_nand_dir, &QPushButton::clicked, this, [this]() {
|
|
|
|
const QString dir_path = QFileDialog::getExistingDirectory(
|
2022-04-30 10:15:15 +01:00
|
|
|
this, tr("Select NAND Directory"),
|
|
|
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)),
|
2021-04-17 14:16:48 +01:00
|
|
|
QFileDialog::ShowDirsOnly);
|
|
|
|
if (!dir_path.isEmpty()) {
|
2022-04-30 10:15:15 +01:00
|
|
|
FileUtil::UpdateUserPath(FileUtil::UserPath::NANDDir, dir_path.toStdString());
|
2021-04-17 14:16:48 +01:00
|
|
|
SetConfiguration();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->open_sdmc_dir, &QPushButton::clicked, []() {
|
2022-04-30 10:15:15 +01:00
|
|
|
QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
|
2021-04-17 14:16:48 +01:00
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->change_sdmc_dir, &QPushButton::clicked, this, [this]() {
|
|
|
|
const QString dir_path = QFileDialog::getExistingDirectory(
|
2022-04-30 10:15:15 +01:00
|
|
|
this, tr("Select SDMC Directory"),
|
|
|
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)),
|
2021-04-17 14:16:48 +01:00
|
|
|
QFileDialog::ShowDirsOnly);
|
|
|
|
if (!dir_path.isEmpty()) {
|
2022-04-30 10:15:15 +01:00
|
|
|
FileUtil::UpdateUserPath(FileUtil::UserPath::SDMCDir, dir_path.toStdString());
|
2021-04-17 14:16:48 +01:00
|
|
|
SetConfiguration();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(ui->toggle_virtual_sd, &QCheckBox::clicked, this, [this]() {
|
|
|
|
ApplyConfiguration();
|
|
|
|
SetConfiguration();
|
|
|
|
});
|
2022-10-22 14:39:47 +01:00
|
|
|
connect(ui->toggle_custom_storage, &QCheckBox::clicked, this, [this]() {
|
|
|
|
ApplyConfiguration();
|
|
|
|
SetConfiguration();
|
|
|
|
});
|
2021-04-17 14:16:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ConfigureStorage::~ConfigureStorage() = default;
|
|
|
|
|
|
|
|
void ConfigureStorage::SetConfiguration() {
|
2022-12-08 11:27:25 +00:00
|
|
|
ui->nand_group->setVisible(Settings::values.use_custom_storage.GetValue());
|
2022-04-30 10:15:15 +01:00
|
|
|
QString nand_path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
|
2021-04-17 14:16:48 +01:00
|
|
|
ui->nand_dir_path->setText(nand_path);
|
2022-04-30 10:15:15 +01:00
|
|
|
ui->open_nand_dir->setEnabled(!nand_path.isEmpty());
|
2021-04-17 14:16:48 +01:00
|
|
|
|
2022-10-22 14:39:47 +01:00
|
|
|
ui->sdmc_group->setVisible(Settings::values.use_virtual_sd &&
|
|
|
|
Settings::values.use_custom_storage);
|
2022-04-30 10:15:15 +01:00
|
|
|
QString sdmc_path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
|
2021-04-17 14:16:48 +01:00
|
|
|
ui->sdmc_dir_path->setText(sdmc_path);
|
2022-04-30 10:15:15 +01:00
|
|
|
ui->open_sdmc_dir->setEnabled(!sdmc_path.isEmpty());
|
2021-04-17 14:16:48 +01:00
|
|
|
|
2022-12-08 11:27:25 +00:00
|
|
|
ui->toggle_virtual_sd->setChecked(Settings::values.use_virtual_sd.GetValue());
|
|
|
|
ui->toggle_custom_storage->setChecked(Settings::values.use_custom_storage.GetValue());
|
2021-04-17 14:16:48 +01:00
|
|
|
|
|
|
|
ui->storage_group->setEnabled(!Core::System::GetInstance().IsPoweredOn());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureStorage::ApplyConfiguration() {
|
|
|
|
Settings::values.use_virtual_sd = ui->toggle_virtual_sd->isChecked();
|
2022-10-22 14:39:47 +01:00
|
|
|
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));
|
|
|
|
}
|
2021-04-17 14:16:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigureStorage::RetranslateUI() {
|
|
|
|
ui->retranslateUi(this);
|
2021-04-18 11:57:20 +01:00
|
|
|
}
|