| 141 | } |
| 142 | |
| 143 | static std::optional<std::string> ScreenshotGetNextPath() |
| 144 | { |
| 145 | auto screenshotDirectory = ScreenshotGetDirectory(); |
| 146 | if (!Path::CreateDirectory(screenshotDirectory)) |
| 147 | { |
| 148 | LOG_ERROR("Unable to save screenshots in OpenRCT2 screenshot directory."); |
| 149 | return std::nullopt; |
| 150 | } |
| 151 | |
| 152 | auto parkName = ScreenshotGetParkName(); |
| 153 | auto dateTime = ScreenshotGetFormattedDateTime(); |
| 154 | auto name = parkName + " " + dateTime; |
| 155 | |
| 156 | // Generate a path with a `tries` number |
| 157 | auto pathComposer = [&screenshotDirectory, &name](int tries) { |
| 158 | auto composedFilename = Platform::SanitiseFilename( |
| 159 | name + ((tries > 0) ? " ("s + std::to_string(tries) + ")"s : ""s) + ".png"s); |
| 160 | return screenshotDirectory + PATH_SEPARATOR + composedFilename; |
| 161 | }; |
| 162 | |
| 163 | for (int tries = 0; tries < 100; tries++) |
| 164 | { |
| 165 | auto path = pathComposer(tries); |
| 166 | if (!File::Exists(path)) |
| 167 | { |
| 168 | return path; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | LOG_ERROR("You have too many saved screenshots saved at exactly the same date and time."); |
| 173 | return std::nullopt; |
| 174 | } |
| 175 | |
| 176 | std::string ScreenshotDumpPNG(RenderTarget& rt) |
| 177 | { |
no test coverage detected