mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-09-06 22:59:07 +01:00
Loader: Remove unnecessary pointer indirection to IOFile
This commit is contained in:
parent
c385b7767d
commit
2d7299a86f
10 changed files with 50 additions and 50 deletions
|
@ -17,7 +17,7 @@
|
|||
|
||||
namespace FileSys {
|
||||
|
||||
ArchiveFactory_RomFS::ArchiveFactory_RomFS(const Loader::AppLoader& app_loader) {
|
||||
ArchiveFactory_RomFS::ArchiveFactory_RomFS(Loader::AppLoader& app_loader) {
|
||||
// Load the RomFS from the app
|
||||
if (Loader::ResultStatus::Success != app_loader.ReadRomFS(romfs_file, data_offset, data_size)) {
|
||||
LOG_ERROR(Service_FS, "Unable to read RomFS!");
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace FileSys {
|
|||
/// File system interface to the RomFS archive
|
||||
class ArchiveFactory_RomFS final : public ArchiveFactory {
|
||||
public:
|
||||
ArchiveFactory_RomFS(const Loader::AppLoader& app_loader);
|
||||
ArchiveFactory_RomFS(Loader::AppLoader& app_loader);
|
||||
|
||||
std::string GetName() const override { return "RomFS"; }
|
||||
ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
|
||||
|
|
|
@ -246,11 +246,11 @@ ResultStatus AppLoader_THREEDSX::Load() {
|
|||
if (is_loaded)
|
||||
return ResultStatus::ErrorAlreadyLoaded;
|
||||
|
||||
if (!file->IsOpen())
|
||||
if (!file.IsOpen())
|
||||
return ResultStatus::Error;
|
||||
|
||||
SharedPtr<CodeSet> codeset;
|
||||
if (Load3DSXFile(*file, Memory::PROCESS_IMAGE_VADDR, &codeset) != ERROR_NONE)
|
||||
if (Load3DSXFile(file, Memory::PROCESS_IMAGE_VADDR, &codeset) != ERROR_NONE)
|
||||
return ResultStatus::Error;
|
||||
codeset->name = filename;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Loader {
|
|||
/// Loads an 3DSX file
|
||||
class AppLoader_THREEDSX final : public AppLoader {
|
||||
public:
|
||||
AppLoader_THREEDSX(std::unique_ptr<FileUtil::IOFile>&& file, std::string filename)
|
||||
AppLoader_THREEDSX(FileUtil::IOFile&& file, std::string filename)
|
||||
: AppLoader(std::move(file)), filename(std::move(filename)) {}
|
||||
|
||||
/**
|
||||
|
|
|
@ -392,15 +392,15 @@ ResultStatus AppLoader_ELF::Load() {
|
|||
if (is_loaded)
|
||||
return ResultStatus::ErrorAlreadyLoaded;
|
||||
|
||||
if (!file->IsOpen())
|
||||
if (!file.IsOpen())
|
||||
return ResultStatus::Error;
|
||||
|
||||
// Reset read pointer in case this file has been read before.
|
||||
file->Seek(0, SEEK_SET);
|
||||
file.Seek(0, SEEK_SET);
|
||||
|
||||
u32 size = static_cast<u32>(file->GetSize());
|
||||
u32 size = static_cast<u32>(file.GetSize());
|
||||
std::unique_ptr<u8[]> buffer(new u8[size]);
|
||||
if (file->ReadBytes(&buffer[0], size) != size)
|
||||
if (file.ReadBytes(&buffer[0], size) != size)
|
||||
return ResultStatus::Error;
|
||||
|
||||
ElfReader elf_reader(&buffer[0]);
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Loader {
|
|||
/// Loads an ELF/AXF file
|
||||
class AppLoader_ELF final : public AppLoader {
|
||||
public:
|
||||
AppLoader_ELF(std::unique_ptr<FileUtil::IOFile>&& file, std::string filename)
|
||||
AppLoader_ELF(FileUtil::IOFile&& file, std::string filename)
|
||||
: AppLoader(std::move(file)), filename(std::move(filename)) { }
|
||||
|
||||
/**
|
||||
|
|
|
@ -90,8 +90,8 @@ static const char* GetFileTypeString(FileType type) {
|
|||
}
|
||||
|
||||
ResultStatus LoadFile(const std::string& filename) {
|
||||
std::unique_ptr<FileUtil::IOFile> file(new FileUtil::IOFile(filename, "rb"));
|
||||
if (!file->IsOpen()) {
|
||||
FileUtil::IOFile file(filename, "rb");
|
||||
if (!file.IsOpen()) {
|
||||
LOG_ERROR(Loader, "Failed to load file %s", filename.c_str());
|
||||
return ResultStatus::Error;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ ResultStatus LoadFile(const std::string& filename) {
|
|||
std::string filename_filename, filename_extension;
|
||||
Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension);
|
||||
|
||||
FileType type = IdentifyFile(*file);
|
||||
FileType type = IdentifyFile(file);
|
||||
FileType filename_type = GuessFromExtension(filename_extension);
|
||||
|
||||
if (type != filename_type) {
|
||||
|
|
|
@ -52,7 +52,7 @@ static inline u32 MakeMagic(char a, char b, char c, char d) {
|
|||
/// Interface for loading an application
|
||||
class AppLoader : NonCopyable {
|
||||
public:
|
||||
AppLoader(std::unique_ptr<FileUtil::IOFile>&& file) : file(std::move(file)) { }
|
||||
AppLoader(FileUtil::IOFile&& file) : file(std::move(file)) { }
|
||||
virtual ~AppLoader() { }
|
||||
|
||||
/**
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
virtual ResultStatus ReadCode(std::vector<u8>& buffer) const {
|
||||
virtual ResultStatus ReadCode(std::vector<u8>& buffer) {
|
||||
return ResultStatus::ErrorNotImplemented;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public:
|
|||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
virtual ResultStatus ReadIcon(std::vector<u8>& buffer) const {
|
||||
virtual ResultStatus ReadIcon(std::vector<u8>& buffer) {
|
||||
return ResultStatus::ErrorNotImplemented;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
virtual ResultStatus ReadBanner(std::vector<u8>& buffer) const {
|
||||
virtual ResultStatus ReadBanner(std::vector<u8>& buffer) {
|
||||
return ResultStatus::ErrorNotImplemented;
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
virtual ResultStatus ReadLogo(std::vector<u8>& buffer) const {
|
||||
virtual ResultStatus ReadLogo(std::vector<u8>& buffer) {
|
||||
return ResultStatus::ErrorNotImplemented;
|
||||
}
|
||||
|
||||
|
@ -105,13 +105,13 @@ public:
|
|||
* @param size The size of the romfs
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
virtual ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const {
|
||||
virtual ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) {
|
||||
return ResultStatus::ErrorNotImplemented;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<FileUtil::IOFile> file;
|
||||
bool is_loaded = false;
|
||||
FileUtil::IOFile file;
|
||||
bool is_loaded = false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -117,7 +117,7 @@ FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) {
|
|||
return FileType::Error;
|
||||
}
|
||||
|
||||
ResultStatus AppLoader_NCCH::LoadExec() const {
|
||||
ResultStatus AppLoader_NCCH::LoadExec() {
|
||||
using Kernel::SharedPtr;
|
||||
using Kernel::CodeSet;
|
||||
|
||||
|
@ -171,8 +171,8 @@ ResultStatus AppLoader_NCCH::LoadExec() const {
|
|||
return ResultStatus::Error;
|
||||
}
|
||||
|
||||
ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer) const {
|
||||
if (!file->IsOpen())
|
||||
ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer) {
|
||||
if (!file.IsOpen())
|
||||
return ResultStatus::Error;
|
||||
|
||||
LOG_DEBUG(Loader, "%d sections:", kMaxSections);
|
||||
|
@ -186,7 +186,7 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>&
|
|||
section.offset, section.size, section.name);
|
||||
|
||||
s64 section_offset = (section.offset + exefs_offset + sizeof(ExeFs_Header) + ncch_offset);
|
||||
file->Seek(section_offset, SEEK_SET);
|
||||
file.Seek(section_offset, SEEK_SET);
|
||||
|
||||
if (is_compressed) {
|
||||
// Section is compressed, read compressed .code section...
|
||||
|
@ -197,7 +197,7 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>&
|
|||
return ResultStatus::ErrorMemoryAllocationFailed;
|
||||
}
|
||||
|
||||
if (file->ReadBytes(&temp_buffer[0], section.size) != section.size)
|
||||
if (file.ReadBytes(&temp_buffer[0], section.size) != section.size)
|
||||
return ResultStatus::Error;
|
||||
|
||||
// Decompress .code section...
|
||||
|
@ -208,7 +208,7 @@ ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>&
|
|||
} else {
|
||||
// Section is uncompressed...
|
||||
buffer.resize(section.size);
|
||||
if (file->ReadBytes(&buffer[0], section.size) != section.size)
|
||||
if (file.ReadBytes(&buffer[0], section.size) != section.size)
|
||||
return ResultStatus::Error;
|
||||
}
|
||||
return ResultStatus::Success;
|
||||
|
@ -221,21 +221,21 @@ ResultStatus AppLoader_NCCH::Load() {
|
|||
if (is_loaded)
|
||||
return ResultStatus::ErrorAlreadyLoaded;
|
||||
|
||||
if (!file->IsOpen())
|
||||
if (!file.IsOpen())
|
||||
return ResultStatus::Error;
|
||||
|
||||
// Reset read pointer in case this file has been read before.
|
||||
file->Seek(0, SEEK_SET);
|
||||
file.Seek(0, SEEK_SET);
|
||||
|
||||
if (file->ReadBytes(&ncch_header, sizeof(NCCH_Header)) != sizeof(NCCH_Header))
|
||||
if (file.ReadBytes(&ncch_header, sizeof(NCCH_Header)) != sizeof(NCCH_Header))
|
||||
return ResultStatus::Error;
|
||||
|
||||
// Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)...
|
||||
if (MakeMagic('N', 'C', 'S', 'D') == ncch_header.magic) {
|
||||
LOG_WARNING(Loader, "Only loading the first (bootable) NCCH within the NCSD file!");
|
||||
ncch_offset = 0x4000;
|
||||
file->Seek(ncch_offset, SEEK_SET);
|
||||
file->ReadBytes(&ncch_header, sizeof(NCCH_Header));
|
||||
file.Seek(ncch_offset, SEEK_SET);
|
||||
file.ReadBytes(&ncch_header, sizeof(NCCH_Header));
|
||||
}
|
||||
|
||||
// Verify we are loading the correct file type...
|
||||
|
@ -244,7 +244,7 @@ ResultStatus AppLoader_NCCH::Load() {
|
|||
|
||||
// Read ExHeader...
|
||||
|
||||
if (file->ReadBytes(&exheader_header, sizeof(ExHeader_Header)) != sizeof(ExHeader_Header))
|
||||
if (file.ReadBytes(&exheader_header, sizeof(ExHeader_Header)) != sizeof(ExHeader_Header))
|
||||
return ResultStatus::Error;
|
||||
|
||||
is_compressed = (exheader_header.codeset_info.flags.flag & 1) == 1;
|
||||
|
@ -274,8 +274,8 @@ ResultStatus AppLoader_NCCH::Load() {
|
|||
LOG_DEBUG(Loader, "ExeFS offset: 0x%08X", exefs_offset);
|
||||
LOG_DEBUG(Loader, "ExeFS size: 0x%08X", exefs_size);
|
||||
|
||||
file->Seek(exefs_offset + ncch_offset, SEEK_SET);
|
||||
if (file->ReadBytes(&exefs_header, sizeof(ExeFs_Header)) != sizeof(ExeFs_Header))
|
||||
file.Seek(exefs_offset + ncch_offset, SEEK_SET);
|
||||
if (file.ReadBytes(&exefs_header, sizeof(ExeFs_Header)) != sizeof(ExeFs_Header))
|
||||
return ResultStatus::Error;
|
||||
|
||||
is_loaded = true; // Set state to loaded
|
||||
|
@ -283,24 +283,24 @@ ResultStatus AppLoader_NCCH::Load() {
|
|||
return LoadExec(); // Load the executable into memory for booting
|
||||
}
|
||||
|
||||
ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) const {
|
||||
ResultStatus AppLoader_NCCH::ReadCode(std::vector<u8>& buffer) {
|
||||
return LoadSectionExeFS(".code", buffer);
|
||||
}
|
||||
|
||||
ResultStatus AppLoader_NCCH::ReadIcon(std::vector<u8>& buffer) const {
|
||||
ResultStatus AppLoader_NCCH::ReadIcon(std::vector<u8>& buffer) {
|
||||
return LoadSectionExeFS("icon", buffer);
|
||||
}
|
||||
|
||||
ResultStatus AppLoader_NCCH::ReadBanner(std::vector<u8>& buffer) const {
|
||||
ResultStatus AppLoader_NCCH::ReadBanner(std::vector<u8>& buffer) {
|
||||
return LoadSectionExeFS("banner", buffer);
|
||||
}
|
||||
|
||||
ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& buffer) const {
|
||||
ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& buffer) {
|
||||
return LoadSectionExeFS("logo", buffer);
|
||||
}
|
||||
|
||||
ResultStatus AppLoader_NCCH::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const {
|
||||
if (!file->IsOpen())
|
||||
ResultStatus AppLoader_NCCH::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) {
|
||||
if (!file.IsOpen())
|
||||
return ResultStatus::Error;
|
||||
|
||||
// Check if the NCCH has a RomFS...
|
||||
|
@ -311,7 +311,7 @@ ResultStatus AppLoader_NCCH::ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_
|
|||
LOG_DEBUG(Loader, "RomFS offset: 0x%08X", romfs_offset);
|
||||
LOG_DEBUG(Loader, "RomFS size: 0x%08X", romfs_size);
|
||||
|
||||
if (file->GetSize () < romfs_offset + romfs_size)
|
||||
if (file.GetSize () < romfs_offset + romfs_size)
|
||||
return ResultStatus::Error;
|
||||
|
||||
// We reopen the file, to allow its position to be independent from file's
|
||||
|
|
|
@ -163,7 +163,7 @@ namespace Loader {
|
|||
/// Loads an NCCH file (e.g. from a CCI, or the first NCCH in a CXI)
|
||||
class AppLoader_NCCH final : public AppLoader {
|
||||
public:
|
||||
AppLoader_NCCH(std::unique_ptr<FileUtil::IOFile>&& file, const std::string& filepath)
|
||||
AppLoader_NCCH(FileUtil::IOFile&& file, const std::string& filepath)
|
||||
: AppLoader(std::move(file)), filepath(filepath) { }
|
||||
|
||||
/**
|
||||
|
@ -184,35 +184,35 @@ public:
|
|||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
ResultStatus ReadCode(std::vector<u8>& buffer) const override;
|
||||
ResultStatus ReadCode(std::vector<u8>& buffer) override;
|
||||
|
||||
/**
|
||||
* Get the icon (typically icon section) of the application
|
||||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
ResultStatus ReadIcon(std::vector<u8>& buffer) const override;
|
||||
ResultStatus ReadIcon(std::vector<u8>& buffer) override;
|
||||
|
||||
/**
|
||||
* Get the banner (typically banner section) of the application
|
||||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
ResultStatus ReadBanner(std::vector<u8>& buffer) const override;
|
||||
ResultStatus ReadBanner(std::vector<u8>& buffer) override;
|
||||
|
||||
/**
|
||||
* Get the logo (typically logo section) of the application
|
||||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
ResultStatus ReadLogo(std::vector<u8>& buffer) const override;
|
||||
ResultStatus ReadLogo(std::vector<u8>& buffer) override;
|
||||
|
||||
/**
|
||||
* Get the RomFS of the application
|
||||
* @param buffer Reference to buffer to store data
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) const override;
|
||||
ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) override;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -222,13 +222,13 @@ private:
|
|||
* @param buffer Vector to read data into
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
ResultStatus LoadSectionExeFS(const char* name, std::vector<u8>& buffer) const;
|
||||
ResultStatus LoadSectionExeFS(const char* name, std::vector<u8>& buffer);
|
||||
|
||||
/**
|
||||
* Loads .code section into memory for booting
|
||||
* @return ResultStatus result of function
|
||||
*/
|
||||
ResultStatus LoadExec() const;
|
||||
ResultStatus LoadExec();
|
||||
|
||||
bool is_compressed = false;
|
||||
|
||||
|
|
Loading…
Reference in a new issue