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
2022-10-30 21:03:49 +02:00
committed by GPUCode
parent 349ac6ac05
commit 281f2926bb
67 changed files with 384 additions and 384 deletions

View File

@ -25,7 +25,7 @@
Config::Config() {
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
sdl2_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "config.ini";
sdl2_config_loc = Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) + "config.ini";
sdl2_config = std::make_unique<INIReader>(sdl2_config_loc);
Reload();
@ -38,8 +38,8 @@ bool Config::LoadINI(const std::string& default_contents, bool retry) {
if (sdl2_config->ParseError() < 0) {
if (retry) {
LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
FileUtil::CreateFullPath(location);
FileUtil::WriteStringToFile(true, location, default_contents);
Common::FS::CreateFullPath(location);
Common::FS::WriteStringToFile(true, location, default_contents);
sdl2_config = std::make_unique<INIReader>(location); // Reopen file
return LoadINI(default_contents, false);

View File

@ -35,7 +35,7 @@ std::vector<u8> GetSMDHData(std::string physical_name) {
std::string update_path = Service::AM::GetTitleContentPath(
Service::FS::MediaType::SDMC, program_id + 0x0000000E'00000000);
if (!FileUtil::Exists(update_path))
if (!Common::FS::Exists(update_path))
return original_smdh;
std::unique_ptr<Loader::AppLoader> update_loader = Loader::GetLoader(update_path);

View File

@ -159,9 +159,9 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
log_filter.ParseFilterString(Settings::values.log_filter);
Log::SetGlobalFilter(log_filter);
Log::AddBackend(std::make_unique<Log::LogcatBackend>());
FileUtil::CreateFullPath(FileUtil::GetUserPath(FileUtil::UserPath::LogDir));
Common::FS::CreateFullPath(Common::FS::GetUserPath(Common::FS::UserPath::LogDir));
Log::AddBackend(std::make_unique<Log::FileBackend>(
FileUtil::GetUserPath(FileUtil::UserPath::LogDir) + LOG_FILE));
Common::FS::GetUserPath(Common::FS::UserPath::LogDir) + LOG_FILE));
LOG_INFO(Frontend, "Logging backend initialised");
// Initialize misc classes

View File

@ -154,7 +154,7 @@ static Core::System::ResultStatus RunCitra(const std::string& filepath) {
Config{};
// Replace with game-specific settings
u64 program_id{};
FileUtil::SetCurrentRomPath(filepath);
Common::FS::SetCurrentRomPath(filepath);
auto app_loader = Loader::GetLoader(filepath);
if (app_loader) {
app_loader->ReadProgramId(program_id);
@ -305,18 +305,18 @@ void Java_org_citra_citra_1emu_NativeLibrary_SwapScreens(JNIEnv* env, [[maybe_un
void Java_org_citra_citra_1emu_NativeLibrary_SetUserDirectory(JNIEnv* env,
[[maybe_unused]] jclass clazz,
jstring j_directory) {
FileUtil::SetCurrentDir(GetJString(env, j_directory));
Common::FS::SetCurrentDir(GetJString(env, j_directory));
}
jobjectArray Java_org_citra_citra_1emu_NativeLibrary_GetInstalledGamePaths(
JNIEnv* env, [[maybe_unused]] jclass clazz) {
std::vector<std::string> games;
const FileUtil::DirectoryEntryCallable ScanDir =
const Common::FS::DirectoryEntryCallable ScanDir =
[&games, &ScanDir](u64*, const std::string& directory, const std::string& virtual_name) {
std::string path = directory + virtual_name;
if (FileUtil::IsDirectory(path)) {
if (Common::FS::IsDirectory(path)) {
path += '/';
FileUtil::ForeachDirectoryEntry(nullptr, path, ScanDir);
Common::FS::ForeachDirectoryEntry(nullptr, path, ScanDir);
} else {
auto loader = Loader::GetLoader(path);
if (loader) {
@ -330,12 +330,12 @@ jobjectArray Java_org_citra_citra_1emu_NativeLibrary_GetInstalledGamePaths(
return true;
};
ScanDir(nullptr, "",
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir) +
Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir) +
"Nintendo "
"3DS/00000000000000000000000000000000/"
"00000000000000000000000000000000/title/00040000");
ScanDir(nullptr, "",
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
"00000000000000000000000000000000/title/00040010");
jobjectArray jgames = env->NewObjectArray(static_cast<jsize>(games.size()),
env->FindClass("java/lang/String"), nullptr);

View File

@ -43,8 +43,8 @@ FuncDL<int(AVCodecParserContext*, AVCodecContext*, uint8_t**, int*, const uint8_
FuncDL<void(AVCodecParserContext*)> av_parser_close_dl;
bool InitFFmpegDL() {
std::string dll_path = FileUtil::GetUserPath(FileUtil::UserPath::DLLDir);
FileUtil::CreateDir(dll_path);
std::string dll_path = Common::FS::GetUserPath(Common::FS::UserPath::DLLDir);
Common::FS::CreateDir(dll_path);
std::wstring w_dll_path = Common::UTF8ToUTF16W(dll_path);
SetDllDirectoryW(w_dll_path.c_str());

View File

@ -170,8 +170,8 @@ static void InitializeLogging() {
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
FileUtil::CreateFullPath(log_dir);
const std::string& log_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir);
Common::FS::CreateFullPath(log_dir);
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
#ifdef _WIN32
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());

View File

@ -22,7 +22,7 @@
Config::Config() {
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
sdl2_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "sdl2-config.ini";
sdl2_config_loc = Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) + "sdl2-config.ini";
sdl2_config = std::make_unique<INIReader>(sdl2_config_loc);
Reload();
@ -35,8 +35,8 @@ bool Config::LoadINI(const std::string& default_contents, bool retry) {
if (sdl2_config->ParseError() < 0) {
if (retry) {
LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
FileUtil::CreateFullPath(location);
FileUtil::WriteStringToFile(true, location, default_contents);
Common::FS::CreateFullPath(location);
Common::FS::WriteStringToFile(true, location, default_contents);
sdl2_config = std::make_unique<INIReader>(location); // Reopen file
return LoadINI(default_contents, false);
@ -208,9 +208,9 @@ void Config::ReadValues() {
sdl2_config->GetBoolean("Data Storage", "use_custom_storage", false);
if (Settings::values.use_custom_storage) {
FileUtil::UpdateUserPath(FileUtil::UserPath::NANDDir,
Common::FS::UpdateUserPath(Common::FS::UserPath::NANDDir,
sdl2_config->GetString("Data Storage", "nand_directory", ""));
FileUtil::UpdateUserPath(FileUtil::UserPath::SDMCDir,
Common::FS::UpdateUserPath(Common::FS::UserPath::SDMCDir,
sdl2_config->GetString("Data Storage", "sdmc_directory", ""));
}

View File

@ -19,8 +19,8 @@
Config::Config() {
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
qt_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "qt-config.ini";
FileUtil::CreateFullPath(qt_config_loc);
qt_config_loc = Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) + "qt-config.ini";
Common::FS::CreateFullPath(qt_config_loc);
qt_config =
std::make_unique<QSettings>(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
Reload();
@ -312,8 +312,8 @@ void Config::ReadDataStorageValues() {
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);
Common::FS::UpdateUserPath(Common::FS::UserPath::NANDDir, nand_dir);
Common::FS::UpdateUserPath(Common::FS::UserPath::SDMCDir, sdmc_dir);
}
qt_config->endGroup();
@ -875,10 +875,10 @@ void Config::SaveDataStorageValues() {
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(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir)),
QStringLiteral(""));
WriteSetting(QStringLiteral("sdmc_directory"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)),
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir)),
QStringLiteral(""));
qt_config->endGroup();

View File

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

View File

@ -117,9 +117,9 @@ void ConfigureGeneral::SetConfiguration() {
QString screenshot_path = UISettings::values.screenshot_path;
if (screenshot_path.isEmpty()) {
screenshot_path =
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::UserDir));
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::UserDir));
screenshot_path.append(QStringLiteral("screenshots/"));
FileUtil::CreateFullPath(screenshot_path.toStdString());
Common::FS::CreateFullPath(screenshot_path.toStdString());
UISettings::values.screenshot_path = screenshot_path;
}
ui->screenshot_dir_path->setText(screenshot_path);
@ -134,7 +134,7 @@ void ConfigureGeneral::ResetDefaults() {
if (answer == QMessageBox::No)
return;
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "qt-config.ini");
Common::FS::Delete(Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) + "qt-config.ini");
std::exit(0);
}

View File

@ -16,33 +16,33 @@ ConfigureStorage::ConfigureStorage(QWidget* parent)
SetConfiguration();
connect(ui->open_nand_dir, &QPushButton::clicked, []() {
QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
QString path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::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(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)),
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir)),
QFileDialog::ShowDirsOnly);
if (!dir_path.isEmpty()) {
FileUtil::UpdateUserPath(FileUtil::UserPath::NANDDir, dir_path.toStdString());
Common::FS::UpdateUserPath(Common::FS::UserPath::NANDDir, dir_path.toStdString());
SetConfiguration();
}
});
connect(ui->open_sdmc_dir, &QPushButton::clicked, []() {
QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
QString path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::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(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)),
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir)),
QFileDialog::ShowDirsOnly);
if (!dir_path.isEmpty()) {
FileUtil::UpdateUserPath(FileUtil::UserPath::SDMCDir, dir_path.toStdString());
Common::FS::UpdateUserPath(Common::FS::UserPath::SDMCDir, dir_path.toStdString());
SetConfiguration();
}
});
@ -61,13 +61,13 @@ ConfigureStorage::~ConfigureStorage() = default;
void ConfigureStorage::SetConfiguration() {
ui->nand_group->setVisible(Settings::values.use_custom_storage);
QString nand_path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
QString nand_path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::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 &&
Settings::values.use_custom_storage);
QString sdmc_path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
QString sdmc_path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir));
ui->sdmc_dir_path->setText(sdmc_path);
ui->open_sdmc_dir->setEnabled(!sdmc_path.isEmpty());
@ -82,10 +82,10 @@ void ConfigureStorage::ApplyConfiguration() {
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));
Common::FS::UpdateUserPath(Common::FS::UserPath::NANDDir,
GetDefaultUserPath(Common::FS::UserPath::NANDDir));
Common::FS::UpdateUserPath(Common::FS::UserPath::SDMCDir,
GetDefaultUserPath(Common::FS::UserPath::SDMCDir));
}
}

View File

@ -493,15 +493,15 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
const bool is_application =
0x0004000000000000 <= program_id && program_id <= 0x00040000FFFFFFFF;
std::string sdmc_dir = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
std::string sdmc_dir = Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir);
open_save_location->setEnabled(
is_application && FileUtil::Exists(FileSys::ArchiveSource_SDSaveData::GetSaveDataPathFor(
is_application && Common::FS::Exists(FileSys::ArchiveSource_SDSaveData::GetSaveDataPathFor(
sdmc_dir, program_id)));
if (extdata_id) {
open_extdata_location->setEnabled(
is_application &&
FileUtil::Exists(FileSys::GetExtDataPathFromId(sdmc_dir, extdata_id)));
Common::FS::Exists(FileSys::GetExtDataPathFromId(sdmc_dir, extdata_id)));
} else {
open_extdata_location->setVisible(false);
}
@ -510,7 +510,7 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
open_application_location->setEnabled(path.toStdString() ==
Service::AM::GetTitleContentPath(media_type, program_id));
open_update_location->setEnabled(
is_application && FileUtil::Exists(Service::AM::GetTitlePath(Service::FS::MediaType::SDMC,
is_application && Common::FS::Exists(Service::AM::GetTitlePath(Service::FS::MediaType::SDMC,
program_id + 0xe00000000) +
"content/"));
auto it = FindMatchingCompatibilityEntry(compatibility_list, program_id);
@ -535,29 +535,29 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
emit OpenFolderRequested(program_id, GameListOpenTarget::UPDATE_DATA);
});
connect(open_texture_dump_location, &QAction::triggered, this, [this, program_id] {
if (FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir),
if (Common::FS::CreateFullPath(fmt::format("{}textures/{:016X}/",
Common::FS::GetUserPath(Common::FS::UserPath::DumpDir),
program_id))) {
emit OpenFolderRequested(program_id, GameListOpenTarget::TEXTURE_DUMP);
}
});
connect(open_texture_load_location, &QAction::triggered, this, [this, program_id] {
if (FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
if (Common::FS::CreateFullPath(fmt::format("{}textures/{:016X}/",
Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
program_id))) {
emit OpenFolderRequested(program_id, GameListOpenTarget::TEXTURE_LOAD);
}
});
connect(open_texture_load_location, &QAction::triggered, this, [this, program_id] {
if (FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
if (Common::FS::CreateFullPath(fmt::format("{}textures/{:016X}/",
Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
program_id))) {
emit OpenFolderRequested(program_id, GameListOpenTarget::TEXTURE_LOAD);
}
});
connect(open_mods_location, &QAction::triggered, this, [this, program_id] {
if (FileUtil::CreateFullPath(fmt::format("{}mods/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
if (Common::FS::CreateFullPath(fmt::format("{}mods/{:016X}/",
Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
program_id))) {
emit OpenFolderRequested(program_id, GameListOpenTarget::MODS);
}
@ -568,7 +568,7 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
emit NavigateToGamedbEntryRequested(program_id, compatibility_list);
});
connect(open_shader_cache_location, &QAction::triggered, this, [this, program_id] {
if (FileUtil::CreateFullPath(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir))) {
if (Common::FS::CreateFullPath(Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir))) {
emit OpenFolderRequested(program_id, GameListOpenTarget::SHADER_CACHE);
}
});
@ -576,14 +576,14 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
const std::string_view cache_type =
Settings::values.separable_shader ? "separable" : "conventional";
const std::string path = fmt::format("{}opengl/precompiled/{}/{:016X}.bin",
FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir),
Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir),
cache_type, program_id);
QFile file{QString::fromStdString(path)};
file.remove();
});
connect(delete_vulkan_disk_shader_cache, &QAction::triggered, this, [] {
const std::string path =
fmt::format("{}vulkan", FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir));
fmt::format("{}vulkan", Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir));
QDir dir{QString::fromStdString(path)};
dir.removeRecursively();
});

