diff options
| author | 2015-01-06 23:10:13 +0000 | |
|---|---|---|
| committer | 2015-01-15 22:23:08 +0100 | |
| commit | 82ec17db7df53ed1c376d1cdaa9a6587719a546d (patch) | |
| tree | 3c2236849146037fbba2fb75ea8a50f53b847a17 /src/core/loader/ncch.cpp | |
| parent | Loader: Don’t assume the file hasn’t been read before. (diff) | |
| download | yuzu-82ec17db7df53ed1c376d1cdaa9a6587719a546d.tar.gz yuzu-82ec17db7df53ed1c376d1cdaa9a6587719a546d.tar.xz yuzu-82ec17db7df53ed1c376d1cdaa9a6587719a546d.zip | |
Loader: Guess filetype from the magic, or fallback to the extension.
Diffstat (limited to 'src/core/loader/ncch.cpp')
| -rw-r--r-- | src/core/loader/ncch.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index edf53c2c0..d6eb549b7 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp | |||
| @@ -97,6 +97,21 @@ static bool LZSS_Decompress(u8* compressed, u32 compressed_size, u8* decompresse | |||
| 97 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 97 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 98 | // AppLoader_NCCH class | 98 | // AppLoader_NCCH class |
| 99 | 99 | ||
| 100 | FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) { | ||
| 101 | u32 magic; | ||
| 102 | file.Seek(0x100, SEEK_SET); | ||
| 103 | if (1 != file.ReadArray<u32>(&magic, 1)) | ||
| 104 | return FileType::Error; | ||
| 105 | |||
| 106 | if (MakeMagic('N', 'C', 'S', 'D') == magic) | ||
| 107 | return FileType::CCI; | ||
| 108 | |||
| 109 | if (MakeMagic('N', 'C', 'C', 'H') == magic) | ||
| 110 | return FileType::CXI; | ||
| 111 | |||
| 112 | return FileType::Error; | ||
| 113 | } | ||
| 114 | |||
| 100 | ResultStatus AppLoader_NCCH::LoadExec() const { | 115 | ResultStatus AppLoader_NCCH::LoadExec() const { |
| 101 | if (!is_loaded) | 116 | if (!is_loaded) |
| 102 | return ResultStatus::ErrorNotLoaded; | 117 | return ResultStatus::ErrorNotLoaded; |
| @@ -171,7 +186,7 @@ ResultStatus AppLoader_NCCH::Load() { | |||
| 171 | file->ReadBytes(&ncch_header, sizeof(NCCH_Header)); | 186 | file->ReadBytes(&ncch_header, sizeof(NCCH_Header)); |
| 172 | 187 | ||
| 173 | // Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)... | 188 | // Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)... |
| 174 | if (0 == memcmp(&ncch_header.magic, "NCSD", 4)) { | 189 | if (MakeMagic('N', 'C', 'S', 'D') == ncch_header.magic) { |
| 175 | LOG_WARNING(Loader, "Only loading the first (bootable) NCCH within the NCSD file!"); | 190 | LOG_WARNING(Loader, "Only loading the first (bootable) NCCH within the NCSD file!"); |
| 176 | ncch_offset = 0x4000; | 191 | ncch_offset = 0x4000; |
| 177 | file->Seek(ncch_offset, SEEK_SET); | 192 | file->Seek(ncch_offset, SEEK_SET); |
| @@ -179,7 +194,7 @@ ResultStatus AppLoader_NCCH::Load() { | |||
| 179 | } | 194 | } |
| 180 | 195 | ||
| 181 | // Verify we are loading the correct file type... | 196 | // Verify we are loading the correct file type... |
| 182 | if (0 != memcmp(&ncch_header.magic, "NCCH", 4)) | 197 | if (MakeMagic('N', 'C', 'C', 'H') != ncch_header.magic) |
| 183 | return ResultStatus::ErrorInvalidFormat; | 198 | return ResultStatus::ErrorInvalidFormat; |
| 184 | 199 | ||
| 185 | // Read ExHeader... | 200 | // Read ExHeader... |