MCPcopy Create free account
hub / github.com/EasyRPG/Player / CloseLogFile

Method CloseLogFile

src/game_config.cpp:367–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365}
366
367void Game_Config::CloseLogFile() {
368 if (!Game_Config::GetLogFileOutput()) {
369 return;
370 }
371
372 Game_Config::GetLogFileOutput().Close();
373
374 // Truncate the logfile when it is too large
375 const std::streamoff log_size = 1024 * 1024; // 1 MB
376 std::vector<char> buf(log_size);
377
378 auto in = FileFinder::Root().OpenInputStream(logging.path);
379 if (in) {
380 in.seekg(0, std::ios_base::end);
381 if (in.tellg() > log_size) {
382 in.seekg(-log_size, std::ios_base::end);
383 // skip current incomplete line
384 std::string line;
385 Utils::ReadLine(in, line);
386
387 // Read the remaining logfile into the buffer
388 in.read(buf.data(), buf.size());
389 size_t read = in.gcount();
390 in.Close();
391
392 // Truncate the logfile and write the data into the logfile
393 auto out = FileFinder::Root().OpenOutputStream(logging.path);
394 if (out) {
395 out.write(buf.data(), read);
396 }
397 }
398 }
399
400 logging.started = false;
401 logging.handle = Filesystem_Stream::OutputStream();
402}
403
404std::string Game_Config::GetConfigPath(CmdlineParser& cp) {
405 std::string path;

Callers

nothing calls this directly

Calls 6

OpenInputStreamMethod · 0.80
dataMethod · 0.80
OpenOutputStreamMethod · 0.80
OutputStreamClass · 0.70
CloseMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected