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.
This commit is contained in:
parent
79a48082e2
commit
7889cafc76
8 changed files with 690 additions and 551 deletions
|
@ -4,6 +4,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#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,
|
||||
};
|
||||
|
||||
FILETYPE_CTR_CCI,
|
||||
FILETYPE_CTR_CIA,
|
||||
FILETYPE_CTR_CXI,
|
||||
FILETYPE_CTR_ELF,
|
||||
FILETYPE_CTR_BIN,
|
||||
/// Return type for functions in Loader namespace
|
||||
enum class ResultStatus {
|
||||
Success,
|
||||
Error,
|
||||
ErrorInvalidFormat,
|
||||
ErrorNotImplemented,
|
||||
ErrorNotLoaded,
|
||||
ErrorAlreadyLoaded,
|
||||
};
|
||||
|
||||
FILETYPE_UNKNOWN
|
||||
/// 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<u8>& 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<u8>& 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<u8>& 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<u8>& GetLogo(ResultStatus& error) const {
|
||||
error = ResultStatus::ErrorNotImplemented;
|
||||
return logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the RomFs archive of the application
|
||||
* @param error ResultStatus result of function
|
||||
* @return Reference to RomFs archive buffer
|
||||
*/
|
||||
virtual const std::vector<u8>& GetRomFs(ResultStatus error) const {
|
||||
error = ResultStatus::ErrorNotImplemented;
|
||||
return romfs;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<u8> code; ///< ExeFS .code section
|
||||
std::vector<u8> icon; ///< ExeFS .icon section
|
||||
std::vector<u8> banner; ///< ExeFS .banner section
|
||||
std::vector<u8> logo; ///< ExeFS .logo section
|
||||
std::vector<u8> 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue