diff options
author | Zach Hilman <DarkLordZach@users.noreply.github.com> | 2018-07-06 16:51:32 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-07-06 16:51:32 +0200 |
commit | 77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2 (patch) | |
tree | 38ef6451732c5eecb0efdd198f3db4d33848453c /src/core/loader/loader.cpp | |
parent | Merge pull request #629 from Subv/depth_test (diff) | |
download | yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.tar yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.tar.gz yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.tar.bz2 yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.tar.lz yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.tar.xz yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.tar.zst yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.zip |
Diffstat (limited to 'src/core/loader/loader.cpp')
-rw-r--r-- | src/core/loader/loader.cpp | 63 |
1 files changed, 25 insertions, 38 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 8831d8e83..1574345a1 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -6,6 +6,7 @@ #include <string> #include "common/logging/log.h" #include "common/string_util.h" +#include "core/file_sys/vfs_real.h" #include "core/hle/kernel/process.h" #include "core/loader/deconstructed_rom_directory.h" #include "core/loader/elf.h" @@ -21,11 +22,11 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { {0x1F000000, 0x600000, false}, // entire VRAM }; -FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath) { +FileType IdentifyFile(FileSys::VirtualFile file) { FileType type; #define CHECK_TYPE(loader) \ - type = AppLoader_##loader::IdentifyType(file, filepath); \ + type = AppLoader_##loader::IdentifyType(file); \ if (FileType::Error != type) \ return type; @@ -41,25 +42,22 @@ FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath) { } FileType IdentifyFile(const std::string& file_name) { - FileUtil::IOFile file(file_name, "rb"); - if (!file.IsOpen()) { - LOG_ERROR(Loader, "Failed to load file {}", file_name); - return FileType::Unknown; - } - - return IdentifyFile(file, file_name); + return IdentifyFile(FileSys::VirtualFile(std::make_shared<FileSys::RealVfsFile>(file_name))); } -FileType GuessFromExtension(const std::string& extension_) { - std::string extension = Common::ToLower(extension_); +FileType GuessFromFilename(const std::string& name) { + if (name == "main") + return FileType::DeconstructedRomDirectory; - if (extension == ".elf") + const std::string extension = Common::ToLower(FileUtil::GetExtensionFromFilename(name)); + + if (extension == "elf") return FileType::ELF; - else if (extension == ".nro") + if (extension == "nro") return FileType::NRO; - else if (extension == ".nso") + if (extension == "nso") return FileType::NSO; - else if (extension == ".nca") + if (extension == "nca") return FileType::NCA; return FileType::Unknown; @@ -93,58 +91,47 @@ const char* GetFileTypeString(FileType type) { * @param filepath the file full path (with name) * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type */ -static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileType type, - const std::string& filename, - const std::string& filepath) { +static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileType type) { switch (type) { // Standard ELF file format. case FileType::ELF: - return std::make_unique<AppLoader_ELF>(std::move(file), filename); + return std::make_unique<AppLoader_ELF>(std::move(file)); // NX NSO file format. case FileType::NSO: - return std::make_unique<AppLoader_NSO>(std::move(file), filepath); + return std::make_unique<AppLoader_NSO>(std::move(file)); // NX NRO file format. case FileType::NRO: - return std::make_unique<AppLoader_NRO>(std::move(file), filepath); + return std::make_unique<AppLoader_NRO>(std::move(file)); // NX NCA file format. case FileType::NCA: - return std::make_unique<AppLoader_NCA>(std::move(file), filepath); + return std::make_unique<AppLoader_NCA>(std::move(file)); // NX deconstructed ROM directory. case FileType::DeconstructedRomDirectory: - return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file), filepath); + return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file)); default: return nullptr; } } -std::unique_ptr<AppLoader> GetLoader(const std::string& filename) { - FileUtil::IOFile file(filename, "rb"); - if (!file.IsOpen()) { - LOG_ERROR(Loader, "Failed to load file {}", filename); - return nullptr; - } - - std::string filename_filename, filename_extension; - Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension); - - FileType type = IdentifyFile(file, filename); - FileType filename_type = GuessFromExtension(filename_extension); +std::unique_ptr<AppLoader> GetLoader(FileSys::VirtualFile file) { + FileType type = IdentifyFile(file); + FileType filename_type = GuessFromFilename(file->GetName()); if (type != filename_type) { - LOG_WARNING(Loader, "File {} has a different type than its extension.", filename); + LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName()); if (FileType::Unknown == type) type = filename_type; } - LOG_DEBUG(Loader, "Loading file {} as {}...", filename, GetFileTypeString(type)); + LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type)); - return GetFileLoader(std::move(file), type, filename_filename, filename); + return GetFileLoader(std::move(file), type); } } // namespace Loader |