View File

@ -43,7 +43,7 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign
}
const std::string physical_name = directory + DIR_SEP + virtual_name;
const bool is_dir = FileUtil::IsDirectory(physical_name);
const bool is_dir = Common::FS::IsDirectory(physical_name);
if (!is_dir && HasSupportedFileExtension(physical_name)) {
std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(physical_name);
if (!loader) {
@ -67,7 +67,7 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign
if (!(program_id & ~0x00040000FFFFFFFF)) {
std::string update_path = Service::AM::GetTitleContentPath(
Service::FS::MediaType::SDMC, program_id | 0x0000000E00000000);
if (FileUtil::Exists(update_path)) {
if (Common::FS::Exists(update_path)) {
std::unique_ptr<Loader::AppLoader> update_loader =
Loader::GetLoader(update_path);
if (update_loader) {
@ -101,7 +101,7 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign
new GameListItemRegion(smdh),
new GameListItem(
QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))),
new GameListItemSize(FileUtil::GetSize(physical_name)),
new GameListItemSize(Common::FS::GetSize(physical_name)),
},
parent_dir);
@ -113,7 +113,7 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign
return true;
};
FileUtil::ForeachDirectoryEntry(nullptr, dir_path, callback);
Common::FS::ForeachDirectoryEntry(nullptr, dir_path, callback);
}
void GameListWorker::run() {
@ -121,12 +121,12 @@ void GameListWorker::run() {
for (UISettings::GameDir& game_dir : game_dirs) {
if (game_dir.path == QStringLiteral("INSTALLED")) {
QString games_path =
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)) +
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir)) +
QStringLiteral("Nintendo "
"3DS/00000000000000000000000000000000/"
"00000000000000000000000000000000/title/00040000");
QString demos_path =
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)) +
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir)) +
QStringLiteral(
"Nintendo "
"3DS/00000000000000000000000000000000/00000000000000000000000000000000/title/"
@ -139,7 +139,7 @@ void GameListWorker::run() {
AddFstEntriesToGameList(demos_path.toStdString(), 2, game_list_dir);
} else if (game_dir.path == QStringLiteral("SYSTEM")) {
QString path =
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)) +
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir)) +
QStringLiteral("00000000000000000000000000000000/title/00040010");
watch_list.append(path);
auto* const game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir);

View File

