diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/file_sys/ivfc_archive.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/service/cfg/cfg.h | 7 | ||||
-rw-r--r-- | src/core/loader/loader.cpp | 26 | ||||
-rw-r--r-- | src/core/loader/loader.h | 28 |
4 files changed, 45 insertions, 18 deletions
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp index e16aa1491..441ca9b53 100644 --- a/src/core/file_sys/ivfc_archive.cpp +++ b/src/core/file_sys/ivfc_archive.cpp @@ -62,7 +62,7 @@ std::unique_ptr<DirectoryBackend> IVFCArchive::OpenDirectory(const Path& path) c //////////////////////////////////////////////////////////////////////////////////////////////////// size_t IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const { - LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length); + LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length); romfs_file->Seek(data_offset + offset, SEEK_SET); size_t read_length = (size_t)std::min((u64)length, data_size - offset); diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index 231528fd6..fc2a16a04 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h @@ -41,8 +41,9 @@ struct SaveConfigBlockEntry { u16 flags; ///< The flags of the block, possibly used for access control }; -// TODO(Link Mauve): use a constexpr once MSVC starts supporting it. -#define C(code) (u16)((code)[0] | ((code)[1] << 8)) +static constexpr u16 C(const char code[2]) { + return code[0] | (code[1] << 8); +} static const std::array<u16, 187> country_codes = {{ 0, C("JP"), 0, 0, 0, 0, 0, 0, // 0-7 @@ -71,8 +72,6 @@ static const std::array<u16, 187> country_codes = {{ C("SM"), C("VA"), C("BM") // 184-186 }}; -#undef C - /** * CFG::GetCountryCodeString service function * Inputs: diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index c4b4f5a5d..6b88169e1 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -26,12 +26,7 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { { 0x1F000000, 0x600000, false }, // entire VRAM }; -/** - * Identifies the type of a bootable file - * @param file open file - * @return FileType of file - */ -static FileType IdentifyFile(FileUtil::IOFile& file) { +FileType IdentifyFile(FileUtil::IOFile& file) { FileType type; #define CHECK_TYPE(loader) \ @@ -48,12 +43,17 @@ static FileType IdentifyFile(FileUtil::IOFile& file) { return FileType::Unknown; } -/** - * Guess the type of a bootable file from its extension - * @param extension_ String extension of bootable file - * @return FileType of file - */ -static FileType GuessFromExtension(const std::string& extension_) { +FileType IdentifyFile(const std::string& file_name) { + FileUtil::IOFile file(file_name, "rb"); + if (!file.IsOpen()) { + LOG_ERROR(Loader, "Failed to load file %s", file_name.c_str()); + return FileType::Unknown; + } + + return IdentifyFile(file); +} + +FileType GuessFromExtension(const std::string& extension_) { std::string extension = Common::ToLower(extension_); if (extension == ".elf" || extension == ".axf") @@ -71,7 +71,7 @@ static FileType GuessFromExtension(const std::string& extension_) { return FileType::Unknown; } -static const char* GetFileTypeString(FileType type) { +const char* GetFileTypeString(FileType type) { switch (type) { case FileType::CCI: return "NCSD"; diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index a37d3348c..8de95dacf 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -33,6 +33,34 @@ enum class FileType { 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 enum class ResultStatus { Success, |