common/fileutil: Convert namespace to Common::FS

Migrates a remaining common file over to the Common namespace, making it
consistent with the rest of common files.

This also allows for high-traffic FS related code to alias the
filesystem function namespace as

namespace FS = Common::FS;

for more concise typing.
This commit is contained in:
Lioncash
2020-08-15 08:33:16 -04:00
parent db96034ea4
commit c4ed791164
40 changed files with 639 additions and 547 deletions

View File

@ -13,10 +13,12 @@
#include "input_common/udp/client.h"
#include "yuzu/configuration/config.h"
namespace FS = Common::FS;
Config::Config(const std::string& config_file, bool is_global) {
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
qt_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + config_file;
FileUtil::CreateFullPath(qt_config_loc);
qt_config_loc = FS::GetUserPath(FS::UserPath::ConfigDir) + config_file;
FS::CreateFullPath(qt_config_loc);
qt_config =
std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
global = is_global;
@ -464,41 +466,36 @@ void Config::ReadDataStorageValues() {
qt_config->beginGroup(QStringLiteral("Data Storage"));
Settings::values.use_virtual_sd = ReadSetting(QStringLiteral("use_virtual_sd"), true).toBool();
FileUtil::GetUserPath(
FileUtil::UserPath::NANDDir,
qt_config
->value(QStringLiteral("nand_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)))
.toString()
.toStdString());
FileUtil::GetUserPath(
FileUtil::UserPath::SDMCDir,
qt_config
->value(QStringLiteral("sdmc_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)))
.toString()
.toStdString());
FileUtil::GetUserPath(
FileUtil::UserPath::LoadDir,
qt_config
->value(QStringLiteral("load_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)))
.toString()
.toStdString());
FileUtil::GetUserPath(
FileUtil::UserPath::DumpDir,
qt_config
->value(QStringLiteral("dump_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::DumpDir)))
.toString()
.toStdString());
FileUtil::GetUserPath(
FileUtil::UserPath::CacheDir,
qt_config
->value(QStringLiteral("cache_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir)))
.toString()
.toStdString());
FS::GetUserPath(FS::UserPath::NANDDir,
qt_config
->value(QStringLiteral("nand_directory"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::NANDDir)))
.toString()
.toStdString());
FS::GetUserPath(FS::UserPath::SDMCDir,
qt_config
->value(QStringLiteral("sdmc_directory"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::SDMCDir)))
.toString()
.toStdString());
FS::GetUserPath(FS::UserPath::LoadDir,
qt_config
->value(QStringLiteral("load_directory"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::LoadDir)))
.toString()
.toStdString());
FS::GetUserPath(FS::UserPath::DumpDir,
qt_config
->value(QStringLiteral("dump_directory"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir)))
.toString()
.toStdString());
FS::GetUserPath(FS::UserPath::CacheDir,
qt_config
->value(QStringLiteral("cache_directory"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::CacheDir)))
.toString()
.toStdString());
Settings::values.gamecard_inserted =
ReadSetting(QStringLiteral("gamecard_inserted"), false).toBool();
Settings::values.gamecard_current_game =
@ -677,11 +674,11 @@ void Config::ReadScreenshotValues() {
UISettings::values.enable_screenshot_save_as =
ReadSetting(QStringLiteral("enable_screenshot_save_as"), true).toBool();
FileUtil::GetUserPath(
FileUtil::UserPath::ScreenshotsDir,
FS::GetUserPath(
FS::UserPath::ScreenshotsDir,
qt_config
->value(QStringLiteral("screenshot_path"), QString::fromStdString(FileUtil::GetUserPath(
FileUtil::UserPath::ScreenshotsDir)))
->value(QStringLiteral("screenshot_path"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::ScreenshotsDir)))
.toString()
.toStdString());
@ -1016,20 +1013,20 @@ void Config::SaveDataStorageValues() {
WriteSetting(QStringLiteral("use_virtual_sd"), Settings::values.use_virtual_sd, true);
WriteSetting(QStringLiteral("nand_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)));
QString::fromStdString(FS::GetUserPath(FS::UserPath::NANDDir)),
QString::fromStdString(FS::GetUserPath(FS::UserPath::NANDDir)));
WriteSetting(QStringLiteral("sdmc_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)));
QString::fromStdString(FS::GetUserPath(FS::UserPath::SDMCDir)),
QString::fromStdString(FS::GetUserPath(FS::UserPath::SDMCDir)));
WriteSetting(QStringLiteral("load_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)));
QString::fromStdString(FS::GetUserPath(FS::UserPath::LoadDir)),
QString::fromStdString(FS::GetUserPath(FS::UserPath::LoadDir)));
WriteSetting(QStringLiteral("dump_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::DumpDir)),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::DumpDir)));
QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir)),
QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir)));
WriteSetting(QStringLiteral("cache_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir)),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir)));
QString::fromStdString(FS::GetUserPath(FS::UserPath::CacheDir)),
QString::fromStdString(FS::GetUserPath(FS::UserPath::CacheDir)));
WriteSetting(QStringLiteral("gamecard_inserted"), Settings::values.gamecard_inserted, false);
WriteSetting(QStringLiteral("gamecard_current_game"), Settings::values.gamecard_current_game,
false);
@ -1180,7 +1177,7 @@ void Config::SaveScreenshotValues() {
WriteSetting(QStringLiteral("enable_screenshot_save_as"),
UISettings::values.enable_screenshot_save_as);
WriteSetting(QStringLiteral("screenshot_path"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir)));
QString::fromStdString(FS::GetUserPath(FS::UserPath::ScreenshotsDir)));
qt_config->endGroup();
}

View File

@ -19,7 +19,8 @@ ConfigureDebug::ConfigureDebug(QWidget* parent) : QWidget(parent), ui(new Ui::Co
SetConfiguration();
connect(ui->open_log_button, &QPushButton::clicked, []() {
QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LogDir));
const auto path =
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::LogDir));
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
});
}

View File

@ -42,16 +42,16 @@ ConfigureFilesystem::~ConfigureFilesystem() = default;
void ConfigureFilesystem::setConfiguration() {
ui->nand_directory_edit->setText(
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)));
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir)));
ui->sdmc_directory_edit->setText(
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)));
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir)));
ui->gamecard_path_edit->setText(QString::fromStdString(Settings::values.gamecard_path));
ui->dump_path_edit->setText(
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::DumpDir)));
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::DumpDir)));
ui->load_path_edit->setText(
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LoadDir)));
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::LoadDir)));
ui->cache_directory_edit->setText(
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir)));
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)));
ui->gamecard_inserted->setChecked(Settings::values.gamecard_inserted);
ui->gamecard_current_game->setChecked(Settings::values.gamecard_current_game);
@ -64,14 +64,16 @@ void ConfigureFilesystem::setConfiguration() {
}
void ConfigureFilesystem::applyConfiguration() {
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir,
ui->nand_directory_edit->text().toStdString());
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir,
ui->sdmc_directory_edit->text().toStdString());
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir, ui->dump_path_edit->text().toStdString());
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir, ui->load_path_edit->text().toStdString());
FileUtil::GetUserPath(FileUtil::UserPath::CacheDir,
ui->cache_directory_edit->text().toStdString());
Common::FS::GetUserPath(Common::FS::UserPath::NANDDir,
ui->nand_directory_edit->text().toStdString());
Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir,
ui->sdmc_directory_edit->text().toStdString());
Common::FS::GetUserPath(Common::FS::UserPath::DumpDir,
ui->dump_path_edit->text().toStdString());
Common::FS::GetUserPath(Common::FS::UserPath::LoadDir,
ui->load_path_edit->text().toStdString());
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir,
ui->cache_directory_edit->text().toStdString());
Settings::values.gamecard_path = ui->gamecard_path_edit->text().toStdString();
Settings::values.gamecard_inserted = ui->gamecard_inserted->isChecked();
@ -121,12 +123,13 @@ void ConfigureFilesystem::SetDirectory(DirectoryTarget target, QLineEdit* edit)
}
void ConfigureFilesystem::ResetMetadata() {
if (!FileUtil::Exists(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP +
"game_list")) {
if (!Common::FS::Exists(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
"game_list")) {
QMessageBox::information(this, tr("Reset Metadata Cache"),
tr("The metadata cache is already empty."));
} else if (FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) +
DIR_SEP + "game_list")) {
} else if (Common::FS::DeleteDirRecursively(
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
"game_list")) {
QMessageBox::information(this, tr("Reset Metadata Cache"),
tr("The operation completed successfully."));
UISettings::values.is_game_list_reload_pending.exchange(true);

View File

@ -79,8 +79,8 @@ void ConfigurePerGameAddons::ApplyConfiguration() {
std::sort(disabled_addons.begin(), disabled_addons.end());
std::sort(current.begin(), current.end());
if (disabled_addons != current) {
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP +
"game_list" + DIR_SEP + fmt::format("{:016X}.pv.txt", title_id));
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
"game_list" + DIR_SEP + fmt::format("{:016X}.pv.txt", title_id));
}
Settings::values.disabled_addons[title_id] = disabled_addons;

