common: fs: Rework the Common Filesystem interface to make use of std::filesystem (#6270)

* common: fs: fs_types: Create filesystem types

Contains various filesystem types used by the Common::FS library

* common: fs: fs_util: Add std::string to std::u8string conversion utility

* common: fs: path_util: Add utlity functions for paths

Contains various utility functions for getting or manipulating filesystem paths used by the Common::FS library

* common: fs: file: Rewrite the IOFile implementation

* common: fs: Reimplement Common::FS library using std::filesystem

* common: fs: fs_paths: Add fs_paths to replace common_paths

* common: fs: path_util: Add the rest of the path functions

* common: Remove the previous Common::FS implementation

* general: Remove unused fs includes

* string_util: Remove unused function and include

* nvidia_flags: Migrate to the new Common::FS library

* settings: Migrate to the new Common::FS library

* logging: backend: Migrate to the new Common::FS library

* core: Migrate to the new Common::FS library

* perf_stats: Migrate to the new Common::FS library

* reporter: Migrate to the new Common::FS library

* telemetry_session: Migrate to the new Common::FS library

* key_manager: Migrate to the new Common::FS library

* bis_factory: Migrate to the new Common::FS library

* registered_cache: Migrate to the new Common::FS library

* xts_archive: Migrate to the new Common::FS library

* service: acc: Migrate to the new Common::FS library

* applets/profile: Migrate to the new Common::FS library

* applets/web: Migrate to the new Common::FS library

* service: filesystem: Migrate to the new Common::FS library

* loader: Migrate to the new Common::FS library

* gl_shader_disk_cache: Migrate to the new Common::FS library

* nsight_aftermath_tracker: Migrate to the new Common::FS library

* vulkan_library: Migrate to the new Common::FS library

* configure_debug: Migrate to the new Common::FS library

* game_list_worker: Migrate to the new Common::FS library

* config: Migrate to the new Common::FS library

* configure_filesystem: Migrate to the new Common::FS library

* configure_per_game_addons: Migrate to the new Common::FS library

* configure_profile_manager: Migrate to the new Common::FS library

* configure_ui: Migrate to the new Common::FS library

* input_profiles: Migrate to the new Common::FS library

* yuzu_cmd: config: Migrate to the new Common::FS library

* yuzu_cmd: Migrate to the new Common::FS library

* vfs_real: Migrate to the new Common::FS library

* vfs: Migrate to the new Common::FS library

* vfs_libzip: Migrate to the new Common::FS library

* service: bcat: Migrate to the new Common::FS library

* yuzu: main: Migrate to the new Common::FS library

* vfs_real: Delete the contents of an existing file in CreateFile

Current usages of CreateFile expect to delete the contents of an existing file, retain this behavior for now.

* input_profiles: Don't iterate the input profile dir if it does not exist

Silences an error produced in the log if the directory does not exist.

* game_list_worker: Skip parsing file if the returned VfsFile is nullptr

Prevents crashes in GetLoader when the virtual file is nullptr

* common: fs: Validate paths for path length

* service: filesystem: Open the mod load directory as read only
This commit is contained in:
Morph
2021-05-25 19:32:56 -04:00
committed by GitHub
parent 08a5cf0b5b
commit 065867e2c2
74 changed files with 3785 additions and 2169 deletions

View File

@ -10,7 +10,7 @@
#include <QScrollArea>
#include <QStandardItemModel>
#include <QVBoxLayout>
#include "common/file_util.h"
#include "common/fs/path_util.h"
#include "common/string_util.h"
#include "core/constants.h"
#include "core/hle/lock.h"
@ -26,9 +26,10 @@ QString FormatUserEntryText(const QString& username, Common::UUID uuid) {
}
QString GetImagePath(Common::UUID uuid) {
const auto path = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
return QString::fromStdString(path);
const auto path =
Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) /
fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormatSwitch());
return QString::fromStdString(Common::FS::PathToUTF8String(path));
}
QPixmap GetIcon(Common::UUID uuid) {

View File

@ -12,7 +12,7 @@
#include <QWebEngineUrlScheme>
#endif
#include "common/file_util.h"
#include "common/fs/path_util.h"
#include "core/core.h"
#include "core/frontend/input_interpreter.h"
#include "input_common/keyboard.h"
@ -322,21 +322,25 @@ void QtNXWebEngineView::LoadExtractedFonts() {
QWebEngineScript nx_font_css;
QWebEngineScript load_nx_font;
const QString fonts_dir = QString::fromStdString(Common::FS::SanitizePath(
fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir))));
auto fonts_dir_str = Common::FS::PathToUTF8String(
Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "fonts/");
std::replace(fonts_dir_str.begin(), fonts_dir_str.end(), '\\', '/');
const auto fonts_dir = QString::fromStdString(fonts_dir_str);
nx_font_css.setName(QStringLiteral("nx_font_css.js"));
load_nx_font.setName(QStringLiteral("load_nx_font.js"));
nx_font_css.setSourceCode(
QString::fromStdString(NX_FONT_CSS)
.arg(fonts_dir + QStringLiteral("/FontStandard.ttf"))
.arg(fonts_dir + QStringLiteral("/FontChineseSimplified.ttf"))
.arg(fonts_dir + QStringLiteral("/FontExtendedChineseSimplified.ttf"))
.arg(fonts_dir + QStringLiteral("/FontChineseTraditional.ttf"))
.arg(fonts_dir + QStringLiteral("/FontKorean.ttf"))
.arg(fonts_dir + QStringLiteral("/FontNintendoExtended.ttf"))
.arg(fonts_dir + QStringLiteral("/FontNintendoExtended2.ttf")));
.arg(fonts_dir + QStringLiteral("FontStandard.ttf"))
.arg(fonts_dir + QStringLiteral("FontChineseSimplified.ttf"))
.arg(fonts_dir + QStringLiteral("FontExtendedChineseSimplified.ttf"))
.arg(fonts_dir + QStringLiteral("FontChineseTraditional.ttf"))
.arg(fonts_dir + QStringLiteral("FontKorean.ttf"))
.arg(fonts_dir + QStringLiteral("FontNintendoExtended.ttf"))
.arg(fonts_dir + QStringLiteral("FontNintendoExtended2.ttf")));
load_nx_font.setSourceCode(QString::fromStdString(LOAD_NX_FONT));
nx_font_css.setInjectionPoint(QWebEngineScript::DocumentReady);

