/[MorrowindCustomClothingSlotCreator]/trunk/libTES3FileFormat/PluginHeader.cs
ViewVC logotype

Contents of /trunk/libTES3FileFormat/PluginHeader.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 33 - (show annotations) (download)
Sat Jul 30 11:47:53 2011 UTC (9 years ago) by william
File size: 5147 byte(s)
*** work out committing individual entries back into the main data stream

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6 using System.Diagnostics;
7
8 namespace libTES3FileFormat
9 {
10 public interface IPluginHeader : IParse, ICommit, IAsBytes, ISizeOffset
11 {
12 //int HeaderSize { get; } // 4bytes
13 float Version { get; }// 4 bytes
14 int Unknown1 { get; }// 4 bytes
15 byte[] CompanyName { get; } // 32 bytes
16 byte[] PluginDescription { get; } // 256 bytes
17 int RecordCount { get; }// 4 bytes
18 }
19 public class PluginHeader : IPluginHeader, ICommitParseAsBytes
20 {
21 private ConsoleLog Log;
22 private const string HEADER_MAGIC = "HEDR";
23 MemoryStream reader = new MemoryStream();
24 public PluginHeader()
25 {
26 this.reader = new MemoryStream();
27 this.Offset = 0;
28 this.Size = 0;
29 }
30 public PluginHeader(BinaryReader br, int offset, int BytesToRead, bool ReadOnly, ConsoleLog Log)
31 : this()
32 {
33 this.Log = Log;
34 br.BaseStream.Seek(offset, SeekOrigin.Begin);
35 this.Offset = offset;
36 this.reader = new MemoryStream(br.ReadBytes(BytesToRead), 0, BytesToRead);
37 this.Parse(this.reader);
38 }
39
40 #region IParse Members
41
42 public bool Parse(MemoryStream stream)
43 {
44 BinaryReader br = new BinaryReader(stream);
45 this.Log.WriteLine();
46 // read header section magic
47 byte[] magic = br.ReadBytes(4);
48 string str_magic = ASCIIEncoding.ASCII.GetString(magic);
49 StringBuilder magic_info_message = new StringBuilder();
50 magic_info_message.Append("\tDetected Header Section: ");
51 magic_info_message.Append(magic.ToStr());
52 magic_info_message.Append(" : " + str_magic);
53
54 // throw assert if not true
55 Debug.Assert(str_magic == PluginHeader.HEADER_MAGIC, string.Format("Excepted: {0} found: {1}",PluginHeader.HEADER_MAGIC, str_magic));
56
57 this.Log.WriteLine(magic_info_message.ToString());
58
59
60 this.Size = br.ReadInt32();
61 this.Log.WriteLine("\t\tHEDR Size: " + this.Size);
62
63 Debug.Assert(this.Size == 300, string.Format("Excepted: {0} found: {1}", 300, this.Size));
64
65 this.Version = br.ReadSingle();// 4 bytes
66 this.Log.WriteLine("\t\tVersion: " + this.Version);
67 this.Unknown1 = br.ReadInt32(); // 4 bytes
68 this.Log.WriteLine("\t\tUnknown1: " + this.Unknown1);
69 this.CompanyName = br.ReadBytes(0x20); // 32 bytes
70 this.Log.WriteLine("\t\tCompanyName: " + this.CompanyName.ToAscii());
71 this.PluginDescription = br.ReadBytes(0x100); // 256 bytes
72 this.Log.WriteLine("\t\tPluginDescription: " + this.PluginDescription.ToAscii());
73 this.RecordCount = br.ReadInt32();// 4 bytes
74 this.Log.WriteLine("\t\tRecordCount: " + this.RecordCount);
75 this.Log.WriteLine();
76
77 return true;
78 }
79 #region IPluginHeader Members
80 //private int _HeaderSize;
81 private float _Version;
82 private int _Unknown1;
83 private byte[] _CompanyName;
84 private byte[] _PluginDescription;
85 private int _RecordCount;
86
87 //public int HeaderSize { get { return _HeaderSize; } private set { _HeaderSize = value; } } // 4bytes
88 public float Version { get { return _Version; } private set { _Version = value; } } // 4 bytes
89 public int Unknown1 { get { return _Unknown1; } private set { _Unknown1 = value; } } // 4 bytes
90 public byte[] CompanyName { get { return _CompanyName; } private set { _CompanyName = value; } } // 32 bytes
91 public byte[] PluginDescription { get { return _PluginDescription; } private set { _PluginDescription = value; } } // 256 bytes
92 public int RecordCount { get { return _RecordCount; } private set { _RecordCount = value; } }// 4 bytes
93 #endregion
94
95
96 #endregion
97 #region ICommit Members
98
99 public bool Commit(ICommitWriter writer)
100 {
101 throw new NotImplementedException();
102 }
103
104 #endregion
105
106 #region IAsBytes Members
107
108 public byte[] AsBytes
109 {
110 get
111 {
112 this.reader.Seek(0, SeekOrigin.Begin);
113 BinaryReader br = new BinaryReader(this.reader);
114 return br.ReadBytes(this.Size);
115 }
116 }
117
118 #endregion
119
120 #region ISizeOffset Members
121
122 private int _Size;
123 public int Size { get { return _Size; } private set { _Size = value; } } // distance from from 8 bytes into HEDR record
124
125 private int _Offset;
126 public int Offset { get { return _Offset; } private set { _Offset = value; } }
127 public int OffsetToNext { get { return this.Size + this.Offset + 8; } } // gets the offset to the MASTER Section
128 #endregion
129 }
130 }
131

  ViewVC Help
Powered by ViewVC 1.1.22