diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/loader/loader.cpp | 26 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 28 |
2 files changed, 41 insertions, 13 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index c4b4f5a5d..6b88169e1 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -26,12 +26,7 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { | |||
| 26 | { 0x1F000000, 0x600000, false }, // entire VRAM | 26 | { 0x1F000000, 0x600000, false }, // entire VRAM |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | /** | 29 | FileType IdentifyFile(FileUtil::IOFile& file) { |
| 30 | * Identifies the type of a bootable file | ||
| 31 | * @param file open file | ||
| 32 | * @return FileType of file | ||
| 33 | */ | ||
| 34 | static FileType IdentifyFile(FileUtil::IOFile& file) { | ||
| 35 | FileType type; | 30 | FileType type; |
| 36 | 31 | ||
| 37 | #define CHECK_TYPE(loader) \ | 32 | #define CHECK_TYPE(loader) \ |
| @@ -48,12 +43,17 @@ static FileType IdentifyFile(FileUtil::IOFile& file) { | |||
| 48 | return FileType::Unknown; | 43 | return FileType::Unknown; |
| 49 | } | 44 | } |
| 50 | 45 | ||
| 51 | /** | 46 | FileType IdentifyFile(const std::string& file_name) { |
| 52 | * Guess the type of a bootable file from its extension | 47 | FileUtil::IOFile file(file_name, "rb"); |
| 53 | * @param extension_ String extension of bootable file | 48 | if (!file.IsOpen()) { |
| 54 | * @return FileType of file | 49 | LOG_ERROR(Loader, "Failed to load file %s", file_name.c_str()); |
| 55 | */ | 50 | return FileType::Unknown; |
| 56 | static FileType GuessFromExtension(const std::string& extension_) { | 51 | } |
| 52 | |||
| 53 | return IdentifyFile(file); | ||
| 54 | } | ||
| 55 | |||
| 56 | FileType GuessFromExtension(const std::string& extension_) { | ||
| 57 | std::string extension = Common::ToLower(extension_); | 57 | std::string extension = Common::ToLower(extension_); |
| 58 | 58 | ||
| 59 | if (extension == ".elf" || extension == ".axf") | 59 | if (extension == ".elf" || extension == ".axf") |
| @@ -71,7 +71,7 @@ static FileType GuessFromExtension(const std::string& extension_) { | |||
| 71 | return FileType::Unknown; | 71 | return FileType::Unknown; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | static const char* GetFileTypeString(FileType type) { | 74 | const char* GetFileTypeString(FileType type) { |
| 75 | switch (type) { | 75 | switch (type) { |
| 76 | case FileType::CCI: | 76 | case FileType::CCI: |
| 77 | return "NCSD"; | 77 | return "NCSD"; |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index a37d3348c..8de95dacf 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -33,6 +33,34 @@ enum class FileType { | |||
| 33 | THREEDSX, //3DSX | 33 | THREEDSX, //3DSX |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | /** | ||
| 37 | * Identifies the type of a bootable file based on the magic value in its header. | ||
| 38 | * @param file open file | ||
| 39 | * @return FileType of file | ||
| 40 | */ | ||
| 41 | FileType IdentifyFile(FileUtil::IOFile& file); | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Identifies the type of a bootable file based on the magic value in its header. | ||
| 45 | * @param file_name path to file | ||
| 46 | * @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine | ||
| 47 | * a filetype, and will never return FileType::Error. | ||
| 48 | */ | ||
| 49 | FileType IdentifyFile(const std::string& file_name); | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Guess the type of a bootable file from its extension | ||
| 53 | * @param extension String extension of bootable file | ||
| 54 | * @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine | ||
| 55 | * a filetype, and will never return FileType::Error. | ||
| 56 | */ | ||
| 57 | FileType GuessFromExtension(const std::string& extension_); | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Convert a FileType into a string which can be displayed to the user. | ||
| 61 | */ | ||
| 62 | const char* GetFileTypeString(FileType type); | ||
| 63 | |||
| 36 | /// Return type for functions in Loader namespace | 64 | /// Return type for functions in Loader namespace |
| 37 | enum class ResultStatus { | 65 | enum class ResultStatus { |
| 38 | Success, | 66 | Success, |