diff --git a/Source/Core/Core/IOS/FS/FileSystem.cpp b/Source/Core/Core/IOS/FS/FileSystem.cpp index f3910c3374..552d68ec8b 100644 --- a/Source/Core/Core/IOS/FS/FileSystem.cpp +++ b/Source/Core/Core/IOS/FS/FileSystem.cpp @@ -5,13 +5,16 @@ #include "Core/IOS/FS/FileSystem.h" #include "Common/Assert.h" +#include "Common/FileUtil.h" #include "Core/IOS/FS/HostBackend/FS.h" namespace IOS::HLE::FS { -std::unique_ptr MakeFileSystem() +std::unique_ptr MakeFileSystem(Location location) { - return std::make_unique(); + const std::string nand_root = + File::GetUserPath(location == Location::Session ? D_SESSION_WIIROOT_IDX : D_WIIROOT_IDX); + return std::make_unique(nand_root); } FileHandle::FileHandle(FileSystem* fs, Fd fd) : m_fs{fs}, m_fd{fd} diff --git a/Source/Core/Core/IOS/FS/FileSystem.h b/Source/Core/Core/IOS/FS/FileSystem.h index 25894a60b0..87890cdbad 100644 --- a/Source/Core/Core/IOS/FS/FileSystem.h +++ b/Source/Core/Core/IOS/FS/FileSystem.h @@ -195,6 +195,12 @@ protected: void Init(); }; -std::unique_ptr MakeFileSystem(); +enum class Location +{ + Configured, + Session, +}; + +std::unique_ptr MakeFileSystem(Location location = Location::Session); } // namespace IOS::HLE::FS diff --git a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp index 4e18e0ac34..1e512a623a 100644 --- a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp +++ b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp @@ -20,14 +20,13 @@ static bool IsValidWiiPath(const std::string& path) return path.compare(0, 1, "/") == 0; } -std::string HostFileSystem::BuildFilename(const std::string& wii_path) +std::string HostFileSystem::BuildFilename(const std::string& wii_path) const { - std::string nand_path = File::GetUserPath(D_SESSION_WIIROOT_IDX); if (wii_path.compare(0, 1, "/") == 0) - return nand_path + Common::EscapePath(wii_path); + return m_root_path + Common::EscapePath(wii_path); ASSERT(false); - return nand_path; + return m_root_path; } // Get total filesize of contents of a directory (recursive) @@ -45,7 +44,7 @@ static u64 ComputeTotalFileSize(const File::FSTEntry& parent_entry) return sizeOfFiles; } -HostFileSystem::HostFileSystem() +HostFileSystem::HostFileSystem(const std::string& root_path) : m_root_path{root_path} { Init(); } @@ -54,6 +53,8 @@ HostFileSystem::~HostFileSystem() = default; void HostFileSystem::DoState(PointerWrap& p) { + p.Do(m_root_path); + // Temporarily close the file, to prevent any issues with the savestating of /tmp for (Handle& handle : m_handles) handle.host_file.reset(); diff --git a/Source/Core/Core/IOS/FS/HostBackend/FS.h b/Source/Core/Core/IOS/FS/HostBackend/FS.h index 60f5d4dfd4..b30e1742f6 100644 --- a/Source/Core/Core/IOS/FS/HostBackend/FS.h +++ b/Source/Core/Core/IOS/FS/HostBackend/FS.h @@ -23,7 +23,7 @@ namespace IOS::HLE::FS class HostFileSystem final : public FileSystem { public: - HostFileSystem(); + HostFileSystem(const std::string& root_path); ~HostFileSystem(); void DoState(PointerWrap& p) override; @@ -73,9 +73,10 @@ private: Handle* GetHandleFromFd(Fd fd); Fd ConvertHandleToFd(const Handle* handle) const; - std::string BuildFilename(const std::string& wii_path); + std::string BuildFilename(const std::string& wii_path) const; std::shared_ptr OpenHostFile(const std::string& host_path); + std::string m_root_path; std::array m_handles{}; std::map> m_open_files; };