View File

@ -34,7 +34,7 @@ constexpr std::array<u8, 107> backup_jpeg{
};
QString GetImagePath(Common::UUID uuid) {
const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
const auto path = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
return QString::fromStdString(path);
}
@ -282,7 +282,7 @@ void ConfigureProfileManager::SetUserImage() {
}
const auto raw_path = QString::fromStdString(
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010");
Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) + "/system/save/8000000000000010");
const QFileInfo raw_info{raw_path};
if (raw_info.exists() && !raw_info.isDir() && !QFile::remove(raw_path)) {
QMessageBox::warning(this, tr("Error deleting file"),

View File

@ -61,9 +61,9 @@ ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::Configur
// Set screenshot path to user specification.
connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] {
const QString& filename =
QFileDialog::getExistingDirectory(
this, tr("Select Screenshots Path..."),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))) +
QFileDialog::getExistingDirectory(this, tr("Select Screenshots Path..."),
QString::fromStdString(Common::FS::GetUserPath(
Common::FS::UserPath::ScreenshotsDir))) +
QDir::separator();
if (!filename.isEmpty()) {
ui->screenshot_path_edit->setText(filename);
@ -82,8 +82,8 @@ void ConfigureUi::ApplyConfiguration() {
UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt();
UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir,
ui->screenshot_path_edit->text().toStdString());
Common::FS::GetUserPath(Common::FS::UserPath::ScreenshotsDir,
ui->screenshot_path_edit->text().toStdString());
Settings::Apply();
}
@ -101,7 +101,7 @@ void ConfigureUi::SetConfiguration() {
ui->enable_screenshot_save_as->setChecked(UISettings::values.enable_screenshot_save_as);
ui->screenshot_path_edit->setText(
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir)));
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ScreenshotsDir)));
}
void ConfigureUi::changeEvent(QEvent* event) {