diff options
author | bunnei <bunneidev@gmail.com> | 2018-07-08 05:24:51 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-07-08 05:24:51 +0200 |
commit | 913896cbd99e414c325c9d47a987376ed6d9fffd (patch) | |
tree | b660920a49f538f0ee00486c50a0d153d53c423d /src/core/loader/loader.cpp | |
parent | Merge pull request #632 from FearlessTobi/add-discord-link (diff) | |
download | yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.gz yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.bz2 yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.lz yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.xz yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.zst yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/loader/loader.cpp | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 1574345a1..8831d8e83 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -6,7 +6,6 @@ #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" @@ -22,11 +21,11 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { {0x1F000000, 0x600000, false}, // entire VRAM }; -FileType IdentifyFile(FileSys::VirtualFile file) { +FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath) { FileType type; #define CHECK_TYPE(loader) \ - type = AppLoader_##loader::IdentifyType(file); \ + type = AppLoader_##loader::IdentifyType(file, filepath); \ if (FileType::Error != type) \ return type; @@ -42,22 +41,25 @@ FileType IdentifyFile(FileSys::VirtualFile file) { } FileType IdentifyFile(const std::string& file_name) { - return IdentifyFile(FileSys::VirtualFile(std::make_shared<FileSys::RealVfsFile>(file_name))); -} + FileUtil::IOFile file(file_name, "rb"); + if (!file.IsOpen()) { + LOG_ERROR(Loader, "Failed to load file {}", file_name); + return FileType::Unknown; + } -FileType GuessFromFilename(const std::string& name) { - if (name == "main") - return FileType::DeconstructedRomDirectory; + return IdentifyFile(file, file_name); +} - const std::string extension = Common::ToLower(FileUtil::GetExtensionFromFilename(name)); +FileType GuessFromExtension(const std::string& extension_) { + std::string extension = Common::ToLower(extension_); - if (extension == "elf") + if (extension == ".elf") return FileType::ELF; - if (extension == "nro") + else if (extension == ".nro") return FileType::NRO; - if (extension == "nso") + else if (extension == ".nso") return FileType::NSO; - if (extension == "nca") + else if (extension == ".nca") return FileType::NCA; return FileType::Unknown; @@ -91,47 +93,58 @@ 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(FileSys::VirtualFile file, FileType type) { +static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileType type, + const std::string& filename, + const std::string& filepath) { switch (type) { // Standard ELF file format. case FileType::ELF: - return std::make_unique<AppLoader_ELF>(std::move(file)); + return std::make_unique<AppLoader_ELF>(std::move(file), filename); // NX NSO file format. case FileType::NSO: - return std::make_unique<AppLoader_NSO>(std::move(file)); + return std::make_unique<AppLoader_NSO>(std::move(file), filepath); // NX NRO file format. case FileType::NRO: - return std::make_unique<AppLoader_NRO>(std::move(file)); + return std::make_unique<AppLoader_NRO>(std::move(file), filepath); // NX NCA file format. case FileType::NCA: - return std::make_unique<AppLoader_NCA>(std::move(file)); + return std::make_unique<AppLoader_NCA>(std::move(file), filepath); // NX deconstructed ROM directory. case FileType::DeconstructedRomDirectory: - return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file)); + return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file), filepath); default: return nullptr; } } -std::unique_ptr<AppLoader> GetLoader(FileSys::VirtualFile file) { - FileType type = IdentifyFile(file); - FileType filename_type = GuessFromFilename(file->GetName()); +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); if (type != filename_type) { - LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName()); + LOG_WARNING(Loader, "File {} has a different type than its extension.", filename); if (FileType::Unknown == type) type = filename_type; } - LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type)); + LOG_DEBUG(Loader, "Loading file {} as {}...", filename, GetFileTypeString(type)); - return GetFileLoader(std::move(file), type); + return GetFileLoader(std::move(file), type, filename_filename, filename); } } // namespace Loader |