diff options
Diffstat (limited to 'src/core/loader/loader.h')
| -rw-r--r-- | src/core/loader/loader.h | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h new file mode 100644 index 000000000..95f16fcb1 --- /dev/null +++ b/src/core/loader/loader.h | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "common/common.h" | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 12 | // Loader namespace | ||
| 13 | |||
| 14 | namespace Loader { | ||
| 15 | |||
| 16 | /// File types supported by CTR | ||
| 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 | ErrorNotUsed, | ||
| 34 | ErrorAlreadyLoaded, | ||
| 35 | }; | ||
| 36 | |||
| 37 | /// Interface for loading an application | ||
| 38 | class AppLoader : NonCopyable { | ||
| 39 | public: | ||
| 40 | AppLoader() { } | ||
| 41 | virtual ~AppLoader() { } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Load the application | ||
| 45 | * @return ResultStatus result of function | ||
| 46 | */ | ||
| 47 | virtual ResultStatus Load() = 0; | ||
| 48 | |||
| 49 | /** | ||
| 50 | * Get the code (typically .code section) of the application | ||
| 51 | * @param error ResultStatus result of function | ||
| 52 | * @return Reference to code buffer | ||
| 53 | */ | ||
| 54 | virtual const std::vector<u8>& ReadCode(ResultStatus& error) const { | ||
| 55 | error = ResultStatus::ErrorNotImplemented; | ||
| 56 | return code; | ||
| 57 | } | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Get the icon (typically icon section) of the application | ||
| 61 | * @param error ResultStatus result of function | ||
| 62 | * @return Reference to icon buffer | ||
| 63 | */ | ||
| 64 | virtual const std::vector<u8>& ReadIcon(ResultStatus& error) const { | ||
| 65 | error = ResultStatus::ErrorNotImplemented; | ||
| 66 | return icon; | ||
| 67 | } | ||
| 68 | |||
| 69 | /** | ||
| 70 | * Get the banner (typically banner section) of the application | ||
| 71 | * @param error ResultStatus result of function | ||
| 72 | * @return Reference to banner buffer | ||
| 73 | */ | ||
| 74 | virtual const std::vector<u8>& ReadBanner(ResultStatus& error) const { | ||
| 75 | error = ResultStatus::ErrorNotImplemented; | ||
| 76 | return banner; | ||
| 77 | } | ||
| 78 | |||
| 79 | /** | ||
| 80 | * Get the logo (typically logo section) of the application | ||
| 81 | * @param error ResultStatus result of function | ||
| 82 | * @return Reference to logo buffer | ||
| 83 | */ | ||
| 84 | virtual const std::vector<u8>& ReadLogo(ResultStatus& error) const { | ||
| 85 | error = ResultStatus::ErrorNotImplemented; | ||
| 86 | return logo; | ||
| 87 | } | ||
| 88 | |||
| 89 | /** | ||
| 90 | * Get the RomFs archive of the application | ||
| 91 | * @param error ResultStatus result of function | ||
| 92 | * @return Reference to RomFs archive buffer | ||
| 93 | */ | ||
| 94 | virtual const std::vector<u8>& ReadRomFS(ResultStatus& error) const { | ||
| 95 | error = ResultStatus::ErrorNotImplemented; | ||
| 96 | return romfs; | ||
| 97 | } | ||
| 98 | |||
| 99 | protected: | ||
| 100 | std::vector<u8> code; ///< ExeFS .code section | ||
| 101 | std::vector<u8> icon; ///< ExeFS .icon section | ||
| 102 | std::vector<u8> banner; ///< ExeFS .banner section | ||
| 103 | std::vector<u8> logo; ///< ExeFS .logo section | ||
| 104 | std::vector<u8> romfs; ///< RomFs archive | ||
| 105 | }; | ||
| 106 | |||
| 107 | /** | ||
| 108 | * Identifies the type of a bootable file | ||
| 109 | * @param filename String filename of bootable file | ||
| 110 | * @return FileType of file | ||
| 111 | */ | ||
| 112 | FileType IdentifyFile(const std::string &filename); | ||
| 113 | |||
| 114 | /** | ||
| 115 | * Identifies and loads a bootable file | ||
| 116 | * @param filename String filename of bootable file | ||
| 117 | * @return ResultStatus result of function | ||
| 118 | */ | ||
| 119 | ResultStatus LoadFile(const std::string& filename); | ||
| 120 | |||
| 121 | } // namespace | ||