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

Function ResolveFilenameForCapture

src/openrct2/interface/Screenshot.cpp:598–630  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

596}
597
598static std::string ResolveFilenameForCapture(const fs::path& filename)
599{
600 if (filename.empty())
601 {
602 // Automatic filename
603 auto path = ScreenshotGetNextPath();
604 if (!path)
605 {
606 throw std::runtime_error("Unable to generate a filename for capture.");
607 }
608 return *path;
609 }
610
611 auto screenshotDirectory = fs::u8path(ScreenshotGetDirectory());
612 auto screenshotPath = fs::absolute(screenshotDirectory / filename);
613
614 // Check the filename isn't attempting to leave the screenshot directory for security
615 if (!IsPathChildOf(screenshotPath, screenshotDirectory))
616 {
617 throw std::runtime_error("Filename is not a child of the screenshot directory.");
618 }
619
620 auto directory = screenshotPath.parent_path();
621 if (!fs::is_directory(directory))
622 {
623 if (!fs::create_directory(directory, screenshotDirectory))
624 {
625 throw std::runtime_error("Unable to create directory.");
626 }
627 }
628
629 return screenshotPath.u8string();
630}
631
632void CaptureImage(const CaptureOptions& options)
633{

Callers 1

CaptureImageFunction · 0.85

Calls 4

ScreenshotGetNextPathFunction · 0.85
ScreenshotGetDirectoryFunction · 0.85
IsPathChildOfFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected