-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathModuleInfo.cs
More file actions
46 lines (40 loc) · 1.29 KB
/
ModuleInfo.cs
File metadata and controls
46 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using JetBrains.Annotations;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Utilities;
namespace EddiDataDefinitions
{
public class ModuleInfo ( DateTime timestamp, List<ModuleInfoItem> modules )
{
[JsonProperty]
public DateTime timestamp { get; } = timestamp;
[JsonProperty]
public List<ModuleInfoItem> Modules { get; } = modules ?? [ ];
[UsedImplicitly]
public static bool TryFromFile (
DateTime journalTimeStamp,
[CanBeNull] out ModuleInfo info, [CanBeNull] out string rawModules,
string filename = "ModulesInfo.json" )
{
info = null;
rawModules = null;
var (raw, parsed) = Files.FromSavedGamesAsync(
filename,
extract: json =>
{
var o = JsonConvert.DeserializeObject<ModuleInfo>( json );
return (o?.timestamp, o);
},
compareTo: journalTimeStamp
).GetResultOrTimeout( TimeSpan.FromSeconds( 5 ) );
if ( parsed?.Modules != null )
{
info = parsed;
rawModules = raw;
return true;
}
return false;
}
}
}