diff options
author | Zach Hilman <DarkLordZach@users.noreply.github.com> | 2018-07-17 21:42:15 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-07-17 21:42:15 +0200 |
commit | 69bfe075b5c3f6b17ce269950d1f8c9aab18e2de (patch) | |
tree | 8fca65bb5b3a0a8fb2b0772020d5b8d47749c3b3 /src/core/hle/service/filesystem/filesystem.cpp | |
parent | Merge pull request #671 from MerryMage/clear-exclusive-state (diff) | |
download | yuzu-69bfe075b5c3f6b17ce269950d1f8c9aab18e2de.tar yuzu-69bfe075b5c3f6b17ce269950d1f8c9aab18e2de.tar.gz yuzu-69bfe075b5c3f6b17ce269950d1f8c9aab18e2de.tar.bz2 yuzu-69bfe075b5c3f6b17ce269950d1f8c9aab18e2de.tar.lz yuzu-69bfe075b5c3f6b17ce269950d1f8c9aab18e2de.tar.xz yuzu-69bfe075b5c3f6b17ce269950d1f8c9aab18e2de.tar.zst yuzu-69bfe075b5c3f6b17ce269950d1f8c9aab18e2de.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/service/filesystem/filesystem.cpp | 77 |
1 files changed, 49 insertions, 28 deletions
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index f58b518b6..902256757 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -4,6 +4,7 @@ #include <boost/container/flat_map.hpp> #include "common/file_util.h" +#include "core/file_sys/errors.h" #include "core/file_sys/filesystem.h" #include "core/file_sys/savedata_factory.h" #include "core/file_sys/sdmc_factory.h" @@ -16,57 +17,77 @@ namespace Service::FileSystem { * Map of registered file systems, identified by type. Once an file system is registered here, it * is never removed until UnregisterFileSystems is called. */ -static boost::container::flat_map<Type, std::unique_ptr<FileSys::FileSystemFactory>> filesystem_map; - -ResultCode RegisterFileSystem(std::unique_ptr<FileSys::FileSystemFactory>&& factory, Type type) { - auto result = filesystem_map.emplace(type, std::move(factory)); +static std::unique_ptr<FileSys::RomFSFactory> romfs_factory; +static std::unique_ptr<FileSys::SaveDataFactory> save_data_factory; +static std::unique_ptr<FileSys::SDMCFactory> sdmc_factory; + +ResultCode RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory) { + ASSERT_MSG(romfs_factory == nullptr, "Tried to register a second RomFS"); + romfs_factory = std::move(factory); + LOG_DEBUG(Service_FS, "Registered RomFS"); + return RESULT_SUCCESS; +} - bool inserted = result.second; - ASSERT_MSG(inserted, "Tried to register more than one system with same id code"); +ResultCode RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory) { + ASSERT_MSG(romfs_factory == nullptr, "Tried to register a second save data"); + save_data_factory = std::move(factory); + LOG_DEBUG(Service_FS, "Registered save data"); + return RESULT_SUCCESS; +} - auto& filesystem = result.first->second; - LOG_DEBUG(Service_FS, "Registered file system {} with id code 0x{:08X}", filesystem->GetName(), - static_cast<u32>(type)); +ResultCode RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory) { + ASSERT_MSG(sdmc_factory == nullptr, "Tried to register a second SDMC"); + sdmc_factory = std::move(factory); + LOG_DEBUG(Service_FS, "Registered SDMC"); return RESULT_SUCCESS; } -ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type, - FileSys::Path& path) { - LOG_TRACE(Service_FS, "Opening FileSystem with type={}", static_cast<u32>(type)); +ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenRomFS(u64 title_id) { + LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}", title_id); - auto itr = filesystem_map.find(type); - if (itr == filesystem_map.end()) { + if (romfs_factory == nullptr) { // TODO(bunnei): Find a better error code for this return ResultCode(-1); } - return itr->second->Open(path); + return romfs_factory->Open(title_id); } -ResultCode FormatFileSystem(Type type) { - LOG_TRACE(Service_FS, "Formatting FileSystem with type={}", static_cast<u32>(type)); +ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenSaveData( + FileSys::SaveDataSpaceId space, FileSys::SaveDataDescriptor save_struct) { + LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}", + static_cast<u8>(space), SaveStructDebugInfo(save_struct)); - auto itr = filesystem_map.find(type); - if (itr == filesystem_map.end()) { - // TODO(bunnei): Find a better error code for this - return ResultCode(-1); + if (save_data_factory == nullptr) { + return ResultCode(ErrorModule::FS, FileSys::ErrCodes::SaveDataNotFound); + } + + return save_data_factory->Open(space, save_struct); +} + +ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenSDMC() { + LOG_TRACE(Service_FS, "Opening SDMC"); + + if (sdmc_factory == nullptr) { + return ResultCode(ErrorModule::FS, FileSys::ErrCodes::SdCardNotFound); } - FileSys::Path unused; - return itr->second->Format(unused); + return sdmc_factory->Open(); } void RegisterFileSystems() { - filesystem_map.clear(); + romfs_factory = nullptr; + save_data_factory = nullptr; + sdmc_factory = nullptr; std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX); std::string sd_directory = FileUtil::GetUserPath(D_SDMC_IDX); - auto savedata = std::make_unique<FileSys::SaveData_Factory>(std::move(nand_directory)); - RegisterFileSystem(std::move(savedata), Type::SaveData); + auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); + save_data_factory = std::move(savedata); - auto sdcard = std::make_unique<FileSys::SDMC_Factory>(std::move(sd_directory)); - RegisterFileSystem(std::move(sdcard), Type::SDMC); + auto sdcard = std::make_unique<FileSys::SDMCFactory>(std::move(sd_directory)); + sdmc_factory = std::move(sdcard); } void InstallInterfaces(SM::ServiceManager& service_manager) { |