2015-01-01 17:39:27 +00:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-08-09 21:02:53 +00:00
|
|
|
#include <array>
|
2015-06-21 14:44:11 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include "core/file_sys/archive_backend.h"
|
2017-10-05 22:24:56 +00:00
|
|
|
#include "core/file_sys/file_backend.h"
|
2015-06-21 14:44:11 +00:00
|
|
|
#include "core/hle/result.h"
|
2015-01-01 17:39:27 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FileSys namespace
|
|
|
|
|
2017-10-05 22:24:56 +00:00
|
|
|
namespace Service {
|
|
|
|
namespace FS {
|
|
|
|
enum class MediaType : u32;
|
|
|
|
}
|
2018-02-24 13:14:54 +00:00
|
|
|
} // namespace Service
|
2017-10-05 22:24:56 +00:00
|
|
|
|
2015-01-01 17:39:27 +00:00
|
|
|
namespace FileSys {
|
|
|
|
|
2018-08-09 21:02:53 +00:00
|
|
|
enum class NCCHFilePathType : u32 {
|
|
|
|
RomFS = 0,
|
|
|
|
Code = 1,
|
|
|
|
ExeFS = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class NCCHFileOpenType : u32 {
|
|
|
|
NCCHData = 0,
|
|
|
|
SaveData = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Helper function to generate a Path for NCCH archives
|
|
|
|
Path MakeNCCHArchivePath(u64 tid, Service::FS::MediaType media_type);
|
|
|
|
|
|
|
|
/// Helper function to generate a Path for NCCH files
|
|
|
|
Path MakeNCCHFilePath(NCCHFileOpenType open_type, u32 content_index, NCCHFilePathType filepath_type,
|
|
|
|
std::array<char, 8>& exefs_filepath);
|
|
|
|
|
2017-10-05 22:24:56 +00:00
|
|
|
/// Archive backend for NCCH Archives (RomFS, ExeFS)
|
|
|
|
class NCCHArchive : public ArchiveBackend {
|
|
|
|
public:
|
|
|
|
explicit NCCHArchive(u64 title_id, Service::FS::MediaType media_type)
|
|
|
|
: title_id(title_id), media_type(media_type) {}
|
|
|
|
|
|
|
|
std::string GetName() const override {
|
|
|
|
return "NCCHArchive";
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
|
|
|
|
const Mode& mode) const override;
|
|
|
|
ResultCode DeleteFile(const Path& path) const override;
|
|
|
|
ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
|
|
|
|
ResultCode DeleteDirectory(const Path& path) const override;
|
|
|
|
ResultCode DeleteDirectoryRecursively(const Path& path) const override;
|
|
|
|
ResultCode CreateFile(const Path& path, u64 size) const override;
|
|
|
|
ResultCode CreateDirectory(const Path& path) const override;
|
|
|
|
ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
|
|
|
ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
|
|
|
|
u64 GetFreeBytes() const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
u64 title_id;
|
|
|
|
Service::FS::MediaType media_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
// File backend for NCCH files
|
|
|
|
class NCCHFile : public FileBackend {
|
|
|
|
public:
|
2018-02-24 13:14:54 +00:00
|
|
|
explicit NCCHFile(std::vector<u8> buffer, std::unique_ptr<DelayGenerator> delay_generator_);
|
2017-10-05 22:24:56 +00:00
|
|
|
|
2018-09-06 20:03:28 +00:00
|
|
|
ResultVal<std::size_t> Read(u64 offset, std::size_t length, u8* buffer) const override;
|
|
|
|
ResultVal<std::size_t> Write(u64 offset, std::size_t length, bool flush,
|
|
|
|
const u8* buffer) override;
|
2017-10-05 22:24:56 +00:00
|
|
|
u64 GetSize() const override;
|
|
|
|
bool SetSize(u64 size) const override;
|
|
|
|
bool Close() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void Flush() const override {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<u8> file_buffer;
|
|
|
|
u64 data_offset;
|
|
|
|
u64 data_size;
|
|
|
|
};
|
|
|
|
|
2016-10-21 14:10:55 +00:00
|
|
|
/// File system interface to the NCCH archive
|
|
|
|
class ArchiveFactory_NCCH final : public ArchiveFactory {
|
2015-01-01 17:39:27 +00:00
|
|
|
public:
|
2017-10-05 22:24:56 +00:00
|
|
|
explicit ArchiveFactory_NCCH();
|
2015-01-01 17:39:27 +00:00
|
|
|
|
2016-09-18 00:38:01 +00:00
|
|
|
std::string GetName() const override {
|
2016-10-21 14:10:55 +00:00
|
|
|
return "NCCH";
|
2016-09-18 00:38:01 +00:00
|
|
|
}
|
2015-02-06 13:53:14 +00:00
|
|
|
|
|
|
|
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
|
2015-12-28 18:51:44 +00:00
|
|
|
ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
|
|
|
|
ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
|
2015-01-01 17:39:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FileSys
|