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();