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

Method Finalise

src/strgen/strgen.cpp:244–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

242 }
243
244 void Finalise(const StringData &data) override
245 {
246 /* Find the plural form with the most amount of cases. */
247 size_t max_plural_forms = 0;
248 for (const auto &pf : _plural_forms) {
249 max_plural_forms = std::max(max_plural_forms, pf.plural_count);
250 }
251
252 fmt::print(this->output_stream,
253 "\n"
254 "static const uint LANGUAGE_PACK_VERSION = 0x{:X};\n"
255 "static const uint LANGUAGE_MAX_PLURAL = {};\n"
256 "static const uint LANGUAGE_MAX_PLURAL_FORMS = {};\n"
257 "static const uint LANGUAGE_TOTAL_STRINGS = {};\n"
258 "\n",
259 data.Version(), std::size(_plural_forms), max_plural_forms, total_strings
260 );
261
262 this->output_stream << "#endif /* TABLE_STRINGS_H */\n";
263
264 this->FileWriter::Finalise();
265
266 std::error_code error_code;
267 if (CompareFiles(this->path, this->real_path)) {
268 /* files are equal. tmp.xxx is not needed */
269 std::filesystem::remove(this->path, error_code); // Just ignore the error
270 } else {
271 /* else rename tmp.xxx into filename */
272 std::filesystem::rename(this->path, this->real_path, error_code);
273 if (error_code) FatalError("rename({}, {}) failed: {}", this->path, this->real_path, error_code.message());
274 }
275 }
276};
277
278/** Class for writing a language to disk. */

Callers

nothing calls this directly

Calls 5

messageMethod · 0.80
CompareFilesFunction · 0.70
printFunction · 0.50
sizeFunction · 0.50
VersionMethod · 0.45

Tested by

no test coverage detected