MCPcopy Create free account
hub / github.com/The-Powder-Toy/The-Powder-Toy / LoadSaveFile

Method LoadSaveFile

src/client/Client.cpp:436–473  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434}
435
436std::unique_ptr<SaveFile> Client::LoadSaveFile(ByteString filename)
437{
438 ByteString err;
439 std::unique_ptr<SaveFile> file;
440 if (Platform::FileExists(filename))
441 {
442 file = std::make_unique<SaveFile>(filename);
443 try
444 {
445 std::vector<char> data;
446 if (Platform::ReadFile(data, filename))
447 {
448 file->SetGameSave(std::make_unique<GameSave>(std::move(data)));
449 }
450 else
451 {
452 err = "failed to open";
453 }
454 }
455 catch (const ParseException &e)
456 {
457 err = e.what();
458 }
459 }
460 else
461 {
462 err = "does not exist";
463 }
464 if (err.size())
465 {
466 std::cerr << "Client: " << filename << ": " << err << std::endl;
467 if (file)
468 {
469 file->SetLoadingError(err.FromUtf8());
470 }
471 }
472 return file;
473}
474
475// stamp-specific wrapper for MergeAuthorInfo
476// also used for clipboard and lua stamps

Callers 1

MainFunction · 0.45

Calls 8

ReadFileFunction · 0.85
moveFunction · 0.85
SetLoadingErrorMethod · 0.80
FromUtf8Method · 0.80
FileExistsFunction · 0.50
SetGameSaveMethod · 0.45
whatMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected