2 using System.Collections;
5 namespace HtmlHelp.ChmDecoding
8 /// The class <c>CHMIdxhdr</c> implements t properties which have been read from the #IDXHDR file.
10 internal sealed class CHMIdxhdr : IDisposable
13 /// Internal flag specifying if the object is going to be disposed
15 private bool disposed = false;
17 /// Internal member storing the binary file data
19 private byte[] _binaryFileData = null;
21 /// Internal member storing the number of topic nodes including the contents and index files
23 private int _numberOfTopicNodes = 0;
25 /// Internal member storing the offset in the #STRINGS file of the ImageList param of the "text/site properties" object of the sitemap contents
27 private int _imageListOffset = 0;
29 /// True if the value of the ImageType param of the "text/site properties" object of the sitemap contents is "Folder".
31 private bool _imageTypeFolder = false;
33 /// Internal member storing the background value
35 private int _background = 0;
37 /// Internal member storing the foreground value
39 private int _foreground = 0;
41 /// Internal member storing the offset in the #STRINGS file of the Font param of the "text/site properties" object of the sitemap contents
43 private int _fontOffset = 0;
45 /// Internal member storing the offset in the #STRINGS file of the FrameName param of the "text/site properties" object of the sitemap contents
47 private int _frameNameOffset = 0;
49 /// Internal member storing the offset in the #STRINGS file of the WindowName param of the "text/site properties" object of the sitemap contents
51 private int _windowNameOffset = 0;
53 /// Internal member storing the number of merged files
55 private int _numberOfMergedFiles = 0;
57 /// Internal member storing the offset in the #STRINGS file of the merged file names
59 private ArrayList _mergedFileOffsets = new ArrayList();
61 /// Internal member storing the associated chmfile object
63 private CHMFile _associatedFile = null;
66 /// Constructor of the class
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)
72 _binaryFileData = binaryFileData;
73 _associatedFile = associatedFile;
78 /// Decodes the binary file data and fills the internal properties
80 /// <returns>true if succeeded</returns>
81 private bool DecodeData()
85 MemoryStream memStream = new MemoryStream(_binaryFileData);
86 BinaryReader binReader = new BinaryReader(memStream);
91 binReader.ReadBytes(4);
92 // unknown timestamp DWORD
93 nTemp = binReader.ReadInt32();
96 nTemp = binReader.ReadInt32();
98 // number of topic nodes including the contents & index files
99 _numberOfTopicNodes = binReader.ReadInt32();
102 nTemp = binReader.ReadInt32();
104 // offset in the strings file
105 _imageListOffset = binReader.ReadInt32();
106 if( _imageListOffset == 0)
107 _imageListOffset = -1; // 0/-1 = none
110 nTemp = binReader.ReadInt32();
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);
116 // offset in the strings file
117 _background = binReader.ReadInt32();
118 // offset in the strings file
119 _foreground = binReader.ReadInt32();
121 // offset in the strings file
122 _fontOffset = binReader.ReadInt32();
124 // window styles DWORD
125 nTemp = binReader.ReadInt32();
126 // window styles DWORD
127 nTemp = binReader.ReadInt32();
130 nTemp = binReader.ReadInt32();
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
141 // informations types DWORD
142 nTemp = binReader.ReadInt32();
145 nTemp = binReader.ReadInt32();
147 // number of merged files in the merged file list DWORD
148 _numberOfMergedFiles = binReader.ReadInt32();
150 nTemp = binReader.ReadInt32();
152 for(int i = 0; i < _numberOfMergedFiles; i++)
154 // DWORD offset value of merged file
155 nTemp = binReader.ReadInt32();
158 _mergedFileOffsets.Add(nTemp);
165 /// Gets the number of topic nodes including the contents and index files
167 public int NumberOfTopicNodes
169 get { return _numberOfTopicNodes; }
173 /// Gets the offset in the #STRINGS file of the ImageList
174 /// param of the "text/site properties" object of the sitemap contents
176 public int ImageListOffset
178 get { return _imageListOffset; }
182 /// True if the value of the ImageType param of the
183 /// "text/site properties" object of the sitemap contents is "Folder".
185 /// <remarks>If this is set to true, the help will display folders instead of books</remarks>
186 public bool ImageTypeFolder
188 get { return _imageTypeFolder; }
192 /// Gets the background setting
194 public int Background
196 get { return _background; }
200 /// Gets the foreground setting
202 public int Foreground
204 get { return _foreground; }
208 /// Gets the offset in the #STRINGS file of the Font
209 /// param of the "text/site properties" object of the sitemap contents
211 public int WindowNameOffset
213 get { return _fontOffset; }
217 /// Gets the offset in the #STRINGS file of the FrameName
218 /// param of the "text/site properties" object of the sitemap contents
220 public int FrameNameOffset
222 get { return _frameNameOffset; }
226 /// Gets the offset in the #STRINGS file of the WindowName
227 /// param of the "text/site properties" object of the sitemap contents
229 public int FontOffset
231 get { return _windowNameOffset; }
235 /// Gets an array list of offset numbers in the #STRINGS file of the
236 /// merged file names.
238 public ArrayList MergedFileOffsets
240 get { return _mergedFileOffsets; }
244 /// Implement IDisposable.
246 public void Dispose()
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);
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
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.
266 /// <param name="disposing">disposing flag</param>
267 private void Dispose(bool disposing)
269 // Check to see if Dispose has already been called.
272 // If disposing equals true, dispose all managed
273 // and unmanaged resources.
276 // Dispose managed resources.
277 _binaryFileData = null;
278 _mergedFileOffsets = null;