| 277 | } |
| 278 | |
| 279 | std::unique_ptr<Object> CreateObjectFromLegacyFile(const utf8* path, bool loadImages) |
| 280 | { |
| 281 | LOG_VERBOSE("CreateObjectFromLegacyFile(..., \"%s\")", path); |
| 282 | |
| 283 | std::unique_ptr<Object> result; |
| 284 | try |
| 285 | { |
| 286 | auto fs = FileStream(path, FileMode::open); |
| 287 | auto chunkReader = SawyerChunkReader(&fs); |
| 288 | |
| 289 | RCTObjectEntry entry = fs.ReadValue<RCTObjectEntry>(); |
| 290 | |
| 291 | if (entry.GetType() != ObjectType::scenarioMeta) |
| 292 | { |
| 293 | result = CreateObject(entry.GetType()); |
| 294 | result->SetDescriptor(ObjectEntryDescriptor(entry)); |
| 295 | result->SetFileName(Path::GetFileNameWithoutExtension(path)); |
| 296 | |
| 297 | utf8 objectName[kDatNameLength + 1] = { 0 }; |
| 298 | ObjectEntryGetNameFixed(objectName, sizeof(objectName), &entry); |
| 299 | LOG_VERBOSE(" entry: { 0x%08X, \"%s\", 0x%08X }", entry.flags, objectName, entry.checksum); |
| 300 | |
| 301 | auto chunk = chunkReader.ReadChunk(); |
| 302 | LOG_VERBOSE(" size: %zu", chunk->GetLength()); |
| 303 | |
| 304 | auto chunkStream = MemoryStream(chunk->GetData(), chunk->GetLength()); |
| 305 | auto readContext = ReadObjectContext(objectName, loadImages, nullptr); |
| 306 | ReadObjectLegacy(*result, &readContext, &chunkStream); |
| 307 | if (readContext.WasError()) |
| 308 | { |
| 309 | throw std::runtime_error("Object has errors"); |
| 310 | } |
| 311 | result->SetSourceGames({ entry.GetSourceGame() }); |
| 312 | } |
| 313 | } |
| 314 | catch (const std::exception& e) |
| 315 | { |
| 316 | LOG_ERROR("Error: %s when processing object %s", e.what(), path); |
| 317 | } |
| 318 | return result; |
| 319 | } |
| 320 | |
| 321 | std::unique_ptr<Object> CreateObjectFromLegacyData(const RCTObjectEntry* entry, const void* data, size_t dataSize) |
| 322 | { |
no test coverage detected