Skip to content

Commit 15bfcd6

Browse files
committed
Removing old ClientDataJson by HourOfCreation
1 parent 3636489 commit 15bfcd6

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Core/Features/Reload/ClientDataJson.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class ClientDataJson
66
{
77
public int ProcessID { get; set; }
88

9+
public int HourOfCreation { get; set; } = 0;
10+
911
// This is needed to serialize enums as strings
1012
[JsonConverter(typeof(JsonStringEnumConverter))]
1113
public ClientMode ClientMode { get; set; }

Core/Features/Reload/ClientDataJsonHelper.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using System.Text.Json;
@@ -63,6 +64,8 @@ public static void WriteData()
6364
if (path == null)
6465
return;
6566

67+
var currentHour = DateTime.Now.Hour;
68+
6669
Log.Info("Writing ClientData");
6770
Utilities.LockingFile(path, (reader, writer) =>
6871
{
@@ -72,6 +75,7 @@ public static void WriteData()
7275
var data = new ClientDataJson
7376
{
7477
ProcessID = Utilities.ProcessID,
78+
HourOfCreation = currentHour,
7579
ClientMode = ClientMode,
7680
PlayerPath = PlayerPath,
7781
WorldPath = WorldPath
@@ -85,13 +89,26 @@ public static void WriteData()
8589
existingData.ClientMode = data.ClientMode;
8690
existingData.PlayerPath = data.PlayerPath;
8791
existingData.WorldPath = data.WorldPath;
92+
existingData.HourOfCreation = data.HourOfCreation;
8893
}
8994
else
9095
{
9196
// Add a new entry
9297
listJson.Add(data);
9398
}
9499

100+
// Remove entries by hour of creation (only keep entries from the current hour)
101+
var newListJson = new List<ClientDataJson>();
102+
foreach (var item in listJson)
103+
{
104+
105+
if (item.HourOfCreation == currentHour)
106+
{
107+
newListJson.Add(item);
108+
}
109+
}
110+
listJson = newListJson;
111+
95112
WriteListToFile(listJson, writer);
96113
});
97114
}

0 commit comments

Comments
 (0)