using System; using System.IO; namespace HtmlHelp.ChmDecoding { /// /// The class TopicEntry stores the data for one topic entry /// internal sealed class TopicEntry { /// /// Internal member storing the offset of this topic entry /// private int _entryOffset = 0; /// /// Internal member storing the index of the binary toc /// private int _tocidxOffset = 0; /// /// Internal member storing the string offset of the title /// private int _titleOffset = 0; /// /// Internal member storuing the urltable offset /// private int _urltableOffset = 0; /// /// Internal member storing the visibility mode /// private int _visibilityMode = 0; /// /// Internal member storing an unknown mode /// private int _unknownMode = 0; /// /// Internal member storing the associated chmfile object /// private CHMFile _associatedFile = null; /// /// Constructor of the class /// /// offset of this entry /// offset in the binary toc index /// offset of the title (in the #STRINGS file) /// offset in the urltable containing the urlstr offset for the url /// visibility mode 2 indicates not in contents, 6 indicates that it is in the contents, 0/4 something else (unknown) /// 0, 2, 4, 8, 10, 12, 16, 32 (unknown) public TopicEntry(int entryOffset, int tocidxOffset, int titleOffset, int urltableOffset, int visibilityMode, int unknownMode) :this(entryOffset, tocidxOffset, titleOffset, urltableOffset, visibilityMode, unknownMode, null) { } /// /// Constructor of the class /// /// offset of this entry /// offset in the binary toc index /// offset of the title (in the #STRINGS file) /// offset in the urltable containing the urlstr offset for the url /// visibility mode 2 indicates not in contents, 6 indicates that it is in the contents, 0/4 something else (unknown) /// 0, 2, 4, 8, 10, 12, 16, 32 (unknown) /// associated chmfile object internal TopicEntry(int entryOffset, int tocidxOffset, int titleOffset, int urltableOffset, int visibilityMode, int unknownMode, CHMFile associatedFile) { _entryOffset = entryOffset; _tocidxOffset = tocidxOffset; _titleOffset = titleOffset; _urltableOffset = urltableOffset; _visibilityMode = visibilityMode; _unknownMode = unknownMode; _associatedFile = associatedFile; } /// /// Standard constructor /// internal TopicEntry() { } #region Data dumping /// /// Dump the class data to a binary writer /// /// writer to write the data internal void Dump(ref BinaryWriter writer) { writer.Write( _entryOffset ); writer.Write( _tocidxOffset ); writer.Write( _titleOffset ); writer.Write( _urltableOffset ); writer.Write( _visibilityMode ); writer.Write( _unknownMode ); } /// /// Reads the object data from a dump store /// /// reader to read the data internal void ReadDump(ref BinaryReader reader) { _entryOffset = reader.ReadInt32(); _tocidxOffset = reader.ReadInt32(); _titleOffset = reader.ReadInt32(); _urltableOffset = reader.ReadInt32(); _visibilityMode = reader.ReadInt32(); _unknownMode = reader.ReadInt32(); } /// /// Sets the associated CHMFile instance /// /// instance to set internal void SetCHMFile(CHMFile associatedFile) { _associatedFile = associatedFile; } #endregion /// /// Gets the associated chm file /// internal CHMFile ChmFile { get { return _associatedFile; } } /// /// Gets the offset of this entry /// internal int EntryOffset { get { return _entryOffset; } } /// /// Gets the tocidx offset /// internal int TOCIdxOffset { get { return _tocidxOffset; } } /// /// Gets the title offset of the #STRINGS file /// internal int TitleOffset { get { return _titleOffset; } } /// /// Gets the urltable offset /// internal int UrlTableOffset { get { return _urltableOffset; } } /// /// Gets the title of the topic entry /// public string Title { get { if( _associatedFile == null) return String.Empty; if( _associatedFile.StringsFile == null) return String.Empty; string sTemp = (string)_associatedFile.StringsFile[ _titleOffset ]; if(sTemp == null) return String.Empty; return sTemp; } } /// /// Gets the url of the topic /// public string Locale { get { if( _associatedFile == null) return String.Empty; if( _associatedFile.UrltblFile == null) return String.Empty; UrlTableEntry utEntry = (UrlTableEntry)_associatedFile.UrltblFile[ _urltableOffset ]; if(utEntry == null) return String.Empty; if(utEntry.URL == "") return String.Empty; return utEntry.URL; } } /// /// Gets the URL of this topic /// public string URL { get { if(Locale.Length <= 0) return "about:blank"; if( (Locale.ToLower().IndexOf("http://") >= 0) || (Locale.ToLower().IndexOf("https://") >= 0) || (Locale.ToLower().IndexOf("mailto:") >= 0) || (Locale.ToLower().IndexOf("ftp://") >= 0) || (Locale.ToLower().IndexOf("ms-its:") >= 0)) return Locale; return HtmlHelpSystem.UrlPrefix + _associatedFile.ChmFilePath + "::/" + Locale; } } /// /// Gets the visibility mode /// public int VisibilityMode { get { return _visibilityMode; } } /// /// Gets the unknown mode /// public int UknownMode { get { return _unknownMode; } } } }