-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathECDependenciesSection.cs
More file actions
102 lines (98 loc) · 4.48 KB
/
Copy pathECDependenciesSection.cs
File metadata and controls
102 lines (98 loc) · 4.48 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
using System.Text.Json;
using QIQI.EProjectFile.Internal;
using QIQI.EProjectFile.Context;
namespace QIQI.EProjectFile.Sections
{
public class ECDependenciesSection : ISection
{
private class KeyImpl : ISectionKey<ECDependenciesSection>
{
public string SectionName => "易模块记录段";
public int SectionKey => 0x0C007319;
public bool IsOptional => false;
public ECDependenciesSection Parse(BlockParserContext context)
{
return context.Consume(reader =>
{
var encoding = context.Encoding;
var that = new ECDependenciesSection();
var count = reader.ReadInt32();
that.ECDependencies = new List<ECDependencyInfo>(count);
for (int i = 0; i < count; i++)
{
var dependency = new ECDependencyInfo();
dependency.InfoVersion = reader.ReadInt32();
if (dependency.InfoVersion > 2)
{
throw new Exception($"{nameof(ECDependencyInfo)}.{nameof(ECDependencyInfo.InfoVersion)} = {dependency.InfoVersion}, not supported");
}
dependency.FileSize = reader.ReadInt32();
dependency.FileLastModifiedDate = DateTime.FromFileTime(reader.ReadInt64());
if (dependency.InfoVersion >= 2)
{
dependency.ReExport = reader.ReadInt32() != 0;
}
dependency.Name = reader.ReadStringWithLengthPrefix(encoding);
dependency.Path = reader.ReadStringWithLengthPrefix(encoding);
var starts = reader.ReadInt32sWithByteSizePrefix();
var counts = reader.ReadInt32sWithByteSizePrefix();
dependency.DefinedIds = new List<ECDependencyInfo.PackedIds>(starts.Length);
for (int indexOfids = 0; indexOfids < starts.Length; indexOfids++)
{
dependency.DefinedIds.Add(new ECDependencyInfo.PackedIds
{
Start = starts[indexOfids],
Count = counts[indexOfids]
});
}
that.ECDependencies.Add(dependency);
}
return that;
});
}
}
public static readonly ISectionKey<ECDependenciesSection> Key = new KeyImpl();
public string SectionName => Key.SectionName;
public int SectionKey => Key.SectionKey;
public bool IsOptional => Key.IsOptional;
public List<ECDependencyInfo> ECDependencies { get; set; }
public byte[] ToBytes(BlockByteifierContext context)
{
return context.Collect(writer =>
{
var encoding = context.Encoding;
writer.Write(ECDependencies.Count);
foreach (var dependency in ECDependencies)
{
writer.Write(dependency.InfoVersion);
writer.Write(dependency.FileSize);
writer.Write(dependency.FileLastModifiedDate.ToFileTime());
if (dependency.InfoVersion >= 2)
{
writer.Write(dependency.ReExport ? 1 : 0);
}
else
{
if (dependency.ReExport)
{
throw new Exception($"Cannot re-export EC when {nameof(dependency.InfoVersion)} is 1");
}
}
writer.WriteStringWithLengthPrefix(encoding, dependency.Name);
writer.WriteStringWithLengthPrefix(encoding, dependency.Path);
writer.WriteInt32sWithByteSizePrefix(dependency.DefinedIds.Select(x => x.Start).ToArray());
writer.WriteInt32sWithByteSizePrefix(dependency.DefinedIds.Select(x => x.Count).ToArray());
}
});
}
public override string ToString()
{
return JsonSerializer.Serialize(this, JsonUtils.Options);
}
}
}