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

Annotation of /trunk/libTES3FileFormat/PluginHeader.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (hide annotations) (download)
Fri Jul 29 12:07:26 2011 UTC (8 years, 5 months ago) by william
File size: 4859 byte(s)
PluginDescription -> Read 256 bytes
RecordCount -> should be an int not a long

1 william 7 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using System.IO;
6 william 8 using System.Diagnostics;
7 william 7
8     namespace libTES3FileFormat
9     {
10     public interface IPluginHeader : IParse, ICommit, IAsBytes, ISizeOffset
11     {
12 william 8 //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 william 9 int RecordCount { get; }// 4 bytes
18 william 7 }
19     public class PluginHeader : IPluginHeader
20     {
21 william 8 private ConsoleLog Log;
22     private const string HEADER_MAGIC = "HEDR";
23 william 7 MemoryStream reader = new MemoryStream();
24     public PluginHeader()
25     {
26     this.reader = new MemoryStream();
27     this.Offset = 0;
28     this.Size = 0;
29     }
30 william 8 public PluginHeader(BinaryReader br, int offset, int BytesToRead, bool ReadOnly, ConsoleLog Log)
31 william 7 : this()
32     {
33 william 8 this.Log = Log;
34 william 7 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 william 8 {
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 william 9 this.Version = br.ReadSingle();// 4 bytes
66 william 8 this.Log.WriteLine("\t\tVersion: " + this.Version);
67 william 9 this.Unknown1 = br.ReadInt32(); // 4 bytes
68 william 8 this.Log.WriteLine("\t\tUnknown1: " + this.Unknown1);
69 william 9 this.CompanyName = br.ReadBytes(0x20); // 32 bytes
70 william 8 this.Log.WriteLine("\t\tCompanyName: " + this.CompanyName.ToAscii());
71 william 9 this.PluginDescription = br.ReadBytes(0x100); // 256 bytes
72 william 8 this.Log.WriteLine("\t\tPluginDescription: " + this.PluginDescription.ToAscii());
73 william 9 this.RecordCount = br.ReadInt32();// 4 bytes
74 william 8 this.Log.WriteLine("\t\tRecordCount: " + this.RecordCount);
75     this.Log.WriteLine();
76 william 7 return true;
77     }
78 william 8 #region IPluginHeader Members
79     private int _HeaderSize;
80     private float _Version;
81     private int _Unknown1;
82     private byte[] _CompanyName;
83     private byte[] _PluginDescription;
84 william 9 private int _RecordCount;
85 william 7
86 william 8 //public int HeaderSize { get { return _HeaderSize; } private set { _HeaderSize = value; } } // 4bytes
87     public float Version { get { return _Version; } private set { _Version = value; } } // 4 bytes
88     public int Unknown1 { get { return _Unknown1; } private set { _Unknown1 = value; } } // 4 bytes
89     public byte[] CompanyName { get { return _CompanyName; } private set { _CompanyName = value; } } // 32 bytes
90     public byte[] PluginDescription { get { return _PluginDescription; } private set { _PluginDescription = value; } } // 256 bytes
91 william 9 public int RecordCount { get { return _RecordCount; } private set { _RecordCount = value; } }// 4 bytes
92 william 7 #endregion
93 william 8
94    
95     #endregion
96 william 7 #region ICommit Members
97    
98     public bool Commit(BinaryWriter writer)
99     {
100     throw new NotImplementedException();
101     }
102    
103     #endregion
104    
105     #region IAsBytes Members
106    
107     public byte[] AsBytes { get { return this.reader.ToArray(); } }
108    
109     #endregion
110    
111     #region ISizeOffset Members
112    
113     private int _Size;
114     public int Size { get { return _Size; } private set { _Size = value; } } // headersize
115    
116     private int _Offset;
117     public int Offset { get { return _Offset; } private set { _Offset = value; } }
118     public int OffsetToNext { get { return this.Size + this.Offset; } } // force this to 16 bytes
119     #endregion
120     }
121     }
122 william 8

  ViewVC Help
Powered by ViewVC 1.1.22