diff options
| author | 2014-06-18 18:58:09 -0400 | |
|---|---|---|
| committer | 2014-06-24 19:29:58 -0400 | |
| commit | 7889cafc76ac99b8509fa3cd1558a09f8a7e5f91 (patch) | |
| tree | e6ffea9ec1c334bfca13404c47a2191fd281554c /src/core/loader/loader.h | |
| parent | NCCH: Changed decompression to load .code directly into memory rather than an... (diff) | |
| download | yuzu-7889cafc76ac99b8509fa3cd1558a09f8a7e5f91.tar.gz yuzu-7889cafc76ac99b8509fa3cd1558a09f8a7e5f91.tar.xz yuzu-7889cafc76ac99b8509fa3cd1558a09f8a7e5f91.zip | |
Loader: Implemented AppLoader interface for abstracting application loading.
- Various cleanups/refactorings to Loader, ELF, and NCCH modules.
- Added AppLoader interface to ELF and NCCH.
- Updated Qt/GLFW frontends to check AppLoader ResultStatus.
NCCH: Removed extra qualification typos.
Loader: Removed unnecessary #include's.
NCCH: Improved readability of memcmp statements.
NCCH: Added missing space.
Elf: Removed unnecessary usage of unique_ptr.
Loader: Removed unnecessary usage of unique_ptr.
Diffstat (limited to 'src/core/loader/loader.h')
| -rw-r--r-- | src/core/loader/loader.h | 103 |
1 files changed, 91 insertions, 12 deletions
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 979003553..42caa29e6 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <vector> | ||
| 8 | |||
| 7 | #include "common/common.h" | 9 | #include "common/common.h" |
| 8 | 10 | ||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -11,16 +13,94 @@ | |||
| 11 | 13 | ||
| 12 | namespace Loader { | 14 | namespace Loader { |
| 13 | 15 | ||
| 14 | enum FileType { | 16 | /// File types supported by CTR |
| 15 | FILETYPE_ERROR, | 17 | enum class FileType { |
| 18 | Error, | ||
| 19 | Unknown, | ||
| 20 | CCI, | ||
| 21 | CXI, | ||
| 22 | CIA, | ||
| 23 | ELF, | ||
| 24 | }; | ||
| 25 | |||
| 26 | /// Return type for functions in Loader namespace | ||
| 27 | enum class ResultStatus { | ||
| 28 | Success, | ||
| 29 | Error, | ||
| 30 | ErrorInvalidFormat, | ||
| 31 | ErrorNotImplemented, | ||
| 32 | ErrorNotLoaded, | ||
| 33 | ErrorAlreadyLoaded, | ||
| 34 | }; | ||
| 35 | |||
| 36 | /// Interface for loading an application | ||
| 37 | class AppLoader : NonCopyable { | ||
| 38 | public: | ||
| 39 | AppLoader() { } | ||
| 40 | virtual ~AppLoader() { } | ||
| 41 | |||
| 42 | /** | ||
| 43 | * Load the application | ||
| 44 | * @return ResultStatus result of function | ||
| 45 | */ | ||
| 46 | virtual const ResultStatus Load() = 0; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * Get the code (typically .code section) of the application | ||
| 50 | * @param error ResultStatus result of function | ||
| 51 | * @return Reference to code buffer | ||
| 52 | */ | ||
| 53 | virtual const std::vector<u8>& GetCode(ResultStatus& error) const { | ||
| 54 | error = ResultStatus::ErrorNotImplemented; | ||
| 55 | return code; | ||
| 56 | } | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Get the icon (typically .icon section) of the application | ||
| 60 | * @param error ResultStatus result of function | ||
| 61 | * @return Reference to icon buffer | ||
| 62 | */ | ||
| 63 | virtual const std::vector<u8>& GetIcon(ResultStatus& error) const { | ||
| 64 | error = ResultStatus::ErrorNotImplemented; | ||
| 65 | return icon; | ||
| 66 | } | ||
| 67 | |||
| 68 | /** | ||
| 69 | * Get the banner (typically .banner section) of the application | ||
| 70 | * @param error ResultStatus result of function | ||
| 71 | * @return Reference to banner buffer | ||
| 72 | */ | ||
| 73 | virtual const std::vector<u8>& GetBanner(ResultStatus& error) const { | ||
| 74 | error = ResultStatus::ErrorNotImplemented; | ||
| 75 | return banner; | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Get the logo (typically .logo section) of the application | ||
| 80 | * @param error ResultStatus result of function | ||
| 81 | * @return Reference to logo buffer | ||
| 82 | */ | ||
| 83 | virtual const std::vector<u8>& GetLogo(ResultStatus& error) const { | ||
| 84 | error = ResultStatus::ErrorNotImplemented; | ||
| 85 | return logo; | ||
| 86 | } | ||
| 16 | 87 | ||
| 17 | FILETYPE_CTR_CCI, | 88 | /** |
| 18 | FILETYPE_CTR_CIA, | 89 | * Get the RomFs archive of the application |
| 19 | FILETYPE_CTR_CXI, | 90 | * @param error ResultStatus result of function |
| 20 | FILETYPE_CTR_ELF, | 91 | * @return Reference to RomFs archive buffer |
| 21 | FILETYPE_CTR_BIN, | 92 | */ |
| 93 | virtual const std::vector<u8>& GetRomFs(ResultStatus error) const { | ||
| 94 | error = ResultStatus::ErrorNotImplemented; | ||
| 95 | return romfs; | ||
| 96 | } | ||
| 22 | 97 | ||
| 23 | FILETYPE_UNKNOWN | 98 | protected: |
| 99 | std::vector<u8> code; ///< ExeFS .code section | ||
| 100 | std::vector<u8> icon; ///< ExeFS .icon section | ||
| 101 | std::vector<u8> banner; ///< ExeFS .banner section | ||
| 102 | std::vector<u8> logo; ///< ExeFS .logo section | ||
| 103 | std::vector<u8> romfs; ///< RomFs archive | ||
| 24 | }; | 104 | }; |
| 25 | 105 | ||
| 26 | /** | 106 | /** |
| @@ -28,14 +108,13 @@ enum FileType { | |||
| 28 | * @param filename String filename of bootable file | 108 | * @param filename String filename of bootable file |
| 29 | * @return FileType of file | 109 | * @return FileType of file |
| 30 | */ | 110 | */ |
| 31 | FileType IdentifyFile(std::string &filename); | 111 | const FileType IdentifyFile(const std::string &filename); |
| 32 | 112 | ||
| 33 | /** | 113 | /** |
| 34 | * Identifies and loads a bootable file | 114 | * Identifies and loads a bootable file |
| 35 | * @param filename String filename of bootable file | 115 | * @param filename String filename of bootable file |
| 36 | * @param error_string Point to string to put error message if an error has occurred | 116 | * @return ResultStatus result of function |
| 37 | * @return True on success, otherwise false | ||
| 38 | */ | 117 | */ |
| 39 | bool LoadFile(std::string &filename, std::string *error_string); | 118 | const ResultStatus LoadFile(std::string& filename); |
| 40 | 119 | ||
| 41 | } // namespace | 120 | } // namespace |