using System; using System.IO; using HtmlHelp.ChmDecoding; namespace HtmlHelp { /// /// The class IndexTopic implements an entry for the IndexItem topics list. /// public sealed class IndexTopic { private DataMode _topicMode = DataMode.TextBased; private string _title=""; private string _local=""; private string _compileFile = ""; private string _chmPath = ""; private int _topicOffset = -1; private CHMFile _associatedFile = null; /// /// Creates a new instance of the class based on an existing TopicEntry /// /// internal static IndexTopic FromTopicEntry(TopicEntry entry) { return new IndexTopic(entry.EntryOffset, entry.ChmFile); //return new IndexTopic( entry.Title, entry.Locale, entry.ChmFile.CompileFile, entry.ChmFile.ChmFilePath); } /// /// Creates a new instance of the class (binary extraction mode) /// /// offset of the topic entry /// associated CHMFile instance internal IndexTopic(int topicOffset, CHMFile associatedFile) { _topicMode = DataMode.Binary; _topicOffset = topicOffset; _associatedFile = associatedFile; } /// /// Constructor of the class /// /// topic title /// topic local (content filename) /// name of the chm file (location of topic) /// path of the chm file public IndexTopic(string Title, string local, string compilefile, string chmpath) { _topicMode = DataMode.TextBased; _title = Title; _local = local; _compileFile = compilefile; _chmPath = chmpath; } #region Data dumping /// /// Dump the class data to a binary writer /// /// writer to write the data internal void Dump(ref BinaryWriter writer) { writer.Write((int)_topicMode); if(_topicMode==DataMode.TextBased) { writer.Write(_title); writer.Write(_local); } else { writer.Write(_topicOffset); } } /// /// Reads the object data from a dump store /// /// reader to read the data internal void ReadDump(ref BinaryReader reader) { _topicMode = (DataMode)reader.ReadInt32(); if(_topicMode==DataMode.TextBased) { _title = reader.ReadString(); _local = reader.ReadString(); } else { _topicOffset = reader.ReadInt32(); } } #endregion /// /// Internally used to set the chm-finos when reading from dump store /// /// /// internal void SetChmInfo(string compilefile, string chmpath) { _compileFile = compilefile; _chmPath = chmpath; } /// /// Gets/Sets the associated CHMFile instance /// internal CHMFile AssociatedFile { get { return _associatedFile; } set { _associatedFile = value; } } /// /// Gets the topic title /// public string Title { get { if((_topicMode == DataMode.Binary )&&(_associatedFile!=null)) { if( _topicOffset >= 0) { TopicEntry te = (TopicEntry) (_associatedFile.TopicsFile[_topicOffset]); if(te != null) { return te.Title; } } } return _title; } } /// /// Gets the local (content filename) /// public string Local { get { if((_topicMode == DataMode.Binary )&&(_associatedFile!=null)) { if( _topicOffset >= 0) { TopicEntry te = (TopicEntry) (_associatedFile.TopicsFile[_topicOffset]); if(te != null) { return te.Locale; } } } return _local; } } /// /// Gets the compile file (location) /// public string CompileFile { get { if(_associatedFile != null) return _associatedFile.CompileFile; return _compileFile; } } /// /// Gets the chm file path /// public string ChmFilePath { get { if(_associatedFile != null) return _associatedFile.ChmFilePath; return _chmPath; } } /// /// Gets the url /// public string URL { get { string sL = Local; if(sL.Length<=0) return "";//"about:blank"; if( (sL.ToLower().IndexOf("http://") >= 0) || (sL.ToLower().IndexOf("https://") >= 0) || (sL.ToLower().IndexOf("mailto:") >= 0) || (sL.ToLower().IndexOf("ftp://") >= 0) || (sL.ToLower().IndexOf("ms-its:") >= 0)) return sL; return HtmlHelpSystem.UrlPrefix + ChmFilePath + "::/" + sL; } } } }