diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/loader/loader.cpp | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 59ca7091a..b8f8f1448 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -3,8 +3,10 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | #include <optional> | ||
| 6 | #include <ostream> | 7 | #include <ostream> |
| 7 | #include <string> | 8 | #include <string> |
| 9 | #include "common/concepts.h" | ||
| 8 | #include "common/file_util.h" | 10 | #include "common/file_util.h" |
| 9 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 10 | #include "common/string_util.h" | 12 | #include "common/string_util.h" |
| @@ -21,27 +23,41 @@ | |||
| 21 | 23 | ||
| 22 | namespace Loader { | 24 | namespace Loader { |
| 23 | 25 | ||
| 24 | FileType IdentifyFile(FileSys::VirtualFile file) { | 26 | namespace { |
| 25 | FileType type; | ||
| 26 | |||
| 27 | #define CHECK_TYPE(loader) \ | ||
| 28 | type = AppLoader_##loader::IdentifyType(file); \ | ||
| 29 | if (FileType::Error != type) \ | ||
| 30 | return type; | ||
| 31 | 27 | ||
| 32 | CHECK_TYPE(DeconstructedRomDirectory) | 28 | template <Common::IsBaseOf<AppLoader> T> |
| 33 | CHECK_TYPE(ELF) | 29 | std::optional<FileType> IdentifyFileLoader(FileSys::VirtualFile file) { |
| 34 | CHECK_TYPE(NSO) | 30 | const auto file_type = T::IdentifyType(file); |
| 35 | CHECK_TYPE(NRO) | 31 | if (file_type != FileType::Error) { |
| 36 | CHECK_TYPE(NCA) | 32 | return file_type; |
| 37 | CHECK_TYPE(XCI) | 33 | } |
| 38 | CHECK_TYPE(NAX) | 34 | return std::nullopt; |
| 39 | CHECK_TYPE(NSP) | 35 | } |
| 40 | CHECK_TYPE(KIP) | ||
| 41 | 36 | ||
| 42 | #undef CHECK_TYPE | 37 | } // namespace |
| 43 | 38 | ||
| 44 | return FileType::Unknown; | 39 | FileType IdentifyFile(FileSys::VirtualFile file) { |
| 40 | if (const auto romdir_type = IdentifyFileLoader<AppLoader_DeconstructedRomDirectory>(file)) { | ||
| 41 | return *romdir_type; | ||
| 42 | } else if (const auto elf_type = IdentifyFileLoader<AppLoader_ELF>(file)) { | ||
| 43 | return *elf_type; | ||
| 44 | } else if (const auto nso_type = IdentifyFileLoader<AppLoader_NSO>(file)) { | ||
| 45 | return *nso_type; | ||
| 46 | } else if (const auto nro_type = IdentifyFileLoader<AppLoader_NRO>(file)) { | ||
| 47 | return *nro_type; | ||
| 48 | } else if (const auto nca_type = IdentifyFileLoader<AppLoader_NCA>(file)) { | ||
| 49 | return *nca_type; | ||
| 50 | } else if (const auto xci_type = IdentifyFileLoader<AppLoader_XCI>(file)) { | ||
| 51 | return *xci_type; | ||
| 52 | } else if (const auto nax_type = IdentifyFileLoader<AppLoader_NAX>(file)) { | ||
| 53 | return *nax_type; | ||
| 54 | } else if (const auto nsp_type = IdentifyFileLoader<AppLoader_NSP>(file)) { | ||
| 55 | return *nsp_type; | ||
| 56 | } else if (const auto kip_type = IdentifyFileLoader<AppLoader_KIP>(file)) { | ||
| 57 | return *kip_type; | ||
| 58 | } else { | ||
| 59 | return FileType::Unknown; | ||
| 60 | } | ||
| 45 | } | 61 | } |
| 46 | 62 | ||
| 47 | FileType GuessFromFilename(const std::string& name) { | 63 | FileType GuessFromFilename(const std::string& name) { |