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