2018-01-17 04:20:12 +01:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include "common/common_types.h"
|
2018-07-19 03:07:11 +02:00
|
|
|
#include "core/file_sys/directory.h"
|
2018-01-17 04:20:12 +01:00
|
|
|
#include "core/hle/result.h"
|
2018-01-21 03:32:36 +01:00
|
|
|
|
2018-08-21 02:36:36 +02:00
|
|
|
namespace FileSys {
|
|
|
|
class BISFactory;
|
|
|
|
class RegisteredCache;
|
|
|
|
class RomFSFactory;
|
|
|
|
class SaveDataFactory;
|
|
|
|
class SDMCFactory;
|
|
|
|
|
|
|
|
enum class ContentRecordType : u8;
|
2018-08-21 16:48:24 +02:00
|
|
|
enum class Mode : u32;
|
2018-08-21 02:36:36 +02:00
|
|
|
enum class SaveDataSpaceId : u8;
|
|
|
|
enum class StorageId : u8;
|
|
|
|
|
|
|
|
struct SaveDataDescriptor;
|
|
|
|
} // namespace FileSys
|
|
|
|
|
2018-01-17 04:20:12 +01:00
|
|
|
namespace Service {
|
2018-01-21 03:32:36 +01:00
|
|
|
|
|
|
|
namespace SM {
|
|
|
|
class ServiceManager;
|
|
|
|
} // namespace SM
|
|
|
|
|
2018-01-17 04:20:12 +01:00
|
|
|
namespace FileSystem {
|
|
|
|
|
2018-07-17 21:42:15 +02:00
|
|
|
ResultCode RegisterRomFS(std::unique_ptr<FileSys::RomFSFactory>&& factory);
|
|
|
|
ResultCode RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory);
|
|
|
|
ResultCode RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory);
|
2018-08-10 02:50:10 +02:00
|
|
|
ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory);
|
2018-07-17 21:42:15 +02:00
|
|
|
|
2018-08-19 03:28:17 +02:00
|
|
|
ResultVal<FileSys::VirtualFile> OpenRomFSCurrentProcess();
|
|
|
|
ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
|
|
|
FileSys::ContentRecordType type);
|
2018-07-19 03:07:11 +02:00
|
|
|
ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space,
|
|
|
|
FileSys::SaveDataDescriptor save_struct);
|
|
|
|
ResultVal<FileSys::VirtualDir> OpenSDMC();
|
2018-07-17 21:42:15 +02:00
|
|
|
|
2018-08-10 02:50:10 +02:00
|
|
|
std::shared_ptr<FileSys::RegisteredCache> GetSystemNANDContents();
|
|
|
|
std::shared_ptr<FileSys::RegisteredCache> GetUserNANDContents();
|
2018-08-16 23:04:38 +02:00
|
|
|
std::shared_ptr<FileSys::RegisteredCache> GetSDMCContents();
|
|
|
|
|
|
|
|
// Creates the SaveData, SDMC, and BIS Factories. Should be called once and before any function
|
|
|
|
// above is called.
|
|
|
|
void CreateFactories(const FileSys::VirtualFilesystem& vfs, bool overwrite = true);
|
2018-03-04 19:03:58 +01:00
|
|
|
|
2018-08-03 17:51:48 +02:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager, const FileSys::VirtualFilesystem& vfs);
|
2018-01-17 04:20:12 +01:00
|
|
|
|
2018-07-19 03:07:11 +02:00
|
|
|
// A class that wraps a VfsDirectory with methods that return ResultVal and ResultCode instead of
|
|
|
|
// pointers and booleans. This makes using a VfsDirectory with switch services much easier and
|
|
|
|
// avoids repetitive code.
|
|
|
|
class VfsDirectoryServiceWrapper {
|
|
|
|
public:
|
|
|
|
explicit VfsDirectoryServiceWrapper(FileSys::VirtualDir backing);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
|
|
|
|
*/
|
|
|
|
std::string GetName() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a file specified by its path
|
|
|
|
* @param path Path relative to the Archive
|
|
|
|
* @param size The size of the new file, filled with zeroes
|
|
|
|
* @return Result of the operation
|
|
|
|
*/
|
|
|
|
ResultCode CreateFile(const std::string& path, u64 size) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a file specified by its path
|
|
|
|
* @param path Path relative to the archive
|
|
|
|
* @return Result of the operation
|
|
|
|
*/
|
|
|
|
ResultCode DeleteFile(const std::string& path) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a directory specified by its path
|
|
|
|
* @param path Path relative to the archive
|
|
|
|
* @return Result of the operation
|
|
|
|
*/
|
|
|
|
ResultCode CreateDirectory(const std::string& path) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a directory specified by its path
|
|
|
|
* @param path Path relative to the archive
|
|
|
|
* @return Result of the operation
|
|
|
|
*/
|
|
|
|
ResultCode DeleteDirectory(const std::string& path) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a directory specified by its path and anything under it
|
|
|
|
* @param path Path relative to the archive
|
|
|
|
* @return Result of the operation
|
|
|
|
*/
|
|
|
|
ResultCode DeleteDirectoryRecursively(const std::string& path) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rename a File specified by its path
|
|
|
|
* @param src_path Source path relative to the archive
|
|
|
|
* @param dest_path Destination path relative to the archive
|
|
|
|
* @return Result of the operation
|
|
|
|
*/
|
|
|
|
ResultCode RenameFile(const std::string& src_path, const std::string& dest_path) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rename a Directory specified by its path
|
|
|
|
* @param src_path Source path relative to the archive
|
|
|
|
* @param dest_path Destination path relative to the archive
|
|
|
|
* @return Result of the operation
|
|
|
|
*/
|
|
|
|
ResultCode RenameDirectory(const std::string& src_path, const std::string& dest_path) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a file specified by its path, using the specified mode
|
|
|
|
* @param path Path relative to the archive
|
|
|
|
* @param mode Mode to open the file with
|
|
|
|
* @return Opened file, or error code
|
|
|
|
*/
|
|
|
|
ResultVal<FileSys::VirtualFile> OpenFile(const std::string& path, FileSys::Mode mode) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a directory specified by its path
|
|
|
|
* @param path Path relative to the archive
|
|
|
|
* @return Opened directory, or error code
|
|
|
|
*/
|
|
|
|
ResultVal<FileSys::VirtualDir> OpenDirectory(const std::string& path);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the free space
|
|
|
|
* @return The number of free bytes in the archive
|
|
|
|
*/
|
|
|
|
u64 GetFreeSpaceSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the type of the specified path
|
|
|
|
* @return The type of the specified path or error code
|
|
|
|
*/
|
|
|
|
ResultVal<FileSys::EntryType> GetEntryType(const std::string& path) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FileSys::VirtualDir backing;
|
|
|
|
};
|
|
|
|
|
2018-01-21 03:32:36 +01:00
|
|
|
} // namespace FileSystem
|
2018-01-17 04:20:12 +01:00
|
|
|
} // namespace Service
|