diff options
| author | 2018-07-07 20:24:51 -0700 | |
|---|---|---|
| committer | 2018-07-07 20:24:51 -0700 | |
| 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.gz yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.xz yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.zip | |
Revert "Virtual Filesystem (#597)"
This reverts commit 77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.
Diffstat (limited to 'src/core/loader/loader.cpp')
| -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 @@ | |||
| 6 | #include <string> | 6 | #include <string> |
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "common/string_util.h" | 8 | #include "common/string_util.h" |
| 9 | #include "core/file_sys/vfs_real.h" | ||
| 10 | #include "core/hle/kernel/process.h" | 9 | #include "core/hle/kernel/process.h" |
| 11 | #include "core/loader/deconstructed_rom_directory.h" | 10 | #include "core/loader/deconstructed_rom_directory.h" |
| 12 | #include "core/loader/elf.h" | 11 | #include "core/loader/elf.h" |
| @@ -22,11 +21,11 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { | |||
| 22 | {0x1F000000, 0x600000, false}, // entire VRAM | 21 | {0x1F000000, 0x600000, false}, // entire VRAM |
| 23 | }; | 22 | }; |
| 24 | 23 | ||
| 25 | FileType IdentifyFile(FileSys::VirtualFile file) { | 24 | FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath) { |
| 26 | FileType type; | 25 | FileType type; |
| 27 | 26 | ||
| 28 | #define CHECK_TYPE(loader) \ | 27 | #define CHECK_TYPE(loader) \ |
| 29 | type = AppLoader_##loader::IdentifyType(file); \ | 28 | type = AppLoader_##loader::IdentifyType(file, filepath); \ |
| 30 | if (FileType::Error != type) \ | 29 | if (FileType::Error != type) \ |
| 31 | return type; | 30 | return type; |
| 32 | 31 | ||
| @@ -42,22 +41,25 @@ FileType IdentifyFile(FileSys::VirtualFile file) { | |||
| 42 | } | 41 | } |
| 43 | 42 | ||
| 44 | FileType IdentifyFile(const std::string& file_name) { | 43 | FileType IdentifyFile(const std::string& file_name) { |
| 45 | return IdentifyFile(FileSys::VirtualFile(std::make_shared<FileSys::RealVfsFile>(file_name))); | 44 | FileUtil::IOFile file(file_name, "rb"); |
| 46 | } | 45 | if (!file.IsOpen()) { |
| 46 | LOG_ERROR(Loader, "Failed to load file {}", file_name); | ||
| 47 | return FileType::Unknown; | ||
| 48 | } | ||
| 47 | 49 | ||
| 48 | FileType GuessFromFilename(const std::string& name) { | 50 | return IdentifyFile(file, file_name); |
| 49 | if (name == "main") | 51 | } |
| 50 | return FileType::DeconstructedRomDirectory; | ||
| 51 | 52 | ||
| 52 | const std::string extension = Common::ToLower(FileUtil::GetExtensionFromFilename(name)); | 53 | FileType GuessFromExtension(const std::string& extension_) { |
| 54 | std::string extension = Common::ToLower(extension_); | ||
| 53 | 55 | ||
| 54 | if (extension == "elf") | 56 | if (extension == ".elf") |
| 55 | return FileType::ELF; | 57 | return FileType::ELF; |
| 56 | if (extension == "nro") | 58 | else if (extension == ".nro") |
| 57 | return FileType::NRO; | 59 | return FileType::NRO; |
| 58 | if (extension == "nso") | 60 | else if (extension == ".nso") |
| 59 | return FileType::NSO; | 61 | return FileType::NSO; |
| 60 | if (extension == "nca") | 62 | else if (extension == ".nca") |
| 61 | return FileType::NCA; | 63 | return FileType::NCA; |
| 62 | 64 | ||
| 63 | return FileType::Unknown; | 65 | return FileType::Unknown; |
| @@ -91,47 +93,58 @@ const char* GetFileTypeString(FileType type) { | |||
| 91 | * @param filepath the file full path (with name) | 93 | * @param filepath the file full path (with name) |
| 92 | * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type | 94 | * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type |
| 93 | */ | 95 | */ |
| 94 | static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileType type) { | 96 | static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileType type, |
| 97 | const std::string& filename, | ||
| 98 | const std::string& filepath) { | ||
| 95 | switch (type) { | 99 | switch (type) { |
| 96 | 100 | ||
| 97 | // Standard ELF file format. | 101 | // Standard ELF file format. |
| 98 | case FileType::ELF: | 102 | case FileType::ELF: |
| 99 | return std::make_unique<AppLoader_ELF>(std::move(file)); | 103 | return std::make_unique<AppLoader_ELF>(std::move(file), filename); |
| 100 | 104 | ||
| 101 | // NX NSO file format. | 105 | // NX NSO file format. |
| 102 | case FileType::NSO: | 106 | case FileType::NSO: |
| 103 | return std::make_unique<AppLoader_NSO>(std::move(file)); | 107 | return std::make_unique<AppLoader_NSO>(std::move(file), filepath); |
| 104 | 108 | ||
| 105 | // NX NRO file format. | 109 | // NX NRO file format. |
| 106 | case FileType::NRO: | 110 | case FileType::NRO: |
| 107 | return std::make_unique<AppLoader_NRO>(std::move(file)); | 111 | return std::make_unique<AppLoader_NRO>(std::move(file), filepath); |
| 108 | 112 | ||
| 109 | // NX NCA file format. | 113 | // NX NCA file format. |
| 110 | case FileType::NCA: | 114 | case FileType::NCA: |
| 111 | return std::make_unique<AppLoader_NCA>(std::move(file)); | 115 | return std::make_unique<AppLoader_NCA>(std::move(file), filepath); |
| 112 | 116 | ||
| 113 | // NX deconstructed ROM directory. | 117 | // NX deconstructed ROM directory. |
| 114 | case FileType::DeconstructedRomDirectory: | 118 | case FileType::DeconstructedRomDirectory: |
| 115 | return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file)); | 119 | return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file), filepath); |
| 116 | 120 | ||
| 117 | default: | 121 | default: |
| 118 | return nullptr; | 122 | return nullptr; |
| 119 | } | 123 | } |
| 120 | } | 124 | } |
| 121 | 125 | ||
| 122 | std::unique_ptr<AppLoader> GetLoader(FileSys::VirtualFile file) { | 126 | std::unique_ptr<AppLoader> GetLoader(const std::string& filename) { |
| 123 | FileType type = IdentifyFile(file); | 127 | FileUtil::IOFile file(filename, "rb"); |
| 124 | FileType filename_type = GuessFromFilename(file->GetName()); | 128 | if (!file.IsOpen()) { |
| 129 | LOG_ERROR(Loader, "Failed to load file {}", filename); | ||
| 130 | return nullptr; | ||
| 131 | } | ||
| 132 | |||
| 133 | std::string filename_filename, filename_extension; | ||
| 134 | Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension); | ||
| 135 | |||
| 136 | FileType type = IdentifyFile(file, filename); | ||
| 137 | FileType filename_type = GuessFromExtension(filename_extension); | ||
| 125 | 138 | ||
| 126 | if (type != filename_type) { | 139 | if (type != filename_type) { |
| 127 | LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName()); | 140 | LOG_WARNING(Loader, "File {} has a different type than its extension.", filename); |
| 128 | if (FileType::Unknown == type) | 141 | if (FileType::Unknown == type) |
| 129 | type = filename_type; | 142 | type = filename_type; |
| 130 | } | 143 | } |
| 131 | 144 | ||
| 132 | LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type)); | 145 | LOG_DEBUG(Loader, "Loading file {} as {}...", filename, GetFileTypeString(type)); |
| 133 | 146 | ||
| 134 | return GetFileLoader(std::move(file), type); | 147 | return GetFileLoader(std::move(file), type, filename_filename, filename); |
| 135 | } | 148 | } |
| 136 | 149 | ||
| 137 | } // namespace Loader | 150 | } // namespace Loader |