View File

@ -5,8 +5,8 @@
#include <array>
#include <QKeySequence>
#include <QSettings>
#include "common/common_paths.h"
#include "common/file_util.h"
#include "common/fs/fs.h"
#include "common/fs/path_util.h"
#include "core/core.h"
#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/hid/controllers/npad.h"
@ -243,27 +243,27 @@ const std::array<UISettings::Shortcut, 17> Config::default_hotkeys{{
// clang-format on
void Config::Initialize(const std::string& config_name) {
const auto fs_config_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir);
const auto config_file = fmt::format("{}.ini", config_name);
switch (type) {
case ConfigType::GlobalConfig:
qt_config_loc = fmt::format("{}" DIR_SEP "{}.ini", FS::GetUserPath(FS::UserPath::ConfigDir),
config_name);
FS::CreateFullPath(qt_config_loc);
qt_config_loc = FS::PathToUTF8String(fs_config_loc / config_file);
void(FS::CreateParentDir(qt_config_loc));
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
QSettings::IniFormat);
Reload();
break;
case ConfigType::PerGameConfig:
qt_config_loc = fmt::format("{}custom" DIR_SEP "{}.ini",
FS::GetUserPath(FS::UserPath::ConfigDir), config_name);
FS::CreateFullPath(qt_config_loc);
qt_config_loc = FS::PathToUTF8String(fs_config_loc / "custom" / config_file);
void(FS::CreateParentDir(qt_config_loc));
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
QSettings::IniFormat);
Reload();
break;
case ConfigType::InputProfile:
qt_config_loc = fmt::format("{}input" DIR_SEP "{}.ini",
FS::GetUserPath(FS::UserPath::ConfigDir), config_name);
FS::CreateFullPath(qt_config_loc);
qt_config_loc = FS::PathToUTF8String(fs_config_loc / "input" / config_file);
void(FS::CreateParentDir(qt_config_loc));
qt_config = std::make_unique<QSettings>(QString::fromStdString(qt_config_loc),
QSettings::IniFormat);
break;
@ -598,30 +598,34 @@ void Config::ReadDataStorageValues() {
qt_config->beginGroup(QStringLiteral("Data Storage"));
Settings::values.use_virtual_sd = ReadSetting(QStringLiteral("use_virtual_sd"), true).toBool();
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::SetYuzuPath(
FS::YuzuPath::NANDDir,
qt_config
->value(QStringLiteral("nand_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::NANDDir)))
.toString()
.toStdString());
FS::SetYuzuPath(
FS::YuzuPath::SDMCDir,
qt_config
->value(QStringLiteral("sdmc_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::SDMCDir)))
.toString()
.toStdString());
FS::SetYuzuPath(
FS::YuzuPath::LoadDir,
qt_config
->value(QStringLiteral("load_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::LoadDir)))
.toString()
.toStdString());
FS::SetYuzuPath(
FS::YuzuPath::DumpDir,
qt_config
->value(QStringLiteral("dump_directory"),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)))
.toString()
.toStdString());
Settings::values.gamecard_inserted =
ReadSetting(QStringLiteral("gamecard_inserted"), false).toBool();
Settings::values.gamecard_current_game =
@ -817,11 +821,11 @@ void Config::ReadScreenshotValues() {
UISettings::values.enable_screenshot_save_as =
ReadSetting(QStringLiteral("enable_screenshot_save_as"), true).toBool();
FS::GetUserPath(
FS::UserPath::ScreenshotsDir,
FS::SetYuzuPath(
FS::YuzuPath::ScreenshotsDir,
qt_config
->value(QStringLiteral("screenshot_path"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::ScreenshotsDir)))
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::ScreenshotsDir)))
.toString()
.toStdString());
@ -1220,17 +1224,17 @@ void Config::SaveDataStorageValues() {
WriteSetting(QStringLiteral("use_virtual_sd"), Settings::values.use_virtual_sd, true);
WriteSetting(QStringLiteral("nand_directory"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::NANDDir)),
QString::fromStdString(FS::GetUserPath(FS::UserPath::NANDDir)));
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::NANDDir)),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::NANDDir)));
WriteSetting(QStringLiteral("sdmc_directory"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::SDMCDir)),
QString::fromStdString(FS::GetUserPath(FS::UserPath::SDMCDir)));
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::SDMCDir)),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::SDMCDir)));
WriteSetting(QStringLiteral("load_directory"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::LoadDir)),
QString::fromStdString(FS::GetUserPath(FS::UserPath::LoadDir)));
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::LoadDir)),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::LoadDir)));
WriteSetting(QStringLiteral("dump_directory"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir)),
QString::fromStdString(FS::GetUserPath(FS::UserPath::DumpDir)));
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)),
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::DumpDir)));
WriteSetting(QStringLiteral("gamecard_inserted"), Settings::values.gamecard_inserted, false);
WriteSetting(QStringLiteral("gamecard_current_game"), Settings::values.gamecard_current_game,
false);
@ -1397,7 +1401,7 @@ void Config::SaveScreenshotValues() {
WriteSetting(QStringLiteral("enable_screenshot_save_as"),
UISettings::values.enable_screenshot_save_as);
WriteSetting(QStringLiteral("screenshot_path"),
QString::fromStdString(FS::GetUserPath(FS::UserPath::ScreenshotsDir)));
QString::fromStdString(FS::GetYuzuPathString(FS::YuzuPath::ScreenshotsDir)));
qt_config->endGroup();
}

