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