citra-emu
/
citra-canary
Archived
1
0
Fork 0

Expose loader helper functions for identifying files.

This commit is contained in:
archshift 2015-08-31 18:28:37 -07:00
parent b3af7aad9e
commit bba12520c4
2 changed files with 41 additions and 13 deletions

View File

@ -26,12 +26,7 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = {
{ 0x1F000000, 0x600000, false }, // entire VRAM { 0x1F000000, 0x600000, false }, // entire VRAM
}; };
/** FileType IdentifyFile(FileUtil::IOFile& file) {
* Identifies the type of a bootable file
* @param file open file
* @return FileType of file
*/
static FileType IdentifyFile(FileUtil::IOFile& file) {
FileType type; FileType type;
#define CHECK_TYPE(loader) \ #define CHECK_TYPE(loader) \
@ -48,12 +43,17 @@ static FileType IdentifyFile(FileUtil::IOFile& file) {
return FileType::Unknown; return FileType::Unknown;
} }
/** FileType IdentifyFile(const std::string& file_name) {
* Guess the type of a bootable file from its extension FileUtil::IOFile file(file_name, "rb");
* @param extension_ String extension of bootable file if (!file.IsOpen()) {
* @return FileType of file LOG_ERROR(Loader, "Failed to load file %s", file_name.c_str());
*/ return FileType::Unknown;
static FileType GuessFromExtension(const std::string& extension_) { }
return IdentifyFile(file);
}
FileType GuessFromExtension(const std::string& extension_) {
std::string extension = Common::ToLower(extension_); std::string extension = Common::ToLower(extension_);
if (extension == ".elf" || extension == ".axf") if (extension == ".elf" || extension == ".axf")
@ -71,7 +71,7 @@ static FileType GuessFromExtension(const std::string& extension_) {
return FileType::Unknown; return FileType::Unknown;
} }
static const char* GetFileTypeString(FileType type) { const char* GetFileTypeString(FileType type) {
switch (type) { switch (type) {
case FileType::CCI: case FileType::CCI:
return "NCSD"; return "NCSD";

View File

@ -33,6 +33,34 @@ enum class FileType {
THREEDSX, //3DSX THREEDSX, //3DSX
}; };
/**
* Identifies the type of a bootable file based on the magic value in its header.
* @param file open file
* @return FileType of file
*/
FileType IdentifyFile(FileUtil::IOFile& file);
/**
* Identifies the type of a bootable file based on the magic value in its header.
* @param file_name path to file
* @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine
* a filetype, and will never return FileType::Error.
*/
FileType IdentifyFile(const std::string& file_name);
/**
* Guess the type of a bootable file from its extension
* @param extension String extension of bootable file
* @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine
* a filetype, and will never return FileType::Error.
*/
FileType GuessFromExtension(const std::string& extension_);
/**
* Convert a FileType into a string which can be displayed to the user.
*/
const char* GetFileTypeString(FileType type);
/// Return type for functions in Loader namespace /// Return type for functions in Loader namespace
enum class ResultStatus { enum class ResultStatus {
Success, Success,