MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / LoadPreview

Method LoadPreview

src/openrct2-ui/windows/LoadSave.cpp:341–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339 }
340
341 void LoadPreview()
342 {
343 _preview = {};
344
345 if (selectedListItem == -1)
346 return;
347
348 if (!ShowPreviews())
349 return;
350
351 if (type == LoadSaveType::track || type == LoadSaveType::heightmap)
352 return;
353
354 if (_listItems[selectedListItem].type == FileType::directory)
355 return;
356
357 auto path = _listItems[selectedListItem].path;
358
359 auto& bgWorker = GetContext()->GetBackgroundWorker();
360
361 if (_previewLoadJob.isValid())
362 {
363 _previewLoadJob.cancel();
364 }
365
366 _previewLoadJob = bgWorker.addJob(
367 [path]() {
368 try
369 {
370 auto fs = FileStream(path, FileMode::open);
371
372 ClassifiedFileInfo info;
373 if (!TryClassifyFile(&fs, &info) || info.Type != ::FileType::park)
374 return ParkPreview{};
375
376 auto& objectRepository = GetContext()->GetObjectRepository();
377 auto parkImporter = ParkImporter::CreateParkFile(objectRepository);
378 parkImporter->LoadFromStream(&fs, false, true, path.c_str());
379 return parkImporter->GetParkPreview();
380 }
381 catch (const std::exception& e)
382 {
383 LOG_ERROR("Could not get preview:", e.what());
384 return ParkPreview{};
385 }
386 },
387 [](const ParkPreview preview) {
388 auto* windowMgr = GetContext()->GetUiContext().GetWindowManager();
389 auto* wnd = windowMgr->FindByClass(WindowClass::loadsave);
390 if (wnd == nullptr)
391 {
392 return;
393 }
394 auto* loadSaveWnd = static_cast<LoadSaveWindow*>(wnd);
395 loadSaveWnd->UpdateParkPreview(preview);
396 });
397 }
398

Callers

nothing calls this directly

Calls 12

GetContextFunction · 0.85
FileStreamClass · 0.85
TryClassifyFileFunction · 0.85
addJobMethod · 0.80
isValidMethod · 0.45
cancelMethod · 0.45
LoadFromStreamMethod · 0.45
GetParkPreviewMethod · 0.45
whatMethod · 0.45
GetWindowManagerMethod · 0.45
FindByClassMethod · 0.45
UpdateParkPreviewMethod · 0.45

Tested by

no test coverage detected