| 127 | } |
| 128 | |
| 129 | static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result) |
| 130 | { |
| 131 | bool success = false; |
| 132 | uint64_t originalPosition = stream->GetPosition(); |
| 133 | try |
| 134 | { |
| 135 | size_t dataLength = static_cast<size_t>(stream->GetLength()); |
| 136 | auto data = stream->ReadArray<uint8_t>(dataLength); |
| 137 | stream->SetPosition(originalPosition); |
| 138 | int32_t fileTypeVersion = DetectFileType(data.get(), dataLength); |
| 139 | |
| 140 | int32_t type = fileTypeVersion & FILE_TYPE_MASK; |
| 141 | int32_t version = fileTypeVersion & FILE_VERSION_MASK; |
| 142 | |
| 143 | if (type == FILE_TYPE_SV4) |
| 144 | { |
| 145 | result->Type = FileType::savedGame; |
| 146 | result->Version = version; |
| 147 | success = true; |
| 148 | } |
| 149 | else if (type == FILE_TYPE_SC4) |
| 150 | { |
| 151 | result->Type = FileType::scenario; |
| 152 | result->Version = version; |
| 153 | success = true; |
| 154 | } |
| 155 | } |
| 156 | catch (const std::exception& e) |
| 157 | { |
| 158 | Console::Error::WriteLine(e.what()); |
| 159 | } |
| 160 | |
| 161 | stream->SetPosition(originalPosition); |
| 162 | return success; |
| 163 | } |
| 164 | |
| 165 | static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result) |
| 166 | { |
no test coverage detected