| 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 | } |