1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using System . IO ;
34using System . Linq ;
45using 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