From 1b6291329e0e283b3b587af8b14b984b78ae20ff Mon Sep 17 00:00:00 2001 From: Xphalnos <164882787+Xphalnos@users.noreply.github.com> Date: Mon, 17 Feb 2025 19:59:40 +0100 Subject: [PATCH] Place Log Backup Outside Emulator Init --- src/common/path_util.cpp | 11 +++++++++++ src/common/path_util.h | 2 ++ src/emulator.cpp | 10 ++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/common/path_util.cpp b/src/common/path_util.cpp index a4312fada..b9a5c9aa9 100644 --- a/src/common/path_util.cpp +++ b/src/common/path_util.cpp @@ -132,6 +132,17 @@ static auto UserPaths = [] { 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) { if (path.empty()) { LOG_ERROR(Common_Filesystem, "Input path is empty, path={}", PathToUTF8String(path)); diff --git a/src/common/path_util.h b/src/common/path_util.h index 7190378d6..ae88ce0ff 100644 --- a/src/common/path_util.h +++ b/src/common/path_util.h @@ -48,6 +48,8 @@ constexpr auto METADATA_DIR = "game_data"; // Filenames constexpr auto LOG_FILE = "shad_log.txt"; +void RenameLog(); + /** * Validates a given path. * diff --git a/src/emulator.cpp b/src/emulator.cpp index d6f1e0750..80528ca7d 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -50,14 +50,8 @@ Emulator::Emulator() { SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); #endif - // 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 / "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); - } + // Rename shad_log.txt to shad_log.old.txt + Common::FS::RenameLog(); // Start logger. Common::Log::Initialize();