mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 22:55:16 +01:00
Keep the shared log.txt and errors.txt when the run writes its own logs (multiplelogs) (#341)
* fix: keep the shared log.txt and errors.txt when the run writes multiplelogs Every start deleted log.txt and errors.txt in the game folder before the settings were read, so a run with multiplelogs (each scenario test) wiped the logs of the player's last ordinary game although it writes its own files in logs/. The shared files are now deleted after the settings, and only without multiplelogs, where the run is about to write them (an errors.txt of an earlier run must still not stay behind a run without errors). The log service keeps what is logged until then, so an early message can't open and empty log.txt before multiplelogs is known. The file names come from one place (utilities/logfiles), covered by unit tests. * refactor(log): the wait for the log file names without Sonar issues The log service skips a pass with an early continue instead of wrapping the writing in an if, so the writing keeps its nesting. No change in behaviour. * fix(log): the node bank preview tool opens its log files after the settings The log service holds every message until OpenLogFiles() is called, and only the game called it. The preview tool kept its whole log in memory and wrote it only at the end, so a crash or a killed run lost it.
This commit is contained in:
@@ -25,6 +25,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "rendering/renderer.h"
|
||||
#include "application/uilayer.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "utilities/logfiles.h"
|
||||
#include "world/SleeperWorker.h"
|
||||
#include "rendering/screenshot.h"
|
||||
#include "utilities/translation.h"
|
||||
@@ -403,8 +404,10 @@ int eu07_application::init(int Argc, char *Argv[])
|
||||
Global.threads.emplace("LogService", std::move(sLoggingService));
|
||||
|
||||
init_debug();
|
||||
result = init_settings(Argc, Argv);
|
||||
// the log files are named by the settings (multiplelogs), so they are cleared and opened once those are read
|
||||
init_files();
|
||||
if ((result = init_settings(Argc, Argv)) != 0)
|
||||
if (result != 0)
|
||||
{
|
||||
ErrorLog("Failed to initialize settings! Maybe you're missing eu07.ini file?");
|
||||
return result;
|
||||
@@ -1262,16 +1265,19 @@ void eu07_application::init_console()
|
||||
|
||||
void eu07_application::init_files()
|
||||
{
|
||||
|
||||
// without multiplelogs the run writes the shared log.txt / errors.txt, and those of the run before go. with it the
|
||||
// run writes files of its own in logs/, and the shared ones are left to whoever ran the game last without it
|
||||
for (auto const &file : stale_log_files(Global.MultipleLogs))
|
||||
{
|
||||
std::error_code error; // not there is fine
|
||||
std::filesystem::remove(file, error);
|
||||
}
|
||||
#ifdef _WIN32
|
||||
DeleteFile("log.txt");
|
||||
DeleteFile("errors.txt");
|
||||
CreateDirectory("logs", nullptr);
|
||||
#elif __unix__
|
||||
unlink("log.txt");
|
||||
unlink("errors.txt");
|
||||
mkdir("logs", 0750);
|
||||
#endif
|
||||
OpenLogFiles();
|
||||
}
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user