file_sys: remove more references to sdmc and nand directory

This commit is contained in:
Vitor Kiguchi 2021-01-26 20:17:37 -03:00
parent 79824e9790
commit a10f9b574b
13 changed files with 24 additions and 32 deletions

View file

@ -14,6 +14,8 @@
namespace FileSys { namespace FileSys {
std::string ArchiveBackend::base_path = FileUtil::GetUserPath(FileUtil::UserPath::UserDir); 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<u8> data) : type(type) { Path::Path(LowPathType type, std::vector<u8> data) : type(type) {
switch (type) { switch (type) {

View file

@ -241,6 +241,9 @@ public:
*/ */
virtual ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const = 0; virtual ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const = 0;
static std::string sdmc_directory;
static std::string nand_directory;
private:
template <class Archive> template <class Archive>
void serialize(Archive& ar, const unsigned int) {} void serialize(Archive& ar, const unsigned int) {}
friend class boost::serialization::access; friend class boost::serialization::access;

View file

@ -370,8 +370,7 @@ u64 SDMCArchive::GetFreeBytes() const {
return 1024 * 1024 * 1024; return 1024 * 1024 * 1024;
} }
ArchiveFactory_SDMC::ArchiveFactory_SDMC(const std::string& sdmc_directory) ArchiveFactory_SDMC::ArchiveFactory_SDMC() {
: sdmc_directory(sdmc_directory) {
LOG_DEBUG(Service_FS, "Directory {} set as SDMC.", sdmc_directory); LOG_DEBUG(Service_FS, "Directory {} set as SDMC.", sdmc_directory);
} }

View file

@ -58,7 +58,7 @@ protected:
/// File system interface to the SDMC archive /// File system interface to the SDMC archive
class ArchiveFactory_SDMC final : public ArchiveFactory { class ArchiveFactory_SDMC final : public ArchiveFactory {
public: public:
explicit ArchiveFactory_SDMC(const std::string& mount_point); explicit ArchiveFactory_SDMC();
/** /**
* Initialize the archive. * Initialize the archive.
@ -76,13 +76,9 @@ public:
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
private: private:
std::string sdmc_directory;
ArchiveFactory_SDMC() = default;
template <class Archive> template <class Archive>
void serialize(Archive& ar, const unsigned int) { void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<ArchiveFactory>(*this); ar& boost::serialization::base_object<ArchiveFactory>(*this);
ar& sdmc_directory;
} }
friend class boost::serialization::access; friend class boost::serialization::access;
}; };

View file

@ -58,8 +58,7 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SDMCWriteOnlyArchive::OpenDirectory
return ERROR_UNSUPPORTED_OPEN_FLAGS; return ERROR_UNSUPPORTED_OPEN_FLAGS;
} }
ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly(const std::string& mount_point) ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly() {
: sdmc_directory(mount_point) {
LOG_DEBUG(Service_FS, "Directory {} set as SDMCWriteOnly.", sdmc_directory); LOG_DEBUG(Service_FS, "Directory {} set as SDMCWriteOnly.", sdmc_directory);
} }

View file

@ -44,7 +44,7 @@ private:
/// File system interface to the SDMC write-only archive /// File system interface to the SDMC write-only archive
class ArchiveFactory_SDMCWriteOnly final : public ArchiveFactory { class ArchiveFactory_SDMCWriteOnly final : public ArchiveFactory {
public: public:
explicit ArchiveFactory_SDMCWriteOnly(const std::string& mount_point); explicit ArchiveFactory_SDMCWriteOnly();
/** /**
* Initialize the archive. * Initialize the archive.
@ -62,13 +62,9 @@ public:
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override;
private: private:
std::string sdmc_directory;
ArchiveFactory_SDMCWriteOnly() = default;
template <class Archive> template <class Archive>
void serialize(Archive& ar, const unsigned int) { void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<ArchiveFactory>(*this); ar& boost::serialization::base_object<ArchiveFactory>(*this);
ar& sdmc_directory;
} }
friend class boost::serialization::access; friend class boost::serialization::access;
}; };

View file

@ -18,12 +18,12 @@ SERIALIZE_EXPORT_IMPL(FileSys::ArchiveSource_SDSaveData)
namespace FileSys { namespace FileSys {
namespace {
std::string GetSaveDataContainerPath(const std::string& sdmc_directory) { std::string GetSaveDataContainerPath(const std::string& sdmc_directory) {
return fmt::format("{}Nintendo 3DS/{}/{}/title/", sdmc_directory, SYSTEM_ID, SDCARD_ID); return fmt::format("{}Nintendo 3DS/{}/{}/title/", sdmc_directory, SYSTEM_ID, SDCARD_ID);
} }
namespace {
std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) { std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) {
u32 high = static_cast<u32>(program_id >> 32); u32 high = static_cast<u32>(program_id >> 32);
u32 low = static_cast<u32>(program_id & 0xFFFFFFFF); u32 low = static_cast<u32>(program_id & 0xFFFFFFFF);

View file

@ -16,6 +16,8 @@
namespace FileSys { namespace FileSys {
std::string GetSaveDataContainerPath(const std::string& sdmc_directory);
/// A common source of SD save data archive /// A common source of SD save data archive
class ArchiveSource_SDSaveData { class ArchiveSource_SDSaveData {
public: public:
@ -33,7 +35,9 @@ private:
ArchiveSource_SDSaveData() = default; ArchiveSource_SDSaveData() = default;
template <class Archive> template <class Archive>
void serialize(Archive& ar, const unsigned int) { 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; friend class boost::serialization::access;
}; };

View file

@ -52,12 +52,9 @@ Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low) {
return {std::move(binary_path)}; return {std::move(binary_path)};
} }
ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path)
: base_path(GetSystemSaveDataContainerPath(nand_path)) {}
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(const Path& path, ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(const Path& path,
u64 program_id) { 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 = std::string relative_path =
GetSystemSaveDataPath(GetSystemSaveDataContainerPath("nand/"), path); GetSystemSaveDataPath(GetSystemSaveDataContainerPath("nand/"), path);
if (!FileUtil::Exists(fullpath)) { if (!FileUtil::Exists(fullpath)) {
@ -71,7 +68,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c
ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path, ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path,
const FileSys::ArchiveFormatInfo& format_info, const FileSys::ArchiveFormatInfo& format_info,
u64 program_id) { u64 program_id) {
std::string fullpath = GetSystemSaveDataPath(base_path, path); std::string fullpath = GetSystemSaveDataPath(GetSystemSaveDataContainerPath(ArchiveFactory::nand_directory), path);
FileUtil::DeleteDirRecursively(fullpath); FileUtil::DeleteDirRecursively(fullpath);
FileUtil::CreateFullPath(fullpath); FileUtil::CreateFullPath(fullpath);
return RESULT_SUCCESS; return RESULT_SUCCESS;

View file

@ -20,7 +20,7 @@ namespace FileSys {
/// File system interface to the SystemSaveData archive /// File system interface to the SystemSaveData archive
class ArchiveFactory_SystemSaveData final : public ArchiveFactory { class ArchiveFactory_SystemSaveData final : public ArchiveFactory {
public: public:
explicit ArchiveFactory_SystemSaveData(const std::string& mount_point); explicit ArchiveFactory_SystemSaveData() = default;
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override;
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info,
@ -32,13 +32,9 @@ public:
} }
private: private:
std::string base_path;
ArchiveFactory_SystemSaveData() = default;
template <class Archive> template <class Archive>
void serialize(Archive& ar, const unsigned int) { void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<ArchiveFactory>(*this); ar& boost::serialization::base_object<ArchiveFactory>(*this);
ar& base_path;
} }
friend class boost::serialization::access; friend class boost::serialization::access;
}; };

View file

@ -1381,7 +1381,7 @@ Module::Module(Core::System& system) : system(system) {
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "CECD::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 = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory); FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory;
// Open the SystemSaveData archive 0x00010026 // Open the SystemSaveData archive 0x00010026
FileSys::Path archive_path(cecd_system_savedata_id); FileSys::Path archive_path(cecd_system_savedata_id);

View file

@ -561,7 +561,7 @@ ResultCode Module::FormatConfig() {
ResultCode Module::LoadConfigNANDSaveFile() { ResultCode Module::LoadConfigNANDSaveFile() {
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); 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 // Open the SystemSaveData archive 0x00010017
FileSys::Path archive_path(cfg_system_savedata_id); FileSys::Path archive_path(cfg_system_savedata_id);

View file

@ -324,13 +324,13 @@ void ArchiveManager::RegisterArchiveTypes() {
std::string sdmc_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir); std::string sdmc_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
auto sdmc_factory = std::make_unique<FileSys::ArchiveFactory_SDMC>(sdmc_directory); auto sdmc_factory = std::make_unique<FileSys::ArchiveFactory_SDMC>();
if (sdmc_factory->Initialize()) if (sdmc_factory->Initialize())
RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC); RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC);
else else
LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path {}", sdmc_directory); LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path {}", sdmc_directory);
auto sdmcwo_factory = std::make_unique<FileSys::ArchiveFactory_SDMCWriteOnly>(sdmc_directory); auto sdmcwo_factory = std::make_unique<FileSys::ArchiveFactory_SDMCWriteOnly>();
if (sdmcwo_factory->Initialize()) if (sdmcwo_factory->Initialize())
RegisterArchiveType(std::move(sdmcwo_factory), ArchiveIdCode::SDMCWriteOnly); RegisterArchiveType(std::move(sdmcwo_factory), ArchiveIdCode::SDMCWriteOnly);
else else
@ -363,7 +363,7 @@ void ArchiveManager::RegisterArchiveTypes() {
RegisterArchiveType(std::move(savedatacheck_factory), ArchiveIdCode::NCCH); RegisterArchiveType(std::move(savedatacheck_factory), ArchiveIdCode::NCCH);
auto systemsavedata_factory = auto systemsavedata_factory =
std::make_unique<FileSys::ArchiveFactory_SystemSaveData>(nand_directory); std::make_unique<FileSys::ArchiveFactory_SystemSaveData>();
RegisterArchiveType(std::move(systemsavedata_factory), ArchiveIdCode::SystemSaveData); RegisterArchiveType(std::move(systemsavedata_factory), ArchiveIdCode::SystemSaveData);
auto selfncch_factory = std::make_unique<FileSys::ArchiveFactory_SelfNCCH>(); auto selfncch_factory = std::make_unique<FileSys::ArchiveFactory_SelfNCCH>();