* 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. */
| 133 | * @return Pathname for a screenshot file. |
| 134 | */ |
| 135 | static 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. */ |
| 173 | static bool MakeSmallScreenshot(bool crashlog) |
no test coverage detected