using System; using System.Collections; using System.IO; namespace HtmlHelp.ChmDecoding { /// /// The class CHMIdxhdr implements t properties which have been read from the #IDXHDR file. /// internal sealed class CHMIdxhdr : IDisposable { /// /// Internal flag specifying if the object is going to be disposed /// private bool disposed = false; /// /// Internal member storing the binary file data /// private byte[] _binaryFileData = null; /// /// Internal member storing the number of topic nodes including the contents and index files /// private int _numberOfTopicNodes = 0; /// /// Internal member storing the offset in the #STRINGS file of the ImageList param of the "text/site properties" object of the sitemap contents /// private int _imageListOffset = 0; /// /// True if the value of the ImageType param of the "text/site properties" object of the sitemap contents is "Folder". /// private bool _imageTypeFolder = false; /// /// Internal member storing the background value /// private int _background = 0; /// /// Internal member storing the foreground value /// private int _foreground = 0; /// /// Internal member storing the offset in the #STRINGS file of the Font param of the "text/site properties" object of the sitemap contents /// private int _fontOffset = 0; /// /// Internal member storing the offset in the #STRINGS file of the FrameName param of the "text/site properties" object of the sitemap contents /// private int _frameNameOffset = 0; /// /// Internal member storing the offset in the #STRINGS file of the WindowName param of the "text/site properties" object of the sitemap contents /// private int _windowNameOffset = 0; /// /// Internal member storing the number of merged files /// private int _numberOfMergedFiles = 0; /// /// Internal member storing the offset in the #STRINGS file of the merged file names /// private ArrayList _mergedFileOffsets = new ArrayList(); /// /// Internal member storing the associated chmfile object /// private CHMFile _associatedFile = null; /// /// Constructor of the class /// /// binary file data of the #IDXHDR file /// associated CHMFile instance public CHMIdxhdr(byte[] binaryFileData, CHMFile associatedFile) { _binaryFileData = binaryFileData; _associatedFile = associatedFile; DecodeData(); } /// /// Decodes the binary file data and fills the internal properties /// /// true if succeeded private bool DecodeData() { bool bRet = true; MemoryStream memStream = new MemoryStream(_binaryFileData); BinaryReader binReader = new BinaryReader(memStream); int nTemp = 0; // 4 character T#SM binReader.ReadBytes(4); // unknown timestamp DWORD nTemp = binReader.ReadInt32(); // unknown 1 nTemp = binReader.ReadInt32(); // number of topic nodes including the contents & index files _numberOfTopicNodes = binReader.ReadInt32(); // unknown DWORD nTemp = binReader.ReadInt32(); // offset in the strings file _imageListOffset = binReader.ReadInt32(); if( _imageListOffset == 0) _imageListOffset = -1; // 0/-1 = none // unknown DWORD nTemp = binReader.ReadInt32(); // 1 if the value of the ImageType param of the "text/site properties" object of the sitemap contents is "Folder". nTemp = binReader.ReadInt32(); _imageTypeFolder = (nTemp == 1); // offset in the strings file _background = binReader.ReadInt32(); // offset in the strings file _foreground = binReader.ReadInt32(); // offset in the strings file _fontOffset = binReader.ReadInt32(); // window styles DWORD nTemp = binReader.ReadInt32(); // window styles DWORD nTemp = binReader.ReadInt32(); // unknown DWORD nTemp = binReader.ReadInt32(); // offset in the strings file _frameNameOffset = binReader.ReadInt32(); if( _frameNameOffset == 0) _frameNameOffset = -1; // 0/-1 = none // offset in the strings file _windowNameOffset = binReader.ReadInt32(); if( _windowNameOffset == 0) _windowNameOffset = -1; // 0/-1 = none // informations types DWORD nTemp = binReader.ReadInt32(); // unknown DWORD nTemp = binReader.ReadInt32(); // number of merged files in the merged file list DWORD _numberOfMergedFiles = binReader.ReadInt32(); nTemp = binReader.ReadInt32(); for(int i = 0; i < _numberOfMergedFiles; i++) { // DWORD offset value of merged file nTemp = binReader.ReadInt32(); if(nTemp > 0) _mergedFileOffsets.Add(nTemp); } return bRet; } /// /// Gets the number of topic nodes including the contents and index files /// public int NumberOfTopicNodes { get { return _numberOfTopicNodes; } } /// /// Gets the offset in the #STRINGS file of the ImageList /// param of the "text/site properties" object of the sitemap contents /// public int ImageListOffset { get { return _imageListOffset; } } /// /// True if the value of the ImageType param of the /// "text/site properties" object of the sitemap contents is "Folder". /// /// If this is set to true, the help will display folders instead of books public bool ImageTypeFolder { get { return _imageTypeFolder; } } /// /// Gets the background setting /// public int Background { get { return _background; } } /// /// Gets the foreground setting /// public int Foreground { get { return _foreground; } } /// /// Gets the offset in the #STRINGS file of the Font /// param of the "text/site properties" object of the sitemap contents /// public int WindowNameOffset { get { return _fontOffset; } } /// /// Gets the offset in the #STRINGS file of the FrameName /// param of the "text/site properties" object of the sitemap contents /// public int FrameNameOffset { get { return _frameNameOffset; } } /// /// Gets the offset in the #STRINGS file of the WindowName /// param of the "text/site properties" object of the sitemap contents /// public int FontOffset { get { return _windowNameOffset; } } /// /// Gets an array list of offset numbers in the #STRINGS file of the /// merged file names. /// public ArrayList MergedFileOffsets { get { return _mergedFileOffsets; } } /// /// Implement IDisposable. /// public void Dispose() { Dispose(true); // This object will be cleaned up by the Dispose method. // Therefore, you should call GC.SupressFinalize to // take this object off the finalization queue // and prevent finalization code for this object // from executing a second time. GC.SuppressFinalize(this); } /// /// Dispose(bool disposing) executes in two distinct scenarios. /// If disposing equals true, the method has been called directly /// or indirectly by a user's code. Managed and unmanaged resources /// can be disposed. /// If disposing equals false, the method has been called by the /// runtime from inside the finalizer and you should not reference /// other objects. Only unmanaged resources can be disposed. /// /// disposing flag private void Dispose(bool disposing) { // Check to see if Dispose has already been called. if(!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources. if(disposing) { // Dispose managed resources. _binaryFileData = null; _mergedFileOffsets = null; } } disposed = true; } } }