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

Function ScreenshotGetNextPath

src/openrct2/interface/Screenshot.cpp:143–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143static 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
176std::string ScreenshotDumpPNG(RenderTarget& rt)
177{

Callers 3

ScreenshotDumpPNGFunction · 0.85
ScreenshotGiantFunction · 0.85

Calls 6

ScreenshotGetDirectoryFunction · 0.85
CreateDirectoryFunction · 0.85
ScreenshotGetParkNameFunction · 0.85
SanitiseFilenameFunction · 0.85
ExistsFunction · 0.85

Tested by

no test coverage detected