MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MakeScreenshotName

Function MakeScreenshotName

src/screenshot.cpp:135–170  ·  view source on GitHub ↗

* Construct a pathname for a screenshot file. * @param default_fn Default filename. * @param ext Extension to use. * @param crashlog Create path for crash.png * @return Pathname for a screenshot file. */

Source from the content-addressed store, hash-verified

133 * @return Pathname for a screenshot file.
134 */
135static std::string_view MakeScreenshotName(std::string_view default_fn, std::string_view ext, bool crashlog = false)
136{
137 bool generate = _screenshot_name.empty();
138
139 if (generate) {
140 if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
141 _screenshot_name = default_fn;
142 } else {
143 _screenshot_name = GenerateDefaultSaveName();
144 }
145 }
146
147 /* Handle user-specified filenames ending in # with automatic numbering */
148 if (_screenshot_name.ends_with("#")) {
149 generate = true;
150 _screenshot_name.pop_back();
151 }
152
153 size_t len = _screenshot_name.size();
154 /* Add extension to screenshot file */
155 format_append(_screenshot_name, ".{}", ext);
156
157 std::string_view screenshot_dir = crashlog ? _personal_dir : FiosGetScreenshotDir();
158
159 for (uint serial = 1;; serial++) {
160 _full_screenshot_path = fmt::format("{}{}", screenshot_dir, _screenshot_name);
161
162 if (!generate) break; // allow overwriting of non-automatic filenames
163 if (!FileExists(_full_screenshot_path)) break;
164 /* If file exists try another one with same name, but just with a higher index */
165 _screenshot_name.erase(len);
166 format_append(_screenshot_name, "#{}.{}", serial, ext);
167 }
168
169 return _full_screenshot_path;
170}
171
172/** Make a screenshot of the current screen. */
173static bool MakeSmallScreenshot(bool crashlog)

Callers 4

MakeSmallScreenshotFunction · 0.85
MakeLargeWorldScreenshotFunction · 0.85
RealMakeScreenshotFunction · 0.85

Calls 9

GenerateDefaultSaveNameFunction · 0.85
format_appendFunction · 0.85
FiosGetScreenshotDirFunction · 0.85
FileExistsFunction · 0.85
pop_backMethod · 0.80
formatFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected