From 44ff7e6c37a89db59b46744223db3dd238175b39 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Mon, 13 Jan 2025 00:15:30 +0000 Subject: [PATCH] Store load time in config to avoid multiple files --- src/OWML.Common/Interfaces/IOwmlConfig.cs | 6 +++++- src/OWML.Common/OwmlConfig.cs | 6 +++++- src/OWML.Launcher/Program.cs | 13 +++++++++++++ src/OWML.Logging/ModLogger.cs | 3 +-- src/OWML.ModHelper.Events/HarmonyHelper.cs | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/OWML.Common/Interfaces/IOwmlConfig.cs b/src/OWML.Common/Interfaces/IOwmlConfig.cs index a1d996ba6..ab70b55b8 100644 --- a/src/OWML.Common/Interfaces/IOwmlConfig.cs +++ b/src/OWML.Common/Interfaces/IOwmlConfig.cs @@ -1,4 +1,6 @@ -namespace OWML.Common +using System; + +namespace OWML.Common { public interface IOwmlConfig { @@ -25,5 +27,7 @@ public interface IOwmlConfig bool IncrementalGC { get; set; } int SocketPort { get; set; } + + DateTime LoadTime { get; set; } } } diff --git a/src/OWML.Common/OwmlConfig.cs b/src/OWML.Common/OwmlConfig.cs index 2b79d4516..97dce15ac 100644 --- a/src/OWML.Common/OwmlConfig.cs +++ b/src/OWML.Common/OwmlConfig.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using Newtonsoft.Json; namespace OWML.Common @@ -17,6 +18,9 @@ public class OwmlConfig : IOwmlConfig [JsonProperty("incrementalGC")] public bool IncrementalGC { get; set; } + [JsonProperty("loadTime")] + public DateTime LoadTime { get; set; } + [JsonIgnore] public bool IsSpaced => Directory.Exists(Path.Combine(GamePath, "Outer Wilds_Data")); diff --git a/src/OWML.Launcher/Program.cs b/src/OWML.Launcher/Program.cs index e5feba26b..036e2ffed 100644 --- a/src/OWML.Launcher/Program.cs +++ b/src/OWML.Launcher/Program.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using OWML.Abstractions; using OWML.Common; using OWML.GameFinder; @@ -25,6 +26,7 @@ public static Container CreateContainer(string[] args) var hasConsolePort = argumentHelper.HasArgument(Constants.ConsolePortArgument); SaveConsolePort(owmlConfig, hasConsolePort, argumentHelper); SaveOwmlPath(owmlConfig); + SaveCurrentLogPath(owmlConfig); var owmlManifest = GetOwmlManifest(); var consoleWriter = CreateConsoleWriter(owmlConfig, owmlManifest, hasConsolePort); @@ -79,6 +81,17 @@ private static void SaveOwmlPath(IOwmlConfig owmlConfig) JsonHelper.SaveJsonObject(Constants.OwmlConfigFileName, owmlConfig); } + private static void SaveCurrentLogPath(IOwmlConfig owmlConfig) + { + if (File.Exists($"{owmlConfig.LogsPath}/latest.txt")) + { + File.Delete($"{owmlConfig.LogsPath}/latest.txt"); + } + + owmlConfig.LoadTime = DateTime.Now; + JsonHelper.SaveJsonObject(Constants.OwmlConfigFileName, owmlConfig); + } + private static IModManifest GetOwmlManifest() => JsonHelper.LoadJsonObject(Constants.OwmlManifestFileName); diff --git a/src/OWML.Logging/ModLogger.cs b/src/OWML.Logging/ModLogger.cs index 83fbd4746..7e62b6440 100644 --- a/src/OWML.Logging/ModLogger.cs +++ b/src/OWML.Logging/ModLogger.cs @@ -14,7 +14,7 @@ public class ModLogger : IModLogger public ModLogger(IOwmlConfig config, IModManifest manifest) { _manifest = manifest; - _logFileName = $"{config.LogsPath}/OWML.Log.{DateTime.Now:yyyy-MM-ddTHH:mm:ss}.txt"; + _logFileName = $"{config.LogsPath}/OWML.Log.{config.LoadTime:yyyy-MM-ddTHH.mm.ss}.txt"; if (!Directory.Exists(config.LogsPath)) { @@ -22,7 +22,6 @@ public ModLogger(IOwmlConfig config, IModManifest manifest) } _latestFileName = $"{config.LogsPath}/latest.txt"; - File.Delete(_latestFileName); } [Obsolete("Use ModHelper.Console.WriteLine with messageType = Debug instead.")] diff --git a/src/OWML.ModHelper.Events/HarmonyHelper.cs b/src/OWML.ModHelper.Events/HarmonyHelper.cs index 50b89c2be..03d49e172 100644 --- a/src/OWML.ModHelper.Events/HarmonyHelper.cs +++ b/src/OWML.ModHelper.Events/HarmonyHelper.cs @@ -33,7 +33,7 @@ private Harmony CreateInstance() if (_owmlConfig.DebugMode) { _console.WriteLine("Enabling Harmony debug mode.", MessageType.Debug); - FileLog.logPath = $"{_owmlConfig.LogsPath}/Harmony.Log.{DateTime.Now:yyyy-MM-ddTHH:mm:ss}.txt"; + FileLog.logPath = $"{_owmlConfig.LogsPath}/Harmony.Log.{_owmlConfig.LoadTime:yyyy-MM-ddTHH.mm.ss}.txt"; HarmonyFileLog.Enabled = true; } harmony = new Harmony(_manifest.UniqueName);