View File

@ -4,7 +4,7 @@
#include <QDesktopServices>
#include <QUrl>
#include "common/file_util.h"
#include "common/fs/path_util.h"
#include "common/logging/backend.h"
#include "common/logging/filter.h"
#include "common/settings.h"
@ -20,7 +20,7 @@ ConfigureDebug::ConfigureDebug(QWidget* parent) : QWidget(parent), ui(new Ui::Co
connect(ui->open_log_button, &QPushButton::clicked, []() {
const auto path =
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::LogDir));
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::LogDir));
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
});
}

View File

@ -4,8 +4,8 @@
#include <QFileDialog>
#include <QMessageBox>
#include "common/common_paths.h"
#include "common/file_util.h"
#include "common/fs/fs.h"
#include "common/fs/path_util.h"
#include "common/settings.h"
#include "ui_configure_filesystem.h"
#include "yuzu/configuration/configure_filesystem.h"
@ -40,14 +40,14 @@ ConfigureFilesystem::~ConfigureFilesystem() = default;
void ConfigureFilesystem::setConfiguration() {
ui->nand_directory_edit->setText(
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir)));
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::NANDDir)));
ui->sdmc_directory_edit->setText(
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir)));
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::SDMCDir)));
ui->gamecard_path_edit->setText(QString::fromStdString(Settings::values.gamecard_path));
ui->dump_path_edit->setText(
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::DumpDir)));
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::DumpDir)));
ui->load_path_edit->setText(
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::LoadDir)));
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::LoadDir)));
ui->gamecard_inserted->setChecked(Settings::values.gamecard_inserted);
ui->gamecard_current_game->setChecked(Settings::values.gamecard_current_game);
@ -60,13 +60,13 @@ void ConfigureFilesystem::setConfiguration() {
}
void ConfigureFilesystem::applyConfiguration() {
Common::FS::GetUserPath(Common::FS::UserPath::NANDDir,
Common::FS::SetYuzuPath(Common::FS::YuzuPath::NANDDir,
ui->nand_directory_edit->text().toStdString());
Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir,
Common::FS::SetYuzuPath(Common::FS::YuzuPath::SDMCDir,
ui->sdmc_directory_edit->text().toStdString());
Common::FS::GetUserPath(Common::FS::UserPath::DumpDir,
Common::FS::SetYuzuPath(Common::FS::YuzuPath::DumpDir,
ui->dump_path_edit->text().toStdString());
Common::FS::GetUserPath(Common::FS::UserPath::LoadDir,
Common::FS::SetYuzuPath(Common::FS::YuzuPath::LoadDir,
ui->load_path_edit->text().toStdString());
Settings::values.gamecard_inserted = ui->gamecard_inserted->isChecked();
@ -104,25 +104,26 @@ void ConfigureFilesystem::SetDirectory(DirectoryTarget target, QLineEdit* edit)
QStringLiteral("NX Gamecard;*.xci"));
} else {
str = QFileDialog::getExistingDirectory(this, caption, edit->text());
if (!str.isNull() && str.back() != QDir::separator()) {
str.append(QDir::separator());
}
}
if (str.isEmpty())
if (str.isNull() || str.isEmpty()) {
return;
}
if (str.back() != QChar::fromLatin1('/')) {
str.append(QChar::fromLatin1('/'));
}
edit->setText(str);
}
void ConfigureFilesystem::ResetMetadata() {
if (!Common::FS::Exists(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
"game_list")) {
if (!Common::FS::Exists(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
"game_list/")) {
QMessageBox::information(this, tr("Reset Metadata Cache"),
tr("The metadata cache is already empty."));
} else if (Common::FS::DeleteDirRecursively(
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
"game_list")) {
} else if (Common::FS::RemoveDirRecursively(
Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "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

@ -14,8 +14,6 @@
#include <QTimer>
#include <QTreeView>
#include "common/common_paths.h"
#include "common/file_util.h"
#include "core/core.h"
#include "core/file_sys/control_metadata.h"
#include "core/file_sys/patch_manager.h"

View File

@ -13,8 +13,8 @@
#include <QTimer>
#include <QTreeView>
#include "common/common_paths.h"
#include "common/file_util.h"
#include "common/fs/fs.h"
#include "common/fs/path_util.h"
#include "core/core.h"
#include "core/file_sys/patch_manager.h"
#include "core/file_sys/xts_archive.h"
@ -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) {
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
"game_list" + DIR_SEP + fmt::format("{:016X}.pv.txt", title_id));
void(Common::FS::RemoveFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
"game_list" / fmt::format("{:016X}.pv.txt", title_id)));
}
Settings::values.disabled_addons[title_id] = disabled_addons;

View File

@ -12,7 +12,7 @@
#include <QTreeView>
#include <QVBoxLayout>
#include "common/assert.h"
#include "common/file_util.h"
#include "common/fs/path_util.h"
#include "common/settings.h"
#include "common/string_util.h"
#include "core/core.h"
@ -34,9 +34,10 @@ constexpr std::array<u8, 107> backup_jpeg{
};
QString GetImagePath(Common::UUID uuid) {
const auto path = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
"/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
return QString::fromStdString(path);
const auto path =
Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) /
fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormatSwitch());
return QString::fromStdString(Common::FS::PathToUTF8String(path));
}
QString GetAccountUsername(const Service::Account::ProfileManager& manager, Common::UUID uuid) {
@ -281,8 +282,8 @@ void ConfigureProfileManager::SetUserImage() {
return;
}
const auto raw_path = QString::fromStdString(
Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) + "/system/save/8000000000000010");
const auto raw_path = QString::fromStdString(Common::FS::PathToUTF8String(
Common::FS::GetYuzuPath(Common::FS::YuzuPath::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

@ -10,7 +10,6 @@
#include <QGraphicsItem>
#include <QMessageBox>
#include "common/assert.h"
#include "common/file_util.h"
#include "common/settings.h"
#include "core/core.h"
#include "core/hle/service/time/time.h"

View File

@ -8,7 +8,7 @@
#include <QDirIterator>
#include "common/common_types.h"
#include "common/file_util.h"
#include "common/fs/path_util.h"
#include "common/settings.h"
#include "core/core.h"
#include "ui_configure_ui.h"
@ -62,13 +62,16 @@ 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 =
auto dir =
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);
QString::fromStdString(Common::FS::GetYuzuPathString(
Common::FS::YuzuPath::ScreenshotsDir)));
if (!dir.isEmpty()) {
if (dir.back() != QChar::fromLatin1('/')) {
dir.append(QChar::fromLatin1('/'));
}
ui->screenshot_path_edit->setText(dir);
}
});
}
@ -84,7 +87,7 @@ 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();
Common::FS::GetUserPath(Common::FS::UserPath::ScreenshotsDir,
Common::FS::SetYuzuPath(Common::FS::YuzuPath::ScreenshotsDir,
ui->screenshot_path_edit->text().toStdString());
Core::System::GetInstance().ApplySettings();
}
@ -102,8 +105,8 @@ void ConfigureUi::SetConfiguration() {
ui->icon_size_combobox->findData(UISettings::values.icon_size));
ui->enable_screenshot_save_as->setChecked(UISettings::values.enable_screenshot_save_as);
ui->screenshot_path_edit->setText(
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ScreenshotsDir)));
ui->screenshot_path_edit->setText(QString::fromStdString(
Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir)));
}
void ConfigureUi::changeEvent(QEvent* event) {

View File

@ -4,8 +4,8 @@
#include <fmt/format.h>
#include "common/common_paths.h"
#include "common/file_util.h"
#include "common/fs/fs.h"
#include "common/fs/path_util.h"
#include "yuzu/configuration/config.h"
#include "yuzu/configuration/input_profiles.h"
@ -14,47 +14,43 @@ namespace FS = Common::FS;
namespace {
bool ProfileExistsInFilesystem(std::string_view profile_name) {
return FS::Exists(fmt::format("{}input" DIR_SEP "{}.ini",
FS::GetUserPath(FS::UserPath::ConfigDir), profile_name));
return FS::Exists(FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "input" /
fmt::format("{}.ini", profile_name));
}
bool IsINI(std::string_view filename) {
const std::size_t index = filename.rfind('.');
if (index == std::string::npos) {
return false;
}
return filename.substr(index) == ".ini";
bool IsINI(const std::filesystem::path& filename) {
return filename.extension() == ".ini";
}
std::string GetNameWithoutExtension(const std::string& filename) {
const std::size_t index = filename.rfind('.');
if (index == std::string::npos) {
return filename;
}
return filename.substr(0, index);
std::filesystem::path GetNameWithoutExtension(std::filesystem::path filename) {
return filename.replace_extension();
}
} // namespace
InputProfiles::InputProfiles() {
const std::string input_profile_loc =
fmt::format("{}input", FS::GetUserPath(FS::UserPath::ConfigDir));
const auto input_profile_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir) / "input";
FS::ForeachDirectoryEntry(
nullptr, input_profile_loc,
[this](u64* entries_out, const std::string& directory, const std::string& filename) {
if (IsINI(filename) && IsProfileNameValid(GetNameWithoutExtension(filename))) {
if (!FS::IsDir(input_profile_loc)) {
return;
}
FS::IterateDirEntries(
input_profile_loc,
[this](const std::filesystem::path& full_path) {
const auto filename = full_path.filename();
const auto name_without_ext =
Common::FS::PathToUTF8String(GetNameWithoutExtension(filename));
if (IsINI(filename) && IsProfileNameValid(name_without_ext)) {
map_profiles.insert_or_assign(
GetNameWithoutExtension(filename),
std::make_unique<Config>(GetNameWithoutExtension(filename),
Config::ConfigType::InputProfile));
name_without_ext,
std::make_unique<Config>(name_without_ext, Config::ConfigType::InputProfile));
}
return true;
});
},
FS::DirEntryFilter::File);
}
InputProfiles::~InputProfiles() = default;
@ -96,7 +92,7 @@ bool InputProfiles::DeleteProfile(const std::string& profile_name) {
}
if (!ProfileExistsInFilesystem(profile_name) ||
FS::Delete(map_profiles[profile_name]->GetConfigFilePath())) {
FS::RemoveFile(map_profiles[profile_name]->GetConfigFilePath())) {
map_profiles.erase(profile_name);
}

View File

@ -12,8 +12,8 @@
#include <QFileInfo>
#include <QSettings>
#include "common/common_paths.h"
#include "common/file_util.h"
#include "common/fs/fs.h"
#include "common/fs/path_util.h"
#include "core/core.h"
#include "core/file_sys/card_image.h"
#include "core/file_sys/content_archive.h"
@ -39,10 +39,11 @@ QString GetGameListCachedObject(const std::string& filename, const std::string&
return generator();
}
const auto path = Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
"game_list" + DIR_SEP + filename + '.' + ext;
const auto path =
Common::FS::PathToUTF8String(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
"game_list" / fmt::format("{}.{}", filename, ext));
Common::FS::CreateFullPath(path);
void(Common::FS::CreateParentDirs(path));
if (!Common::FS::Exists(path)) {
const auto str = generator();
@ -70,12 +71,15 @@ std::pair<std::vector<u8>, std::string> GetGameListCachedObject(
return generator();
}
const auto path1 = Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
"game_list" + DIR_SEP + filename + ".jpeg";
const auto path2 = Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
"game_list" + DIR_SEP + filename + ".appname.txt";
const auto game_list_dir =
Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "game_list";
const auto jpeg_name = fmt::format("{}.jpeg", filename);
const auto app_name = fmt::format("{}.appname.txt", filename);
Common::FS::CreateFullPath(path1);
const auto path1 = Common::FS::PathToUTF8String(game_list_dir / jpeg_name);
const auto path2 = Common::FS::PathToUTF8String(game_list_dir / app_name);
void(Common::FS::CreateParentDirs(path1));
if (!Common::FS::Exists(path1) || !Common::FS::Exists(path2)) {
const auto [icon, nacp] = generator();
@ -281,23 +285,27 @@ void GameListWorker::AddTitlesToGameList(GameListDir* parent_dir) {
}
}
void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_path,
unsigned int recursion, GameListDir* parent_dir) {
void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_path, bool deep_scan,
GameListDir* parent_dir) {
auto& system = Core::System::GetInstance();
const auto callback = [this, target, recursion, parent_dir,
&system](u64* num_entries_out, const std::string& directory,
const std::string& virtual_name) -> bool {
const auto callback = [this, target, parent_dir,
&system](const std::filesystem::path& path) -> bool {
if (stop_processing) {
// Breaks the callback loop.
return false;
}
const std::string physical_name = directory + DIR_SEP + virtual_name;
const bool is_dir = Common::FS::IsDirectory(physical_name);
const auto physical_name = Common::FS::PathToUTF8String(path);
const auto is_dir = Common::FS::IsDir(path);
if (!is_dir &&
(HasSupportedFileExtension(physical_name) || IsExtractedNCAMain(physical_name))) {
const auto file = vfs->OpenFile(physical_name, FileSys::Mode::Read);
if (!file) {
return true;
}
auto loader = Loader::GetLoader(system, file);
if (!loader) {
return true;
@ -343,15 +351,19 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa
compatibility_list, patch),
parent_dir);
}
} else if (is_dir && recursion > 0) {
} else if (is_dir) {
watch_list.append(QString::fromStdString(physical_name));
ScanFileSystem(target, physical_name, recursion - 1, parent_dir);
}
return true;
};
Common::FS::ForeachDirectoryEntry(nullptr, dir_path, callback);
if (deep_scan) {
Common::FS::IterateDirEntriesRecursively(dir_path, callback,
Common::FS::DirEntryFilter::All);
} else {
Common::FS::IterateDirEntries(dir_path, callback, Common::FS::DirEntryFilter::File);
}
}
void GameListWorker::run() {
@ -376,9 +388,9 @@ void GameListWorker::run() {
auto* const game_list_dir = new GameListDir(game_dir);
emit DirEntryReady(game_list_dir);
ScanFileSystem(ScanTarget::FillManualContentProvider, game_dir.path.toStdString(),
game_dir.deep_scan ? 256 : 0, game_list_dir);
game_dir.deep_scan, game_list_dir);
ScanFileSystem(ScanTarget::PopulateGameList, game_dir.path.toStdString(),
game_dir.deep_scan ? 256 : 0, game_list_dir);
game_dir.deep_scan, game_list_dir);
}
}

