Place Log Backup Outside Emulator Init

This commit is contained in:
Xphalnos 2025-02-17 19:59:40 +01:00
parent 8ddc545592
commit 1b6291329e
3 changed files with 15 additions and 8 deletions

View File

@ -132,6 +132,17 @@ static auto UserPaths = [] {
return paths; return paths;
}(); }();
void RenameLog() {
// Renaming shad_log.txt to shad_log.old.txt when booting.
const auto LogDir = Common::FS::GetUserPath(Common::FS::PathType::LogDir);
const auto CurrentLog = LogDir / LOG_FILE;
const auto NewLogName = LogDir / "shad_log.old.txt";
// Avoid crash due to shad_log.txt not existing.
if (std::filesystem::exists(CurrentLog)) {
rename(CurrentLog, NewLogName);
}
}
bool ValidatePath(const fs::path& path) { bool ValidatePath(const fs::path& path) {
if (path.empty()) { if (path.empty()) {
LOG_ERROR(Common_Filesystem, "Input path is empty, path={}", PathToUTF8String(path)); LOG_ERROR(Common_Filesystem, "Input path is empty, path={}", PathToUTF8String(path));

View File

@ -48,6 +48,8 @@ constexpr auto METADATA_DIR = "game_data";
// Filenames // Filenames
constexpr auto LOG_FILE = "shad_log.txt"; constexpr auto LOG_FILE = "shad_log.txt";
void RenameLog();
/** /**
* Validates a given path. * Validates a given path.
* *

View File

@ -50,14 +50,8 @@ Emulator::Emulator() {
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
#endif #endif
// Renaming shad_log.txt to shad_log.old.txt when booting. // Rename shad_log.txt to shad_log.old.txt
const auto LogDir = Common::FS::GetUserPath(Common::FS::PathType::LogDir); Common::FS::RenameLog();
const auto CurrentLog = LogDir / "shad_log.txt";
const auto NewLogName = LogDir / "shad_log.old.txt";
// Avoid crash due to shad_log.txt not existing.
if (std::filesystem::exists(CurrentLog)) {
rename(CurrentLog, NewLogName);
}
// Start logger. // Start logger.
Common::Log::Initialize(); Common::Log::Initialize();