Skip to content

Commit 3b1f165

Browse files
authored
Merge pull request #607 from ow-mods/dev
Updated file logging
2 parents f43dba8 + 952b07e commit 3b1f165

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

src/OWML.Common/Interfaces/IOwmlConfig.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace OWML.Common
1+
using System;
2+
3+
namespace OWML.Common
24
{
35
public interface IOwmlConfig
46
{
@@ -25,5 +27,7 @@ public interface IOwmlConfig
2527
bool IncrementalGC { get; set; }
2628

2729
int SocketPort { get; set; }
30+
31+
DateTime LoadTime { get; set; }
2832
}
2933
}

src/OWML.Common/OwmlConfig.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using Newtonsoft.Json;
34

45
namespace OWML.Common
@@ -17,6 +18,9 @@ public class OwmlConfig : IOwmlConfig
1718
[JsonProperty("incrementalGC")]
1819
public bool IncrementalGC { get; set; }
1920

21+
[JsonProperty("loadTime")]
22+
public DateTime LoadTime { get; set; }
23+
2024
[JsonIgnore]
2125
public bool IsSpaced => Directory.Exists(Path.Combine(GamePath, "Outer Wilds_Data"));
2226

src/OWML.Launcher/OWML.Manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "Alek",
44
"name": "OWML",
55
"uniqueName": "Alek.OWML",
6-
"version": "2.14.0",
6+
"version": "2.14.1",
77
"minGameVersion": "1.1.15.1018",
88
"maxGameVersion": "1.1.15.1018"
99
}

src/OWML.Launcher/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using OWML.Abstractions;
34
using OWML.Common;
45
using OWML.GameFinder;
@@ -25,6 +26,7 @@ public static Container CreateContainer(string[] args)
2526
var hasConsolePort = argumentHelper.HasArgument(Constants.ConsolePortArgument);
2627
SaveConsolePort(owmlConfig, hasConsolePort, argumentHelper);
2728
SaveOwmlPath(owmlConfig);
29+
SaveCurrentLogPath(owmlConfig);
2830
var owmlManifest = GetOwmlManifest();
2931
var consoleWriter = CreateConsoleWriter(owmlConfig, owmlManifest, hasConsolePort);
3032

@@ -79,6 +81,17 @@ private static void SaveOwmlPath(IOwmlConfig owmlConfig)
7981
JsonHelper.SaveJsonObject(Constants.OwmlConfigFileName, owmlConfig);
8082
}
8183

84+
private static void SaveCurrentLogPath(IOwmlConfig owmlConfig)
85+
{
86+
if (File.Exists($"{owmlConfig.LogsPath}/latest.txt"))
87+
{
88+
File.Delete($"{owmlConfig.LogsPath}/latest.txt");
89+
}
90+
91+
owmlConfig.LoadTime = DateTime.Now;
92+
JsonHelper.SaveJsonObject(Constants.OwmlConfigFileName, owmlConfig);
93+
}
94+
8295
private static IModManifest GetOwmlManifest() =>
8396
JsonHelper.LoadJsonObject<ModManifest>(Constants.OwmlManifestFileName);
8497

src/OWML.Logging/ModLogger.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ public class ModLogger : IModLogger
99
{
1010
private readonly IModManifest _manifest;
1111
private static string _logFileName;
12+
private static string _latestFileName;
1213

1314
public ModLogger(IOwmlConfig config, IModManifest manifest)
1415
{
1516
_manifest = manifest;
16-
_logFileName = $"{config.LogsPath}/OWML.Log.{DateTime.Now:dd-MM-yyyy-HH.mm.ss}.txt";
17+
_logFileName = $"{config.LogsPath}/OWML.Log.{config.LoadTime:yyyy-MM-ddTHH.mm.ss}.txt";
1718

1819
if (!Directory.Exists(config.LogsPath))
1920
{
2021
Directory.CreateDirectory(config.LogsPath);
2122
}
23+
24+
_latestFileName = $"{config.LogsPath}/latest.txt";
2225
}
2326

2427
[Obsolete("Use ModHelper.Console.WriteLine with messageType = Debug instead.")]
@@ -29,7 +32,18 @@ public void Log(string s) =>
2932
public void Log(params object[] objects) =>
3033
Log(string.Join(" ", objects.Select(o => o.ToString()).ToArray()));
3134

32-
private static void LogInternal(string message) =>
33-
File.AppendAllText(_logFileName, $"{DateTime.Now}: {message}{Environment.NewLine}");
35+
private static void LogInternal(string message)
36+
{
37+
var text = $"{DateTime.Now}: {message}{Environment.NewLine}";
38+
try
39+
{
40+
File.AppendAllText(_logFileName, text);
41+
File.AppendAllText(_latestFileName, text);
42+
}
43+
catch
44+
{
45+
// ignored
46+
}
47+
}
3448
}
3549
}

src/OWML.ModHelper.Events/HarmonyHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private Harmony CreateInstance()
3333
if (_owmlConfig.DebugMode)
3434
{
3535
_console.WriteLine("Enabling Harmony debug mode.", MessageType.Debug);
36-
FileLog.logPath = $"{_owmlConfig.LogsPath}/Harmony.Log.{DateTime.Now:dd-MM-yyyy-HH.mm.ss}.txt";
36+
FileLog.logPath = $"{_owmlConfig.LogsPath}/Harmony.Log.{_owmlConfig.LoadTime:yyyy-MM-ddTHH.mm.ss}.txt";
3737
HarmonyFileLog.Enabled = true;
3838
}
3939
harmony = new Harmony(_manifest.UniqueName);

0 commit comments

Comments
 (0)