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