From a10f9b574b34cabf9577010b84e31a8bb81e7cc5 Mon Sep 17 00:00:00 2001 From: Vitor Kiguchi Date: Tue, 26 Jan 2021 20:17:37 -0300 Subject: [PATCH] file_sys: remove more references to sdmc and nand directory --- src/core/file_sys/archive_backend.cpp | 2 ++ src/core/file_sys/archive_backend.h | 3 +++ src/core/file_sys/archive_sdmc.cpp | 3 +-- src/core/file_sys/archive_sdmc.h | 6 +----- src/core/file_sys/archive_sdmcwriteonly.cpp | 3 +-- src/core/file_sys/archive_sdmcwriteonly.h | 6 +----- src/core/file_sys/archive_source_sd_savedata.cpp | 4 ++-- src/core/file_sys/archive_source_sd_savedata.h | 6 +++++- src/core/file_sys/archive_systemsavedata.cpp | 7 ++----- src/core/file_sys/archive_systemsavedata.h | 6 +----- src/core/hle/service/cecd/cecd.cpp | 2 +- src/core/hle/service/cfg/cfg.cpp | 2 +- src/core/hle/service/fs/archive.cpp | 6 +++--- 13 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp index cefbbf4c8..75cf0417a 100644 --- a/src/core/file_sys/archive_backend.cpp +++ b/src/core/file_sys/archive_backend.cpp @@ -14,6 +14,8 @@ namespace FileSys { std::string ArchiveBackend::base_path = FileUtil::GetUserPath(FileUtil::UserPath::UserDir); +std::string ArchiveFactory::sdmc_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir); +std::string ArchiveFactory::nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); Path::Path(LowPathType type, std::vector data) : type(type) { switch (type) { diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index c1cc7c772..c4ef06dfa 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -241,6 +241,9 @@ public: */ virtual ResultVal GetFormatInfo(const Path& path, u64 program_id) const = 0; + static std::string sdmc_directory; + static std::string nand_directory; +private: template void serialize(Archive& ar, const unsigned int) {} friend class boost::serialization::access; diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index d3b4425a3..a5f60876e 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp @@ -370,8 +370,7 @@ u64 SDMCArchive::GetFreeBytes() const { return 1024 * 1024 * 1024; } -ArchiveFactory_SDMC::ArchiveFactory_SDMC(const std::string& sdmc_directory) - : sdmc_directory(sdmc_directory) { +ArchiveFactory_SDMC::ArchiveFactory_SDMC() { LOG_DEBUG(Service_FS, "Directory {} set as SDMC.", sdmc_directory); } diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h index 265dd7e93..acfce8e3d 100644 --- a/src/core/file_sys/archive_sdmc.h +++ b/src/core/file_sys/archive_sdmc.h @@ -58,7 +58,7 @@ protected: /// File system interface to the SDMC archive class ArchiveFactory_SDMC final : public ArchiveFactory { public: - explicit ArchiveFactory_SDMC(const std::string& mount_point); + explicit ArchiveFactory_SDMC(); /** * Initialize the archive. @@ -76,13 +76,9 @@ public: ResultVal GetFormatInfo(const Path& path, u64 program_id) const override; private: - std::string sdmc_directory; - - ArchiveFactory_SDMC() = default; template void serialize(Archive& ar, const unsigned int) { ar& boost::serialization::base_object(*this); - ar& sdmc_directory; } friend class boost::serialization::access; }; diff --git a/src/core/file_sys/archive_sdmcwriteonly.cpp b/src/core/file_sys/archive_sdmcwriteonly.cpp index 241e93f0a..e866fcd13 100644 --- a/src/core/file_sys/archive_sdmcwriteonly.cpp +++ b/src/core/file_sys/archive_sdmcwriteonly.cpp @@ -58,8 +58,7 @@ ResultVal> SDMCWriteOnlyArchive::OpenDirectory return ERROR_UNSUPPORTED_OPEN_FLAGS; } -ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly(const std::string& mount_point) - : sdmc_directory(mount_point) { +ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly() { LOG_DEBUG(Service_FS, "Directory {} set as SDMCWriteOnly.", sdmc_directory); } diff --git a/src/core/file_sys/archive_sdmcwriteonly.h b/src/core/file_sys/archive_sdmcwriteonly.h index f4149961c..025cc6bd0 100644 --- a/src/core/file_sys/archive_sdmcwriteonly.h +++ b/src/core/file_sys/archive_sdmcwriteonly.h @@ -44,7 +44,7 @@ private: /// File system interface to the SDMC write-only archive class ArchiveFactory_SDMCWriteOnly final : public ArchiveFactory { public: - explicit ArchiveFactory_SDMCWriteOnly(const std::string& mount_point); + explicit ArchiveFactory_SDMCWriteOnly(); /** * Initialize the archive. @@ -62,13 +62,9 @@ public: ResultVal GetFormatInfo(const Path& path, u64 program_id) const override; private: - std::string sdmc_directory; - - ArchiveFactory_SDMCWriteOnly() = default; template void serialize(Archive& ar, const unsigned int) { ar& boost::serialization::base_object(*this); - ar& sdmc_directory; } friend class boost::serialization::access; }; diff --git a/src/core/file_sys/archive_source_sd_savedata.cpp b/src/core/file_sys/archive_source_sd_savedata.cpp index 652463a29..396e3c627 100644 --- a/src/core/file_sys/archive_source_sd_savedata.cpp +++ b/src/core/file_sys/archive_source_sd_savedata.cpp @@ -18,12 +18,12 @@ SERIALIZE_EXPORT_IMPL(FileSys::ArchiveSource_SDSaveData) namespace FileSys { -namespace { - std::string GetSaveDataContainerPath(const std::string& sdmc_directory) { return fmt::format("{}Nintendo 3DS/{}/{}/title/", sdmc_directory, SYSTEM_ID, SDCARD_ID); } +namespace { + std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) { u32 high = static_cast(program_id >> 32); u32 low = static_cast(program_id & 0xFFFFFFFF); diff --git a/src/core/file_sys/archive_source_sd_savedata.h b/src/core/file_sys/archive_source_sd_savedata.h index 4ac028a3d..bff6fa2f2 100644 --- a/src/core/file_sys/archive_source_sd_savedata.h +++ b/src/core/file_sys/archive_source_sd_savedata.h @@ -16,6 +16,8 @@ namespace FileSys { +std::string GetSaveDataContainerPath(const std::string& sdmc_directory); + /// A common source of SD save data archive class ArchiveSource_SDSaveData { public: @@ -33,7 +35,9 @@ private: ArchiveSource_SDSaveData() = default; template void serialize(Archive& ar, const unsigned int) { - ar& mount_point; + if (Archive::is_loading::value) { + mount_point = GetSaveDataContainerPath(ArchiveFactory::sdmc_directory); + } } friend class boost::serialization::access; }; diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp index cffbc4e02..03592fdae 100644 --- a/src/core/file_sys/archive_systemsavedata.cpp +++ b/src/core/file_sys/archive_systemsavedata.cpp @@ -52,12 +52,9 @@ Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low) { return {std::move(binary_path)}; } -ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path) - : base_path(GetSystemSaveDataContainerPath(nand_path)) {} - ResultVal> ArchiveFactory_SystemSaveData::Open(const Path& path, u64 program_id) { - const std::string fullpath = GetSystemSaveDataPath(base_path, path); + const std::string fullpath = GetSystemSaveDataPath(GetSystemSaveDataContainerPath(ArchiveFactory::nand_directory), path); std::string relative_path = GetSystemSaveDataPath(GetSystemSaveDataContainerPath("nand/"), path); if (!FileUtil::Exists(fullpath)) { @@ -71,7 +68,7 @@ ResultVal> ArchiveFactory_SystemSaveData::Open(c ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, u64 program_id) { - std::string fullpath = GetSystemSaveDataPath(base_path, path); + std::string fullpath = GetSystemSaveDataPath(GetSystemSaveDataContainerPath(ArchiveFactory::nand_directory), path); FileUtil::DeleteDirRecursively(fullpath); FileUtil::CreateFullPath(fullpath); return RESULT_SUCCESS; diff --git a/src/core/file_sys/archive_systemsavedata.h b/src/core/file_sys/archive_systemsavedata.h index ae70a1935..4cd1597ed 100644 --- a/src/core/file_sys/archive_systemsavedata.h +++ b/src/core/file_sys/archive_systemsavedata.h @@ -20,7 +20,7 @@ namespace FileSys { /// File system interface to the SystemSaveData archive class ArchiveFactory_SystemSaveData final : public ArchiveFactory { public: - explicit ArchiveFactory_SystemSaveData(const std::string& mount_point); + explicit ArchiveFactory_SystemSaveData() = default; ResultVal> Open(const Path& path, u64 program_id) override; ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, @@ -32,13 +32,9 @@ public: } private: - std::string base_path; - - ArchiveFactory_SystemSaveData() = default; template void serialize(Archive& ar, const unsigned int) { ar& boost::serialization::base_object(*this); - ar& base_path; } friend class boost::serialization::access; }; diff --git a/src/core/hle/service/cecd/cecd.cpp b/src/core/hle/service/cecd/cecd.cpp index 3593a167c..90fffa987 100644 --- a/src/core/hle/service/cecd/cecd.cpp +++ b/src/core/hle/service/cecd/cecd.cpp @@ -1381,7 +1381,7 @@ Module::Module(Core::System& system) : system(system) { system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "CECD::change_state_event"); const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); - FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory); + FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory; // Open the SystemSaveData archive 0x00010026 FileSys::Path archive_path(cecd_system_savedata_id); diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 67724e89e..a111a62a9 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -561,7 +561,7 @@ ResultCode Module::FormatConfig() { ResultCode Module::LoadConfigNANDSaveFile() { const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); - FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory); + FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory; // Open the SystemSaveData archive 0x00010017 FileSys::Path archive_path(cfg_system_savedata_id); diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index e36fec4de..66c2001ed 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -324,13 +324,13 @@ void ArchiveManager::RegisterArchiveTypes() { std::string sdmc_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir); std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); - auto sdmc_factory = std::make_unique(sdmc_directory); + auto sdmc_factory = std::make_unique(); if (sdmc_factory->Initialize()) RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC); else LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path {}", sdmc_directory); - auto sdmcwo_factory = std::make_unique(sdmc_directory); + auto sdmcwo_factory = std::make_unique(); if (sdmcwo_factory->Initialize()) RegisterArchiveType(std::move(sdmcwo_factory), ArchiveIdCode::SDMCWriteOnly); else @@ -363,7 +363,7 @@ void ArchiveManager::RegisterArchiveTypes() { RegisterArchiveType(std::move(savedatacheck_factory), ArchiveIdCode::NCCH); auto systemsavedata_factory = - std::make_unique(nand_directory); + std::make_unique(); RegisterArchiveType(std::move(systemsavedata_factory), ArchiveIdCode::SystemSaveData); auto selfncch_factory = std::make_unique();