mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-24 16:31:05 +00:00
. (Will git move this to the right place?)
This commit is contained in:
parent
ac7bc214ab
commit
2414fe33f8
@ -16,16 +16,15 @@
|
|||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
ArchiveFactory_RomFS::ArchiveFactory_RomFS(const Loader::AppLoader& app_loader)
|
ArchiveFactory_RomFS::ArchiveFactory_RomFS(const Loader::AppLoader& app_loader) {
|
||||||
: romfs_data(std::make_shared<std::vector<u8>>()) {
|
|
||||||
// Load the RomFS from the app
|
// Load the RomFS from the app
|
||||||
if (Loader::ResultStatus::Success != app_loader.ReadRomFS(*romfs_data)) {
|
if (Loader::ResultStatus::Success != app_loader.ReadRomFS (m_romfs_file, m_offset, m_size)) {
|
||||||
LOG_ERROR(Service_FS, "Unable to read RomFS!");
|
LOG_ERROR(Service_FS, "Unable to read RomFS!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path& path) {
|
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path& path) {
|
||||||
auto archive = Common::make_unique<IVFCArchive>(romfs_data);
|
auto archive = Common::make_unique<IVFCArchive>(m_romfs_file, m_offset, m_size);
|
||||||
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
|
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@ public:
|
|||||||
ResultCode Format(const Path& path) override;
|
ResultCode Format(const Path& path) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<std::vector<u8>> romfs_data;
|
std::shared_ptr<FileUtil::IOFile> m_romfs_file;
|
||||||
|
u64 m_offset;
|
||||||
|
u64 m_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
@ -31,17 +31,14 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(co
|
|||||||
auto vec = path.AsBinary();
|
auto vec = path.AsBinary();
|
||||||
const u32* data = reinterpret_cast<u32*>(vec.data());
|
const u32* data = reinterpret_cast<u32*>(vec.data());
|
||||||
std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]);
|
std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]);
|
||||||
FileUtil::IOFile file(file_path, "rb");
|
auto file = std::make_shared<FileUtil::IOFile>(file_path, "rb");
|
||||||
|
|
||||||
if (!file.IsOpen()) {
|
if (!file->IsOpen()) {
|
||||||
return ResultCode(-1); // TODO(Subv): Find the right error code
|
return ResultCode(-1); // TODO(Subv): Find the right error code
|
||||||
}
|
}
|
||||||
auto size = file.GetSize();
|
auto size = file->GetSize();
|
||||||
auto raw_data = std::make_shared<std::vector<u8>>(size);
|
|
||||||
file.ReadBytes(raw_data->data(), size);
|
|
||||||
file.Close();
|
|
||||||
|
|
||||||
auto archive = Common::make_unique<IVFCArchive>(std::move(raw_data));
|
auto archive = Common::make_unique<IVFCArchive>(file, 0, size);
|
||||||
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
|
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,15 +16,12 @@
|
|||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
IVFCArchive::IVFCArchive(std::shared_ptr<const std::vector<u8>> data) : data(data) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string IVFCArchive::GetName() const {
|
std::string IVFCArchive::GetName() const {
|
||||||
return "IVFC";
|
return "IVFC";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<FileBackend> IVFCArchive::OpenFile(const Path& path, const Mode mode) const {
|
std::unique_ptr<FileBackend> IVFCArchive::OpenFile(const Path& path, const Mode mode) const {
|
||||||
return Common::make_unique<IVFCFile>(data);
|
return Common::make_unique<IVFCFile>(m_romfs_file, m_offset, m_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IVFCArchive::DeleteFile(const Path& path) const {
|
bool IVFCArchive::DeleteFile(const Path& path) const {
|
||||||
@ -66,8 +63,10 @@ std::unique_ptr<DirectoryBackend> IVFCArchive::OpenDirectory(const Path& path) c
|
|||||||
|
|
||||||
size_t IVFCFile::Read(const u64 offset, const u32 length, u8* buffer) const {
|
size_t IVFCFile::Read(const u64 offset, const u32 length, u8* buffer) const {
|
||||||
LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length);
|
LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length);
|
||||||
memcpy(buffer, data->data() + offset, length);
|
m_romfs_file->Seek(m_offset + offset, SEEK_SET);
|
||||||
return length;
|
u32 read_length = (u32) std::min((u64) length, m_size - offset);
|
||||||
|
|
||||||
|
return m_romfs_file->ReadBytes(buffer, read_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t IVFCFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const {
|
size_t IVFCFile::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const {
|
||||||
@ -76,7 +75,7 @@ size_t IVFCFile::Write(const u64 offset, const u32 length, const u32 flush, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t IVFCFile::GetSize() const {
|
size_t IVFCFile::GetSize() const {
|
||||||
return sizeof(u8) * data->size();
|
return sizeof(u8) * m_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IVFCFile::SetSize(const u64 size) const {
|
bool IVFCFile::SetSize(const u64 size) const {
|
||||||
|
@ -26,7 +26,8 @@ namespace FileSys {
|
|||||||
*/
|
*/
|
||||||
class IVFCArchive : public ArchiveBackend {
|
class IVFCArchive : public ArchiveBackend {
|
||||||
public:
|
public:
|
||||||
IVFCArchive(std::shared_ptr<const std::vector<u8>> data);
|
IVFCArchive(std::shared_ptr<FileUtil::IOFile> romfs_file, u64 offset, u64 size)
|
||||||
|
: m_romfs_file(romfs_file), m_offset(offset), m_size(size) {}
|
||||||
|
|
||||||
std::string GetName() const override;
|
std::string GetName() const override;
|
||||||
|
|
||||||
@ -40,12 +41,15 @@ public:
|
|||||||
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
|
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<const std::vector<u8>> data;
|
std::shared_ptr<FileUtil::IOFile> m_romfs_file;
|
||||||
|
u64 m_offset;
|
||||||
|
u64 m_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IVFCFile : public FileBackend {
|
class IVFCFile : public FileBackend {
|
||||||
public:
|
public:
|
||||||
IVFCFile(std::shared_ptr<const std::vector<u8>> data) : data(data) {}
|
IVFCFile(std::shared_ptr<FileUtil::IOFile> romfs_file, u64 offset, u64 size)
|
||||||
|
: m_romfs_file(romfs_file), m_offset(offset), m_size(size) {}
|
||||||
|
|
||||||
bool Open() override { return true; }
|
bool Open() override { return true; }
|
||||||
size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
|
size_t Read(const u64 offset, const u32 length, u8* buffer) const override;
|
||||||
@ -56,7 +60,9 @@ public:
|
|||||||
void Flush() const override { }
|
void Flush() const override { }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<const std::vector<u8>> data;
|
std::shared_ptr<FileUtil::IOFile> m_romfs_file;
|
||||||
|
u64 m_offset;
|
||||||
|
u64 m_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IVFCDirectory : public DirectoryBackend {
|
class IVFCDirectory : public DirectoryBackend {
|
||||||
|
@ -122,7 +122,7 @@ ResultStatus LoadFile(const std::string& filename) {
|
|||||||
case FileType::CXI:
|
case FileType::CXI:
|
||||||
case FileType::CCI:
|
case FileType::CCI:
|
||||||
{
|
{
|
||||||
AppLoader_NCCH app_loader(std::move(file));
|
AppLoader_NCCH app_loader(std::move(file), filename);
|
||||||
|
|
||||||
// Load application and RomFS
|
// Load application and RomFS
|
||||||
if (ResultStatus::Success == app_loader.Load()) {
|
if (ResultStatus::Success == app_loader.Load()) {
|
||||||
|
@ -93,10 +93,13 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the RomFS of the application
|
* Get the RomFS of the application
|
||||||
* @param buffer Reference to buffer to store data
|
* Since the RomFS is huge, we return a file reference instead of copying to a buffer
|
||||||
|
* @param romfs_file The file containing the RomFS
|
||||||
|
* @param offset The offset the romfs begins on
|
||||||
|
* @param size The size of the romfs
|
||||||
* @return ResultStatus result of function
|
* @return ResultStatus result of function
|
||||||
*/
|
*/
|
||||||
virtual ResultStatus ReadRomFS(std::vector<u8>& buffer) const {
|
virtual ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const {
|
||||||
return ResultStatus::ErrorNotImplemented;
|
return ResultStatus::ErrorNotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& buffer) const {
|
|||||||
return LoadSectionExeFS("logo", buffer);
|
return LoadSectionExeFS("logo", buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const {
|
ResultStatus AppLoader_NCCH::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const {
|
||||||
if (!file->IsOpen())
|
if (!file->IsOpen())
|
||||||
return ResultStatus::Error;
|
return ResultStatus::Error;
|
||||||
|
|
||||||
@ -286,12 +286,16 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const {
|
|||||||
LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset);
|
LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset);
|
||||||
LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size);
|
LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size);
|
||||||
|
|
||||||
buffer.resize(romfs_size);
|
if (file->GetSize () < romfs_offset + romfs_size)
|
||||||
|
|
||||||
file->Seek(romfs_offset, SEEK_SET);
|
|
||||||
if (file->ReadBytes(&buffer[0], romfs_size) != romfs_size)
|
|
||||||
return ResultStatus::Error;
|
return ResultStatus::Error;
|
||||||
|
|
||||||
|
// We reopen the file, to avoid reuse of the file offset
|
||||||
|
romfs_file.reset(new FileUtil::IOFile(filepath, "rb"));
|
||||||
|
offset = romfs_offset;
|
||||||
|
size = romfs_size;
|
||||||
|
|
||||||
|
if (!romfs_file->IsOpen())
|
||||||
|
return ResultStatus::Error;
|
||||||
return ResultStatus::Success;
|
return ResultStatus::Success;
|
||||||
}
|
}
|
||||||
LOG_DEBUG(Loader, "NCCH has no RomFS");
|
LOG_DEBUG(Loader, "NCCH has no RomFS");
|
||||||
|
@ -163,7 +163,8 @@ namespace Loader {
|
|||||||
/// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI)
|
/// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI)
|
||||||
class AppLoader_NCCH final : public AppLoader {
|
class AppLoader_NCCH final : public AppLoader {
|
||||||
public:
|
public:
|
||||||
AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file) : AppLoader(std::move(file)) { }
|
AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file, std::string filepath)
|
||||||
|
: AppLoader(std::move(file)), filepath(filepath) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of the file
|
* Returns the type of the file
|
||||||
@ -211,7 +212,7 @@ public:
|
|||||||
* @param buffer Reference to buffer to store data
|
* @param buffer Reference to buffer to store data
|
||||||
* @return ResultStatus result of function
|
* @return ResultStatus result of function
|
||||||
*/
|
*/
|
||||||
ResultStatus ReadRomFS(std::vector<u8>& buffer) const override;
|
ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -244,6 +245,8 @@ private:
|
|||||||
NCCH_Header ncch_header;
|
NCCH_Header ncch_header;
|
||||||
ExeFs_Header exefs_header;
|
ExeFs_Header exefs_header;
|
||||||
ExHeader_Header exheader_header;
|
ExHeader_Header exheader_header;
|
||||||
|
|
||||||
|
std::string filepath;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Loader
|
} // namespace Loader
|
||||||
|
Loading…
Reference in New Issue
Block a user