- Change dispatcher lock release to be more like documented in Windows Internals...
[reactos.git] / irc / TechBot / CHMLibrary / CHMDecoding / CHMIdxhdr.cs
1 using System;
2 using System.Collections;
3 using System.IO;
4
5 namespace HtmlHelp.ChmDecoding
6 {
7 /// <summary>
8 /// The class <c>CHMIdxhdr</c> implements t properties which have been read from the #IDXHDR file.
9 /// </summary>
10 internal sealed class CHMIdxhdr : IDisposable
11 {
12 /// <summary>
13 /// Internal flag specifying if the object is going to be disposed
14 /// </summary>
15 private bool disposed = false;
16 /// <summary>
17 /// Internal member storing the binary file data
18 /// </summary>
19 private byte[] _binaryFileData = null;
20 /// <summary>
21 /// Internal member storing the number of topic nodes including the contents and index files
22 /// </summary>
23 private int _numberOfTopicNodes = 0;
24 /// <summary>
25 /// Internal member storing the offset in the #STRINGS file of the ImageList param of the "text/site properties" object of the sitemap contents
26 /// </summary>
27 private int _imageListOffset = 0;
28 /// <summary>
29 /// True if the value of the ImageType param of the "text/site properties" object of the sitemap contents is "Folder".
30 /// </summary>
31 private bool _imageTypeFolder = false;
32 /// <summary>
33 /// Internal member storing the background value
34 /// </summary>
35 private int _background = 0;
36 /// <summary>
37 /// Internal member storing the foreground value
38 /// </summary>
39 private int _foreground = 0;
40 /// <summary>
41 /// Internal member storing the offset in the #STRINGS file of the Font param of the "text/site properties" object of the sitemap contents
42 /// </summary>
43 private int _fontOffset = 0;
44 /// <summary>
45 /// Internal member storing the offset in the #STRINGS file of the FrameName param of the "text/site properties" object of the sitemap contents
46 /// </summary>
47 private int _frameNameOffset = 0;
48 /// <summary>
49 /// Internal member storing the offset in the #STRINGS file of the WindowName param of the "text/site properties" object of the sitemap contents
50 /// </summary>
51 private int _windowNameOffset = 0;
52 /// <summary>
53 /// Internal member storing the number of merged files
54 /// </summary>
55 private int _numberOfMergedFiles = 0;
56 /// <summary>
57 /// Internal member storing the offset in the #STRINGS file of the merged file names
58 /// </summary>
59 private ArrayList _mergedFileOffsets = new ArrayList();
60 /// <summary>
61 /// Internal member storing the associated chmfile object
62 /// </summary>
63 private CHMFile _associatedFile = null;
64
65 /// <summary>
66 /// Constructor of the class
67 /// </summary>
68 /// <param name="binaryFileData">binary file data of the #IDXHDR file</param>
69 /// <param name="associatedFile">associated CHMFile instance</param>
70 public CHMIdxhdr(byte[] binaryFileData, CHMFile associatedFile)
71 {
72 _binaryFileData = binaryFileData;
73 _associatedFile = associatedFile;
74 DecodeData();
75 }
76
77 /// <summary>
78 /// Decodes the binary file data and fills the internal properties
79 /// </summary>
80 /// <returns>true if succeeded</returns>
81 private bool DecodeData()
82 {
83 bool bRet = true;
84
85 MemoryStream memStream = new MemoryStream(_binaryFileData);
86 BinaryReader binReader = new BinaryReader(memStream);
87
88 int nTemp = 0;
89
90 // 4 character T#SM
91 binReader.ReadBytes(4);
92 // unknown timestamp DWORD
93 nTemp = binReader.ReadInt32();
94
95 // unknown 1
96 nTemp = binReader.ReadInt32();
97
98 // number of topic nodes including the contents & index files
99 _numberOfTopicNodes = binReader.ReadInt32();
100
101 // unknown DWORD
102 nTemp = binReader.ReadInt32();
103
104 // offset in the strings file
105 _imageListOffset = binReader.ReadInt32();
106 if( _imageListOffset == 0)
107 _imageListOffset = -1; // 0/-1 = none
108
109 // unknown DWORD
110 nTemp = binReader.ReadInt32();
111
112 // 1 if the value of the ImageType param of the "text/site properties" object of the sitemap contents is "Folder".
113 nTemp = binReader.ReadInt32();
114 _imageTypeFolder = (nTemp == 1);
115
116 // offset in the strings file
117 _background = binReader.ReadInt32();
118 // offset in the strings file
119 _foreground = binReader.ReadInt32();
120
121 // offset in the strings file
122 _fontOffset = binReader.ReadInt32();
123
124 // window styles DWORD
125 nTemp = binReader.ReadInt32();
126 // window styles DWORD
127 nTemp = binReader.ReadInt32();
128
129 // unknown DWORD
130 nTemp = binReader.ReadInt32();
131
132 // offset in the strings file
133 _frameNameOffset = binReader.ReadInt32();
134 if( _frameNameOffset == 0)
135 _frameNameOffset = -1; // 0/-1 = none
136 // offset in the strings file
137 _windowNameOffset = binReader.ReadInt32();
138 if( _windowNameOffset == 0)
139 _windowNameOffset = -1; // 0/-1 = none
140
141 // informations types DWORD
142 nTemp = binReader.ReadInt32();
143
144 // unknown DWORD
145 nTemp = binReader.ReadInt32();
146
147 // number of merged files in the merged file list DWORD
148 _numberOfMergedFiles = binReader.ReadInt32();
149
150 nTemp = binReader.ReadInt32();
151
152 for(int i = 0; i < _numberOfMergedFiles; i++)
153 {
154 // DWORD offset value of merged file
155 nTemp = binReader.ReadInt32();
156
157 if(nTemp > 0)
158 _mergedFileOffsets.Add(nTemp);
159 }
160
161 return bRet;
162 }
163
164 /// <summary>
165 /// Gets the number of topic nodes including the contents and index files
166 /// </summary>
167 public int NumberOfTopicNodes
168 {
169 get { return _numberOfTopicNodes; }
170 }
171
172 /// <summary>
173 /// Gets the offset in the #STRINGS file of the ImageList
174 /// param of the "text/site properties" object of the sitemap contents
175 /// </summary>
176 public int ImageListOffset
177 {
178 get { return _imageListOffset; }
179 }
180
181 /// <summary>
182 /// True if the value of the ImageType param of the
183 /// "text/site properties" object of the sitemap contents is "Folder".
184 /// </summary>
185 /// <remarks>If this is set to true, the help will display folders instead of books</remarks>
186 public bool ImageTypeFolder
187 {
188 get { return _imageTypeFolder; }
189 }
190
191 /// <summary>
192 /// Gets the background setting
193 /// </summary>
194 public int Background
195 {
196 get { return _background; }
197 }
198
199 /// <summary>
200 /// Gets the foreground setting
201 /// </summary>
202 public int Foreground
203 {
204 get { return _foreground; }
205 }
206
207 /// <summary>
208 /// Gets the offset in the #STRINGS file of the Font
209 /// param of the "text/site properties" object of the sitemap contents
210 /// </summary>
211 public int WindowNameOffset
212 {
213 get { return _fontOffset; }
214 }
215
216 /// <summary>
217 /// Gets the offset in the #STRINGS file of the FrameName
218 /// param of the "text/site properties" object of the sitemap contents
219 /// </summary>
220 public int FrameNameOffset
221 {
222 get { return _frameNameOffset; }
223 }
224
225 /// <summary>
226 /// Gets the offset in the #STRINGS file of the WindowName
227 /// param of the "text/site properties" object of the sitemap contents
228 /// </summary>
229 public int FontOffset
230 {
231 get { return _windowNameOffset; }
232 }
233
234 /// <summary>
235 /// Gets an array list of offset numbers in the #STRINGS file of the
236 /// merged file names.
237 /// </summary>
238 public ArrayList MergedFileOffsets
239 {
240 get { return _mergedFileOffsets; }
241 }
242
243 /// <summary>
244 /// Implement IDisposable.
245 /// </summary>
246 public void Dispose()
247 {
248 Dispose(true);
249 // This object will be cleaned up by the Dispose method.
250 // Therefore, you should call GC.SupressFinalize to
251 // take this object off the finalization queue
252 // and prevent finalization code for this object
253 // from executing a second time.
254 GC.SuppressFinalize(this);
255 }
256
257 /// <summary>
258 /// Dispose(bool disposing) executes in two distinct scenarios.
259 /// If disposing equals true, the method has been called directly
260 /// or indirectly by a user's code. Managed and unmanaged resources
261 /// can be disposed.
262 /// If disposing equals false, the method has been called by the
263 /// runtime from inside the finalizer and you should not reference
264 /// other objects. Only unmanaged resources can be disposed.
265 /// </summary>
266 /// <param name="disposing">disposing flag</param>
267 private void Dispose(bool disposing)
268 {
269 // Check to see if Dispose has already been called.
270 if(!this.disposed)
271 {
272 // If disposing equals true, dispose all managed
273 // and unmanaged resources.
274 if(disposing)
275 {
276 // Dispose managed resources.
277 _binaryFileData = null;
278 _mergedFileOffsets = null;
279 }
280
281
282 }
283 disposed = true;
284 }
285 }
286 }