Last change
on this file since 1191 was 1114, checked in by iritscen, 5 years ago |
Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.
|
File size:
2.4 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.IO;
|
---|
4 | using System.Text;
|
---|
5 |
|
---|
6 | namespace Oni
|
---|
7 | {
|
---|
8 | internal sealed class SubtitleExporter : Exporter
|
---|
9 | {
|
---|
10 | public SubtitleExporter(InstanceFileManager fileManager, string outputDirPath)
|
---|
11 | : base(fileManager, outputDirPath)
|
---|
12 | {
|
---|
13 | }
|
---|
14 |
|
---|
15 | protected override List<InstanceDescriptor> GetSupportedDescriptors(InstanceFile file)
|
---|
16 | {
|
---|
17 | return file.GetNamedDescriptors(TemplateTag.SUBT);
|
---|
18 | }
|
---|
19 |
|
---|
20 | protected override void ExportInstance(InstanceDescriptor descriptor)
|
---|
21 | {
|
---|
22 | var filePath = Path.Combine(OutputDirPath, descriptor.FullName + ".txt");
|
---|
23 |
|
---|
24 | int baseOffset;
|
---|
25 | int[] offsets;
|
---|
26 |
|
---|
27 | using (var reader = descriptor.OpenRead(16))
|
---|
28 | {
|
---|
29 | baseOffset = reader.ReadInt32();
|
---|
30 | offsets = reader.ReadInt32Array(reader.ReadInt32());
|
---|
31 | }
|
---|
32 |
|
---|
33 | using (var rawReader = descriptor.GetRawReader(baseOffset))
|
---|
34 | using (var outStream = File.Create(filePath))
|
---|
35 | using (var writer = new BinaryWriter(outStream))
|
---|
36 | {
|
---|
37 | int fileOffset = (int)rawReader.Position;
|
---|
38 | var buffer = new List<byte>();
|
---|
39 |
|
---|
40 | foreach (int offset in offsets)
|
---|
41 | {
|
---|
42 | rawReader.Position = fileOffset + offset;
|
---|
43 |
|
---|
44 | while (true)
|
---|
45 | {
|
---|
46 | byte b = rawReader.ReadByte();
|
---|
47 |
|
---|
48 | if (b == 0)
|
---|
49 | {
|
---|
50 | buffer.Add((byte)'=');
|
---|
51 | break;
|
---|
52 | }
|
---|
53 |
|
---|
54 | buffer.Add(b);
|
---|
55 | }
|
---|
56 |
|
---|
57 | writer.Write(buffer.ToArray());
|
---|
58 | buffer.Clear();
|
---|
59 |
|
---|
60 | while (true)
|
---|
61 | {
|
---|
62 | byte b = rawReader.ReadByte();
|
---|
63 |
|
---|
64 | if (b == 0)
|
---|
65 | {
|
---|
66 | buffer.AddRange(Encoding.UTF8.GetBytes(Environment.NewLine));
|
---|
67 | break;
|
---|
68 | }
|
---|
69 |
|
---|
70 | buffer.Add(b);
|
---|
71 | }
|
---|
72 |
|
---|
73 | writer.Write(buffer.ToArray());
|
---|
74 | buffer.Clear();
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.