Ejemplo n.º 1
0
        /// <summary>
        /// Decodes the binary file data and fills the internal properties
        /// </summary>
        /// <returns>true if succeeded</returns>
        private bool DecodeData()
        {
            bool bRet = true;

            MemoryStream memStream = new MemoryStream(_binaryFileData);
            BinaryReader binReader = new BinaryReader(memStream);

            int nCurOffset = 0;

            while ((memStream.Position < memStream.Length) && (bRet))
            {
                int entryOffset    = nCurOffset;
                int tocIdx         = binReader.ReadInt32();
                int titleOffset    = binReader.ReadInt32();
                int urltablOffset  = binReader.ReadInt32();
                int visibilityMode = binReader.ReadInt16();
                int unknownMode    = binReader.ReadInt16();

                TopicEntry newEntry = new TopicEntry(entryOffset, tocIdx, titleOffset, urltablOffset, visibilityMode, unknownMode, _associatedFile);
                _topicTable.Add(newEntry);

                nCurOffset = (int)memStream.Position;
            }

            return(bRet);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the object data from a dump store
        /// </summary>
        /// <param name="reader">reader to read the data</param>
        internal void ReadDump(ref BinaryReader reader)
        {
            int i    = 0;
            int nCnt = reader.ReadInt32();

            for (i = 0; i < nCnt; i++)
            {
                TopicEntry newItem = new TopicEntry();
                newItem.SetCHMFile(_associatedFile);
                newItem.ReadDump(ref reader);
                _topicTable.Add(newItem);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Decodes the binary file data and fills the internal properties
        /// </summary>
        /// <returns>true if succeeded</returns>
        private bool DecodeData()
        {
            _toc         = new ArrayList();
            _offsetTable = new Hashtable();

            bool bRet = true;

            MemoryStream memStream = new MemoryStream(_binaryFileData);
            BinaryReader binReader = new BinaryReader(memStream);

            int nCurOffset = 0;

            _offset2028        = binReader.ReadInt32();
            _offset16structs   = binReader.ReadInt32();
            _numberOf16structs = binReader.ReadInt32();
            _offsetOftopics    = binReader.ReadInt32();

            binReader.BaseStream.Seek(_offset2028, SeekOrigin.Begin);

            if (RecursivelyBuildTree(ref binReader, _offset2028, _toc, null))
            {
                binReader.BaseStream.Seek(_offset16structs, SeekOrigin.Begin);
                nCurOffset = (int)binReader.BaseStream.Position;

                for (int i = 0; i < _numberOf16structs; i++)
                {
                    int tocOffset   = binReader.ReadInt32();
                    int sqNr        = binReader.ReadInt32();
                    int topOffset   = binReader.ReadInt32();
                    int hhctopicIdx = binReader.ReadInt32();

                    nCurOffset = (int)binReader.BaseStream.Position;

                    int topicIdx = -1;
                    // if the topic offset is within the range of the stream
                    // and is >= the offset of the first topic dword
                    if ((topOffset < (binReader.BaseStream.Length - 4)) && (topOffset >= _offsetOftopics))
                    {
                        // read the index of the topic for this item
                        binReader.BaseStream.Seek(topOffset, SeekOrigin.Begin);
                        topicIdx = binReader.ReadInt32();
                        binReader.BaseStream.Seek(nCurOffset, SeekOrigin.Begin);


                        TOCItem item = (TOCItem)_offsetTable[tocOffset.ToString()];
                        if (item != null)
                        {
                            if ((topicIdx < _associatedFile.TopicsFile.TopicTable.Count) && (topicIdx >= 0))
                            {
                                TopicEntry te = (TopicEntry)(_associatedFile.TopicsFile.TopicTable[topicIdx]);
                                if ((te != null) && (item.TopicOffset < 0))
                                {
                                    item.TopicOffset = te.EntryOffset;
                                }
                            }
                        }
                    }
                }
            }

            return(bRet);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Recursively reads the binary toc tree from the file
        /// </summary>
        /// <param name="binReader">reference to binary reader</param>
        /// <param name="NodeOffset">offset of the first node in the current level</param>
        /// <param name="level">arraylist of TOCItems for the current level</param>
        /// <param name="parentItem">parent item for the item</param>
        /// <returns>Returns true if succeeded</returns>
        private bool RecursivelyBuildTree(ref BinaryReader binReader, int NodeOffset, ArrayList level, TOCItem parentItem)
        {
            bool bRet       = true;
            int  nextOffset = 0;

            int nReadOffset = (int)binReader.BaseStream.Position;

            binReader.BaseStream.Seek(NodeOffset, SeekOrigin.Begin);

            do
            {
                int nCurOffset = (int)binReader.BaseStream.Position;

                int unkn1 = binReader.ReadInt16();                 // unknown
                int unkn2 = binReader.ReadInt16();                 // unknown

                int flag = binReader.ReadInt32();

                int nFolderAdd = 0;

                if ((_associatedFile != null) && (_associatedFile.ImageTypeFolder))
                {
                    // get the value which should be added, to display folders instead of books
                    if (HtmlHelpSystem.UseHH2TreePics)
                    {
                        nFolderAdd = 8;
                    }
                    else
                    {
                        nFolderAdd = 4;
                    }
                }

                int nFolderImgIdx = (HtmlHelpSystem.UseHH2TreePics ? (TOCItem.STD_FOLDER_HH2 + nFolderAdd) : (TOCItem.STD_FOLDER_HH1 + nFolderAdd));
                int nFileImgIdx   = (HtmlHelpSystem.UseHH2TreePics ? TOCItem.STD_FILE_HH2 : TOCItem.STD_FILE_HH1);

                int stdImage = ((flag & 0x4) != 0) ? nFolderImgIdx : nFileImgIdx;

                int stringOffset = binReader.ReadInt32();

                int ParentOffset = binReader.ReadInt32();
                nextOffset = binReader.ReadInt32();

                int firstChildOffset = 0;
                int unkn3            = 0;

                if ((flag & 0x4) != 0)
                {
                    firstChildOffset = binReader.ReadInt32();
                    unkn3            = binReader.ReadInt32();          // unknown
                }

                TOCItem newItem = new TOCItem();
                newItem.ImageIndex     = stdImage;
                newItem.Offset         = nCurOffset;
                newItem.OffsetNext     = nextOffset;
                newItem.AssociatedFile = _associatedFile;
                newItem.TocMode        = DataMode.Binary;
                newItem.Parent         = parentItem;

                if ((flag & 0x08) == 0)
                {
                    // toc item doesn't have a local value (=> stringOffset = offset of strings file)
                    newItem.Name = _associatedFile.StringsFile[stringOffset];
                }
                else
                {
                    // this item has a topic entry (=> stringOffset = index of topic entry)
                    if ((stringOffset < _associatedFile.TopicsFile.TopicTable.Count) && (stringOffset >= 0))
                    {
                        TopicEntry te = (TopicEntry)(_associatedFile.TopicsFile.TopicTable[stringOffset]);
                        if (te != null)
                        {
                            newItem.TopicOffset = te.EntryOffset;
                        }
                    }
                }

                _offsetTable[nCurOffset.ToString()] = newItem;

                // if this item has children (firstChildOffset > 0)
                if (firstChildOffset > 0)
                {
                    bRet &= RecursivelyBuildTree(ref binReader, firstChildOffset, newItem.Children, newItem);
                }

                level.Add(newItem);

                if (nCurOffset != nextOffset)
                {
                    binReader.BaseStream.Seek(nextOffset, SeekOrigin.Begin);
                }
            }while(nextOffset != 0);

            binReader.BaseStream.Seek(nReadOffset, SeekOrigin.Begin);

            return(bRet);
        }