IOS/FS: Make the NAND root path a parameter

Cleaner than having the backend figure out which NAND root to use.
This commit is contained in:
Léo Lam 2018-03-12 18:18:22 +01:00
parent c56f31906c
commit 4e547772da
4 changed files with 21 additions and 10 deletions

View File

@ -5,13 +5,16 @@
#include "Core/IOS/FS/FileSystem.h" #include "Core/IOS/FS/FileSystem.h"
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/FileUtil.h"
#include "Core/IOS/FS/HostBackend/FS.h" #include "Core/IOS/FS/HostBackend/FS.h"
namespace IOS::HLE::FS namespace IOS::HLE::FS
{ {
std::unique_ptr<FileSystem> MakeFileSystem() std::unique_ptr<FileSystem> MakeFileSystem(Location location)
{ {
return std::make_unique<HostFileSystem>(); const std::string nand_root =
File::GetUserPath(location == Location::Session ? D_SESSION_WIIROOT_IDX : D_WIIROOT_IDX);
return std::make_unique<HostFileSystem>(nand_root);
} }
FileHandle::FileHandle(FileSystem* fs, Fd fd) : m_fs{fs}, m_fd{fd} FileHandle::FileHandle(FileSystem* fs, Fd fd) : m_fs{fs}, m_fd{fd}

View File

@ -195,6 +195,12 @@ protected:
void Init(); void Init();
}; };
std::unique_ptr<FileSystem> MakeFileSystem(); enum class Location
{
Configured,
Session,
};
std::unique_ptr<FileSystem> MakeFileSystem(Location location = Location::Session);
} // namespace IOS::HLE::FS } // namespace IOS::HLE::FS

View File

@ -20,14 +20,13 @@ static bool IsValidWiiPath(const std::string& path)
return path.compare(0, 1, "/") == 0; 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) if (wii_path.compare(0, 1, "/") == 0)
return nand_path + Common::EscapePath(wii_path); return m_root_path + Common::EscapePath(wii_path);
ASSERT(false); ASSERT(false);
return nand_path; return m_root_path;
} }
// Get total filesize of contents of a directory (recursive) // Get total filesize of contents of a directory (recursive)
@ -45,7 +44,7 @@ static u64 ComputeTotalFileSize(const File::FSTEntry& parent_entry)
return sizeOfFiles; return sizeOfFiles;
} }
HostFileSystem::HostFileSystem() HostFileSystem::HostFileSystem(const std::string& root_path) : m_root_path{root_path}
{ {
Init(); Init();
} }
@ -54,6 +53,8 @@ HostFileSystem::~HostFileSystem() = default;
void HostFileSystem::DoState(PointerWrap& p) void HostFileSystem::DoState(PointerWrap& p)
{ {
p.Do(m_root_path);
// Temporarily close the file, to prevent any issues with the savestating of /tmp // Temporarily close the file, to prevent any issues with the savestating of /tmp
for (Handle& handle : m_handles) for (Handle& handle : m_handles)
handle.host_file.reset(); handle.host_file.reset();

View File

@ -23,7 +23,7 @@ namespace IOS::HLE::FS
class HostFileSystem final : public FileSystem class HostFileSystem final : public FileSystem
{ {
public: public:
HostFileSystem(); HostFileSystem(const std::string& root_path);
~HostFileSystem(); ~HostFileSystem();
void DoState(PointerWrap& p) override; void DoState(PointerWrap& p) override;
@ -73,9 +73,10 @@ private:
Handle* GetHandleFromFd(Fd fd); Handle* GetHandleFromFd(Fd fd);
Fd ConvertHandleToFd(const Handle* handle) const; 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<File::IOFile> OpenHostFile(const std::string& host_path); std::shared_ptr<File::IOFile> OpenHostFile(const std::string& host_path);
std::string m_root_path;
std::array<Handle, 16> m_handles{}; std::array<Handle, 16> m_handles{};
std::map<std::string, std::weak_ptr<File::IOFile>> m_open_files; std::map<std::string, std::weak_ptr<File::IOFile>> m_open_files;
}; };