forked from ACEmulator/GDLCacheBinParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSegment.cs
46 lines (35 loc) · 900 Bytes
/
Segment.cs
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 System;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace PhatACCacheBinParser
{
abstract class Segment : IUnpackable
{
protected static JsonSerializer Serializer = new JsonSerializer();
static Segment()
{
Serializer.Converters.Add(new JavaScriptDateTimeConverter());
Serializer.NullValueHandling = NullValueHandling.Ignore;
}
private bool parsed;
/// <summary>
/// You can only call Parse() once on an instantiated object.
/// </summary>
public virtual bool Unpack(BinaryReader reader)
{
if (parsed)
throw new InvalidOperationException();
parsed = true;
return true;
}
public virtual bool WriteJSONOutput(string outputFolder)
{
if (!parsed)
throw new InvalidOperationException();
if (!Directory.Exists(outputFolder))
Directory.CreateDirectory(outputFolder);
return false;
}
}
}