diff options
Diffstat (limited to 'src/core/loader/loader.cpp')
| -rw-r--r-- | src/core/loader/loader.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp new file mode 100644 index 000000000..96cb81de0 --- /dev/null +++ b/src/core/loader/loader.cpp | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <memory> | ||
| 6 | |||
| 7 | #include "core/loader/loader.h" | ||
| 8 | #include "core/loader/elf.h" | ||
| 9 | #include "core/loader/ncch.h" | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 12 | |||
| 13 | namespace Loader { | ||
| 14 | |||
| 15 | /** | ||
| 16 | * Identifies the type of a bootable file | ||
| 17 | * @param filename String filename of bootable file | ||
| 18 | * @todo (ShizZy) this function sucks... make it actually check file contents etc. | ||
| 19 | * @return FileType of file | ||
| 20 | */ | ||
| 21 | FileType IdentifyFile(const std::string &filename) { | ||
| 22 | if (filename.size() == 0) { | ||
| 23 | ERROR_LOG(LOADER, "invalid filename %s", filename.c_str()); | ||
| 24 | return FileType::Error; | ||
| 25 | } | ||
| 26 | std::string extension = filename.size() >= 5 ? filename.substr(filename.size() - 4) : ""; | ||
| 27 | |||
| 28 | if (!strcasecmp(extension.c_str(), ".elf")) { | ||
| 29 | return FileType::ELF; // TODO(bunnei): Do some filetype checking :p | ||
| 30 | } | ||
| 31 | else if (!strcasecmp(extension.c_str(), ".axf")) { | ||
| 32 | return FileType::ELF; // TODO(bunnei): Do some filetype checking :p | ||
| 33 | } | ||
| 34 | else if (!strcasecmp(extension.c_str(), ".cxi")) { | ||
| 35 | return FileType::CXI; // TODO(bunnei): Do some filetype checking :p | ||
| 36 | } | ||
| 37 | else if (!strcasecmp(extension.c_str(), ".cci")) { | ||
| 38 | return FileType::CCI; // TODO(bunnei): Do some filetype checking :p | ||
| 39 | } | ||
| 40 | return FileType::Unknown; | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Identifies and loads a bootable file | ||
| 45 | * @param filename String filename of bootable file | ||
| 46 | * @return ResultStatus result of function | ||
| 47 | */ | ||
| 48 | ResultStatus LoadFile(const std::string& filename) { | ||
| 49 | INFO_LOG(LOADER, "Loading file %s...", filename.c_str()); | ||
| 50 | |||
| 51 | switch (IdentifyFile(filename)) { | ||
| 52 | |||
| 53 | // Standard ELF file format... | ||
| 54 | case FileType::ELF: { | ||
| 55 | return AppLoader_ELF(filename).Load(); | ||
| 56 | } | ||
| 57 | |||
| 58 | // NCCH/NCSD container formats... | ||
| 59 | case FileType::CXI: | ||
| 60 | case FileType::CCI: { | ||
| 61 | return AppLoader_NCCH(filename).Load(); | ||
| 62 | } | ||
| 63 | |||
| 64 | // Error occurred durring IdentifyFile... | ||
| 65 | case FileType::Error: | ||
| 66 | |||
| 67 | // IdentifyFile could know identify file type... | ||
| 68 | case FileType::Unknown: | ||
| 69 | |||
| 70 | default: | ||
| 71 | return ResultStatus::ErrorInvalidFormat; | ||
| 72 | } | ||
| 73 | |||
| 74 | return ResultStatus::Error; | ||
| 75 | } | ||
| 76 | |||
| 77 | } // namespace Loader | ||