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. 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/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index b5cc65157..ebdd190b5 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "common/common_paths.h" #include "common/file_util.h" #include "common/logging/log.h" #include "common/string_util.h" @@ -389,7 +390,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() { @@ -399,11 +400,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; } @@ -528,36 +529,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 d6c9e15ac..568e27853 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h @@ -9,7 +9,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; }; 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(); 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);