Merging r37048, r37051, r37052, r37055 from the-real-msvc branch
[reactos.git] / irc / TechBot / CHMLibrary / CHMDecoding / TopicEntry.cs
1 using System;
2 using System.IO;
3
4 namespace HtmlHelp.ChmDecoding
5 {
6 /// <summary>
7 /// The class <c>TopicEntry</c> stores the data for one topic entry
8 /// </summary>
9 internal sealed class TopicEntry
10 {
11 /// <summary>
12 /// Internal member storing the offset of this topic entry
13 /// </summary>
14 private int _entryOffset = 0;
15 /// <summary>
16 /// Internal member storing the index of the binary toc
17 /// </summary>
18 private int _tocidxOffset = 0;
19 /// <summary>
20 /// Internal member storing the string offset of the title
21 /// </summary>
22 private int _titleOffset = 0;
23 /// <summary>
24 /// Internal member storuing the urltable offset
25 /// </summary>
26 private int _urltableOffset = 0;
27 /// <summary>
28 /// Internal member storing the visibility mode
29 /// </summary>
30 private int _visibilityMode = 0;
31 /// <summary>
32 /// Internal member storing an unknown mode
33 /// </summary>
34 private int _unknownMode = 0;
35 /// <summary>
36 /// Internal member storing the associated chmfile object
37 /// </summary>
38 private CHMFile _associatedFile = null;
39
40 /// <summary>
41 /// Constructor of the class
42 /// </summary>
43 /// <param name="entryOffset">offset of this entry</param>
44 /// <param name="tocidxOffset">offset in the binary toc index</param>
45 /// <param name="titleOffset">offset of the title (in the #STRINGS file)</param>
46 /// <param name="urltableOffset">offset in the urltable containing the urlstr offset for the url</param>
47 /// <param name="visibilityMode">visibility mode 2 indicates not in contents, 6 indicates that it is in the contents, 0/4 something else (unknown)</param>
48 /// <param name="unknownMode">0, 2, 4, 8, 10, 12, 16, 32 (unknown)</param>
49 public TopicEntry(int entryOffset, int tocidxOffset, int titleOffset, int urltableOffset, int visibilityMode, int unknownMode) :this(entryOffset, tocidxOffset, titleOffset, urltableOffset, visibilityMode, unknownMode, null)
50 {
51
52 }
53
54 /// <summary>
55 /// Constructor of the class
56 /// </summary>
57 /// <param name="entryOffset">offset of this entry</param>
58 /// <param name="tocidxOffset">offset in the binary toc index</param>
59 /// <param name="titleOffset">offset of the title (in the #STRINGS file)</param>
60 /// <param name="urltableOffset">offset in the urltable containing the urlstr offset for the url</param>
61 /// <param name="visibilityMode">visibility mode 2 indicates not in contents, 6 indicates that it is in the contents, 0/4 something else (unknown)</param>
62 /// <param name="unknownMode">0, 2, 4, 8, 10, 12, 16, 32 (unknown)</param>
63 /// <param name="associatedFile">associated chmfile object</param>
64 internal TopicEntry(int entryOffset, int tocidxOffset, int titleOffset, int urltableOffset, int visibilityMode, int unknownMode, CHMFile associatedFile)
65 {
66 _entryOffset = entryOffset;
67 _tocidxOffset = tocidxOffset;
68 _titleOffset = titleOffset;
69 _urltableOffset = urltableOffset;
70 _visibilityMode = visibilityMode;
71 _unknownMode = unknownMode;
72 _associatedFile = associatedFile;
73 }
74
75 /// <summary>
76 /// Standard constructor
77 /// </summary>
78 internal TopicEntry()
79 {
80 }
81
82 #region Data dumping
83 /// <summary>
84 /// Dump the class data to a binary writer
85 /// </summary>
86 /// <param name="writer">writer to write the data</param>
87 internal void Dump(ref BinaryWriter writer)
88 {
89 writer.Write( _entryOffset );
90 writer.Write( _tocidxOffset );
91 writer.Write( _titleOffset );
92 writer.Write( _urltableOffset );
93 writer.Write( _visibilityMode );
94 writer.Write( _unknownMode );
95 }
96
97 /// <summary>
98 /// Reads the object data from a dump store
99 /// </summary>
100 /// <param name="reader">reader to read the data</param>
101 internal void ReadDump(ref BinaryReader reader)
102 {
103 _entryOffset = reader.ReadInt32();
104 _tocidxOffset = reader.ReadInt32();
105 _titleOffset = reader.ReadInt32();
106 _urltableOffset = reader.ReadInt32();
107 _visibilityMode = reader.ReadInt32();
108 _unknownMode = reader.ReadInt32();
109 }
110
111 /// <summary>
112 /// Sets the associated CHMFile instance
113 /// </summary>
114 /// <param name="associatedFile">instance to set</param>
115 internal void SetCHMFile(CHMFile associatedFile)
116 {
117 _associatedFile = associatedFile;
118 }
119 #endregion
120
121 /// <summary>
122 /// Gets the associated chm file
123 /// </summary>
124 internal CHMFile ChmFile
125 {
126 get { return _associatedFile; }
127 }
128
129 /// <summary>
130 /// Gets the offset of this entry
131 /// </summary>
132 internal int EntryOffset
133 {
134 get { return _entryOffset; }
135 }
136
137 /// <summary>
138 /// Gets the tocidx offset
139 /// </summary>
140 internal int TOCIdxOffset
141 {
142 get { return _tocidxOffset; }
143 }
144
145 /// <summary>
146 /// Gets the title offset of the #STRINGS file
147 /// </summary>
148 internal int TitleOffset
149 {
150 get { return _titleOffset; }
151 }
152
153 /// <summary>
154 /// Gets the urltable offset
155 /// </summary>
156 internal int UrlTableOffset
157 {
158 get { return _urltableOffset; }
159 }
160
161 /// <summary>
162 /// Gets the title of the topic entry
163 /// </summary>
164 public string Title
165 {
166 get
167 {
168 if( _associatedFile == null)
169 return String.Empty;
170
171 if( _associatedFile.StringsFile == null)
172 return String.Empty;
173
174 string sTemp = (string)_associatedFile.StringsFile[ _titleOffset ];
175
176 if(sTemp == null)
177 return String.Empty;
178
179 return sTemp;
180 }
181 }
182
183 /// <summary>
184 /// Gets the url of the topic
185 /// </summary>
186 public string Locale
187 {
188 get
189 {
190 if( _associatedFile == null)
191 return String.Empty;
192
193 if( _associatedFile.UrltblFile == null)
194 return String.Empty;
195
196 UrlTableEntry utEntry = (UrlTableEntry)_associatedFile.UrltblFile[ _urltableOffset ];
197
198 if(utEntry == null)
199 return String.Empty;
200
201 if(utEntry.URL == "")
202 return String.Empty;
203
204 return utEntry.URL;
205 }
206 }
207
208 /// <summary>
209 /// Gets the URL of this topic
210 /// </summary>
211 public string URL
212 {
213 get
214 {
215 if(Locale.Length <= 0)
216 return "about:blank";
217
218 if( (Locale.ToLower().IndexOf("http://") >= 0) ||
219 (Locale.ToLower().IndexOf("https://") >= 0) ||
220 (Locale.ToLower().IndexOf("mailto:") >= 0) ||
221 (Locale.ToLower().IndexOf("ftp://") >= 0) ||
222 (Locale.ToLower().IndexOf("ms-its:") >= 0))
223 return Locale;
224
225 return HtmlHelpSystem.UrlPrefix + _associatedFile.ChmFilePath + "::/" + Locale;
226 }
227 }
228
229 /// <summary>
230 /// Gets the visibility mode
231 /// </summary>
232 public int VisibilityMode
233 {
234 get { return _visibilityMode; }
235 }
236
237 /// <summary>
238 /// Gets the unknown mode
239 /// </summary>
240 public int UknownMode
241 {
242 get { return _unknownMode; }
243 }
244 }
245 }