diff options
author | Zach Hilman <[email protected]> | 2018-07-18 21:07:11 -0400 |
---|---|---|
committer | bunnei <[email protected]> | 2018-07-18 18:07:11 -0700 |
commit | 29aff8d5ab46c8d0199aa4bfa7eeff5d4fa2d7ef (patch) | |
tree | 3202e2ce55ab6387a4ca366a509eccdd963434c3 /src/core/loader/loader.cpp | |
parent | 924c473bb3a80cf1452949d8c0328912464a6807 (diff) | |
download | yuzu-android-29aff8d5ab46c8d0199aa4bfa7eeff5d4fa2d7ef.tar.gz yuzu-android-29aff8d5ab46c8d0199aa4bfa7eeff5d4fa2d7ef.zip |
Virtual Filesystem 2: Electric Boogaloo (#676)
* Virtual Filesystem
* Fix delete bug and documentate
* Review fixes + other stuff
* Fix puyo regression
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 |