From 7889cafc76ac99b8509fa3cd1558a09f8a7e5f91 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 18 Jun 2014 18:58:09 -0400 Subject: 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. --- src/core/loader/loader.h | 103 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 12 deletions(-) (limited to 'src/core/loader/loader.h') diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 97900355..42caa29e 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -4,6 +4,8 @@ #pragma once +#include + #include "common/common.h" //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -11,16 +13,94 @@ namespace Loader { -enum FileType { - FILETYPE_ERROR, +/// File types supported by CTR +enum class FileType { + Error, + Unknown, + CCI, + CXI, + CIA, + ELF, +}; + +/// Return type for functions in Loader namespace +enum class ResultStatus { + Success, + Error, + ErrorInvalidFormat, + ErrorNotImplemented, + ErrorNotLoaded, + ErrorAlreadyLoaded, +}; + +/// Interface for loading an application +class AppLoader : NonCopyable { +public: + AppLoader() { } + virtual ~AppLoader() { } + + /** + * Load the application + * @return ResultStatus result of function + */ + virtual const ResultStatus Load() = 0; + + /** + * Get the code (typically .code section) of the application + * @param error ResultStatus result of function + * @return Reference to code buffer + */ + virtual const std::vector& GetCode(ResultStatus& error) const { + error = ResultStatus::ErrorNotImplemented; + return code; + } + + /** + * Get the icon (typically .icon section) of the application + * @param error ResultStatus result of function + * @return Reference to icon buffer + */ + virtual const std::vector& GetIcon(ResultStatus& error) const { + error = ResultStatus::ErrorNotImplemented; + return icon; + } + + /** + * Get the banner (typically .banner section) of the application + * @param error ResultStatus result of function + * @return Reference to banner buffer + */ + virtual const std::vector& GetBanner(ResultStatus& error) const { + error = ResultStatus::ErrorNotImplemented; + return banner; + } + + /** + * Get the logo (typically .logo section) of the application + * @param error ResultStatus result of function + * @return Reference to logo buffer + */ + virtual const std::vector& GetLogo(ResultStatus& error) const { + error = ResultStatus::ErrorNotImplemented; + return logo; + } - FILETYPE_CTR_CCI, - FILETYPE_CTR_CIA, - FILETYPE_CTR_CXI, - FILETYPE_CTR_ELF, - FILETYPE_CTR_BIN, + /** + * Get the RomFs archive of the application + * @param error ResultStatus result of function + * @return Reference to RomFs archive buffer + */ + virtual const std::vector& GetRomFs(ResultStatus error) const { + error = ResultStatus::ErrorNotImplemented; + return romfs; + } - FILETYPE_UNKNOWN +protected: + std::vector code; ///< ExeFS .code section + std::vector icon; ///< ExeFS .icon section + std::vector banner; ///< ExeFS .banner section + std::vector logo; ///< ExeFS .logo section + std::vector romfs; ///< RomFs archive }; /** @@ -28,14 +108,13 @@ enum FileType { * @param filename String filename of bootable file * @return FileType of file */ -FileType IdentifyFile(std::string &filename); +const FileType IdentifyFile(const std::string &filename); /** * Identifies and loads a bootable file * @param filename String filename of bootable file - * @param error_string Point to string to put error message if an error has occurred - * @return True on success, otherwise false + * @return ResultStatus result of function */ -bool LoadFile(std::string &filename, std::string *error_string); +const ResultStatus LoadFile(std::string& filename); } // namespace -- cgit v1.2.3