@ -138,8 +138,8 @@ static void InitializeLogging() {
log_filter.ParseFilterString(Settings::values.log_filter);
Log::SetGlobalFilter(log_filter);
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
FileUtil::CreateFullPath(log_dir);
const std::string& log_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir);
Common::FS::CreateFullPath(log_dir);
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
#ifdef _WIN32
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
@ -1324,13 +1324,13 @@ void GMainWindow::OnGameListOpenFolder(u64 data_id, GameListOpenTarget target) {
switch (target) {
case GameListOpenTarget::SAVE_DATA: {
open_target = "Save Data";
std::string sdmc_dir = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
std::string sdmc_dir = Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir);
path = FileSys::ArchiveSource_SDSaveData::GetSaveDataPathFor(sdmc_dir, data_id);
break;
}
case GameListOpenTarget::EXT_DATA: {
open_target = "Extra Data";
std::string sdmc_dir = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
std::string sdmc_dir = Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir);
path = FileSys::GetExtDataPathFromId(sdmc_dir, data_id);
break;
}
@ -1349,24 +1349,24 @@ void GMainWindow::OnGameListOpenFolder(u64 data_id, GameListOpenTarget target) {
case GameListOpenTarget::TEXTURE_DUMP: {
open_target = "Dumped Textures";
path = fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), data_id);
Common::FS::GetUserPath(Common::FS::UserPath::DumpDir), data_id);
break;
}
case GameListOpenTarget::TEXTURE_LOAD: {
open_target = "Custom Textures";
path = fmt::format("{}textures/{:016X}/",
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), data_id);
Common::FS::GetUserPath(Common::FS::UserPath::LoadDir), data_id);
break;
}
case GameListOpenTarget::MODS: {
open_target = "Mods";
path = fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
path = fmt::format("{}mods/{:016X}/", Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
data_id);
break;
}
case GameListOpenTarget::SHADER_CACHE: {
open_target = "Shader Cache";
path = FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir);
path = Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir);
break;
}
default:
@ -1410,9 +1410,9 @@ void GMainWindow::OnGameListDumpRomFS(QString game_path, u64 program_id) {
dialog->setValue(0);
const auto base_path = fmt::format(
"{}romfs/{:016X}", FileUtil::GetUserPath(FileUtil::UserPath::DumpDir), program_id);
"{}romfs/{:016X}", Common::FS::GetUserPath(Common::FS::UserPath::DumpDir), program_id);
const auto update_path =
fmt::format("{}romfs/{:016X}", FileUtil::GetUserPath(FileUtil::UserPath::DumpDir),
fmt::format("{}romfs/{:016X}", Common::FS::GetUserPath(Common::FS::UserPath::DumpDir),
program_id | 0x0004000e00000000);
using FutureWatcher = QFutureWatcher<std::pair<Loader::ResultStatus, Loader::ResultStatus>>;
auto* future_watcher = new FutureWatcher(this);
@ -1443,12 +1443,12 @@ void GMainWindow::OnGameListDumpRomFS(QString game_path, u64 program_id) {
void GMainWindow::OnGameListOpenDirectory(const QString& directory) {
QString path;
if (directory == QStringLiteral("INSTALLED")) {
path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir) +
path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir) +
"Nintendo "
"3DS/00000000000000000000000000000000/"
"00000000000000000000000000000000/title/00040000");
} else if (directory == QStringLiteral("SYSTEM")) {
path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir) +
"00000000000000000000000000000000/title/00040010");
} else {
path = directory;
@ -1873,7 +1873,7 @@ void GMainWindow::OnRemoveAmiibo() {
void GMainWindow::OnOpenCitraFolder() {
QDesktopServices::openUrl(QUrl::fromLocalFile(
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::UserDir))));
QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::UserDir))));
}
void GMainWindow::OnToggleFilterBar() {
@ -1973,12 +1973,12 @@ void GMainWindow::OnSaveMovie() {
void GMainWindow::OnCaptureScreenshot() {
OnPauseGame();
QString path = UISettings::values.screenshot_path;
if (!FileUtil::IsDirectory(path.toStdString())) {
if (!FileUtil::CreateFullPath(path.toStdString())) {
if (!Common::FS::IsDirectory(path.toStdString())) {
if (!Common::FS::CreateFullPath(path.toStdString())) {
QMessageBox::information(this, tr("Invalid Screenshot Directory"),
tr("Cannot create specified screenshot directory. Screenshot "
"path is set back to its default value."));
path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::UserDir));
path = QString::fromStdString(Common::FS::GetUserPath(Common::FS::UserPath::UserDir));
path.append(QStringLiteral("screenshots/"));
UISettings::values.screenshot_path = path;
};
@ -2482,7 +2482,7 @@ int main(int argc, char* argv[]) {
QCoreApplication::setApplicationName(QStringLiteral("Citra"));
#ifdef __APPLE__
std::string bin_path = FileUtil::GetBundleDirectory() + DIR_SEP + "..";
std::string bin_path = Common::FS::GetBundleDirectory() + DIR_SEP + "..";
chdir(bin_path.c_str());
#endif
QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);

View File

@ -76,7 +76,7 @@
// This namespace has various generic functions related to files and paths.
// The code still needs a ton of cleanup.
// REMEMBER: strdup considered harmful!
namespace FileUtil {
namespace Common::FS {
// Remove any ending forward slashes from directory paths
// Modifies argument.
@ -198,7 +198,7 @@ bool CreateFullPath(const std::string& fullPath) {
int panicCounter = 100;
LOG_TRACE(Common_Filesystem, "path {}", fullPath);
if (FileUtil::Exists(fullPath)) {
if (Common::FS::Exists(fullPath)) {
LOG_DEBUG(Common_Filesystem, "path exists {}", fullPath);
return true;
}
@ -214,7 +214,7 @@ bool CreateFullPath(const std::string& fullPath) {
// Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
std::string const subPath(fullPath.substr(0, position + 1));
if (!FileUtil::IsDirectory(subPath) && !FileUtil::CreateDir(subPath)) {
if (!Common::FS::IsDirectory(subPath) && !Common::FS::CreateDir(subPath)) {
LOG_ERROR(Common, "CreateFullPath: directory creation failed");
return false;
}
@ -233,7 +233,7 @@ bool DeleteDir(const std::string& filename) {
LOG_TRACE(Common_Filesystem, "directory {}", filename);
// check if a directory
if (!FileUtil::IsDirectory(filename)) {
if (!Common::FS::IsDirectory(filename)) {
LOG_ERROR(Common_Filesystem, "Not a directory {}", filename);
return false;
}
@ -373,7 +373,7 @@ u64 GetSize(FILE* f) {
bool CreateEmptyFile(const std::string& filename) {
LOG_TRACE(Common_Filesystem, "{}", filename);
if (!FileUtil::IOFile(filename, "wb").IsOpen()) {
if (!Common::FS::IOFile(filename, "wb").IsOpen()) {
LOG_ERROR(Common_Filesystem, "failed {}: {}", filename, GetLastErrorMsg());
return false;
}
@ -501,7 +501,7 @@ bool DeleteDirRecursively(const std::string& directory, unsigned int recursion)
return false;
// Delete the outermost directory
FileUtil::DeleteDir(directory);
Common::FS::DeleteDir(directory);
return true;
}
@ -509,10 +509,10 @@ void CopyDir(const std::string& source_path, const std::string& dest_path) {
#ifndef _WIN32
if (source_path == dest_path)
return;
if (!FileUtil::Exists(source_path))
if (!Common::FS::Exists(source_path))
return;
if (!FileUtil::Exists(dest_path))
FileUtil::CreateFullPath(dest_path);
if (!Common::FS::Exists(dest_path))
Common::FS::CreateFullPath(dest_path);
DIR* dirp = opendir(source_path.c_str());
if (!dirp)
@ -531,11 +531,11 @@ void CopyDir(const std::string& source_path, const std::string& dest_path) {
if (IsDirectory(source)) {
source += '/';
dest += '/';
if (!FileUtil::Exists(dest))
FileUtil::CreateFullPath(dest);
if (!Common::FS::Exists(dest))
Common::FS::CreateFullPath(dest);
CopyDir(source, dest);
} else if (!FileUtil::Exists(dest))
FileUtil::Copy(source, dest);
} else if (!Common::FS::Exists(dest))
Common::FS::Copy(source, dest);
}
closedir(dirp);
#endif
@ -560,7 +560,7 @@ std::optional<std::string> GetCurrentDir() {
#endif
free(dir);
return strDir;
} // namespace FileUtil
} // namespace Common::FS
bool SetCurrentDir(const std::string& directory) {
#ifdef _WIN32
@ -689,7 +689,7 @@ void SetUserPath(const std::string& path) {
} else {
#ifdef _WIN32
user_path = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
if (!FileUtil::IsDirectory(user_path)) {
if (!Common::FS::IsDirectory(user_path)) {
user_path = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP;
} else {
LOG_INFO(Common_Filesystem, "Using the local user directory");
@ -698,13 +698,13 @@ void SetUserPath(const std::string& path) {
g_paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
g_paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
#elif ANDROID
if (FileUtil::Exists(DIR_SEP SDCARD_DIR)) {
if (Common::FS::Exists(DIR_SEP SDCARD_DIR)) {
user_path = DIR_SEP SDCARD_DIR DIR_SEP EMU_DATA_DIR DIR_SEP;
g_paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
g_paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
}
#else
if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) {
if (Common::FS::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) {
user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
g_paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
g_paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
@ -779,7 +779,7 @@ const void UpdateUserPath(UserPath path, const std::string& filename) {
if (filename.empty()) {
return;
}
if (!FileUtil::IsDirectory(filename)) {
if (!Common::FS::IsDirectory(filename)) {
LOG_ERROR(Common_Filesystem, "Path is not a directory. UserPath: {} filename: {}", path,
filename);
return;
@ -998,7 +998,7 @@ bool IOFile::Close() {
u64 IOFile::GetSize() const {
if (IsOpen())
return FileUtil::GetSize(m_file);
return Common::FS::GetSize(m_file);
return 0;
}
@ -1070,4 +1070,4 @@ bool IOFile::Resize(u64 size) {
return m_good;
}
} // namespace FileUtil
} // namespace Common::FS

View File

@ -22,7 +22,7 @@
#include "common/string_util.h"
#endif
namespace FileUtil {
namespace Common::FS {
// User paths for GetUserPath
enum class UserPath {
@ -383,7 +383,7 @@ private:
friend class boost::serialization::access;
};
} // namespace FileUtil
} // namespace Common::FS
// To deal with Windows being dumb at unicode:
template <typename T>

View File

@ -145,16 +145,16 @@ void LogcatBackend::Write(const Entry& entry) {
}
FileBackend::FileBackend(const std::string& filename) : bytes_written(0) {
if (FileUtil::Exists(filename + ".old.txt")) {
FileUtil::Delete(filename + ".old.txt");
if (Common::FS::Exists(filename + ".old.txt")) {
Common::FS::Delete(filename + ".old.txt");
}
if (FileUtil::Exists(filename)) {
FileUtil::Rename(filename, filename + ".old.txt");
if (Common::FS::Exists(filename)) {
Common::FS::Rename(filename, filename + ".old.txt");
}
// _SH_DENYWR allows read only access to the file for other programs.
// It is #defined to 0 on other platforms
file = FileUtil::IOFile(filename, "w", _SH_DENYWR);
file = Common::FS::IOFile(filename, "w", _SH_DENYWR);
}
void FileBackend::Write(const Entry& entry) {

View File

@ -114,7 +114,7 @@ public:
void Write(const Entry& entry) override;
private:
FileUtil::IOFile file;
Common::FS::IOFile file;
std::size_t bytes_written;
};

View File

@ -64,12 +64,12 @@ void CheatEngine::UpdateCheat(int index, const std::shared_ptr<CheatBase>& new_c
}
void CheatEngine::SaveCheatFile() const {
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
const std::string cheat_dir = Common::FS::GetUserPath(Common::FS::UserPath::CheatsDir);
const std::string filepath = fmt::format(
"{}{:016X}.txt", cheat_dir, system.Kernel().GetCurrentProcess()->codeset->program_id);
if (!FileUtil::IsDirectory(cheat_dir)) {
FileUtil::CreateDir(cheat_dir);
if (!Common::FS::IsDirectory(cheat_dir)) {
Common::FS::CreateDir(cheat_dir);
}
std::ofstream file;
@ -84,15 +84,15 @@ void CheatEngine::SaveCheatFile() const {
}
void CheatEngine::LoadCheatFile() {
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
const std::string cheat_dir = Common::FS::GetUserPath(Common::FS::UserPath::CheatsDir);
const std::string filepath = fmt::format(
"{}{:016X}.txt", cheat_dir, system.Kernel().GetCurrentProcess()->codeset->program_id);
if (!FileUtil::IsDirectory(cheat_dir)) {
FileUtil::CreateDir(cheat_dir);
if (!Common::FS::IsDirectory(cheat_dir)) {
Common::FS::CreateDir(cheat_dir);
}
if (!FileUtil::Exists(filepath))
if (!Common::FS::Exists(filepath))
return;
auto gateway_cheats = GatewayCheat::LoadFile(filepath);

View File

@ -248,7 +248,7 @@ System::ResultStatus System::SingleStep() {
}
System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath) {
FileUtil::SetCurrentRomPath(filepath);
Common::FS::SetCurrentRomPath(filepath);
app_loader = Loader::GetLoader(filepath);
if (!app_loader) {
LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
@ -314,8 +314,8 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
if (Settings::values.custom_textures) {
const u64 program_id = Kernel().GetCurrentProcess()->codeset->program_id;
FileUtil::CreateFullPath(fmt::format(
"{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), program_id));
Common::FS::CreateFullPath(fmt::format(
"{}textures/{:016X}/", Common::FS::GetUserPath(Common::FS::UserPath::LoadDir), program_id));
custom_tex_cache->FindCustomTextures(program_id);
}
if (Settings::values.preload_textures) {

View File

@ -45,14 +45,14 @@ void CustomTexCache::FindCustomTextures(u64 program_id) {
// [TitleID]/tex1_[width]x[height]_[64-bit hash]_[format].png
const std::string load_path = fmt::format(
"{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir), program_id);
"{}textures/{:016X}/", Common::FS::GetUserPath(Common::FS::UserPath::LoadDir), program_id);
if (FileUtil::Exists(load_path)) {
FileUtil::FSTEntry texture_dir;
std::vector<FileUtil::FSTEntry> textures;
if (Common::FS::Exists(load_path)) {
Common::FS::FSTEntry texture_dir;
std::vector<Common::FS::FSTEntry> textures;
// 64 nested folders should be plenty for most cases
FileUtil::ScanDirectoryTree(load_path, texture_dir, 64);
FileUtil::GetAllFilesFromNestedEntries(texture_dir, textures);
Common::FS::ScanDirectoryTree(load_path, texture_dir, 64);
Common::FS::GetAllFilesFromNestedEntries(texture_dir, textures);
for (const auto& file : textures) {
if (file.isDirectory)

View File

@ -412,7 +412,7 @@ bool FFmpegMuxer::Init(const std::string& path, const Layout::FramebufferLayout&
InitializeFFmpegLibraries();
if (!FileUtil::CreateFullPath(path)) {
if (!Common::FS::CreateFullPath(path)) {
return false;
}

View File

@ -30,7 +30,7 @@ namespace FileSys {
*/
class FixSizeDiskFile : public DiskFile {
public:
FixSizeDiskFile(FileUtil::IOFile&& file, const Mode& mode,
FixSizeDiskFile(Common::FS::IOFile&& file, const Mode& mode,
std::unique_ptr<DelayGenerator> delay_generator_)
: DiskFile(std::move(file), mode, std::move(delay_generator_)) {
size = GetSize();
@ -144,7 +144,7 @@ public:
break; // Expected 'success' case
}
FileUtil::IOFile file(full_path, "r+b");
Common::FS::IOFile file(full_path, "r+b");
if (!file.IsOpen()) {
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path);
return ERROR_FILE_NOT_FOUND;
@ -248,7 +248,7 @@ Path ArchiveFactory_ExtSaveData::GetCorrectedPath(const Path& path) {
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(const Path& path,
u64 program_id) {
std::string fullpath = GetExtSaveDataPath(mount_point, GetCorrectedPath(path)) + "user/";
if (!FileUtil::Exists(fullpath)) {
if (!Common::FS::Exists(fullpath)) {
// TODO(Subv): Verify the archive behavior of SharedExtSaveData compared to ExtSaveData.
// ExtSaveData seems to return FS_NotFound (120) when the archive doesn't exist.
if (!shared) {
@ -270,12 +270,12 @@ ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path,
// These folders are always created with the ExtSaveData
std::string user_path = GetExtSaveDataPath(mount_point, corrected_path) + "user/";
std::string boss_path = GetExtSaveDataPath(mount_point, corrected_path) + "boss/";
FileUtil::CreateFullPath(user_path);
FileUtil::CreateFullPath(boss_path);
Common::FS::CreateFullPath(user_path);
Common::FS::CreateFullPath(boss_path);
// Write the format metadata
std::string metadata_path = GetExtSaveDataPath(mount_point, corrected_path) + "metadata";
FileUtil::IOFile file(metadata_path, "wb");
Common::FS::IOFile file(metadata_path, "wb");
if (!file.IsOpen()) {
// TODO(Subv): Find the correct error code
@ -289,7 +289,7 @@ ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path,
ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Path& path,
u64 program_id) const {
std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata";
FileUtil::IOFile file(metadata_path, "rb");
Common::FS::IOFile file(metadata_path, "rb");
if (!file.IsOpen()) {
LOG_ERROR(Service_FS, "Could not open metadata information for archive");
@ -305,7 +305,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat
void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data,
std::size_t icon_size) {
std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path);
FileUtil::IOFile icon_file(game_path + "icon", "wb");
Common::FS::IOFile icon_file(game_path + "icon", "wb");
icon_file.WriteBytes(icon_data, icon_size);
}

View File

@ -97,14 +97,14 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCArchive::OpenFileBase(const Path& pa
return ERROR_NOT_FOUND;
} else {
// Create the file
FileUtil::CreateEmptyFile(full_path);
Common::FS::CreateEmptyFile(full_path);
}
break;
case PathParser::FileFound:
break; // Expected 'success' case
}
FileUtil::IOFile file(full_path, mode.write_flag ? "r+b" : "rb");
Common::FS::IOFile file(full_path, mode.write_flag ? "r+b" : "rb");
if (!file.IsOpen()) {
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path);
return ERROR_NOT_FOUND;
@ -141,7 +141,7 @@ ResultCode SDMCArchive::DeleteFile(const Path& path) const {
break; // Expected 'success' case
}
if (FileUtil::Delete(full_path)) {
if (Common::FS::Delete(full_path)) {
return RESULT_SUCCESS;
}
@ -168,7 +168,7 @@ ResultCode SDMCArchive::RenameFile(const Path& src_path, const Path& dest_path)
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
if (FileUtil::Rename(src_path_full, dest_path_full)) {
if (Common::FS::Rename(src_path_full, dest_path_full)) {
return RESULT_SUCCESS;
}
@ -218,12 +218,12 @@ static ResultCode DeleteDirectoryHelper(const Path& path, const std::string& mou
}
ResultCode SDMCArchive::DeleteDirectory(const Path& path) const {
return DeleteDirectoryHelper(path, mount_point, FileUtil::DeleteDir);
return DeleteDirectoryHelper(path, mount_point, Common::FS::DeleteDir);
}
ResultCode SDMCArchive::DeleteDirectoryRecursively(const Path& path) const {
return DeleteDirectoryHelper(
path, mount_point, [](const std::string& p) { return FileUtil::DeleteDirRecursively(p); });
path, mount_point, [](const std::string& p) { return Common::FS::DeleteDirRecursively(p); });
}
ResultCode SDMCArchive::CreateFile(const FileSys::Path& path, u64 size) const {
@ -255,11 +255,11 @@ ResultCode SDMCArchive::CreateFile(const FileSys::Path& path, u64 size) const {
}
if (size == 0) {
FileUtil::CreateEmptyFile(full_path);
Common::FS::CreateEmptyFile(full_path);
return RESULT_SUCCESS;
}
FileUtil::IOFile file(full_path, "wb");
Common::FS::IOFile file(full_path, "wb");
// Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
// We do this by seeking to the right size, then writing a single null byte.
if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) {
@ -297,7 +297,7 @@ ResultCode SDMCArchive::CreateDirectory(const Path& path) const {
break; // Expected 'success' case
}
if (FileUtil::CreateDir(mount_point + path.AsString())) {
if (Common::FS::CreateDir(mount_point + path.AsString())) {
return RESULT_SUCCESS;
}
@ -325,7 +325,7 @@ ResultCode SDMCArchive::RenameDirectory(const Path& src_path, const Path& dest_p
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
if (FileUtil::Rename(src_path_full, dest_path_full)) {
if (Common::FS::Rename(src_path_full, dest_path_full)) {
return RESULT_SUCCESS;
}
@ -382,7 +382,7 @@ bool ArchiveFactory_SDMC::Initialize() {
return false;
}
if (!FileUtil::CreateFullPath(sdmc_directory)) {
if (!Common::FS::CreateFullPath(sdmc_directory)) {
LOG_ERROR(Service_FS, "Unable to create SDMC path.");
return false;
}

View File

@ -69,7 +69,7 @@ bool ArchiveFactory_SDMCWriteOnly::Initialize() {
return false;
}
if (!FileUtil::CreateFullPath(sdmc_directory)) {
if (!Common::FS::CreateFullPath(sdmc_directory)) {
LOG_ERROR(Service_FS, "Unable to create SDMC path.");
return false;
}

View File

@ -45,7 +45,7 @@ ArchiveSource_SDSaveData::ArchiveSource_SDSaveData(const std::string& sdmc_direc
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveSource_SDSaveData::Open(u64 program_id) {
std::string concrete_mount_point = GetSaveDataPath(mount_point, program_id);
if (!FileUtil::Exists(concrete_mount_point)) {
if (!Common::FS::Exists(concrete_mount_point)) {
// When a SaveData archive is created for the first time, it is not yet formatted and the
// save file/directory structure expected by the game has not yet been initialized.
// Returning the NotFormatted error code will signal the game to provision the SaveData
@ -60,12 +60,12 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveSource_SDSaveData::Open(u64 pr
ResultCode ArchiveSource_SDSaveData::Format(u64 program_id,
const FileSys::ArchiveFormatInfo& format_info) {
std::string concrete_mount_point = GetSaveDataPath(mount_point, program_id);
FileUtil::DeleteDirRecursively(concrete_mount_point);
FileUtil::CreateFullPath(concrete_mount_point);
Common::FS::DeleteDirRecursively(concrete_mount_point);
Common::FS::CreateFullPath(concrete_mount_point);
// Write the format metadata
std::string metadata_path = GetSaveDataMetadataPath(mount_point, program_id);
FileUtil::IOFile file(metadata_path, "wb");
Common::FS::IOFile file(metadata_path, "wb");
if (file.IsOpen()) {
file.WriteBytes(&format_info, sizeof(format_info));
@ -76,7 +76,7 @@ ResultCode ArchiveSource_SDSaveData::Format(u64 program_id,
ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program_id) const {
std::string metadata_path = GetSaveDataMetadataPath(mount_point, program_id);
FileUtil::IOFile file(metadata_path, "rb");
Common::FS::IOFile file(metadata_path, "rb");
if (!file.IsOpen()) {
LOG_ERROR(Service_FS, "Could not open metadata information for archive");

View File

@ -58,7 +58,7 @@ ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string&
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(const Path& path,
u64 program_id) {
std::string fullpath = GetSystemSaveDataPath(base_path, path);
if (!FileUtil::Exists(fullpath)) {
if (!Common::FS::Exists(fullpath)) {
// TODO(Subv): Check error code, this one is probably wrong
return ERR_NOT_FORMATTED;
}
@ -70,8 +70,8 @@ ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path,
const FileSys::ArchiveFormatInfo& format_info,
u64 program_id) {
std::string fullpath = GetSystemSaveDataPath(base_path, path);
FileUtil::DeleteDirRecursively(fullpath);
FileUtil::CreateFullPath(fullpath);
Common::FS::DeleteDirRecursively(fullpath);
Common::FS::CreateFullPath(fullpath);
return RESULT_SUCCESS;
}

View File

@ -66,7 +66,7 @@ Loader::ResultStatus CIAContainer::Load(const FileBackend& backend) {
}
Loader::ResultStatus CIAContainer::Load(const std::string& filepath) {
FileUtil::IOFile file(filepath, "rb");
Common::FS::IOFile file(filepath, "rb");
if (!file.IsOpen())
return Loader::ResultStatus::Error;

View File

@ -58,7 +58,7 @@ bool DiskFile::Close() const {
////////////////////////////////////////////////////////////////////////////////////////////////////
DiskDirectory::DiskDirectory(const std::string& path) {
directory.size = FileUtil::ScanDirectoryTree(path, directory);
directory.size = Common::FS::ScanDirectoryTree(path, directory);
directory.isDirectory = true;
children_iterator = directory.children.begin();
}
@ -67,7 +67,7 @@ u32 DiskDirectory::Read(const u32 count, Entry* entries) {
u32 entries_read = 0;
while (entries_read < count && children_iterator != directory.children.cend()) {
const FileUtil::FSTEntry& file = *children_iterator;
const Common::FS::FSTEntry& file = *children_iterator;
const std::string& filename = file.virtualName;
Entry& entry = entries[entries_read];
@ -80,7 +80,7 @@ u32 DiskDirectory::Read(const u32 count, Entry* entries) {
break;
}
FileUtil::SplitFilename83(filename, entry.short_name, entry.extension);
Common::FS::SplitFilename83(filename, entry.short_name, entry.extension);
entry.is_directory = file.isDirectory;
entry.is_hidden = (filename[0] == '.');

View File

@ -25,9 +25,9 @@ namespace FileSys {
class DiskFile : public FileBackend {
public:
DiskFile(FileUtil::IOFile&& file_, const Mode& mode_,
DiskFile(Common::FS::IOFile&& file_, const Mode& mode_,
std::unique_ptr<DelayGenerator> delay_generator_)
: file(new FileUtil::IOFile(std::move(file_))) {
: file(new Common::FS::IOFile(std::move(file_))) {
delay_generator = std::move(delay_generator_);
mode.hex = mode_.hex;
}
@ -45,7 +45,7 @@ public:
protected:
Mode mode;
std::unique_ptr<FileUtil::IOFile> file;
std::unique_ptr<Common::FS::IOFile> file;
private:
DiskFile() = default;
@ -74,11 +74,11 @@ public:
}
protected:
FileUtil::FSTEntry directory{};
Common::FS::FSTEntry directory{};
// We need to remember the last entry we returned, so a subsequent call to Read will continue
// from the next one. This iterator will always point to the next unread entry.
std::vector<FileUtil::FSTEntry>::iterator children_iterator;
std::vector<Common::FS::FSTEntry>::iterator children_iterator;
private:
DiskDirectory() = default;

View File

@ -140,17 +140,17 @@ std::string LayeredFS::ReadName(u32 offset, u32 name_length) {
}
void LayeredFS::LoadRelocations() {
if (!FileUtil::Exists(patch_path)) {
if (!Common::FS::Exists(patch_path)) {
return;
}
const FileUtil::DirectoryEntryCallable callback = [this,
const Common::FS::DirectoryEntryCallable callback = [this,
&callback](u64* /*num_entries_out*/,
const std::string& directory,
const std::string& virtual_name) {
auto* parent = directory_path_map.at(directory.substr(patch_path.size() - 1));
if (FileUtil::IsDirectory(directory + virtual_name + DIR_SEP)) {
if (Common::FS::IsDirectory(directory + virtual_name + DIR_SEP)) {
const auto path = (directory + virtual_name + DIR_SEP).substr(patch_path.size() - 1);
if (!directory_path_map.count(path)) { // Add this directory
auto directory = std::make_unique<Directory>();
@ -161,7 +161,7 @@ void LayeredFS::LoadRelocations() {
parent->directories.emplace_back(std::move(directory));
LOG_INFO(Service_FS, "LayeredFS created directory {}", path);
}
return FileUtil::ForeachDirectoryEntry(nullptr, directory + virtual_name + DIR_SEP,
return Common::FS::ForeachDirectoryEntry(nullptr, directory + virtual_name + DIR_SEP,
callback);
}
@ -179,16 +179,16 @@ void LayeredFS::LoadRelocations() {
auto* file = file_path_map.at(path);
file->relocation.type = 1;
file->relocation.replace_file_path = directory + virtual_name;
file->relocation.size = FileUtil::GetSize(directory + virtual_name);
file->relocation.size = Common::FS::GetSize(directory + virtual_name);
LOG_INFO(Service_FS, "LayeredFS replacement file in use for {}", path);
return true;
};
FileUtil::ForeachDirectoryEntry(nullptr, patch_path, callback);
Common::FS::ForeachDirectoryEntry(nullptr, patch_path, callback);
}
void LayeredFS::LoadExtRelocations() {
if (!FileUtil::Exists(patch_ext_path)) {
if (!Common::FS::Exists(patch_ext_path)) {
return;
}
@ -197,11 +197,11 @@ void LayeredFS::LoadExtRelocations() {
patch_ext_path.erase(patch_ext_path.size() - 1, 1);
}
FileUtil::FSTEntry result;
FileUtil::ScanDirectoryTree(patch_ext_path, result, 256);
Common::FS::FSTEntry result;
Common::FS::ScanDirectoryTree(patch_ext_path, result, 256);
for (const auto& entry : result.children) {
if (FileUtil::IsDirectory(entry.physicalName)) {
if (Common::FS::IsDirectory(entry.physicalName)) {
continue;
}
@ -230,7 +230,7 @@ void LayeredFS::LoadExtRelocations() {
continue;
}
FileUtil::IOFile patch_file(entry.physicalName, "rb");
Common::FS::IOFile patch_file(entry.physicalName, "rb");
if (!patch_file) {
LOG_ERROR(Service_FS, "LayeredFS Could not open file {}", entry.physicalName);
continue;
@ -522,7 +522,7 @@ std::size_t LayeredFS::ReadFile(std::size_t offset, std::size_t length, u8* buff
romfs->ReadFile(relocation.original_offset + relative_offset, to_read,
buffer + read_size);
} else if (relocation.type == 1) { // replace
FileUtil::IOFile replace_file(relocation.replace_file_path, "rb");
Common::FS::IOFile replace_file(relocation.replace_file_path, "rb");
if (replace_file) {
replace_file.Seek(relative_offset, SEEK_SET);
replace_file.ReadBytes(buffer + read_size, to_read);
@ -548,7 +548,7 @@ std::size_t LayeredFS::ReadFile(std::size_t offset, std::size_t length, u8* buff
}
bool LayeredFS::ExtractDirectory(Directory& current, const std::string& target_path) {
if (!FileUtil::CreateFullPath(target_path + current.path)) {
if (!Common::FS::CreateFullPath(target_path + current.path)) {
LOG_ERROR(Service_FS, "Could not create path {}", target_path + current.path);
return false;
}
@ -560,7 +560,7 @@ bool LayeredFS::ExtractDirectory(Directory& current, const std::string& target_p
const auto path = target_path + file->path;
LOG_INFO(Service_FS, "Extracting {} to {}", file->path, path);
FileUtil::IOFile target_file(path, "wb");
Common::FS::IOFile target_file(path, "wb");
if (!target_file) {
LOG_ERROR(Service_FS, "Could not open file {}", path);
return false;

View File

@ -116,7 +116,7 @@ static bool LZSS_Decompress(const u8* compressed, u32 compressed_size, u8* decom
NCCHContainer::NCCHContainer(const std::string& filepath, u32 ncch_offset, u32 partition)
: ncch_offset(ncch_offset), partition(partition), filepath(filepath) {
file = FileUtil::IOFile(filepath, "rb");
file = Common::FS::IOFile(filepath, "rb");
}
Loader::ResultStatus NCCHContainer::OpenFile(const std::string& filepath, u32 ncch_offset,
@ -124,7 +124,7 @@ Loader::ResultStatus NCCHContainer::OpenFile(const std::string& filepath, u32 nc
this->filepath = filepath;
this->ncch_offset = ncch_offset;
this->partition = partition;
file = FileUtil::IOFile(filepath, "rb");
file = Common::FS::IOFile(filepath, "rb");
if (!file.IsOpen()) {
LOG_WARNING(Service_FS, "Failed to open {}", filepath);
@ -330,7 +330,7 @@ Loader::ResultStatus NCCHContainer::Load() {
// System archives and DLC don't have an extended header but have RomFS
if (ncch_header.extended_header_size) {
auto read_exheader = [this](FileUtil::IOFile& file) {
auto read_exheader = [this](Common::FS::IOFile& file) {
const std::size_t size = sizeof(exheader_header);
return file && file.ReadBytes(&exheader_header, size) == size;
};
@ -360,7 +360,7 @@ Loader::ResultStatus NCCHContainer::Load() {
}
const auto mods_path =
fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
fmt::format("{}mods/{:016X}/", Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
GetModId(ncch_header.program_id));
const std::array<std::string, 2> exheader_override_paths{{
mods_path + "exheader.bin",
@ -369,7 +369,7 @@ Loader::ResultStatus NCCHContainer::Load() {
bool has_exheader_override = false;
for (const auto& path : exheader_override_paths) {
FileUtil::IOFile exheader_override_file{path, "rb"};
Common::FS::IOFile exheader_override_file{path, "rb"};
if (read_exheader(exheader_override_file)) {
has_exheader_override = true;
break;
@ -430,7 +430,7 @@ Loader::ResultStatus NCCHContainer::Load() {
.ProcessData(data, data, sizeof(exefs_header));
}
exefs_file = FileUtil::IOFile(filepath, "rb");
exefs_file = Common::FS::IOFile(filepath, "rb");
has_exefs = true;
}
@ -451,15 +451,15 @@ Loader::ResultStatus NCCHContainer::Load() {
Loader::ResultStatus NCCHContainer::LoadOverrides() {
// Check for split-off files, mark the archive as tainted if we will use them
std::string romfs_override = filepath + ".romfs";
if (FileUtil::Exists(romfs_override)) {
if (Common::FS::Exists(romfs_override)) {
is_tainted = true;
}
// If we have a split-off exefs file/folder, it takes priority
std::string exefs_override = filepath + ".exefs";
std::string exefsdir_override = filepath + ".exefsdir/";
if (FileUtil::Exists(exefs_override)) {
exefs_file = FileUtil::IOFile(exefs_override, "rb");
if (Common::FS::Exists(exefs_override)) {
exefs_file = Common::FS::IOFile(exefs_override, "rb");
if (exefs_file.ReadBytes(&exefs_header, sizeof(ExeFs_Header)) == sizeof(ExeFs_Header)) {
LOG_DEBUG(Service_FS, "Loading ExeFS section from {}", exefs_override);
@ -467,9 +467,9 @@ Loader::ResultStatus NCCHContainer::LoadOverrides() {
is_tainted = true;
has_exefs = true;
} else {
exefs_file = FileUtil::IOFile(filepath, "rb");
exefs_file = Common::FS::IOFile(filepath, "rb");
}
} else if (FileUtil::Exists(exefsdir_override) && FileUtil::IsDirectory(exefsdir_override)) {
} else if (Common::FS::Exists(exefsdir_override) && Common::FS::IsDirectory(exefsdir_override)) {
is_tainted = true;
}
@ -585,7 +585,7 @@ Loader::ResultStatus NCCHContainer::ApplyCodePatch(std::vector<u8>& code) const
};
const auto mods_path =
fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
fmt::format("{}mods/{:016X}/", Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
GetModId(ncch_header.program_id));
const std::array<PatchLocation, 6> patch_paths{{
{mods_path + "exefs/code.ips", Patch::ApplyIpsPatch},
@ -597,7 +597,7 @@ Loader::ResultStatus NCCHContainer::ApplyCodePatch(std::vector<u8>& code) const
}};
for (const PatchLocation& info : patch_paths) {
FileUtil::IOFile file{info.path, "rb"};
Common::FS::IOFile file{info.path, "rb"};
if (!file)
continue;
@ -631,7 +631,7 @@ Loader::ResultStatus NCCHContainer::LoadOverrideExeFSSection(const char* name,
return Loader::ResultStatus::Error;
const auto mods_path =
fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
fmt::format("{}mods/{:016X}/", Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
GetModId(ncch_header.program_id));
const std::array<std::string, 3> override_paths{{
mods_path + "exefs/" + override_name,
@ -640,7 +640,7 @@ Loader::ResultStatus NCCHContainer::LoadOverrideExeFSSection(const char* name,
}};
for (const auto& path : override_paths) {
FileUtil::IOFile section_file(path, "rb");
Common::FS::IOFile section_file(path, "rb");
if (section_file.IsOpen()) {
auto section_size = section_file.GetSize();
@ -683,7 +683,7 @@ Loader::ResultStatus NCCHContainer::ReadRomFS(std::shared_ptr<RomFSReader>& romf
return Loader::ResultStatus::Error;
// We reopen the file, to allow its position to be independent from file's
FileUtil::IOFile romfs_file_inner(filepath, "rb");
Common::FS::IOFile romfs_file_inner(filepath, "rb");
if (!romfs_file_inner.IsOpen())
return Loader::ResultStatus::Error;
@ -698,10 +698,10 @@ Loader::ResultStatus NCCHContainer::ReadRomFS(std::shared_ptr<RomFSReader>& romf
}
const auto path =
fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
fmt::format("{}mods/{:016X}/", Common::FS::GetUserPath(Common::FS::UserPath::LoadDir),
GetModId(ncch_header.program_id));
if (use_layered_fs &&
(FileUtil::Exists(path + "romfs/") || FileUtil::Exists(path + "romfs_ext/"))) {
(Common::FS::Exists(path + "romfs/") || Common::FS::Exists(path + "romfs_ext/"))) {
romfs_file = std::make_shared<LayeredFS>(std::move(direct_romfs), path + "romfs/",
path + "romfs_ext/");
@ -730,8 +730,8 @@ Loader::ResultStatus NCCHContainer::DumpRomFS(const std::string& target_path) {
Loader::ResultStatus NCCHContainer::ReadOverrideRomFS(std::shared_ptr<RomFSReader>& romfs_file) {
// Check for RomFS overrides
std::string split_filepath = filepath + ".romfs";
if (FileUtil::Exists(split_filepath)) {
FileUtil::IOFile romfs_file_inner(split_filepath, "rb");
if (Common::FS::Exists(split_filepath)) {
Common::FS::IOFile romfs_file_inner(split_filepath, "rb");
if (romfs_file_inner.IsOpen()) {
LOG_WARNING(Service_FS, "File {} overriding built-in RomFS; LayeredFS not enabled",
split_filepath);

View File

@ -368,8 +368,8 @@ private:
u32 partition = 0;
std::string filepath;
FileUtil::IOFile file;
FileUtil::IOFile exefs_file;
Common::FS::IOFile file;
Common::FS::IOFile exefs_file;
};
} // namespace FileSys

View File

@ -59,7 +59,7 @@ PathParser::PathParser(const Path& path) {
PathParser::HostStatus PathParser::GetHostStatus(std::string_view mount_point) const {
std::string path{mount_point};
if (!FileUtil::IsDirectory(path))
if (!Common::FS::IsDirectory(path))
return InvalidMountPoint;
if (path_sequence.empty()) {
return DirectoryFound;
@ -70,17 +70,17 @@ PathParser::HostStatus PathParser::GetHostStatus(std::string_view mount_point) c
path += '/';
path += *iter;
if (!FileUtil::Exists(path))
if (!Common::FS::Exists(path))
return PathNotFound;
if (FileUtil::IsDirectory(path))
if (Common::FS::IsDirectory(path))
continue;
return FileInPath;
}
path += "/" + path_sequence.back();
if (!FileUtil::Exists(path))
if (!Common::FS::Exists(path))
return NotFound;
if (FileUtil::IsDirectory(path))
if (Common::FS::IsDirectory(path))
return DirectoryFound;
return FileFound;
}

View File

@ -30,11 +30,11 @@ private:
*/
class DirectRomFSReader : public RomFSReader {
public:
DirectRomFSReader(FileUtil::IOFile&& file, std::size_t file_offset, std::size_t data_size)
DirectRomFSReader(Common::FS::IOFile&& file, std::size_t file_offset, std::size_t data_size)
: is_encrypted(false), file(std::move(file)), file_offset(file_offset),
data_size(data_size) {}
DirectRomFSReader(FileUtil::IOFile&& file, std::size_t file_offset, std::size_t data_size,
DirectRomFSReader(Common::FS::IOFile&& file, std::size_t file_offset, std::size_t data_size,
const std::array<u8, 16>& key, const std::array<u8, 16>& ctr,
std::size_t crypto_offset)
: is_encrypted(true), file(std::move(file)), key(key), ctr(ctr), file_offset(file_offset),
@ -50,7 +50,7 @@ public:
private:
bool is_encrypted;
FileUtil::IOFile file;
Common::FS::IOFile file;
std::array<u8, 16> key;
std::array<u8, 16> ctr;
u64 file_offset;

View File

@ -79,14 +79,14 @@ ResultVal<std::unique_ptr<FileBackend>> SaveDataArchive::OpenFile(const Path& pa
return ERROR_FILE_NOT_FOUND;
} else {
// Create the file
FileUtil::CreateEmptyFile(full_path);
Common::FS::CreateEmptyFile(full_path);
}
break;
case PathParser::FileFound:
break; // Expected 'success' case
}
FileUtil::IOFile file(full_path, mode.write_flag ? "r+b" : "rb");
Common::FS::IOFile file(full_path, mode.write_flag ? "r+b" : "rb");
if (!file.IsOpen()) {
LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path);
return ERROR_FILE_NOT_FOUND;
@ -123,7 +123,7 @@ ResultCode SaveDataArchive::DeleteFile(const Path& path) const {
break; // Expected 'success' case
}
if (FileUtil::Delete(full_path)) {
if (Common::FS::Delete(full_path)) {
return RESULT_SUCCESS;
}
@ -150,7 +150,7 @@ ResultCode SaveDataArchive::RenameFile(const Path& src_path, const Path& dest_pa
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
if (FileUtil::Rename(src_path_full, dest_path_full)) {
if (Common::FS::Rename(src_path_full, dest_path_full)) {
return RESULT_SUCCESS;
}
@ -200,12 +200,12 @@ static ResultCode DeleteDirectoryHelper(const Path& path, const std::string& mou
}
ResultCode SaveDataArchive::DeleteDirectory(const Path& path) const {
return DeleteDirectoryHelper(path, mount_point, FileUtil::DeleteDir);
return DeleteDirectoryHelper(path, mount_point, Common::FS::DeleteDir);
}
ResultCode SaveDataArchive::DeleteDirectoryRecursively(const Path& path) const {
return DeleteDirectoryHelper(
path, mount_point, [](const std::string& p) { return FileUtil::DeleteDirRecursively(p); });
path, mount_point, [](const std::string& p) { return Common::FS::DeleteDirRecursively(p); });
}
ResultCode SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) const {
@ -237,11 +237,11 @@ ResultCode SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) cons
}
if (size == 0) {
FileUtil::CreateEmptyFile(full_path);
Common::FS::CreateEmptyFile(full_path);
return RESULT_SUCCESS;
}
FileUtil::IOFile file(full_path, "wb");
Common::FS::IOFile file(full_path, "wb");
// Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
// We do this by seeking to the right size, then writing a single null byte.
if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) {
@ -281,7 +281,7 @@ ResultCode SaveDataArchive::CreateDirectory(const Path& path) const {
break; // Expected 'success' case
}
if (FileUtil::CreateDir(mount_point + path.AsString())) {
if (Common::FS::CreateDir(mount_point + path.AsString())) {
return RESULT_SUCCESS;
}
@ -309,7 +309,7 @@ ResultCode SaveDataArchive::RenameDirectory(const Path& src_path, const Path& de
const auto src_path_full = path_parser_src.BuildHostPath(mount_point);
const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point);
if (FileUtil::Rename(src_path_full, dest_path_full)) {
if (Common::FS::Rename(src_path_full, dest_path_full)) {
return RESULT_SUCCESS;
}

View File

@ -12,9 +12,9 @@ namespace FileSys {
bool SeedDB::Load() {
seeds.clear();
const std::string path{
fmt::format("{}/seeddb.bin", FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir))};
if (!FileUtil::Exists(path)) {
if (!FileUtil::CreateFullPath(path)) {
fmt::format("{}/seeddb.bin", Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir))};
if (!Common::FS::Exists(path)) {
if (!Common::FS::CreateFullPath(path)) {
LOG_ERROR(Service_FS, "Failed to create seed database");
return false;
}
@ -24,7 +24,7 @@ bool SeedDB::Load() {
}
return true;
}
FileUtil::IOFile file{path, "rb"};
Common::FS::IOFile file{path, "rb"};
if (!file.IsOpen()) {
LOG_ERROR(Service_FS, "Failed to open seed database");
return false;
@ -59,12 +59,12 @@ bool SeedDB::Load() {
bool SeedDB::Save() {
const std::string path{
fmt::format("{}/seeddb.bin", FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir))};
if (!FileUtil::CreateFullPath(path)) {
fmt::format("{}/seeddb.bin", Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir))};
if (!Common::FS::CreateFullPath(path)) {
LOG_ERROR(Service_FS, "Failed to create seed database");
return false;
}
FileUtil::IOFile file{path, "wb"};
Common::FS::IOFile file{path, "wb"};
if (!file.IsOpen()) {
LOG_ERROR(Service_FS, "Failed to open seed database");
return false;

View File

@ -17,7 +17,7 @@
namespace FileSys {
Loader::ResultStatus TitleMetadata::Load(const std::string& file_path) {
FileUtil::IOFile file(file_path, "rb");
Common::FS::IOFile file(file_path, "rb");
if (!file.IsOpen())
return Loader::ResultStatus::Error;
@ -78,7 +78,7 @@ Loader::ResultStatus TitleMetadata::Load(const std::vector<u8>& file_data, std::
}
Loader::ResultStatus TitleMetadata::Save(const std::string& file_path) {
FileUtil::IOFile file(file_path, "wb");
Common::FS::IOFile file(file_path, "wb");
if (!file.IsOpen())
return Loader::ResultStatus::Error;

View File

@ -18,7 +18,7 @@ void MiiSelector::Finalize(u32 return_code, HLE::Applets::MiiData mii) {
std::vector<HLE::Applets::MiiData> LoadMiis() {
std::vector<HLE::Applets::MiiData> miis;
std::string nand_directory{FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)};
std::string nand_directory{Common::FS::GetUserPath(Common::FS::UserPath::NANDDir)};
FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
auto archive_result = extdata_archive_factory.Open(Service::PTM::ptm_shared_extdata_id, 0);

View File

@ -107,7 +107,7 @@ ResultCode CIAFile::WriteTitleMetadata() {
// If a TMD already exists for this app (ie 00000000.tmd), the incoming TMD
// will be the same plus one, (ie 00000001.tmd), both will be kept until
// the install is finalized and old contents can be discarded.
if (FileUtil::Exists(GetTitleMetadataPath(media_type, tmd.GetTitleID())))
if (Common::FS::Exists(GetTitleMetadataPath(media_type, tmd.GetTitleID())))
is_update = true;
std::string tmd_path = GetTitleMetadataPath(media_type, tmd.GetTitleID(), is_update);
@ -115,7 +115,7 @@ ResultCode CIAFile::WriteTitleMetadata() {
// Create content/ folder if it doesn't exist
std::string tmd_folder;
Common::SplitPath(tmd_path, &tmd_folder, nullptr, nullptr);
FileUtil::CreateFullPath(tmd_folder);
Common::FS::CreateFullPath(tmd_folder);
// Save TMD so that we can start getting new .app paths
if (tmd.Save(tmd_path) != Loader::ResultStatus::Success)
@ -126,7 +126,7 @@ ResultCode CIAFile::WriteTitleMetadata() {
Common::SplitPath(GetTitleContentPath(media_type, tmd.GetTitleID(),
FileSys::TMDContentIndex::Main, is_update),
&app_folder, nullptr, nullptr);
FileUtil::CreateFullPath(app_folder);
Common::FS::CreateFullPath(app_folder);
auto content_count = container.GetTitleMetadata().GetContentCount();
content_written.resize(content_count);
@ -169,7 +169,7 @@ ResultVal<std::size_t> CIAFile::WriteContentData(u64 offset, std::size_t length,
// Since the incoming TMD has already been written, we can use GetTitleContentPath
// to get the content paths to write to.
FileSys::TitleMetadata tmd = container.GetTitleMetadata();
FileUtil::IOFile file(GetTitleContentPath(media_type, tmd.GetTitleID(), i, is_update),
Common::FS::IOFile file(GetTitleContentPath(media_type, tmd.GetTitleID(), i, is_update),
content_written[i] ? "ab" : "wb");
if (!file.IsOpen()) {
@ -285,7 +285,7 @@ bool CIAFile::Close() const {
// Install aborted
if (!complete) {
LOG_ERROR(Service_AM, "CIAFile closed prematurely, aborting install...");
FileUtil::DeleteDir(GetTitlePath(media_type, container.GetTitleMetadata().GetTitleID()));
Common::FS::DeleteDir(GetTitlePath(media_type, container.GetTitleMetadata().GetTitleID()));
return true;
}
@ -294,7 +294,7 @@ bool CIAFile::Close() const {
GetTitleMetadataPath(media_type, container.GetTitleMetadata().GetTitleID(), false);
std::string new_tmd_path =
GetTitleMetadataPath(media_type, container.GetTitleMetadata().GetTitleID(), true);
if (FileUtil::Exists(new_tmd_path) && old_tmd_path != new_tmd_path) {
if (Common::FS::Exists(new_tmd_path) && old_tmd_path != new_tmd_path) {
FileSys::TitleMetadata old_tmd;
FileSys::TitleMetadata new_tmd;
@ -315,10 +315,10 @@ bool CIAFile::Close() const {
if (abort)
break;
FileUtil::Delete(GetTitleContentPath(media_type, old_tmd.GetTitleID(), old_index));
Common::FS::Delete(GetTitleContentPath(media_type, old_tmd.GetTitleID(), old_index));
}
FileUtil::Delete(old_tmd_path);
Common::FS::Delete(old_tmd_path);
}
return true;
}
@ -329,7 +329,7 @@ InstallStatus InstallCIA(const std::string& path,
std::function<ProgressCallback>&& update_callback) {
LOG_INFO(Service_AM, "Installing {}...", path);
if (!FileUtil::Exists(path)) {
if (!Common::FS::Exists(path)) {
LOG_ERROR(Service_AM, "File {} does not exist!", path);
return InstallStatus::ErrorFileNotFound;
}
@ -350,7 +350,7 @@ InstallStatus InstallCIA(const std::string& path,
}
}
FileUtil::IOFile file(path, "rb");
Common::FS::IOFile file(path, "rb");
if (!file.IsOpen())
return InstallStatus::ErrorFailedToOpenFile;
@ -374,11 +374,11 @@ InstallStatus InstallCIA(const std::string& path,
LOG_INFO(Service_AM, "Installed {} successfully.", path);
const FileUtil::DirectoryEntryCallable callback =
const Common::FS::DirectoryEntryCallable callback =
[&callback](u64* num_entries_out, const std::string& directory,
const std::string& virtual_name) -> bool {
const std::string physical_name = directory + DIR_SEP + virtual_name;
const bool is_dir = FileUtil::IsDirectory(physical_name);
const bool is_dir = Common::FS::IsDirectory(physical_name);
if (!is_dir) {
std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(physical_name);
if (!loader) {
@ -392,10 +392,10 @@ InstallStatus InstallCIA(const std::string& path,
}
return true;
} else {
return FileUtil::ForeachDirectoryEntry(nullptr, physical_name, callback);
return Common::FS::ForeachDirectoryEntry(nullptr, physical_name, callback);
}
};
if (!FileUtil::ForeachDirectoryEntry(
if (!Common::FS::ForeachDirectoryEntry(
nullptr,
GetTitlePath(
Service::AM::GetTitleMediaType(container.GetTitleMetadata().GetTitleID()),
@ -439,9 +439,9 @@ std::string GetTitleMetadataPath(Service::FS::MediaType media_type, u64 tid, boo
constexpr u32 MAX_TMD_ID = 0xFFFFFFFF;
u32 base_id = MAX_TMD_ID;
u32 update_id = 0;
FileUtil::FSTEntry entries;
FileUtil::ScanDirectoryTree(content_path, entries);
for (const FileUtil::FSTEntry& entry : entries.children) {
Common::FS::FSTEntry entries;
Common::FS::ScanDirectoryTree(content_path, entries);
for (const Common::FS::FSTEntry& entry : entries.children) {
std::string filename_filename, filename_extension;
Common::SplitPath(entry.virtualName, nullptr, &filename_filename, &filename_extension);
@ -522,12 +522,12 @@ std::string GetTitlePath(Service::FS::MediaType media_type, u64 tid) {
std::string GetMediaTitlePath(Service::FS::MediaType media_type) {
if (media_type == Service::FS::MediaType::NAND)
return fmt::format("{}{}/title/", FileUtil::GetUserPath(FileUtil::UserPath::NANDDir),
return fmt::format("{}{}/title/", Common::FS::GetUserPath(Common::FS::UserPath::NANDDir),
SYSTEM_ID);
if (media_type == Service::FS::MediaType::SDMC)
return fmt::format("{}Nintendo 3DS/{}/{}/title/",
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), SYSTEM_ID,
Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir), SYSTEM_ID,
SDCARD_ID);
if (media_type == Service::FS::MediaType::GameCard) {
@ -546,10 +546,10 @@ void Module::ScanForTitles(Service::FS::MediaType media_type) {
std::string title_path = GetMediaTitlePath(media_type);
FileUtil::FSTEntry entries;
FileUtil::ScanDirectoryTree(title_path, entries, 1);
for (const FileUtil::FSTEntry& tid_high : entries.children) {
for (const FileUtil::FSTEntry& tid_low : tid_high.children) {
Common::FS::FSTEntry entries;
Common::FS::ScanDirectoryTree(title_path, entries, 1);
for (const Common::FS::FSTEntry& tid_high : entries.children) {
for (const Common::FS::FSTEntry& tid_low : tid_high.children) {
std::string tid_string = tid_high.virtualName + tid_low.virtualName;
if (tid_string.length() == TITLE_ID_VALID_LENGTH) {
@ -632,7 +632,7 @@ void Module::Interface::FindDLCContentInfos(Kernel::HLERequestContext& ctx) {
content_info.ownership =
OWNERSHIP_OWNED; // TODO(Steveice10): Pull this from the ticket.
if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, content_requested[i]))) {
if (Common::FS::Exists(GetTitleContentPath(media_type, title_id, content_requested[i]))) {
content_info.ownership |= OWNERSHIP_DOWNLOADED;
}
@ -684,7 +684,7 @@ void Module::Interface::ListDLCContentInfos(Kernel::HLERequestContext& ctx) {
content_info.ownership =
OWNERSHIP_OWNED; // TODO(Steveice10): Pull this from the ticket.
if (FileUtil::Exists(GetTitleContentPath(media_type, title_id, i))) {
if (Common::FS::Exists(GetTitleContentPath(media_type, title_id, i))) {
content_info.ownership |= OWNERSHIP_DOWNLOADED;
}
@ -802,17 +802,17 @@ void Module::Interface::DeleteUserProgram(Kernel::HLERequestContext& ctx) {
}
LOG_INFO(Service_AM, "Deleting title 0x{:016x}", title_id);
std::string path = GetTitlePath(media_type, title_id);
if (!FileUtil::Exists(path)) {
if (!Common::FS::Exists(path)) {
rb.Push(ResultCode(ErrorDescription::NotFound, ErrorModule::AM, ErrorSummary::InvalidState,
ErrorLevel::Permanent));
LOG_ERROR(Service_AM, "Title not found");
return;
}
bool success = FileUtil::DeleteDirRecursively(path);
bool success = Common::FS::DeleteDirRecursively(path);
am->ScanForAllTitles();
rb.Push(RESULT_SUCCESS);
if (!success)
LOG_ERROR(Service_AM, "FileUtil::DeleteDirRecursively unexpectedly failed");
LOG_ERROR(Service_AM, "Common::FS::DeleteDirRecursively unexpectedly failed");
}
void Module::Interface::GetProductCode(Kernel::HLERequestContext& ctx) {
@ -821,7 +821,7 @@ void Module::Interface::GetProductCode(Kernel::HLERequestContext& ctx) {
u64 title_id = rp.Pop<u64>();
std::string path = GetTitleContentPath(media_type, title_id);
if (!FileUtil::Exists(path)) {
if (!Common::FS::Exists(path)) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultCode(ErrorDescription::NotFound, ErrorModule::AM, ErrorSummary::InvalidState,
ErrorLevel::Permanent));
@ -1016,7 +1016,7 @@ void Module::Interface::CheckContentRights(Kernel::HLERequestContext& ctx) {
// TODO(shinyquagsire23): Read tickets for this instead?
bool has_rights =
FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index));
Common::FS::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index));
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS); // No error
@ -1032,7 +1032,7 @@ void Module::Interface::CheckContentRightsIgnorePlatform(Kernel::HLERequestConte
// TODO(shinyquagsire23): Read tickets for this instead?
bool has_rights =
FileUtil::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index));
Common::FS::Exists(GetTitleContentPath(Service::FS::MediaType::SDMC, tid, content_index));
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS); // No error
@ -1396,17 +1396,17 @@ void Module::Interface::DeleteProgram(Kernel::HLERequestContext& ctx) {
LOG_INFO(Service_AM, "Deleting title 0x{:016x}", title_id);
std::string path = GetTitlePath(media_type, title_id);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
if (!FileUtil::Exists(path)) {
if (!Common::FS::Exists(path)) {
rb.Push(ResultCode(ErrorDescription::NotFound, ErrorModule::AM, ErrorSummary::InvalidState,
ErrorLevel::Permanent));
LOG_ERROR(Service_AM, "Title not found");
return;
}
bool success = FileUtil::DeleteDirRecursively(path);
bool success = Common::FS::DeleteDirRecursively(path);
am->ScanForAllTitles();
rb.Push(RESULT_SUCCESS);
if (!success)
LOG_ERROR(Service_AM, "FileUtil::DeleteDirRecursively unexpectedly failed");
LOG_ERROR(Service_AM, "Common::FS::DeleteDirRecursively unexpectedly failed");
}
void Module::Interface::GetSystemUpdaterMutex(Kernel::HLERequestContext& ctx) {

View File

@ -213,10 +213,10 @@ bool Module::LoadLegacySharedFont() {
// generated by the APT:U service. The best way to get is by dumping it from RAM. We've provided
// a homebrew app to do this: https://github.com/citra-emu/3dsutils. Put the resulting file
// "shared_font.bin" in the Citra "sysdata" directory.
std::string filepath = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + SHARED_FONT;
std::string filepath = Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir) + SHARED_FONT;
FileUtil::CreateFullPath(filepath); // Create path if not already created
FileUtil::IOFile file(filepath, "rb");
Common::FS::CreateFullPath(filepath); // Create path if not already created
Common::FS::IOFile file(filepath, "rb");
if (file.IsOpen()) {
file.ReadBytes(shared_font_mem->GetPointer(), file.GetSize());
return true;

View File

@ -1380,7 +1380,7 @@ Module::Module(Core::System& system) : system(system) {
change_state_event =
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "CECD::change_state_event");
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
const std::string& nand_directory = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory);
// Open the SystemSaveData archive 0x00010026

View File

@ -560,7 +560,7 @@ ResultCode Module::FormatConfig() {
} // namespace Service::CFG
ResultCode Module::LoadConfigNANDSaveFile() {
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
const std::string& nand_directory = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory);
// Open the SystemSaveData archive 0x00010017

View File

@ -32,10 +32,10 @@
namespace Service::FS {
MediaType GetMediaTypeFromPath(std::string_view path) {
if (path.rfind(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), 0) == 0) {
if (path.rfind(Common::FS::GetUserPath(Common::FS::UserPath::NANDDir), 0) == 0) {
return MediaType::NAND;
}
if (path.rfind(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), 0) == 0) {
if (path.rfind(Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir), 0) == 0) {
return MediaType::SDMC;
}
return MediaType::GameCard;
@ -263,9 +263,9 @@ ResultCode ArchiveManager::DeleteExtSaveData(MediaType media_type, u32 high, u32
std::string media_type_directory;
if (media_type == MediaType::NAND) {
media_type_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
media_type_directory = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
} else if (media_type == MediaType::SDMC) {
media_type_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
media_type_directory = Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir);
} else {
LOG_ERROR(Service_FS, "Unsupported media type {}", media_type);
return ResultCode(-1); // TODO(Subv): Find the right error code
@ -275,7 +275,7 @@ ResultCode ArchiveManager::DeleteExtSaveData(MediaType media_type, u32 high, u32
std::string base_path =
FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND);
std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path);
if (FileUtil::Exists(extsavedata_path) && !FileUtil::DeleteDirRecursively(extsavedata_path))
if (Common::FS::Exists(extsavedata_path) && !Common::FS::DeleteDirRecursively(extsavedata_path))
return ResultCode(-1); // TODO(Subv): Find the right error code
return RESULT_SUCCESS;
}
@ -284,10 +284,10 @@ ResultCode ArchiveManager::DeleteSystemSaveData(u32 high, u32 low) {
// Construct the binary path to the archive first
const FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
const std::string& nand_directory = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
const std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
const std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
if (!FileUtil::DeleteDirRecursively(systemsavedata_path)) {
if (!Common::FS::DeleteDirRecursively(systemsavedata_path)) {
return ResultCode(-1); // TODO(Subv): Find the right error code
}
@ -298,10 +298,10 @@ ResultCode ArchiveManager::CreateSystemSaveData(u32 high, u32 low) {
// Construct the binary path to the archive first
const FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
const std::string& nand_directory = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
const std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
const std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
if (!FileUtil::CreateFullPath(systemsavedata_path)) {
if (!Common::FS::CreateFullPath(systemsavedata_path)) {
return ResultCode(-1); // TODO(Subv): Find the right error code
}
@ -322,8 +322,8 @@ void ArchiveManager::RegisterArchiveTypes() {
// TODO(Subv): Add the other archive types (see here for the known types:
// http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes).
std::string sdmc_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
std::string sdmc_directory = Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir);
std::string nand_directory = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
auto sdmc_factory = std::make_unique<FileSys::ArchiveFactory_SDMC>(sdmc_directory);
if (sdmc_factory->Initialize())
RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC);

View File

@ -134,7 +134,7 @@ void Module::Interface::CheckNew3DS(Kernel::HLERequestContext& ctx) {
}
static void WriteGameCoinData(GameCoin gamecoin_data) {
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
const std::string& nand_directory = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
FileSys::Path archive_path(ptm_shared_extdata_id);
@ -167,7 +167,7 @@ static void WriteGameCoinData(GameCoin gamecoin_data) {
}
static GameCoin ReadGameCoinData() {
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
const std::string& nand_directory = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
FileSys::Path archive_path(ptm_shared_extdata_id);
@ -197,7 +197,7 @@ static GameCoin ReadGameCoinData() {
Module::Module() {
// Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't
// exist
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
const std::string& nand_directory = Common::FS::GetUserPath(Common::FS::UserPath::NANDDir);
FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
const FileSys::Path archive_path(ptm_shared_extdata_id);
const auto archive_result = extdata_archive_factory.Open(archive_path, 0);

View File

@ -159,8 +159,8 @@ void LoadBootromKeys() {
// by other applications e.g. process9. These normal keys thus aren't used by any application
// and have no value for emulation
const std::string filepath = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + BOOTROM9;
auto file = FileUtil::IOFile(filepath, "rb");
const std::string filepath = Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir) + BOOTROM9;
auto file = Common::FS::IOFile(filepath, "rb");
if (!file) {
return;
}
@ -310,8 +310,8 @@ void LoadNativeFirmKeysNew3DS() {
// The first 0x10 bytes of the secret_sector are used as a key to decrypt a KeyX from the
// native_firm
const std::string filepath =
FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + SECRET_SECTOR;
auto secret = FileUtil::IOFile(filepath, "rb");
Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir) + SECRET_SECTOR;
auto secret = Common::FS::IOFile(filepath, "rb");
if (!secret) {
return;
}
@ -426,8 +426,8 @@ void LoadNativeFirmKeysNew3DS() {
}
void LoadPresetKeys() {
const std::string filepath = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + AES_KEYS;
FileUtil::CreateFullPath(filepath); // Create path if not already created
const std::string filepath = Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir) + AES_KEYS;
Common::FS::CreateFullPath(filepath); // Create path if not already created
std::ifstream file;
OpenFStream(file, filepath, std::ios_base::in);
if (!file) {

View File

@ -52,8 +52,8 @@ void InitSlots() {
return;
initialized = true;
const std::string filepath = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + BOOTROM9;
FileUtil::IOFile file(filepath, "rb");
const std::string filepath = Common::FS::GetUserPath(Common::FS::UserPath::SysDataDir) + BOOTROM9;
Common::FS::IOFile file(filepath, "rb");
if (!file) {
return;
}

View File

@ -94,7 +94,7 @@ static u32 TranslateAddr(u32 addr, const THREEloadinfo* loadinfo, u32* offsets)
using Kernel::CodeSet;
static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr,
static THREEDSX_Error Load3DSXFile(Common::FS::IOFile& file, u32 base_addr,
std::shared_ptr<CodeSet>* out_codeset) {
if (!file.IsOpen())
return ERROR_FILE;
@ -248,7 +248,7 @@ static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr,
return ERROR_NONE;
}
FileType AppLoader_THREEDSX::IdentifyType(FileUtil::IOFile& file) {
FileType AppLoader_THREEDSX::IdentifyType(Common::FS::IOFile& file) {
u32 magic;
file.Seek(0, SEEK_SET);
if (1 != file.ReadArray<u32>(&magic, 1))
@ -315,7 +315,7 @@ ResultStatus AppLoader_THREEDSX::ReadRomFS(std::shared_ptr<FileSys::RomFSReader>
LOG_DEBUG(Loader, "RomFS size: {:#010X}", romfs_size);
// We reopen the file, to allow its position to be independent from file's
FileUtil::IOFile romfs_file_inner(filepath, "rb");
Common::FS::IOFile romfs_file_inner(filepath, "rb");
if (!romfs_file_inner.IsOpen())
return ResultStatus::Error;

View File

@ -17,16 +17,16 @@ namespace Loader {
/// Loads an 3DSX file
class AppLoader_THREEDSX final : public AppLoader {
public:
AppLoader_THREEDSX(FileUtil::IOFile&& file, const std::string& filename,
AppLoader_THREEDSX(Common::FS::IOFile&& file, const std::string& filename,
const std::string& filepath)
: AppLoader(std::move(file)), filename(std::move(filename)), filepath(filepath) {}
/**
* Returns the type of the file
* @param file FileUtil::IOFile open file
* @param file Common::FS::IOFile open file
* @return FileType found, or FileType::Error if this loader doesn't know it
*/
static FileType IdentifyType(FileUtil::IOFile& file);
static FileType IdentifyType(Common::FS::IOFile& file);
FileType GetFileType() override {
return IdentifyType(file);

View File

@ -364,7 +364,7 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const
namespace Loader {
FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file) {
FileType AppLoader_ELF::IdentifyType(Common::FS::IOFile& file) {
u32 magic;
file.Seek(0, SEEK_SET);
if (1 != file.ReadArray<u32>(&magic, 1))

View File

@ -17,15 +17,15 @@ namespace Loader {
/// Loads an ELF/AXF file
class AppLoader_ELF final : public AppLoader {
public:
AppLoader_ELF(FileUtil::IOFile&& file, std::string filename)
AppLoader_ELF(Common::FS::IOFile&& file, std::string filename)
: AppLoader(std::move(file)), filename(std::move(filename)) {}
/**
* Returns the type of the file
* @param file FileUtil::IOFile open file
* @param file Common::FS::IOFile open file
* @return FileType found, or FileType::Error if this loader doesn't know it
*/
static FileType IdentifyType(FileUtil::IOFile& file);
static FileType IdentifyType(Common::FS::IOFile& file);
FileType GetFileType() override {
return IdentifyType(file);

View File

@ -15,7 +15,7 @@
namespace Loader {
FileType IdentifyFile(FileUtil::IOFile& file) {
FileType IdentifyFile(Common::FS::IOFile& file) {
FileType type;
#define CHECK_TYPE(loader) \
@ -33,7 +33,7 @@ FileType IdentifyFile(FileUtil::IOFile& file) {
}
FileType IdentifyFile(const std::string& file_name) {
FileUtil::IOFile file(file_name, "rb");
Common::FS::IOFile file(file_name, "rb");
if (!file.IsOpen()) {
LOG_ERROR(Loader, "Failed to load file {}", file_name);
return FileType::Unknown;
@ -91,7 +91,7 @@ const char* GetFileTypeString(FileType type) {
* @param filepath the file full path (with name)
* @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type
*/
static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileType type,
static std::unique_ptr<AppLoader> GetFileLoader(Common::FS::IOFile&& file, FileType type,
const std::string& filename,
const std::string& filepath) {
switch (type) {
@ -115,7 +115,7 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileTyp
}
std::unique_ptr<AppLoader> GetLoader(const std::string& filename) {
FileUtil::IOFile file(filename, "rb");
Common::FS::IOFile file(filename, "rb");
if (!file.IsOpen()) {
LOG_ERROR(Loader, "Failed to load file {}", filename);
return nullptr;

View File

@ -41,7 +41,7 @@ enum class FileType {
* @param file open file
* @return FileType of file
*/
FileType IdentifyFile(FileUtil::IOFile& file);
FileType IdentifyFile(Common::FS::IOFile& file);
/**
* Identifies the type of a bootable file based on the magic value in its header.
@ -84,7 +84,7 @@ constexpr u32 MakeMagic(char a, char b, char c, char d) {
/// Interface for loading an application
class AppLoader : NonCopyable {
public:
explicit AppLoader(FileUtil::IOFile&& file) : file(std::move(file)) {}
explicit AppLoader(Common::FS::IOFile&& file) : file(std::move(file)) {}
virtual ~AppLoader() {}
/**
@ -232,7 +232,7 @@ public:
}
protected:
FileUtil::IOFile file;
Common::FS::IOFile file;
bool is_loaded = false;
};

View File

@ -34,7 +34,7 @@ namespace Loader {
static const u64 UPDATE_MASK = 0x0000000e00000000;
FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) {
FileType AppLoader_NCCH::IdentifyType(Common::FS::IOFile& file) {
u32 magic;
file.Seek(0x100, SEEK_SET);
if (1 != file.ReadArray<u32>(&magic, 1))

View File

@ -18,16 +18,16 @@ namespace Loader {
/// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI)
class AppLoader_NCCH final : public AppLoader {
public:
AppLoader_NCCH(FileUtil::IOFile&& file, const std::string& filepath)
AppLoader_NCCH(Common::FS::IOFile&& file, const std::string& filepath)
: AppLoader(std::move(file)), base_ncch(filepath), overlay_ncch(&base_ncch),
filepath(filepath) {}
/**
* Returns the type of the file
* @param file FileUtil::IOFile open file
* @param file Common::FS::IOFile open file
* @return FileType found, or FileType::Error if this loader doesn't know it
*/
static FileType IdentifyType(FileUtil::IOFile& file);
static FileType IdentifyType(Common::FS::IOFile& file);
FileType GetFileType() override {
return IdentifyType(file);

View File

@ -483,7 +483,7 @@ Movie::ValidationResult Movie::ValidateInput(const std::vector<u8>& input,
void Movie::SaveMovie() {
LOG_INFO(Movie, "Saving recorded movie to '{}'", record_movie_file);
FileUtil::IOFile save_record(record_movie_file, "wb");
Common::FS::IOFile save_record(record_movie_file, "wb");
if (!save_record.IsGood()) {
LOG_ERROR(Movie, "Unable to open file to save movie");
@ -521,7 +521,7 @@ void Movie::SetPlaybackCompletionCallback(std::function<void()> completion_callb
void Movie::StartPlayback(const std::string& movie_file) {
LOG_INFO(Movie, "Loading Movie for playback");
FileUtil::IOFile save_record(movie_file, "rb");
Common::FS::IOFile save_record(movie_file, "rb");
const u64 size = save_record.GetSize();
if (save_record.IsGood() && size > sizeof(CTMHeader)) {
@ -575,7 +575,7 @@ void Movie::SetReadOnly(bool read_only_) {
}
static boost::optional<CTMHeader> ReadHeader(const std::string& movie_file) {
FileUtil::IOFile save_record(movie_file, "rb");
Common::FS::IOFile save_record(movie_file, "rb");
const u64 size = save_record.GetSize();
if (!save_record || size <= sizeof(CTMHeader)) {
@ -609,7 +609,7 @@ void Movie::PrepareForRecording() {
Movie::ValidationResult Movie::ValidateMovie(const std::string& movie_file) const {
LOG_INFO(Movie, "Validating Movie file '{}'", movie_file);
FileUtil::IOFile save_record(movie_file, "rb");
Common::FS::IOFile save_record(movie_file, "rb");
const u64 size = save_record.GetSize();
if (!save_record || size <= sizeof(CTMHeader)) {

View File

@ -38,11 +38,11 @@ PerfStats::~PerfStats() {
std::ostringstream stream;
std::copy(perf_history.begin() + IgnoreFrames, perf_history.begin() + current_index,
std::ostream_iterator<double>(stream, "\n"));
const std::string& path = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
const std::string& path = Common::FS::GetUserPath(Common::FS::UserPath::LogDir);
// %F Date format expanded is "%Y-%m-%d"
const std::string filename =
fmt::format("{}/{:%F-%H-%M}_{:016X}.csv", path, *std::localtime(&t), title_id);
FileUtil::IOFile file(filename, "w");
Common::FS::IOFile file(filename, "w");
file.WriteString(stream.str());
}

View File

@ -41,11 +41,11 @@ std::string GetSaveStatePath(u64 program_id, u32 slot) {
const u64 movie_id = Movie::GetInstance().GetCurrentMovieID();
if (movie_id) {
return fmt::format("{}{:016X}.movie{:016X}.{:02d}.cst",
FileUtil::GetUserPath(FileUtil::UserPath::StatesDir), program_id,
Common::FS::GetUserPath(Common::FS::UserPath::StatesDir), program_id,
movie_id, slot);
} else {
return fmt::format("{}{:016X}.{:02d}.cst",
FileUtil::GetUserPath(FileUtil::UserPath::StatesDir), program_id, slot);
Common::FS::GetUserPath(Common::FS::UserPath::StatesDir), program_id, slot);
}
}
@ -53,14 +53,14 @@ std::vector<SaveStateInfo> ListSaveStates(u64 program_id) {
std::vector<SaveStateInfo> result;
for (u32 slot = 1; slot <= SaveStateSlotCount; ++slot) {
const auto path = GetSaveStatePath(program_id, slot);
if (!FileUtil::Exists(path)) {
if (!Common::FS::Exists(path)) {
continue;
}
SaveStateInfo info;
info.slot = slot;
FileUtil::IOFile file(path, "rb");
Common::FS::IOFile file(path, "rb");
if (!file) {
LOG_ERROR(Core, "Could not open file {}", path);
continue;
@ -108,11 +108,11 @@ void System::SaveState(u32 slot) const {
reinterpret_cast<const u8*>(str.data()), str.size());
const auto path = GetSaveStatePath(title_id, slot);
if (!FileUtil::CreateFullPath(path)) {
if (!Common::FS::CreateFullPath(path)) {
throw std::runtime_error("Could not create path " + path);
}
FileUtil::IOFile file(path, "wb");
Common::FS::IOFile file(path, "wb");
if (!file) {
throw std::runtime_error("Could not open file " + path);
}
@ -143,9 +143,9 @@ void System::LoadState(u32 slot) {
std::vector<u8> decompressed;
{
std::vector<u8> buffer(FileUtil::GetSize(path) - sizeof(CSTHeader));
std::vector<u8> buffer(Common::FS::GetSize(path) - sizeof(CSTHeader));
FileUtil::IOFile file(path, "rb");
Common::FS::IOFile file(path, "rb");
file.Seek(sizeof(CSTHeader), SEEK_SET); // Skip header
if (file.ReadBytes(buffer.data(), buffer.size()) != buffer.size()) {
throw std::runtime_error("Could not read from file at " + path);

View File

@ -131,8 +131,8 @@ void LogSettings() {
LogSetting("DataStorage_UseVirtualSd", values.use_virtual_sd);
LogSetting("DataStorage_UseCustomStorage", values.use_custom_storage);
if (values.use_custom_storage) {
LogSetting("DataStorage_SdmcDir", FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir));
LogSetting("DataStorage_NandDir", FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
LogSetting("DataStorage_SdmcDir", Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir));
LogSetting("DataStorage_NandDir", Common::FS::GetUserPath(Common::FS::UserPath::NANDDir));
}
LogSetting("System_IsNew3ds", values.is_new_3ds);
LogSetting("System_RegionValue", values.region_value);

View File

@ -29,18 +29,18 @@ static u64 GenerateTelemetryId() {
u64 GetTelemetryId() {
u64 telemetry_id{};
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
const std::string filename{Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) +
"telemetry_id"};
if (FileUtil::Exists(filename)) {
FileUtil::IOFile file(filename, "rb");
if (Common::FS::Exists(filename)) {
Common::FS::IOFile file(filename, "rb");
if (!file.IsOpen()) {
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
return {};
}
file.ReadBytes(&telemetry_id, sizeof(u64));
} else {
FileUtil::IOFile file(filename, "wb");
Common::FS::IOFile file(filename, "wb");
if (!file.IsOpen()) {
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
return {};
@ -54,10 +54,10 @@ u64 GetTelemetryId() {
u64 RegenerateTelemetryId() {
const u64 new_telemetry_id{GenerateTelemetryId()};
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
const std::string filename{Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir) +
"telemetry_id"};
FileUtil::IOFile file(filename, "wb");
Common::FS::IOFile file(filename, "wb");
if (!file.IsOpen()) {
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
return {};

View File

@ -75,7 +75,7 @@ void Recorder::Finish(const std::string& filename) {
try {
// Open file and write header
FileUtil::IOFile file(filename, "wb");
Common::FS::IOFile file(filename, "wb");
std::size_t written = file.WriteObject(header);
if (written != 1 || file.Tell() != initial.gpu_registers)
throw "Failed to write header";

View File

@ -153,8 +153,8 @@ static void SaveBanList(const Network::Room::BanList& ban_list, const std::strin
static void InitializeLogging(const std::string& log_file) {
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
FileUtil::CreateFullPath(log_dir);
const std::string& log_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir);
Common::FS::CreateFullPath(log_dir);
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + log_file));
#ifdef _WIN32

View File

@ -22,9 +22,9 @@ TEST_CASE("PathParser", "[core][file_sys]") {
TEST_CASE("PathParser - Host file system", "[core][file_sys]") {
std::string test_dir = "./test";
FileUtil::CreateDir(test_dir);
FileUtil::CreateDir(test_dir + "/z");
FileUtil::CreateEmptyFile(test_dir + "/a");
Common::FS::CreateDir(test_dir);
Common::FS::CreateDir(test_dir + "/z");
Common::FS::CreateEmptyFile(test_dir + "/a");
REQUIRE(PathParser(Path("/a")).GetHostStatus(test_dir) == PathParser::FileFound);
REQUIRE(PathParser(Path("/b")).GetHostStatus(test_dir) == PathParser::NotFound);
@ -32,7 +32,7 @@ TEST_CASE("PathParser - Host file system", "[core][file_sys]") {
REQUIRE(PathParser(Path("/a/c")).GetHostStatus(test_dir) == PathParser::FileInPath);
REQUIRE(PathParser(Path("/b/c")).GetHostStatus(test_dir) == PathParser::PathNotFound);
FileUtil::DeleteDirRecursively(test_dir);
Common::FS::DeleteDirRecursively(test_dir);
}
} // namespace FileSys

View File

@ -47,7 +47,7 @@ ShaderDiskCacheRaw::ShaderDiskCacheRaw(u64 unique_identifier, ProgramType progra
: unique_identifier{unique_identifier}, program_type{program_type}, config{config},
program_code{std::move(program_code)} {}
bool ShaderDiskCacheRaw::Load(FileUtil::IOFile& file) {
bool ShaderDiskCacheRaw::Load(Common::FS::IOFile& file) {
if (file.ReadBytes(&unique_identifier, sizeof(u64)) != sizeof(u64) ||
file.ReadBytes(&program_type, sizeof(u32)) != sizeof(u32)) {
return false;
@ -77,7 +77,7 @@ bool ShaderDiskCacheRaw::Load(FileUtil::IOFile& file) {
return true;
}
bool ShaderDiskCacheRaw::Save(FileUtil::IOFile& file) const {
bool ShaderDiskCacheRaw::Save(Common::FS::IOFile& file) const {
if (file.WriteObject(unique_identifier) != 1 ||
file.WriteObject(static_cast<u32>(program_type)) != 1) {
return false;
@ -114,7 +114,7 @@ std::optional<std::vector<ShaderDiskCacheRaw>> ShaderDiskCache::LoadTransferable
}
tried_to_load = true;
FileUtil::IOFile file(GetTransferablePath(), "rb");
Common::FS::IOFile file(GetTransferablePath(), "rb");
if (!file.IsOpen()) {
LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}",
GetTitleID());
@ -177,7 +177,7 @@ ShaderDiskCache::LoadPrecompiled(bool compressed) {
if (!IsUsable())
return {};
FileUtil::IOFile file(GetPrecompiledPath(), "rb");
Common::FS::IOFile file(GetPrecompiledPath(), "rb");
if (!file.IsOpen()) {
LOG_INFO(Render_OpenGL, "No precompiled shader cache found for game with title id={}",
GetTitleID());
@ -197,7 +197,7 @@ ShaderDiskCache::LoadPrecompiled(bool compressed) {
}
std::optional<std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>, ShaderDumpsMap>>
ShaderDiskCache::LoadPrecompiledFile(FileUtil::IOFile& file, bool compressed) {
ShaderDiskCache::LoadPrecompiledFile(Common::FS::IOFile& file, bool compressed) {
// Read compressed file from disk and decompress to virtual precompiled cache file
std::vector<u8> precompiled_file(file.GetSize());
file.ReadBytes(precompiled_file.data(), precompiled_file.size());
@ -301,7 +301,7 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCache::LoadDecompiledEntry()
return entry;
}
void ShaderDiskCache::SaveDecompiledToFile(FileUtil::IOFile& file, u64 unique_identifier,
void ShaderDiskCache::SaveDecompiledToFile(Common::FS::IOFile& file, u64 unique_identifier,
const ShaderDecompiler::ProgramResult& result,
bool sanitize_mul) {
if (!IsUsable())
@ -331,7 +331,7 @@ bool ShaderDiskCache::SaveDecompiledToCache(u64 unique_identifier,
}
void ShaderDiskCache::InvalidateAll() {
if (!FileUtil::Delete(GetTransferablePath())) {
if (!Common::FS::Delete(GetTransferablePath())) {
LOG_ERROR(Render_OpenGL, "Failed to invalidate transferable file={}",
GetTransferablePath());
}
@ -342,7 +342,7 @@ void ShaderDiskCache::InvalidatePrecompiled() {
// Clear virtual precompiled cache file
decompressed_precompiled_cache.resize(0);
if (!FileUtil::Delete(GetPrecompiledPath())) {
if (!Common::FS::Delete(GetPrecompiledPath())) {
LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
}
}
@ -357,7 +357,7 @@ void ShaderDiskCache::SaveRaw(const ShaderDiskCacheRaw& entry) {
return;
}
FileUtil::IOFile file = AppendTransferableFile();
Common::FS::IOFile file = AppendTransferableFile();
if (!file.IsOpen())
return;
if (file.WriteObject(TransferableEntryKind::Raw) != 1 || !entry.Save(file)) {
@ -413,7 +413,7 @@ void ShaderDiskCache::SaveDumpToFile(u64 unique_identifier, GLuint program, bool
if (!IsUsable())
return;
FileUtil::IOFile file = AppendPrecompiledFile();
Common::FS::IOFile file = AppendPrecompiledFile();
if (!file.IsOpen())
return;
@ -444,14 +444,14 @@ bool ShaderDiskCache::IsUsable() const {
return tried_to_load && Settings::values.use_disk_shader_cache;
}
FileUtil::IOFile ShaderDiskCache::AppendTransferableFile() {
Common::FS::IOFile ShaderDiskCache::AppendTransferableFile() {
if (!EnsureDirectories())
return {};
const auto transferable_path{GetTransferablePath()};
const bool existed = FileUtil::Exists(transferable_path);
const bool existed = Common::FS::Exists(transferable_path);
FileUtil::IOFile file(transferable_path, "ab");
Common::FS::IOFile file(transferable_path, "ab");
if (!file.IsOpen()) {
LOG_ERROR(Render_OpenGL, "Failed to open transferable cache in path={}", transferable_path);
return {};
@ -467,14 +467,14 @@ FileUtil::IOFile ShaderDiskCache::AppendTransferableFile() {
return file;
}
FileUtil::IOFile ShaderDiskCache::AppendPrecompiledFile() {
Common::FS::IOFile ShaderDiskCache::AppendPrecompiledFile() {
if (!EnsureDirectories())
return {};
const auto precompiled_path{GetPrecompiledPath()};
const bool existed = FileUtil::Exists(precompiled_path);
const bool existed = Common::FS::Exists(precompiled_path);
FileUtil::IOFile file(precompiled_path, "ab");
Common::FS::IOFile file(precompiled_path, "ab");
if (!file.IsOpen()) {
LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path);
return {};
@ -506,7 +506,7 @@ void ShaderDiskCache::SaveVirtualPrecompiledFile() {
decompressed_precompiled_cache.data(), decompressed_precompiled_cache.size());
const auto precompiled_path{GetPrecompiledPath()};
FileUtil::IOFile file(precompiled_path, "wb");
Common::FS::IOFile file(precompiled_path, "wb");
if (!file.IsOpen()) {
LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path);
@ -521,24 +521,24 @@ void ShaderDiskCache::SaveVirtualPrecompiledFile() {
bool ShaderDiskCache::EnsureDirectories() const {
const auto CreateDir = [](const std::string& dir) {
if (!FileUtil::CreateDir(dir)) {
if (!Common::FS::CreateDir(dir)) {
LOG_ERROR(Render_OpenGL, "Failed to create directory={}", dir);
return false;
}
return true;
};
return CreateDir(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)) &&
return CreateDir(Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir)) &&
CreateDir(GetBaseDir()) && CreateDir(GetTransferableDir()) &&
CreateDir(GetPrecompiledDir()) && CreateDir(GetPrecompiledShaderDir());
}
std::string ShaderDiskCache::GetTransferablePath() {
return FileUtil::SanitizePath(GetTransferableDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
return Common::FS::SanitizePath(GetTransferableDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
}
std::string ShaderDiskCache::GetPrecompiledPath() {
return FileUtil::SanitizePath(GetPrecompiledShaderDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
return Common::FS::SanitizePath(GetPrecompiledShaderDir() + DIR_SEP_CHR + GetTitleID() + ".bin");
}
std::string ShaderDiskCache::GetTransferableDir() const {
@ -557,7 +557,7 @@ std::string ShaderDiskCache::GetPrecompiledShaderDir() const {
}
std::string ShaderDiskCache::GetBaseDir() const {
return FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir) + DIR_SEP "opengl";
return Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir) + DIR_SEP "opengl";
}
u64 ShaderDiskCache::GetProgramID() {

View File

@ -27,7 +27,7 @@ namespace Core {
class System;
}
namespace FileUtil {
namespace Common::FS {
class IOFile;
}
@ -49,9 +49,9 @@ public:
ShaderDiskCacheRaw() = default;
~ShaderDiskCacheRaw() = default;
bool Load(FileUtil::IOFile& file);
bool Load(Common::FS::IOFile& file);
bool Save(FileUtil::IOFile& file) const;
bool Save(Common::FS::IOFile& file) const;
u64 GetUniqueIdentifier() const {
return unique_identifier;
@ -124,14 +124,14 @@ public:
private:
/// Loads the transferable cache. Returns empty on failure.
std::optional<std::pair<ShaderDecompiledMap, ShaderDumpsMap>> LoadPrecompiledFile(
FileUtil::IOFile& file, bool compressed);
Common::FS::IOFile& file, bool compressed);
/// Loads a decompiled cache entry from m_precompiled_cache_virtual_file. Returns empty on
/// failure.
std::optional<ShaderDiskCacheDecompiled> LoadDecompiledEntry();
/// Saves a decompiled entry to the passed file. Does not check for collisions.
void SaveDecompiledToFile(FileUtil::IOFile& file, u64 unique_identifier,
void SaveDecompiledToFile(Common::FS::IOFile& file, u64 unique_identifier,
const ShaderDecompiler::ProgramResult& code, bool sanitize_mul);
/// Saves a decompiled entry to the virtual precompiled cache. Does not check for collisions.
@ -142,7 +142,7 @@ private:
bool IsUsable() const;
/// Opens current game's transferable file and write it's header if it doesn't exist
FileUtil::IOFile AppendTransferableFile();
Common::FS::IOFile AppendTransferableFile();
/// Save precompiled header to precompiled_cache_in_memory
void SavePrecompiledHeaderToVirtualPrecompiledCache();
@ -223,7 +223,7 @@ private:
u64 program_id{};
std::string title_id;
FileUtil::IOFile AppendPrecompiledFile();
Common::FS::IOFile AppendPrecompiledFile();
};
} // namespace OpenGL

View File

@ -123,17 +123,17 @@ void SetOutput(float4 color_in)
)";
std::vector<std::string> GetPostProcessingShaderList(bool anaglyph) {
std::string shader_dir = FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir);
std::string shader_dir = Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir);
std::vector<std::string> shader_names;
if (!FileUtil::IsDirectory(shader_dir)) {
FileUtil::CreateDir(shader_dir);
if (!Common::FS::IsDirectory(shader_dir)) {
Common::FS::CreateDir(shader_dir);
}
if (anaglyph) {
shader_dir = shader_dir + "anaglyph";
if (!FileUtil::IsDirectory(shader_dir)) {
FileUtil::CreateDir(shader_dir);
if (!Common::FS::IsDirectory(shader_dir)) {
Common::FS::CreateDir(shader_dir);
}
}
@ -141,7 +141,7 @@ std::vector<std::string> GetPostProcessingShaderList(bool anaglyph) {
const auto callback = [&shader_names](u64* num_entries_out, const std::string& directory,
const std::string& virtual_name) -> bool {
const std::string physical_name = directory + DIR_SEP + virtual_name;
if (!FileUtil::IsDirectory(physical_name)) {
if (!Common::FS::IsDirectory(physical_name)) {
// The following is done to avoid coupling this to Qt
std::size_t dot_pos = virtual_name.rfind(".");
if (dot_pos != std::string::npos) {
@ -153,7 +153,7 @@ std::vector<std::string> GetPostProcessingShaderList(bool anaglyph) {
return true;
};
FileUtil::ForeachDirectoryEntry(nullptr, shader_dir, callback);
Common::FS::ForeachDirectoryEntry(nullptr, shader_dir, callback);
std::sort(shader_names.begin(), shader_names.end());
@ -161,7 +161,7 @@ std::vector<std::string> GetPostProcessingShaderList(bool anaglyph) {
}
std::string GetPostProcessingShaderCode(bool anaglyph, std::string_view shader) {
std::string shader_dir = FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir);
std::string shader_dir = Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir);
std::string shader_path;
if (anaglyph) {
@ -174,7 +174,7 @@ std::string GetPostProcessingShaderCode(bool anaglyph, std::string_view shader)
const std::string& directory,
const std::string& virtual_name) -> bool {
const std::string physical_name = directory + DIR_SEP + virtual_name;
if (!FileUtil::IsDirectory(physical_name)) {
if (!Common::FS::IsDirectory(physical_name)) {
// The following is done to avoid coupling this to Qt
std::size_t dot_pos = virtual_name.rfind(".");
if (dot_pos != std::string::npos) {
@ -188,7 +188,7 @@ std::string GetPostProcessingShaderCode(bool anaglyph, std::string_view shader)
return true;
};
FileUtil::ForeachDirectoryEntry(nullptr, shader_dir, callback);
Common::FS::ForeachDirectoryEntry(nullptr, shader_dir, callback);
if (shader_path.empty()) {
return "";
}

View File

@ -106,7 +106,7 @@ void PipelineCache::LoadDiskCache() {
vk::PipelineCacheCreateInfo cache_info = {.initialDataSize = 0, .pInitialData = nullptr};
std::vector<u8> cache_data;
FileUtil::IOFile cache_file{cache_file_path, "r"};
Common::FS::IOFile cache_file{cache_file_path, "r"};
if (cache_file.IsOpen()) {
LOG_INFO(Render_Vulkan, "Loading pipeline cache");
@ -135,7 +135,7 @@ void PipelineCache::SaveDiskCache() {
const std::string cache_file_path = fmt::format("{}{:x}{:x}.bin", GetPipelineCacheDir(),
instance.GetVendorID(), instance.GetDeviceID());
FileUtil::IOFile cache_file{cache_file_path, "wb"};
Common::FS::IOFile cache_file{cache_file_path, "wb"};
if (!cache_file.IsOpen()) {
LOG_INFO(Render_Vulkan, "Unable to open pipeline cache for writing");
return;
@ -582,7 +582,7 @@ bool PipelineCache::IsCacheValid(const u8* data, u64 size) const {
bool PipelineCache::EnsureDirectories() const {
const auto CreateDir = [](const std::string& dir) {
if (!FileUtil::CreateDir(dir)) {
if (!Common::FS::CreateDir(dir)) {
LOG_ERROR(Render_Vulkan, "Failed to create directory={}", dir);
return false;
}
@ -590,12 +590,12 @@ bool PipelineCache::EnsureDirectories() const {
return true;
};
return CreateDir(FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir)) &&
return CreateDir(Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir)) &&
CreateDir(GetPipelineCacheDir());
}
std::string PipelineCache::GetPipelineCacheDir() const {
return FileUtil::GetUserPath(FileUtil::UserPath::ShaderDir) + "vulkan" + DIR_SEP;
return Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir) + "vulkan" + DIR_SEP;
}
} // namespace Vulkan