| 596 | } |
| 597 | |
| 598 | static 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 | |
| 632 | void CaptureImage(const CaptureOptions& options) |
| 633 | { |
no test coverage detected