ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/OniSplit/BinImporter.cs
Revision: 1114
Committed: Wed Jan 22 14:08:57 2020 UTC (5 years, 8 months ago) by iritscen
File size: 1107 byte(s)
Log Message:
Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File Contents

# Content
1 using System;
2 using System.IO;
3 using Oni.Metadata;
4
5 namespace Oni
6 {
7 internal class BinImporter : Importer
8 {
9 public override void Import(string filePath, string outputDirPath)
10 {
11 using (var reader = new BinaryReader(filePath))
12 {
13 int tag = reader.ReadInt32();
14
15 if (!Enum.IsDefined(typeof(BinaryTag), tag))
16 throw new NotSupportedException(string.Format(".bin file with tag '{0:x}' is unuspported", tag));
17
18 var tagName = ((BinaryTag)tag).ToString();
19
20 BeginImport();
21
22 var bina = CreateInstance(TemplateTag.BINA, tagName + Path.GetFileNameWithoutExtension(filePath));
23
24 using (var writer = bina.OpenWrite())
25 {
26 writer.Write(reader.Length);
27 writer.Write(32);
28 }
29
30 RawWriter.Write(tag);
31 RawWriter.Write(reader.ReadBytes(reader.Length - 4));
32
33 Write(outputDirPath);
34 }
35 }
36 }
37 }