| 365 | } |
| 366 | |
| 367 | void 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 | |
| 404 | std::string Game_Config::GetConfigPath(CmdlineParser& cp) { |
| 405 | std::string path; |
nothing calls this directly
no test coverage detected