Skip to content

Commit

Permalink
Store load time in config to avoid multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
misternebula committed Jan 13, 2025
1 parent 3a5e280 commit 44ff7e6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/OWML.Common/Interfaces/IOwmlConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace OWML.Common
using System;

namespace OWML.Common
{
public interface IOwmlConfig
{
Expand All @@ -25,5 +27,7 @@ public interface IOwmlConfig
bool IncrementalGC { get; set; }

int SocketPort { get; set; }

DateTime LoadTime { get; set; }
}
}
6 changes: 5 additions & 1 deletion src/OWML.Common/OwmlConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using Newtonsoft.Json;

namespace OWML.Common
Expand All @@ -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"));

Expand Down
13 changes: 13 additions & 0 deletions src/OWML.Launcher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using OWML.Abstractions;
using OWML.Common;
using OWML.GameFinder;
Expand All @@ -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);

Expand Down Expand Up @@ -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<ModManifest>(Constants.OwmlManifestFileName);

Expand Down
3 changes: 1 addition & 2 deletions src/OWML.Logging/ModLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ 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))
{
Directory.CreateDirectory(config.LogsPath);
}

_latestFileName = $"{config.LogsPath}/latest.txt";
File.Delete(_latestFileName);
}

[Obsolete("Use ModHelper.Console.WriteLine with messageType = Debug instead.")]
Expand Down
2 changes: 1 addition & 1 deletion src/OWML.ModHelper.Events/HarmonyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 44ff7e6

Please sign in to comment.