Change remaining .xml build files to .rbuild and fixup links.
[reactos.git] / irc / TechBot / CHMLibrary / IndexTopic.cs
1 using System;
2 using System.IO;
3
4 using HtmlHelp.ChmDecoding;
5
6 namespace HtmlHelp
7 {
8 /// <summary>
9 /// The class <c>IndexTopic</c> implements an entry for the <see cref="IndexItem">IndexItem</see> topics list.
10 /// </summary>
11 public sealed class IndexTopic
12 {
13 private DataMode _topicMode = DataMode.TextBased;
14 private string _title="";
15 private string _local="";
16 private string _compileFile = "";
17 private string _chmPath = "";
18 private int _topicOffset = -1;
19 private CHMFile _associatedFile = null;
20
21 /// <summary>
22 /// Creates a new instance of the class based on an existing TopicEntry
23 /// </summary>
24 /// <param name="entry"></param>
25 internal static IndexTopic FromTopicEntry(TopicEntry entry)
26 {
27 return new IndexTopic(entry.EntryOffset, entry.ChmFile);
28 //return new IndexTopic( entry.Title, entry.Locale, entry.ChmFile.CompileFile, entry.ChmFile.ChmFilePath);
29 }
30
31 /// <summary>
32 /// Creates a new instance of the class (binary extraction mode)
33 /// </summary>
34 /// <param name="topicOffset">offset of the topic entry</param>
35 /// <param name="associatedFile">associated CHMFile instance</param>
36 internal IndexTopic(int topicOffset, CHMFile associatedFile)
37 {
38 _topicMode = DataMode.Binary;
39 _topicOffset = topicOffset;
40 _associatedFile = associatedFile;
41 }
42
43 /// <summary>
44 /// Constructor of the class
45 /// </summary>
46 /// <param name="Title">topic title</param>
47 /// <param name="local">topic local (content filename)</param>
48 /// <param name="compilefile">name of the chm file (location of topic)</param>
49 /// <param name="chmpath">path of the chm file</param>
50 public IndexTopic(string Title, string local, string compilefile, string chmpath)
51 {
52 _topicMode = DataMode.TextBased;
53 _title = Title;
54 _local = local;
55 _compileFile = compilefile;
56 _chmPath = chmpath;
57 }
58
59 #region Data dumping
60 /// <summary>
61 /// Dump the class data to a binary writer
62 /// </summary>
63 /// <param name="writer">writer to write the data</param>
64 internal void Dump(ref BinaryWriter writer)
65 {
66 writer.Write((int)_topicMode);
67
68 if(_topicMode==DataMode.TextBased)
69 {
70 writer.Write(_title);
71 writer.Write(_local);
72 }
73 else
74 {
75 writer.Write(_topicOffset);
76 }
77 }
78
79 /// <summary>
80 /// Reads the object data from a dump store
81 /// </summary>
82 /// <param name="reader">reader to read the data</param>
83 internal void ReadDump(ref BinaryReader reader)
84 {
85 _topicMode = (DataMode)reader.ReadInt32();
86
87 if(_topicMode==DataMode.TextBased)
88 {
89 _title = reader.ReadString();
90 _local = reader.ReadString();
91 }
92 else
93 {
94 _topicOffset = reader.ReadInt32();
95 }
96 }
97 #endregion
98
99 /// <summary>
100 /// Internally used to set the chm-finos when reading from dump store
101 /// </summary>
102 /// <param name="compilefile"></param>
103 /// <param name="chmpath"></param>
104 internal void SetChmInfo(string compilefile, string chmpath)
105 {
106 _compileFile = compilefile;
107 _chmPath = chmpath;
108 }
109
110 /// <summary>
111 /// Gets/Sets the associated CHMFile instance
112 /// </summary>
113 internal CHMFile AssociatedFile
114 {
115 get { return _associatedFile; }
116 set { _associatedFile = value; }
117 }
118
119 /// <summary>
120 /// Gets the topic title
121 /// </summary>
122 public string Title
123 {
124 get
125 {
126 if((_topicMode == DataMode.Binary )&&(_associatedFile!=null))
127 {
128 if( _topicOffset >= 0)
129 {
130 TopicEntry te = (TopicEntry) (_associatedFile.TopicsFile[_topicOffset]);
131 if(te != null)
132 {
133 return te.Title;
134 }
135 }
136 }
137
138 return _title;
139 }
140 }
141
142 /// <summary>
143 /// Gets the local (content filename)
144 /// </summary>
145 public string Local
146 {
147 get
148 {
149 if((_topicMode == DataMode.Binary )&&(_associatedFile!=null))
150 {
151 if( _topicOffset >= 0)
152 {
153 TopicEntry te = (TopicEntry) (_associatedFile.TopicsFile[_topicOffset]);
154 if(te != null)
155 {
156 return te.Locale;
157 }
158 }
159 }
160
161 return _local;
162 }
163 }
164
165 /// <summary>
166 /// Gets the compile file (location)
167 /// </summary>
168 public string CompileFile
169 {
170 get
171 {
172 if(_associatedFile != null)
173 return _associatedFile.CompileFile;
174
175 return _compileFile;
176 }
177 }
178
179 /// <summary>
180 /// Gets the chm file path
181 /// </summary>
182 public string ChmFilePath
183 {
184 get
185 {
186 if(_associatedFile != null)
187 return _associatedFile.ChmFilePath;
188
189 return _chmPath;
190 }
191 }
192
193 /// <summary>
194 /// Gets the url
195 /// </summary>
196 public string URL
197 {
198 get
199 {
200 string sL = Local;
201
202 if(sL.Length<=0)
203 return "";//"about:blank";
204
205 if( (sL.ToLower().IndexOf("http://") >= 0) ||
206 (sL.ToLower().IndexOf("https://") >= 0) ||
207 (sL.ToLower().IndexOf("mailto:") >= 0) ||
208 (sL.ToLower().IndexOf("ftp://") >= 0) ||
209 (sL.ToLower().IndexOf("ms-its:") >= 0))
210 return sL;
211
212 return HtmlHelpSystem.UrlPrefix + ChmFilePath + "::/" + sL;
213 }
214 }
215 }
216 }