View File

@ -70,7 +70,7 @@ private:
PopulateGameList,
};
void ScanFileSystem(ScanTarget target, const std::string& dir_path, unsigned int recursion,
void ScanFileSystem(ScanTarget target, const std::string& dir_path, bool deep_scan,
GameListDir* parent_dir);
std::shared_ptr<FileSys::VfsFilesystem> vfs;

View File

@ -66,9 +66,10 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
#include <QtConcurrent/QtConcurrent>
#include <fmt/format.h>
#include "common/common_paths.h"
#include "common/detached_tasks.h"
#include "common/file_util.h"
#include "common/fs/fs.h"
#include "common/fs/fs_paths.h"
#include "common/fs/path_util.h"
#include "common/logging/backend.h"
#include "common/logging/filter.h"
#include "common/logging/log.h"
@ -178,36 +179,25 @@ static void InitializeLogging() {
log_filter.ParseFilterString(Settings::values.log_filter);
Log::SetGlobalFilter(log_filter);
const std::string& log_dir = FS::GetUserPath(FS::UserPath::LogDir);
FS::CreateFullPath(log_dir);
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
const auto log_dir = FS::GetYuzuPath(FS::YuzuPath::LogDir);
void(FS::CreateDir(log_dir));
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir / LOG_FILE));
#ifdef _WIN32
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
#endif
}
static void RemoveCachedContents() {
const auto offline_fonts = Common::FS::SanitizePath(
fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
Common::FS::DirectorySeparator::PlatformDefault);
const auto cache_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir);
const auto offline_fonts = cache_dir / "fonts";
const auto offline_manual = cache_dir / "offline_web_applet_manual";
const auto offline_legal_information = cache_dir / "offline_web_applet_legal_information";
const auto offline_system_data = cache_dir / "offline_web_applet_system_data";
const auto offline_manual = Common::FS::SanitizePath(
fmt::format("{}/offline_web_applet_manual",
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
Common::FS::DirectorySeparator::PlatformDefault);
const auto offline_legal_information = Common::FS::SanitizePath(
fmt::format("{}/offline_web_applet_legal_information",
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
Common::FS::DirectorySeparator::PlatformDefault);
const auto offline_system_data = Common::FS::SanitizePath(
fmt::format("{}/offline_web_applet_system_data",
Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
Common::FS::DirectorySeparator::PlatformDefault);
Common::FS::DeleteDirRecursively(offline_fonts);
Common::FS::DeleteDirRecursively(offline_manual);
Common::FS::DeleteDirRecursively(offline_legal_information);
Common::FS::DeleteDirRecursively(offline_system_data);
void(Common::FS::RemoveDirRecursively(offline_fonts));
void(Common::FS::RemoveDirRecursively(offline_manual));
void(Common::FS::RemoveDirRecursively(offline_legal_information));
void(Common::FS::RemoveDirRecursively(offline_system_data));
}
GMainWindow::GMainWindow()
@ -1418,7 +1408,8 @@ void GMainWindow::BootGame(const QString& filename, std::size_t program_index) {
title_name = metadata.first->GetApplicationName();
}
if (res != Loader::ResultStatus::Success || title_name.empty()) {
title_name = Common::FS::GetFilename(filename.toStdString());
title_name = Common::FS::PathToUTF8String(
std::filesystem::path{filename.toStdU16String()}.filename());
}
LOG_INFO(Frontend, "Booting game: {:016X} | {} | {}", title_id, title_name, title_version);
UpdateWindowTitle(title_name, title_version);
@ -1538,7 +1529,7 @@ void GMainWindow::OnGameListLoadFile(QString game_path) {
void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target,
const std::string& game_path) {
std::string path;
std::filesystem::path path;
QString open_target;
auto& system = Core::System::GetInstance();
@ -1567,7 +1558,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
switch (target) {
case GameListOpenTarget::SaveData: {
open_target = tr("Save Data");
const std::string nand_dir = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
const auto nand_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir);
if (has_user_save) {
// User save data
@ -1592,34 +1583,38 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
Service::Account::ProfileManager manager;
const auto user_id = manager.GetUser(static_cast<std::size_t>(index));
ASSERT(user_id);
path = nand_dir + FileSys::SaveDataFactory::GetFullPath(
system, FileSys::SaveDataSpaceId::NandUser,
FileSys::SaveDataType::SaveData, program_id, user_id->uuid, 0);
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
program_id, user_id->uuid, 0);
path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path);
} else {
// Device save data
path = nand_dir + FileSys::SaveDataFactory::GetFullPath(
system, FileSys::SaveDataSpaceId::NandUser,
FileSys::SaveDataType::SaveData, program_id, {}, 0);
const auto device_save_data_path = FileSys::SaveDataFactory::GetFullPath(
system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
program_id, {}, 0);
path = Common::FS::ConcatPathSafe(nand_dir, device_save_data_path);
}
if (!Common::FS::Exists(path)) {
Common::FS::CreateFullPath(path);
Common::FS::CreateDir(path);
if (!Common::FS::CreateDirs(path)) {
LOG_ERROR(Frontend, "Unable to create the directories for save data");
}
break;
}
case GameListOpenTarget::ModData: {
open_target = tr("Mod Data");
const auto load_dir = Common::FS::GetUserPath(Common::FS::UserPath::LoadDir);
path = fmt::format("{}{:016X}", load_dir, program_id);
path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::LoadDir) /
fmt::format("{:016X}", program_id);
break;
}
default:
UNIMPLEMENTED();
}
const QString qpath = QString::fromStdString(path);
const QString qpath = QString::fromStdString(Common::FS::PathToUTF8String(path));
const QDir dir(qpath);
if (!dir.exists()) {
QMessageBox::warning(this, tr("Error Opening %1 Folder").arg(open_target),
@ -1632,33 +1627,35 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
}
void GMainWindow::OnTransferableShaderCacheOpenFile(u64 program_id) {
const QString shader_dir =
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir));
const QString transferable_shader_cache_folder_path =
shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable");
const QString transferable_shader_cache_file_path =
transferable_shader_cache_folder_path + QDir::separator() +
QString::fromStdString(fmt::format("{:016X}.bin", program_id));
const auto shader_cache_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ShaderDir);
const auto transferable_shader_cache_folder_path = shader_cache_dir / "opengl" / "transferable";
const auto transferable_shader_cache_file_path =
transferable_shader_cache_folder_path / fmt::format("{:016X}.bin", program_id);
if (!QFile::exists(transferable_shader_cache_file_path)) {
if (!Common::FS::Exists(transferable_shader_cache_file_path)) {
QMessageBox::warning(this, tr("Error Opening Transferable Shader Cache"),
tr("A shader cache for this title does not exist."));
return;
}
const auto qt_shader_cache_folder_path =
QString::fromStdString(Common::FS::PathToUTF8String(transferable_shader_cache_folder_path));
const auto qt_shader_cache_file_path =
QString::fromStdString(Common::FS::PathToUTF8String(transferable_shader_cache_file_path));
// Windows supports opening a folder with selecting a specified file in explorer. On every other
// OS we just open the transferable shader cache folder without preselecting the transferable
// shader cache file for the selected game.
#if defined(Q_OS_WIN)
const QString explorer = QStringLiteral("explorer");
QStringList param;
if (!QFileInfo(transferable_shader_cache_file_path).isDir()) {
if (!QFileInfo(qt_shader_cache_file_path).isDir()) {
param << QStringLiteral("/select,");
}
param << QDir::toNativeSeparators(transferable_shader_cache_file_path);
param << QDir::toNativeSeparators(qt_shader_cache_file_path);
QProcess::startDetached(explorer, param);
#else
QDesktopServices::openUrl(QUrl::fromLocalFile(transferable_shader_cache_folder_path));
QDesktopServices::openUrl(QUrl::fromLocalFile(qt_shader_cache_folder_path));
#endif
}
@ -1736,8 +1733,8 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
RemoveAddOnContent(program_id, entry_type);
break;
}
Common::FS::DeleteDirRecursively(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) +
DIR_SEP + "game_list");
void(Common::FS::RemoveDirRecursively(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
"game_list"));
game_list->PopulateAsync(UISettings::values.game_dirs);
}
@ -1826,21 +1823,17 @@ void GMainWindow::OnGameListRemoveFile(u64 program_id, GameListRemoveTarget targ
}
void GMainWindow::RemoveTransferableShaderCache(u64 program_id) {
const QString shader_dir =
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir));
const QString transferable_shader_cache_folder_path =
shader_dir + QStringLiteral("opengl") + QDir::separator() + QStringLiteral("transferable");
const QString transferable_shader_cache_file_path =
transferable_shader_cache_folder_path + QDir::separator() +
QString::fromStdString(fmt::format("{:016X}.bin", program_id));
const auto shader_cache_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ShaderDir);
const auto transferable_shader_cache_file_path =
shader_cache_dir / "opengl" / "transferable" / fmt::format("{:016X}.bin", program_id);
if (!QFile::exists(transferable_shader_cache_file_path)) {
if (!Common::FS::Exists(transferable_shader_cache_file_path)) {
QMessageBox::warning(this, tr("Error Removing Transferable Shader Cache"),
tr("A shader cache for this title does not exist."));
return;
}
if (QFile::remove(transferable_shader_cache_file_path)) {
if (Common::FS::RemoveFile(transferable_shader_cache_file_path)) {
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed the transferable shader cache."));
} else {
@ -1850,19 +1843,16 @@ void GMainWindow::RemoveTransferableShaderCache(u64 program_id) {
}
void GMainWindow::RemoveCustomConfiguration(u64 program_id) {
const QString config_dir =
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir));
const QString custom_config_file_path =
config_dir + QStringLiteral("custom") + QDir::separator() +
QString::fromStdString(fmt::format("{:016X}.ini", program_id));
const auto custom_config_file_path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) /
"custom" / fmt::format("{:016X}.ini", program_id);
if (!QFile::exists(custom_config_file_path)) {
if (!Common::FS::Exists(custom_config_file_path)) {
QMessageBox::warning(this, tr("Error Removing Custom Configuration"),
tr("A custom configuration for this title does not exist."));
return;
}
if (QFile::remove(custom_config_file_path)) {
if (Common::FS::RemoveFile(custom_config_file_path)) {
QMessageBox::information(this, tr("Successfully Removed"),
tr("Successfully removed the custom game configuration."));
} else {
@ -1899,8 +1889,10 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
return;
}
const auto path = fmt::format(
"{}{:016X}/romfs", Common::FS::GetUserPath(Common::FS::UserPath::DumpDir), *romfs_title_id);
const auto dump_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::DumpDir);
const auto romfs_dir = fmt::format("{:016X}/romfs", *romfs_title_id);
const auto path = Common::FS::PathToUTF8String(dump_dir / romfs_dir);
FileSys::VirtualFile romfs;
@ -1978,24 +1970,29 @@ void GMainWindow::OnGameListNavigateToGamedbEntry(u64 program_id,
}
void GMainWindow::OnGameListOpenDirectory(const QString& directory) {
QString path;
std::filesystem::path fs_path;
if (directory == QStringLiteral("SDMC")) {
path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir) +
"Nintendo/Contents/registered");
fs_path =
Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir) / "Nintendo/Contents/registered";
} else if (directory == QStringLiteral("UserNAND")) {
path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
"user/Contents/registered");
fs_path =
Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "user/Contents/registered";
} else if (directory == QStringLiteral("SysNAND")) {
path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
"system/Contents/registered");
fs_path =
Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "system/Contents/registered";
} else {
path = directory;
fs_path = directory.toStdString();
}
if (!QFileInfo::exists(path)) {
QMessageBox::critical(this, tr("Error Opening %1").arg(path), tr("Folder does not exist!"));
const auto qt_path = QString::fromStdString(Common::FS::PathToUTF8String(fs_path));
if (!Common::FS::IsDir(fs_path)) {
QMessageBox::critical(this, tr("Error Opening %1").arg(qt_path),
tr("Folder does not exist!"));
return;
}
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
QDesktopServices::openUrl(QUrl::fromLocalFile(qt_path));
}
void GMainWindow::OnGameListAddDirectory() {
@ -2189,8 +2186,8 @@ void GMainWindow::OnMenuInstallToNAND() {
: tr("%n file(s) failed to install\n", "", failed_files.size()));
QMessageBox::information(this, tr("Install Results"), install_results);
Common::FS::DeleteDirRecursively(Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) +
DIR_SEP + "game_list");
void(Common::FS::RemoveDirRecursively(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
"game_list"));
game_list->PopulateAsync(UISettings::values.game_dirs);
ui.action_Install_File_NAND->setEnabled(true);
}
@ -2706,7 +2703,7 @@ void GMainWindow::LoadAmiibo(const QString& filename) {
void GMainWindow::OnOpenYuzuFolder() {
QDesktopServices::openUrl(QUrl::fromLocalFile(
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::UserDir))));
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::YuzuDir))));
}
void GMainWindow::OnAbout() {
@ -2728,7 +2725,7 @@ void GMainWindow::OnCaptureScreenshot() {
const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID();
const auto screenshot_path =
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::ScreenshotsDir));
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir));
const auto date =
QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz"));
QString filename = QStringLiteral("%1%2_%3.png")
@ -2757,23 +2754,26 @@ void GMainWindow::OnCaptureScreenshot() {
// TODO: Written 2020-10-01: Remove per-game config migration code when it is irrelevant
void GMainWindow::MigrateConfigFiles() {
const std::string& config_dir_str = Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir);
const QDir config_dir = QDir(QString::fromStdString(config_dir_str));
const auto config_dir_fs_path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir);
const QDir config_dir =
QDir(QString::fromStdString(Common::FS::PathToUTF8String(config_dir_fs_path)));
const QStringList config_dir_list = config_dir.entryList(QStringList(QStringLiteral("*.ini")));
Common::FS::CreateFullPath(fmt::format("{}custom" DIR_SEP, config_dir_str));
for (QStringList::const_iterator it = config_dir_list.constBegin();
it != config_dir_list.constEnd(); ++it) {
if (!Common::FS::CreateDirs(config_dir_fs_path / "custom")) {
LOG_ERROR(Frontend, "Failed to create new config file directory");
}
for (auto it = config_dir_list.constBegin(); it != config_dir_list.constEnd(); ++it) {
const auto filename = it->toStdString();
if (filename.find_first_not_of("0123456789abcdefACBDEF", 0) < 16) {
continue;
}
const auto origin = fmt::format("{}{}", config_dir_str, filename);
const auto destination = fmt::format("{}custom" DIR_SEP "{}", config_dir_str, filename);
const auto origin = config_dir_fs_path / filename;
const auto destination = config_dir_fs_path / "custom" / filename;
LOG_INFO(Frontend, "Migrating config file from {} to {}", origin, destination);
if (!Common::FS::Rename(origin, destination)) {
if (!Common::FS::RenameFile(origin, destination)) {
// Delete the old config file if one already exists in the new location.
Common::FS::Delete(origin);
void(Common::FS::RemoveFile(origin));
}
}
}
@ -2965,18 +2965,16 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) {
if (res == QMessageBox::Cancel)
return;
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::KeysDir) +
"prod.keys_autogenerated");
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::KeysDir) +
"console.keys_autogenerated");
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::KeysDir) +
"title.keys_autogenerated");
const auto keys_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir);
void(Common::FS::RemoveFile(keys_dir / "prod.keys_autogenerated"));
void(Common::FS::RemoveFile(keys_dir / "console.keys_autogenerated"));
void(Common::FS::RemoveFile(keys_dir / "title.keys_autogenerated"));
}
Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance();
if (keys.BaseDeriveNecessary()) {
Core::Crypto::PartitionDataManager pdm{vfs->OpenDirectory(
Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir), FileSys::Mode::Read)};
Core::Crypto::PartitionDataManager pdm{vfs->OpenDirectory("", FileSys::Mode::Read)};
const auto function = [this, &keys, &pdm] {
keys.PopulateFromPartitionData(pdm);
@ -3289,12 +3287,17 @@ int main(int argc, char* argv[]) {
QCoreApplication::setOrganizationName(QStringLiteral("yuzu team"));
QCoreApplication::setApplicationName(QStringLiteral("yuzu"));
#ifdef _WIN32
// Increases the maximum open file limit to 4096
_setmaxstdio(4096);
#endif
#ifdef __APPLE__
// If you start a bundle (binary) on OSX without the Terminal, the working directory is "/".
// But since we require the working directory to be the executable path for the location of
// the user folder in the Qt Frontend, we need to cd into that working directory
const std::string bin_path = Common::FS::GetBundleDirectory() + DIR_SEP + "..";
chdir(bin_path.c_str());
const auto bin_path = Common::FS::GetBundleDirectory() / "..";
chdir(Common::FS::PathToUTF8String(bin_path).c_str());
#endif
#ifdef __linux__