From b03332d09b127e51d027c23ddebb8dc745cae9ad Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Fri, 28 Sep 2018 17:08:39 -0400 Subject: [PATCH 1/4] fs: remove ArchiveFactory_ExtSaveData::Initialize This is unnecessary as any open archive would create the full path for themselves --- src/core/file_sys/archive_extsavedata.cpp | 9 --------- src/core/file_sys/archive_extsavedata.h | 6 ------ src/core/hle/service/fs/archive.cpp | 12 ++---------- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index e8da21193..c64526416 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -194,15 +194,6 @@ ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_ LOG_DEBUG(Service_FS, "Directory {} set as base for ExtSaveData.", mount_point); } -bool ArchiveFactory_ExtSaveData::Initialize() { - if (!FileUtil::CreateFullPath(mount_point)) { - LOG_ERROR(Service_FS, "Unable to create ExtSaveData base path."); - return false; - } - - return true; -} - Path ArchiveFactory_ExtSaveData::GetCorrectedPath(const Path& path) { if (!shared) return path; diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h index 79d266df4..151b367b5 100644 --- a/src/core/file_sys/archive_extsavedata.h +++ b/src/core/file_sys/archive_extsavedata.h @@ -20,12 +20,6 @@ class ArchiveFactory_ExtSaveData final : public ArchiveFactory { public: ArchiveFactory_ExtSaveData(const std::string& mount_point, bool shared); - /** - * Initialize the archive. - * @return true if it initialized successfully - */ - bool Initialize(); - std::string GetName() const override { return "ExtSaveData"; } diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 752e0ffef..d54a7b866 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -646,19 +646,11 @@ void RegisterArchiveTypes() { auto extsavedata_factory = std::make_unique(sdmc_directory, false); - if (extsavedata_factory->Initialize()) - RegisterArchiveType(std::move(extsavedata_factory), ArchiveIdCode::ExtSaveData); - else - LOG_ERROR(Service_FS, "Can't instantiate ExtSaveData archive with path {}", - extsavedata_factory->GetMountPoint()); + RegisterArchiveType(std::move(extsavedata_factory), ArchiveIdCode::ExtSaveData); auto sharedextsavedata_factory = std::make_unique(nand_directory, true); - if (sharedextsavedata_factory->Initialize()) - RegisterArchiveType(std::move(sharedextsavedata_factory), ArchiveIdCode::SharedExtSaveData); - else - LOG_ERROR(Service_FS, "Can't instantiate SharedExtSaveData archive with path {}", - sharedextsavedata_factory->GetMountPoint()); + RegisterArchiveType(std::move(sharedextsavedata_factory), ArchiveIdCode::SharedExtSaveData); // Create the NCCH archive, basically a small variation of the RomFS archive auto savedatacheck_factory = std::make_unique(); From 2757eff122d6c0fb5557e197bdcc15b5417ddd42 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Fri, 28 Sep 2018 17:21:45 -0400 Subject: [PATCH 2/4] ptm: access FS via backend directly --- src/core/hle/service/ptm/ptm.cpp | 46 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp index 5f22e9ba6..b9df66e3b 100644 --- a/src/core/hle/service/ptm/ptm.cpp +++ b/src/core/hle/service/ptm/ptm.cpp @@ -3,10 +3,12 @@ // Refer to the license.txt file included. #include +#include "common/common_paths.h" +#include "common/file_util.h" #include "common/logging/log.h" +#include "core/file_sys/archive_extsavedata.h" #include "core/file_sys/errors.h" #include "core/file_sys/file_backend.h" -#include "core/hle/service/fs/archive.h" #include "core/hle/service/ptm/ptm.h" #include "core/hle/service/ptm/ptm_gets.h" #include "core/hle/service/ptm/ptm_play.h" @@ -136,42 +138,44 @@ void Module::Interface::CheckNew3DS(Kernel::HLERequestContext& ctx) { } static void WriteGameCoinData(GameCoin gamecoin_data) { + std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); + FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true); + FileSys::Path archive_path(ptm_shared_extdata_id); - auto archive_result = - Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); + auto archive_result = extdata_archive_factory.Open(archive_path); + std::unique_ptr archive; FileSys::Path gamecoin_path("/gamecoin.dat"); // If the archive didn't exist, create the files inside if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) { // Format the archive to create the directories - Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, - FileSys::ArchiveFormatInfo(), archive_path); + extdata_archive_factory.Format(archive_path, FileSys::ArchiveFormatInfo()); // Open it again to get a valid archive now that the folder exists - archive_result = - Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); + archive = extdata_archive_factory.Open(archive_path).Unwrap(); // Create the game coin file - Service::FS::CreateFileInArchive(*archive_result, gamecoin_path, sizeof(GameCoin)); + archive->CreateFile(gamecoin_path, sizeof(GameCoin)); } else { ASSERT_MSG(archive_result.Succeeded(), "Could not open the PTM SharedExtSaveData archive!"); + archive = std::move(archive_result).Unwrap(); } FileSys::Mode open_mode = {}; open_mode.write_flag.Assign(1); // Open the file and write the default gamecoin information - auto gamecoin_result = - Service::FS::OpenFileFromArchive(*archive_result, gamecoin_path, open_mode); + auto gamecoin_result = archive->OpenFile(gamecoin_path, open_mode); if (gamecoin_result.Succeeded()) { auto gamecoin = std::move(gamecoin_result).Unwrap(); - gamecoin->backend->Write(0, sizeof(GameCoin), true, - reinterpret_cast(&gamecoin_data)); - gamecoin->backend->Close(); + gamecoin->Write(0, sizeof(GameCoin), true, reinterpret_cast(&gamecoin_data)); + gamecoin->Close(); } } static GameCoin ReadGameCoinData() { + std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); + FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true); + FileSys::Path archive_path(ptm_shared_extdata_id); - auto archive_result = - Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); + auto archive_result = extdata_archive_factory.Open(archive_path); if (!archive_result.Succeeded()) { LOG_ERROR(Service_PTM, "Could not open the PTM SharedExtSaveData archive!"); return default_game_coin; @@ -181,8 +185,7 @@ static GameCoin ReadGameCoinData() { FileSys::Mode open_mode = {}; open_mode.read_flag.Assign(1); - auto gamecoin_result = - Service::FS::OpenFileFromArchive(*archive_result, gamecoin_path, open_mode); + auto gamecoin_result = (*archive_result)->OpenFile(gamecoin_path, open_mode); if (!gamecoin_result.Succeeded()) { LOG_ERROR(Service_PTM, "Could not open the game coin data file!"); return default_game_coin; @@ -190,17 +193,18 @@ static GameCoin ReadGameCoinData() { u16 result; auto gamecoin = std::move(gamecoin_result).Unwrap(); GameCoin gamecoin_data; - gamecoin->backend->Read(0, sizeof(GameCoin), reinterpret_cast(&gamecoin_data)); - gamecoin->backend->Close(); + gamecoin->Read(0, sizeof(GameCoin), reinterpret_cast(&gamecoin_data)); + gamecoin->Close(); return gamecoin_data; } Module::Module() { // Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't // exist + std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); + FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true); FileSys::Path archive_path(ptm_shared_extdata_id); - auto archive_result = - Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); + auto archive_result = extdata_archive_factory.Open(archive_path); // If the archive didn't exist, write the default game coin file if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) { WriteGameCoinData(default_game_coin); From bcb5d438a993e31047b07338483201e49e6a1236 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Fri, 28 Sep 2018 17:32:05 -0400 Subject: [PATCH 3/4] cfg: access FS via backend directly --- src/core/hle/service/cfg/cfg.cpp | 31 ++++++++++++++++--------------- src/core/hle/service/cfg/cfg.h | 8 ++++++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 1b99c0e2c..7d4a1ff7c 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "common/common_paths.h" #include "common/file_util.h" #include "common/logging/log.h" #include "common/string_util.h" @@ -388,7 +389,7 @@ ResultCode Module::CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const ResultCode Module::DeleteConfigNANDSaveFile() { FileSys::Path path("/config"); - return Service::FS::DeleteFileFromArchive(cfg_system_save_data_archive, path); + return cfg_system_save_data_archive->DeleteFile(path); } ResultCode Module::UpdateConfigNANDSavegame() { @@ -398,11 +399,11 @@ ResultCode Module::UpdateConfigNANDSavegame() { FileSys::Path path("/config"); - auto config_result = Service::FS::OpenFileFromArchive(cfg_system_save_data_archive, path, mode); + auto config_result = cfg_system_save_data_archive->OpenFile(path, mode); ASSERT_MSG(config_result.Succeeded(), "could not open file"); auto config = std::move(config_result).Unwrap(); - config->backend->Write(0, CONFIG_SAVEFILE_SIZE, 1, cfg_config_file_buffer.data()); + config->Write(0, CONFIG_SAVEFILE_SIZE, 1, cfg_config_file_buffer.data()); return RESULT_SUCCESS; } @@ -527,36 +528,36 @@ ResultCode Module::FormatConfig() { } ResultCode Module::LoadConfigNANDSaveFile() { + std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); + FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory); + // Open the SystemSaveData archive 0x00010017 FileSys::Path archive_path(cfg_system_savedata_id); - auto archive_result = - Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); + auto archive_result = systemsavedata_factory.Open(archive_path); // If the archive didn't exist, create the files inside if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) { // Format the archive to create the directories - Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SystemSaveData, - FileSys::ArchiveFormatInfo(), archive_path); + systemsavedata_factory.Format(archive_path, FileSys::ArchiveFormatInfo()); // Open it again to get a valid archive now that the folder exists - archive_result = - Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); + cfg_system_save_data_archive = systemsavedata_factory.Open(archive_path).Unwrap(); + } else { + ASSERT_MSG(archive_result.Succeeded(), "Could not open the CFG SystemSaveData archive!"); + + cfg_system_save_data_archive = std::move(archive_result).Unwrap(); } - ASSERT_MSG(archive_result.Succeeded(), "Could not open the CFG SystemSaveData archive!"); - - cfg_system_save_data_archive = *archive_result; - FileSys::Path config_path("/config"); FileSys::Mode open_mode = {}; open_mode.read_flag.Assign(1); - auto config_result = Service::FS::OpenFileFromArchive(*archive_result, config_path, open_mode); + auto config_result = cfg_system_save_data_archive->OpenFile(config_path, open_mode); // Read the file if it already exists if (config_result.Succeeded()) { auto config = std::move(config_result).Unwrap(); - config->backend->Read(0, CONFIG_SAVEFILE_SIZE, cfg_config_file_buffer.data()); + config->Read(0, CONFIG_SAVEFILE_SIZE, cfg_config_file_buffer.data()); return RESULT_SUCCESS; } diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index f240d194b..e7e0c9596 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h @@ -8,7 +8,11 @@ #include #include #include "common/common_types.h" -#include "core/hle/service/fs/archive.h" +#include "core/hle/service/service.h" + +namespace FileSys { +class ArchiveBackend; +} namespace Service::CFG { @@ -399,7 +403,7 @@ public: private: static constexpr u32 CONFIG_SAVEFILE_SIZE = 0x8000; std::array cfg_config_file_buffer; - Service::FS::ArchiveHandle cfg_system_save_data_archive; + std::unique_ptr cfg_system_save_data_archive; u32 preferred_region_code = 0; }; From 89a5b9b622743eac7f6b3fab0e22f2f8f47c13bb Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Fri, 28 Sep 2018 17:34:47 -0400 Subject: [PATCH 4/4] qt/configure_system: FS decoupled --- src/citra_qt/configuration/configure_system.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/citra_qt/configuration/configure_system.cpp b/src/citra_qt/configuration/configure_system.cpp index 1fe5b41ee..5597e0a6b 100644 --- a/src/citra_qt/configuration/configure_system.cpp +++ b/src/citra_qt/configuration/configure_system.cpp @@ -7,7 +7,6 @@ #include "citra_qt/ui_settings.h" #include "core/core.h" #include "core/hle/service/cfg/cfg.h" -#include "core/hle/service/fs/archive.h" #include "core/hle/service/ptm/ptm.h" #include "core/settings.h" #include "ui_configure_system.h" @@ -252,11 +251,8 @@ void ConfigureSystem::setConfiguration() { ui->group_system_settings->setEnabled(false); } else { // This tab is enabled only when game is not running (i.e. all service are not initialized). - // Temporarily register archive types and load the config savegame file to memory. - Service::FS::RegisterArchiveTypes(); cfg = std::make_shared(); ReadSystemSettings(); - Service::FS::UnregisterArchiveTypes(); ui->label_disable_info->hide(); } @@ -348,10 +344,7 @@ void ConfigureSystem::applyConfiguration() { // apply play coin u16 new_play_coin = static_cast(ui->spinBox_play_coins->value()); if (play_coin != new_play_coin) { - // archive types must be registered to set play coins - Service::FS::RegisterArchiveTypes(); Service::PTM::Module::SetPlayCoins(new_play_coin); - Service::FS::UnregisterArchiveTypes(); } // update the config savegame if any item is modified.