+++ /dev/null
-using System;\r
-using System.Diagnostics;\r
-using System.Collections;\r
-using System.Collections.Specialized;\r
-using System.IO;\r
-using System.Text;\r
-using System.Runtime.InteropServices;\r
-using System.Globalization;\r
-// using HtmlHelp.Storage;\r
-\r
-namespace HtmlHelp.ChmDecoding\r
-{\r
- /// <summary>\r
- /// Internal enumeration for specifying the type of the html-help file\r
- /// </summary>\r
- internal enum HtmlHelpFileType\r
- {\r
- /// <summary>\r
- /// CHM - compiled contents file\r
- /// </summary>\r
- /// <remarks>A file with this extension must always exist. If the file would be too long, some parts \r
- /// can be splitted into the filestypes below.</remarks>\r
- CHM = 0,\r
- /// <summary>\r
- /// CHI - compiled system file\r
- /// </summary>\r
- CHI = 1,\r
- /// <summary>\r
- /// CHQ - compiled fulltext search file\r
- /// </summary>\r
- CHQ = 2,\r
- /// <summary>\r
- /// CHW - compiled index file\r
- /// </summary>\r
- CHW = 3\r
-\r
- }\r
-\r
- /// <summary>\r
- /// The class <c>CHMFile</c> implemts methods and properties for handling a single chmfile.\r
- /// </summary>\r
- public sealed class CHMFile : IDisposable\r
- {\r
- /// <summary>\r
- /// Internal member storing a reference to the hosting HtmlHelpSystem instance\r
- /// </summary>\r
- private HtmlHelpSystem _systemInstance = null;\r
- /// <summary>\r
- /// Internal flag specifying if only system data has been loaded\r
- /// </summary>\r
- private bool _onlySystem = false;\r
- /// <summary>\r
- /// Internal flag specifying if the object is going to be disposed\r
- /// </summary>\r
- private bool disposed = false;\r
- /// <summary>\r
- /// Internal arraylist containing the table of contents\r
- /// </summary>\r
- private ArrayList _toc = new ArrayList();\r
- /// <summary>\r
- /// Internal arraylist containing items of the toc which are merge-Links\r
- /// </summary>\r
- private ArrayList _mergeLinks = new ArrayList();\r
- /// <summary>\r
- /// Internal member storing the read information types\r
- /// </summary>\r
- private ArrayList _informationTypes = new ArrayList();\r
- /// <summary>\r
- /// Internal member storing the read categories\r
- /// </summary>\r
- private ArrayList _categories = new ArrayList();\r
- /// <summary>\r
- /// Internal arraylist containing the index (klinks)\r
- /// </summary>\r
- private ArrayList _indexKLinks = new ArrayList();\r
- /// <summary>\r
- /// Internal arraylist containing the index (alinks)\r
- /// </summary>\r
- private ArrayList _indexALinks = new ArrayList();\r
- /// <summary>\r
- /// Internal member storing the full filename\r
- /// </summary>\r
- private string _chmFileName = "";\r
- /// <summary>\r
- /// Internal member storing the full filename of the chi-file (includes all system files)\r
- /// The file name is zero-length if there is no chi-file\r
- /// </summary>\r
- private string _chiFileName = "";\r
- /// <summary>\r
- /// Internal member storing the full filename of the chw-file (includes the help index)\r
- /// The file name is zero-length if there is no chw-file\r
- /// </summary>\r
- private string _chwFileName = "";\r
- /// <summary>\r
- /// Internal member storing the full filename of the chq-file (includes the fulltext contents)\r
- /// The file name is zero-length if there is no chq-file\r
- /// </summary>\r
- private string _chqFileName = "";\r
- /// <summary>\r
- /// Internal member storing the decoded information from the internal #SYSTEM file\r
- /// </summary>\r
- private CHMSystem _systemFile = null;\r
- /// <summary>\r
- /// Internal member storing the decoded information from the internal #IDXHDR file\r
- /// </summary>\r
- private CHMIdxhdr _idxhdrFile = null;\r
- /// <summary>\r
- /// Internal member storing the decoded information from the internal #STRINGS file\r
- /// </summary>\r
- private CHMStrings _stringsFile = null;\r
- /// <summary>\r
- /// Internal member storing the decoded information from the internal #URLSTR file\r
- /// </summary>\r
- private CHMUrlstr _urlstrFile = null;\r
- /// <summary>\r
- /// Internal member storing the decoded information from the internal #URLTBL file\r
- /// </summary>\r
- private CHMUrltable _urltblFile = null;\r
- /// <summary>\r
- /// Internal member storing the decoded information from the internal #TOPICS file\r
- /// </summary>\r
- private CHMTopics _topicsFile = null;\r
- /// <summary>\r
- /// Internal member storing the decoded information from the internal #TOCIDX file\r
- /// </summary>\r
- private CHMTocidx _tocidxFile = null;\r
- /// <summary>\r
- /// Internal member storing the decoded information from the internal binary index file (KLinks).\r
- /// </summary>\r
- private CHMBtree _kLinks = null;\r
- /// <summary>\r
- /// Internal member storing the decoded information from the internal binary index file (ALinks).\r
- /// </summary>\r
- private CHMBtree _aLinks = null;\r
- /// <summary>\r
- /// Internal member storing the fulltext searcher for this file\r
- /// </summary>\r
- private FullTextEngine _ftSearcher = null;\r
- /// <summary>\r
- /// Internal member storing the default encoder\r
- /// </summary>\r
- private Encoding _textEncoding = Encoding.GetEncoding(1252); // standard windows-1252 encoder\r
- /// <summary>\r
- /// Internal memebr storing the chm file info\r
- /// </summary>\r
- private ChmFileInfo _chmFileInfo = null;\r
- /// <summary>\r
- /// Internal flag specifying if the dump must be written (if enabled)\r
- /// </summary>\r
- private bool _mustWriteDump = false;\r
- /// <summary>\r
- /// Internal flag specifying if data was read using the dump\r
- /// </summary>\r
- private bool _dumpRead = false;\r
- /// <summary>\r
- /// Internal member for specifying the number of dump-reading trys.\r
- /// If dump-reading fails, this is used that it will not be opened a second time\r
- /// (in CHM-Systems with CHM, CHI, etc. files)\r
- /// </summary>\r
- private int _dumpReadTrys = 0;\r
- /// <summary>\r
- /// Internal member storing the dumping info instance\r
- /// </summary>\r
- private DumpingInfo _dmpInfo = null;\r
-\r
- private CHMStream.CHMStream _currentWrapper;\r
- private CHMStream.CHMStream _baseStream=null;\r
- public CHMStream.CHMStream BaseStream\r
- {\r
- get \r
- { \r
- if (_baseStream==null)\r
- _baseStream=new CHMStream.CHMStream(this.ChmFilePath);\r
- return _baseStream; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Creates a new instance of the class\r
- /// </summary>\r
- /// <param name="systemInstance">a reference to the hosting HtmlHelpSystem instance</param>\r
- /// <param name="chmFile">chm file to read</param>\r
- public CHMFile(HtmlHelpSystem systemInstance, string chmFile) : this(systemInstance, chmFile, false, null)\r
- {\r
- }\r
-\r
- /// <summary>\r
- /// Creates a new instance of the class\r
- /// </summary>\r
- /// <param name="systemInstance">a reference to the hosting HtmlHelpSystem instance</param>\r
- /// <param name="chmFile">chm file to read</param>\r
- /// <param name="dmpInfo">A dumping info class</param>\r
- public CHMFile(HtmlHelpSystem systemInstance, string chmFile, DumpingInfo dmpInfo) : this(systemInstance, chmFile, false, dmpInfo)\r
- {\r
- }\r
-\r
- /// <summary>\r
- /// Creates a new instance of the class\r
- /// </summary>\r
- /// <param name="systemInstance">a reference to the hosting HtmlHelpSystem instance</param>\r
- /// <param name="chmFile">chm file to read</param>\r
- /// <param name="onlySystemData">true if only system data should be extracted (no index or toc)</param>\r
- internal CHMFile(HtmlHelpSystem systemInstance, string chmFile, bool onlySystemData) : this(systemInstance, chmFile, onlySystemData, null)\r
- {\r
- }\r
-\r
- /// <summary>\r
- /// Creates a new instance of the class\r
- /// </summary>\r
- /// <param name="systemInstance">a reference to the hosting HtmlHelpSystem instance</param>\r
- /// <param name="chmFile">chm file to read</param>\r
- /// <param name="onlySystemData">true if only system data should be extracted (no index or toc)</param>\r
- /// <param name="dmpInfo">A dumping info class</param>\r
- internal CHMFile(HtmlHelpSystem systemInstance, string chmFile, bool onlySystemData, DumpingInfo dmpInfo)\r
- {\r
- _systemInstance = systemInstance;\r
- _dumpReadTrys=0;\r
-\r
- _dmpInfo = dmpInfo;\r
- if(dmpInfo != null)\r
- {\r
- dmpInfo.ChmFile = this;\r
- }\r
-\r
- if( ! chmFile.ToLower().EndsWith(".chm") )\r
- {\r
- throw new ArgumentException("HtmlHelp file must have the extension .chm !", "chmFile");\r
- }\r
-\r
- _chmFileName = chmFile;\r
- _chiFileName = "";\r
-\r
- // Read the IStorage file system\r
- if( File.Exists(chmFile) )\r
- {\r
- _onlySystem = onlySystemData;\r
- \r
- DateTime dtStartHH = DateTime.Now;\r
-\r
- string sCHIName = _chmFileName.Substring(0, _chmFileName.Length-3) + "chi";\r
- string sCHQName = _chmFileName.Substring(0, _chmFileName.Length-3) + "chq";\r
- string sCHWName = _chmFileName.Substring(0, _chmFileName.Length-3) + "chw";\r
-\r
- // If there is a CHI file present (this file includes the internal system files for the current chm file)\r
- if( File.Exists(sCHIName) )\r
- {\r
- _chiFileName = sCHIName;\r
- \r
- ReadFile(_chiFileName, HtmlHelpFileType.CHI);\r
- }\r
-\r
- // If there is a CHW file present (this file includes the internal binary index of the help)\r
- if(( File.Exists(sCHWName) ) && (!_onlySystem) )\r
- {\r
- _chwFileName = sCHWName;\r
- \r
- ReadFile(_chwFileName, HtmlHelpFileType.CHW);\r
- }\r
-\r
- // If there is a CHQ file present (this file includes the fulltext-search data)\r
- if(( File.Exists(sCHQName) ) && (!_onlySystem) )\r
- {\r
- _chqFileName = sCHQName;\r
- \r
- ReadFile(_chqFileName, HtmlHelpFileType.CHQ);\r
- }\r
-\r
- ReadFile(chmFile, HtmlHelpFileType.CHM);\r
-\r
- if(_mustWriteDump)\r
- { \r
- _mustWriteDump = !SaveDump(dmpInfo);\r
-\r
- }\r
-\r
- // check the default-topic setting\r
- if(_systemFile.DefaultTopic.Length > 0)\r
- {\r
- CHMStream.CHMStream iw=null;\r
- iw = new CHMStream.CHMStream(chmFile);\r
- _currentWrapper=iw;\r
-\r
- // tryo to open the topic file\r
- MemoryStream fileObject = iw.OpenStream( _systemFile.DefaultTopic);\r
- if( fileObject != null)\r
- {\r
- // if succeed, the topic default topic is OK\r
- fileObject.Close();\r
- } \r
- else \r
- {\r
- // set the first topic of the toc-tree as default topic\r
- if(_toc.Count > 0)\r
- {\r
- _systemFile.SetDefaultTopic( ((TOCItem) _toc[0]).Local );\r
- }\r
- }\r
- _currentWrapper=null;\r
- } \r
- else \r
- {\r
- // set the first topic of the toc-tree as default topic\r
- if(_toc.Count > 0)\r
- {\r
- _systemFile.SetDefaultTopic( ((TOCItem) _toc[0]).Local );\r
- }\r
- }\r
-\r
- _chmFileInfo = new ChmFileInfo(this);\r
- } \r
- else \r
- {\r
- throw new ArgumentException("File '" + chmFile + "' not found !", "chmFile");\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Read a IStorage file\r
- /// </summary>\r
- /// <param name="fname">filename</param>\r
- /// <param name="type">type of file</param>\r
- private void ReadFile(string fname, HtmlHelpFileType type)\r
- {\r
- CHMStream.CHMStream iw=null;\r
- iw=new CHMStream.CHMStream(); \r
- iw.OpenCHM(fname);\r
- _currentWrapper=iw;\r
- MemoryStream fileObject=null; \r
-\r
- // ITStorageWrapper iw = null;\r
-\r
- // Open the internal chm system files and parse their content\r
- // FileObject fileObject = null;\r
- // iw = new ITStorageWrapper(fname, false); \r
-\r
- if( (type != HtmlHelpFileType.CHQ) && (type != HtmlHelpFileType.CHW) )\r
- { \r
- fileObject = iw.OpenStream("#SYSTEM");\r
- if ((fileObject != null) && (fileObject.Length>0))\r
- _systemFile = new CHMSystem(fileObject.ToArray(), this); \r
-\r
- fileObject = iw.OpenStream("#IDXHDR");\r
- if ((fileObject != null) && (fileObject.Length>0))\r
- _idxhdrFile = new CHMIdxhdr(fileObject.ToArray(), this); \r
- \r
- // try to read Dump\r
- if((!_dumpRead)&&(CheckDump(_dmpInfo))&&(_dumpReadTrys==0))\r
- {\r
- _dumpReadTrys++;\r
- _dumpRead = LoadDump(_dmpInfo); \r
- }\r
-\r
- if( (!_dumpRead)||(!_dmpInfo.DumpStrings) )\r
- {\r
- fileObject = iw.OpenStream( "#STRINGS");\r
- if ((fileObject != null) && (fileObject.Length>0))\r
- _stringsFile = new CHMStrings(fileObject.ToArray(), this);\r
- }\r
-\r
- if( (!_dumpRead)||(!_dmpInfo.DumpUrlStr) )\r
- {\r
- fileObject = iw.OpenStream( "#URLSTR");\r
- if ((fileObject != null) && (fileObject.Length>0))\r
- _urlstrFile = new CHMUrlstr(fileObject.ToArray(), this);\r
- }\r
-\r
- if( (!_dumpRead)||(!_dmpInfo.DumpUrlTbl) )\r
- {\r
- fileObject = iw.OpenStream( "#URLTBL");\r
- if ((fileObject != null) && (fileObject.Length>0))\r
- _urltblFile = new CHMUrltable(fileObject.ToArray(), this);\r
- }\r
-\r
- if( (!_dumpRead)||(!_dmpInfo.DumpTopics) )\r
- {\r
- fileObject = iw.OpenStream( "#TOPICS");\r
- if ((fileObject != null) && (fileObject.Length>0))\r
- _topicsFile = new CHMTopics(fileObject.ToArray(), this);\r
- }\r
-\r
- if(!_onlySystem)\r
- {\r
- if( (!_dumpRead)||(!_dmpInfo.DumpBinaryTOC) )\r
- {\r
- fileObject = iw.OpenStream( "#TOCIDX");\r
- if( (fileObject != null) && (fileObject.Length>0) && (_systemFile.BinaryTOC) )\r
- {\r
- _tocidxFile = new CHMTocidx(fileObject.ToArray(), this);\r
- _toc = _tocidxFile.TOC; \r
- }\r
- }\r
- }\r
-\r
- if( (_systemFile != null) && (!_onlySystem) )\r
- {\r
- if(!_systemFile.BinaryTOC)\r
- {\r
- if( (!_dumpRead)||(!_dmpInfo.DumpTextTOC) )\r
- {\r
- CHMStream.chmUnitInfo HHCInfo=iw.GetFileInfoByExtension(".hhc");\r
- if (HHCInfo!=null)\r
- {\r
- fileObject = iw.OpenStream(HHCInfo); \r
- if ((fileObject != null) && (fileObject.Length>0))\r
- {\r
- ASCIIEncoding ascii=new ASCIIEncoding(); \r
- string fileString =ascii.GetString(fileObject.ToArray(),0,(int)fileObject.Length);\r
-\r
- _toc = HHCParser.ParseHHC(fileString, this);\r
- }\r
-\r
- if(HHCParser.HasMergeLinks)\r
- _mergeLinks = HHCParser.MergeItems;\r
- } \r
- }\r
- } \r
- }\r
- }\r
-\r
- if( type != HtmlHelpFileType.CHQ ) // no index information in CHQ files (only fulltext search)\r
- {\r
- if( (_systemFile != null) && (!_onlySystem) )\r
- {\r
- if( ! _systemFile.BinaryIndex )\r
- {\r
- if( (!_dumpRead)||(!_dmpInfo.DumpTextIndex) )\r
- {\r
- fileObject = iw.OpenStream( _systemFile.IndexFile);\r
- if ((fileObject != null) && (fileObject.Length>0))\r
- {\r
-\r
- string fileString = this.TextEncoding.GetString(fileObject.ToArray(),0,(int)fileObject.Length);\r
- // string fileString = fileObject.ReadFromFile(this.TextEncoding);\r
- fileObject.Close();\r
-\r
- _indexKLinks = HHKParser.ParseHHK(fileString, this);\r
- _indexKLinks.Sort();\r
- }\r
- }\r
- } \r
- else \r
- {\r
- if( (!_dumpRead)||(!_dmpInfo.DumpBinaryIndex) )\r
- {\r
- fileObject=iw.OpenStream(@"$WWKeywordLinks\BTree");\r
- if ((fileObject != null) && (fileObject.Length>0))\r
- {\r
- _kLinks = new CHMBtree(fileObject.ToArray(), this);\r
- _indexKLinks = _kLinks.IndexList;\r
- }\r
-\r
- fileObject =iw.OpenStream(@"$WWAssociativeLinks\BTree");\r
- if ((fileObject != null) && (fileObject.Length>0))\r
- { \r
- _aLinks = new CHMBtree(fileObject.ToArray(), this);\r
- _indexALinks = _aLinks.IndexList;\r
- _indexALinks.Sort(); \r
- } \r
- }\r
- }\r
- }\r
- }\r
-\r
- if( (type != HtmlHelpFileType.CHI) && (type != HtmlHelpFileType.CHW) )\r
- {\r
- if( (_systemFile != null) && (!_onlySystem) )\r
- {\r
- if( _systemFile.FullTextSearch)\r
- {\r
- if( (!_dumpRead)||(!_dmpInfo.DumpFullText) )\r
- {\r
- fileObject = iw.OpenStream("$FIftiMain");\r
- if(( fileObject != null) && (fileObject .Length>0))\r
- _ftSearcher = new FullTextEngine(fileObject .ToArray(), this); \r
- }\r
- }\r
- }\r
- }\r
- _currentWrapper=null;\r
- }\r
-\r
- /// <summary>\r
- /// Enumerates the files in the chm storage and gets all files matching a given extension.\r
- /// </summary>\r
- /// <param name="extension">extension to return</param>\r
- /// <returns>Returns an arraylist of filenames or null if nothing found</returns>\r
- /// <remarks>On large CHMs, enumerations are very slow. Only use it if necessary !</remarks>\r
- internal ArrayList EnumFilesByExtension(string extension)\r
- {\r
- ArrayList arrRet = new ArrayList();\r
-\r
- CHMStream.CHMStream iw = null;\r
- if(_currentWrapper == null)\r
- iw = new CHMStream.CHMStream(_chmFileName);\r
- else\r
- iw = _currentWrapper;\r
-\r
- arrRet=iw.GetFileListByExtenstion(extension);\r
- \r
- if(arrRet.Count > 0)\r
- return arrRet;\r
-\r
- return null;\r
- }\r
-\r
- /// <summary>\r
- /// Searches an TOC entry using the local\r
- /// </summary>\r
- /// <param name="local">local to search</param>\r
- /// <returns>Returns the TOC item</returns>\r
- internal TOCItem GetTOCItemByLocal(string local)\r
- {\r
- return GetTOCItemByLocal(this.TOC, local);\r
- }\r
-\r
- /// <summary>\r
- /// Recursively searches an TOC entry using its local\r
- /// </summary>\r
- /// <param name="arrTOC">toc level list</param>\r
- /// <param name="local">local to search</param>\r
- /// <returns>Returns the TOC item</returns>\r
- private TOCItem GetTOCItemByLocal(ArrayList arrTOC, string local)\r
- {\r
- TOCItem ret = null;\r
- foreach(TOCItem curItem in arrTOC)\r
- {\r
- string scL = curItem.Local.ToLower();\r
- string sL = local.ToLower();\r
-\r
- while(scL[0]=='/') // delete prefixing '/'\r
- scL = scL.Substring(1);\r
-\r
- while(sL[0]=='/') // delete prefixing '/'\r
- sL = sL.Substring(1);\r
-\r
- if(scL == sL)\r
- return curItem;\r
-\r
- if(curItem.Children.Count > 0)\r
- {\r
- ret = GetTOCItemByLocal(curItem.Children, local);\r
- if(ret != null)\r
- return ret;\r
- }\r
- }\r
-\r
- return ret;\r
- }\r
-\r
- /// <summary>\r
- /// Removes a TOCItem from the toc\r
- /// </summary>\r
- /// <param name="rem">item to remove</param>\r
- /// <returns>Returns true if removed</returns>\r
- internal bool RemoveTOCItem(TOCItem rem)\r
- {\r
- if(rem == null)\r
- return false;\r
-\r
- return RemoveTOCItem(this.TOC, rem);\r
- }\r
-\r
- /// <summary>\r
- /// Recursively searches a TOCItem and removes it if found\r
- /// </summary>\r
- /// <param name="arrTOC">toc level list</param>\r
- /// <param name="rem">item to remove</param>\r
- /// <returns>Returns true if removed</returns>\r
- private bool RemoveTOCItem(ArrayList arrTOC, TOCItem rem)\r
- {\r
- for(int i=0; i<arrTOC.Count;i++)\r
- {\r
- TOCItem curItem = arrTOC[i] as TOCItem;\r
-\r
- if(curItem == rem)\r
- {\r
- arrTOC.RemoveAt(i);\r
- return true;\r
- }\r
-\r
- if(curItem.Children.Count > 0)\r
- {\r
- bool bRem = RemoveTOCItem(curItem.Children, rem);\r
- if(bRem)\r
- return true;\r
- }\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /// <summary>\r
- /// Returns true if the HtmlHelpSystem instance contains 1 or more information types\r
- /// </summary>\r
- public bool HasInformationTypes\r
- {\r
- get { return (_informationTypes.Count>0); }\r
- }\r
-\r
- /// <summary>\r
- /// Returns true if the HtmlHelpSystem instance contains 1 or more categories\r
- /// </summary>\r
- public bool HasCategories\r
- {\r
- get { return (_categories.Count>0); }\r
- }\r
-\r
- /// <summary>\r
- /// Gets an ArrayList of <see cref="InformationType">InformationType</see> items\r
- /// </summary>\r
- public ArrayList InformationTypes\r
- {\r
- get { return _informationTypes; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets an ArrayList of <see cref="Category">Category</see> items\r
- /// </summary>\r
- public ArrayList Categories\r
- {\r
- get { return _categories; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the information type specified by its name\r
- /// </summary>\r
- /// <param name="name">name of the information type to receive</param>\r
- /// <returns>Returns the Instance for the name or null if not found</returns>\r
- public InformationType GetInformationType(string name)\r
- {\r
- if(HasInformationTypes)\r
- {\r
- for(int i=0; i<_informationTypes.Count;i++)\r
- {\r
- InformationType iT = _informationTypes[i] as InformationType;\r
-\r
- if(iT.Name == name)\r
- return iT;\r
- }\r
- }\r
-\r
- return null;\r
- }\r
-\r
- /// <summary>\r
- /// Gets the category specifiyd by its name\r
- /// </summary>\r
- /// <param name="name">name of the category</param>\r
- /// <returns>Returns the Instance for the name or null if not found</returns>\r
- public Category GetCategory(string name)\r
- {\r
- if(HasCategories)\r
- {\r
- for(int i=0; i<_categories.Count;i++)\r
- {\r
- Category cat = _categories[i] as Category;\r
-\r
- if(cat.Name == name)\r
- return cat;\r
- }\r
- }\r
-\r
- return null;\r
- }\r
-\r
- #region Dumping methods\r
- \r
- /// <summary>\r
- /// Checks if a dump for this file exists and if it can be read\r
- /// </summary>\r
- /// <param name="dmpInfo">dumping info class</param>\r
- /// <returns>true if it can be read</returns>\r
- private bool CheckDump(DumpingInfo dmpInfo)\r
- {\r
- if(_dumpReadTrys<=0)\r
- _mustWriteDump = false;\r
-\r
- if(_onlySystem)\r
- return false;\r
-\r
- if( dmpInfo != null )\r
- {\r
- if(_dumpReadTrys > 0)\r
- return _mustWriteDump;\r
-\r
- _mustWriteDump = !dmpInfo.DumpExists;\r
- return !_mustWriteDump;\r
- }\r
-\r
- return false;\r
- }\r
-\r
- /// <summary>\r
- /// Saves the the toc and index into a data dump\r
- /// </summary>\r
- /// <param name="dmpInfo">dumping info</param>\r
- /// <returns>true if succeed</returns>\r
- private bool SaveDump(DumpingInfo dmpInfo)\r
- {\r
- if(dmpInfo == null)\r
- return false;\r
-\r
- bool bRet = false;\r
-\r
-\r
- BinaryWriter writer = dmpInfo.Writer;\r
-\r
- int nCnt = 0;\r
- try\r
- {\r
- Debug.WriteLine("writing dump-file header");\r
- FileInfo fi = new FileInfo(_chmFileName);\r
- string ftime = fi.LastWriteTime.ToString("dd.MM.yyyy HH:mm:ss.ffffff");\r
-\r
- writer.Write("HtmlHelpSystem dump file 1.0");\r
- writer.Write(ftime);\r
- writer.Write(_textEncoding.CodePage);\r
-\r
- // strings dumping\r
- if(dmpInfo.DumpStrings)\r
- {\r
- writer.Write(true); // data should be in dump\r
-\r
- if(_stringsFile==null)\r
- {\r
- writer.Write(false); // data not supported by the chm\r
- } \r
- else \r
- {\r
- Debug.WriteLine("writing #STRINGS");\r
- writer.Write(true); // data supported and following\r
- _stringsFile.Dump(ref writer);\r
- }\r
- } \r
- else \r
- {\r
- writer.Write(false); // data is not in dump\r
- }\r
-\r
- // urlstr dumping\r
- if(dmpInfo.DumpUrlStr)\r
- {\r
- writer.Write(true);\r
-\r
- if(_urlstrFile==null)\r
- {\r
- writer.Write(false);\r
- } \r
- else \r
- {\r
- Debug.WriteLine("writing #URLSTR");\r
- writer.Write(true);\r
- _urlstrFile.Dump(ref writer);\r
- }\r
- } \r
- else \r
- {\r
- writer.Write(false);\r
- }\r
-\r
- // urltbl dumping\r
- if(dmpInfo.DumpUrlTbl)\r
- {\r
- writer.Write(true);\r
-\r
- if(_urltblFile==null)\r
- {\r
- writer.Write(false);\r
- } \r
- else \r
- {\r
- Debug.WriteLine("writing #URLTBL");\r
- writer.Write(true);\r
- _urltblFile.Dump(ref writer);\r
- }\r
- } \r
- else \r
- {\r
- writer.Write(false);\r
- }\r
-\r
- // topics dumping\r
- if(dmpInfo.DumpTopics)\r
- {\r
- writer.Write(true);\r
-\r
- if(_topicsFile==null)\r
- {\r
- writer.Write(false);\r
- } \r
- else \r
- {\r
- Debug.WriteLine("writing #TOPICS");\r
- writer.Write(true);\r
- _topicsFile.Dump(ref writer);\r
- }\r
- } \r
- else \r
- {\r
- writer.Write(false);\r
- }\r
-\r
- // ftsearch dumping\r
- if(dmpInfo.DumpFullText)\r
- {\r
- writer.Write(true);\r
-\r
- if(_ftSearcher==null)\r
- {\r
- writer.Write(false);\r
- } \r
- else \r
- {\r
- Debug.WriteLine("writing $FIftiMain");\r
- writer.Write(true);\r
- _ftSearcher.Dump(ref writer);\r
- }\r
- } \r
- else \r
- {\r
- writer.Write(false);\r
- }\r
-\r
- // TOC dumping\r
- bool bWriteTOC = false;\r
-\r
- if( (_systemFile.BinaryTOC) && (dmpInfo.DumpBinaryTOC) )\r
- {\r
- Debug.WriteLine("writing binary TOC");\r
- bWriteTOC = true;\r
- }\r
-\r
- if( (!_systemFile.BinaryTOC) && (dmpInfo.DumpTextTOC) )\r
- {\r
- Debug.WriteLine("writing text-based TOC");\r
- bWriteTOC = true;\r
- }\r
-\r
- writer.Write(bWriteTOC);\r
-\r
- if(bWriteTOC)\r
- {\r
- // write table of contents\r
- writer.Write( _toc.Count );\r
-\r
- for(nCnt=0; nCnt < _toc.Count; nCnt++)\r
- {\r
- TOCItem curItem = ((TOCItem)(_toc[nCnt]));\r
- curItem.Dump( ref writer );\r
- }\r
- }\r
-\r
- // Index dumping\r
- bool bWriteIdx = false;\r
-\r
- if( (_systemFile.BinaryIndex) && (dmpInfo.DumpBinaryIndex) )\r
- {\r
- Debug.WriteLine("writing binary index");\r
- bWriteIdx = true;\r
- }\r
-\r
- if( (!_systemFile.BinaryIndex) && (dmpInfo.DumpTextIndex) )\r
- {\r
- Debug.WriteLine("writing text-based index");\r
- bWriteIdx = true;\r
- }\r
-\r
- writer.Write(bWriteIdx);\r
-\r
- if(bWriteIdx)\r
- {\r
- // write index\r
- writer.Write( _indexALinks.Count );\r
- for(nCnt=0; nCnt < _indexALinks.Count; nCnt++)\r
- {\r
- IndexItem curItem = ((IndexItem)(_indexALinks[nCnt]));\r
- curItem.Dump( ref writer );\r
- }\r
-\r
- writer.Write( _indexKLinks.Count );\r
- for(nCnt=0; nCnt < _indexKLinks.Count; nCnt++)\r
- {\r
- IndexItem curItem = ((IndexItem)(_indexKLinks[nCnt]));\r
- curItem.Dump( ref writer );\r
- }\r
- }\r
-\r
- // Information types dumping\r
- writer.Write( _informationTypes.Count );\r
-\r
- Debug.WriteLine("writing " + _informationTypes.Count.ToString() + " information types");\r
-\r
- for(nCnt=0; nCnt<_informationTypes.Count;nCnt++)\r
- {\r
- InformationType curType = _informationTypes[nCnt] as InformationType;\r
- \r
- curType.Dump(ref writer);\r
- }\r
-\r
- // Categories dumping\r
- writer.Write( _categories.Count );\r
-\r
- Debug.WriteLine("writing " + _categories.Count.ToString() + " categories");\r
-\r
- for(nCnt=0; nCnt<_categories.Count; nCnt++)\r
- {\r
- Category curCat = _categories[nCnt] as Category;\r
-\r
- curCat.Dump( ref writer);\r
- }\r
-\r
- bRet=true;\r
- }\r
- finally\r
- {\r
- dmpInfo.SaveData();\r
- }\r
-\r
- return bRet;\r
- }\r
-\r
- /// <summary>\r
- /// Parses a HHC file which is located in the current CHM.\r
- /// </summary>\r
- /// <param name="hhcFile">hhc file to parse</param>\r
- /// <returns>an arraylist with toc items</returns>\r
- public ArrayList ParseHHC(string hhcFile)\r
- {\r
- ArrayList arrRet = new ArrayList();\r
- \r
- CHMStream.CHMStream iw=null;\r
- iw=new CHMStream.CHMStream(); \r
- iw.OpenCHM(_chmFileName); \r
- MemoryStream fileObject=null; \r
-\r
- fileObject = iw.OpenStream(hhcFile);\r
- if( fileObject != null)\r
- { \r
- ASCIIEncoding ascii=new ASCIIEncoding(); \r
- string fileString =ascii.GetString(fileObject.ToArray(),0,(int)fileObject.Length); \r
- fileObject.Close();\r
-\r
- arrRet = HHCParser.ParseHHC(fileString, this);\r
-\r
- if(HHCParser.HasMergeLinks)\r
- {\r
- foreach(TOCItem curItem in HHCParser.MergeItems)\r
- {\r
- _mergeLinks.Add(curItem);\r
- }\r
- }\r
- }\r
-\r
- return arrRet;\r
- }\r
-\r
- /// <summary>\r
- /// Loads the toc and index from a data dump\r
- /// </summary>\r
- /// <param name="dmpInfo">dumping info</param>\r
- /// <returns>true if succeed</returns>\r
- private bool LoadDump(DumpingInfo dmpInfo)\r
- {\r
- if(dmpInfo == null)\r
- return false;\r
-\r
- bool bRet = false;\r
-\r
- try\r
- {\r
- BinaryReader reader = dmpInfo.Reader;\r
-\r
- if(reader == null)\r
- {\r
- Debug.WriteLine("No reader returned !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false;\r
- }\r
-\r
- int nCnt = 0;\r
-\r
- Debug.WriteLine("reading dump-file header");\r
- FileInfo fi = new FileInfo(_chmFileName);\r
- string ftime = fi.LastWriteTime.ToString("dd.MM.yyyy HH:mm:ss.ffffff");\r
-\r
- string header = reader.ReadString();\r
-\r
- if( header != "HtmlHelpSystem dump file 1.0")\r
- {\r
- Debug.WriteLine("Unsupported dump-file format !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false;\r
- }\r
-\r
- string ftimecheck = reader.ReadString();\r
-\r
- reader.ReadInt32(); // codepage, we'll use the same as for the chm file which is already set.\r
-\r
-// if(ftimecheck != ftime)\r
-// {\r
-// Debug.WriteLine("Dump is out of date (CHM file changed during last dump creation) !");\r
-// dmpInfo.SaveData(); // closes the dump\r
-// _mustWriteDump = true;\r
-// return false; // force reload\r
-// }\r
- \r
-\r
- bool bFlag=false; // true if data should be in dump\r
- bool bFlagSupp=false; // false if data is not supported by the chm\r
-\r
- bFlag = reader.ReadBoolean();\r
-\r
- if(bFlag)\r
- {\r
- bFlagSupp = reader.ReadBoolean();\r
-\r
- if(!dmpInfo.DumpStrings)\r
- {\r
- Debug.WriteLine("Dumped #STRINGS found but not expected !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
-\r
- if(bFlagSupp)\r
- {\r
- Debug.WriteLine("reading #STRINGS");\r
- _stringsFile = new CHMStrings();\r
- _stringsFile.SetCHMFile(this);\r
- _stringsFile.ReadDump(ref reader);\r
- }\r
- } \r
- else \r
- {\r
- if(dmpInfo.DumpStrings)\r
- {\r
- Debug.WriteLine("Dumped #STRINGS expected but not found !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
- }\r
-\r
- bFlag = reader.ReadBoolean();\r
-\r
- if(bFlag)\r
- {\r
- bFlagSupp = reader.ReadBoolean();\r
-\r
- if(!dmpInfo.DumpUrlStr)\r
- {\r
- Debug.WriteLine("Dumped #URLSTR found but not expected !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
-\r
- if(bFlagSupp)\r
- {\r
- Debug.WriteLine("reading #URLSTR");\r
- _urlstrFile = new CHMUrlstr();\r
- _urlstrFile.SetCHMFile(this);\r
- _urlstrFile.ReadDump(ref reader);\r
- }\r
- }\r
- else \r
- {\r
- if(dmpInfo.DumpUrlStr)\r
- {\r
- Debug.WriteLine("Dumped #URLSTR expected but not found !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
- }\r
-\r
- bFlag = reader.ReadBoolean();\r
-\r
- if(bFlag)\r
- {\r
- bFlagSupp = reader.ReadBoolean();\r
-\r
- if(!dmpInfo.DumpUrlTbl)\r
- {\r
- Debug.WriteLine("Dumped #URLTBL found but not expected !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
-\r
- if(bFlagSupp)\r
- {\r
- Debug.WriteLine("reading #URLTBL");\r
- _urltblFile = new CHMUrltable();\r
- _urltblFile.SetCHMFile(this);\r
- _urltblFile.ReadDump(ref reader);\r
- }\r
- }\r
- else \r
- {\r
- if(dmpInfo.DumpUrlTbl)\r
- {\r
- Debug.WriteLine("Dumped #URLTBL expected but not found !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
- }\r
-\r
- bFlag = reader.ReadBoolean();\r
-\r
- if(bFlag)\r
- {\r
- bFlagSupp = reader.ReadBoolean();\r
-\r
- if(!dmpInfo.DumpTopics)\r
- {\r
- Debug.WriteLine("Dumped #TOPICS found but not expected !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
-\r
- if(bFlagSupp)\r
- {\r
- Debug.WriteLine("reading #TOPICS");\r
- _topicsFile = new CHMTopics();\r
- _topicsFile.SetCHMFile(this);\r
- _topicsFile.ReadDump(ref reader);\r
- }\r
- }\r
- else \r
- {\r
- if(dmpInfo.DumpTopics)\r
- {\r
- Debug.WriteLine("Dumped #TOPICS expected but not found !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
- }\r
-\r
- bFlag = reader.ReadBoolean();\r
-\r
- if(bFlag)\r
- {\r
- bFlagSupp = reader.ReadBoolean();\r
-\r
- if(!dmpInfo.DumpFullText)\r
- {\r
- Debug.WriteLine("Dumped $FIftiMain found but not expected !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
-\r
- if(bFlagSupp)\r
- {\r
- Debug.WriteLine("reading $FIftiMain");\r
- _ftSearcher = new FullTextEngine();\r
- _ftSearcher.SetCHMFile(this);\r
- _ftSearcher.ReadDump(ref reader);\r
- }\r
- }\r
- else \r
- {\r
- if(dmpInfo.DumpFullText)\r
- {\r
- Debug.WriteLine("Dumped $FIftiMain expected but not found !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
- }\r
-\r
- // read table of contents\r
- _toc.Clear();\r
- bFlag = reader.ReadBoolean();\r
-\r
- if(bFlag)\r
- {\r
- if((_systemFile.BinaryTOC)&&(!dmpInfo.DumpBinaryTOC))\r
- {\r
- Debug.WriteLine("Binary TOC expected but not found !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- } \r
-\r
- if((!_systemFile.BinaryTOC)&&(!dmpInfo.DumpTextTOC))\r
- {\r
- Debug.WriteLine("Text-based TOC expected but not found !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
-\r
- if(_systemFile.BinaryTOC)\r
- Debug.WriteLine("reading binary TOC");\r
- else\r
- Debug.WriteLine("reading text-based TOC");\r
-\r
- int nTocCnt = reader.ReadInt32();\r
-\r
- for(nCnt=0; nCnt < nTocCnt; nCnt++)\r
- {\r
- TOCItem item = new TOCItem();\r
- item.AssociatedFile = this;\r
- item.ChmFile = _chmFileName;\r
- item.ReadDump(ref reader);\r
- if(item.MergeLink.Length > 0)\r
- _mergeLinks.Add(item);\r
-\r
- _toc.Add(item);\r
- }\r
- } \r
- else \r
- {\r
- if((_systemFile.BinaryTOC)&&(dmpInfo.DumpBinaryTOC))\r
- {\r
- Debug.WriteLine("Binary TOC expected but no TOC dump !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- } \r
-\r
- if((!_systemFile.BinaryTOC)&&(dmpInfo.DumpTextTOC))\r
- {\r
- Debug.WriteLine("Text-based TOC expected but no TOC dump !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
- }\r
-\r
- // read index\r
- _indexALinks.Clear();\r
- _indexKLinks.Clear();\r
-\r
- bFlag = reader.ReadBoolean();\r
-\r
- if(bFlag)\r
- {\r
- if((_systemFile.BinaryIndex)&&(!dmpInfo.DumpBinaryIndex))\r
- {\r
- Debug.WriteLine("Binary index expected but not found !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
-\r
- if((!_systemFile.BinaryIndex)&&(!dmpInfo.DumpTextIndex))\r
- {\r
- Debug.WriteLine("Binary index expected but not found !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
-\r
- if(_systemFile.BinaryIndex)\r
- Debug.WriteLine("reading binary index");\r
- else\r
- Debug.WriteLine("reading text-based index");\r
-\r
- int nIndxaCnt = reader.ReadInt32();\r
-\r
- for(nCnt=0; nCnt < nIndxaCnt; nCnt++)\r
- {\r
- IndexItem item = new IndexItem();\r
- item.ChmFile = this;\r
- item.ReadDump(ref reader);\r
- _indexALinks.Add(item);\r
- }\r
-\r
- \r
- int nIndxkCnt = reader.ReadInt32();\r
-\r
- for(nCnt=0; nCnt < nIndxkCnt; nCnt++)\r
- {\r
- IndexItem item = new IndexItem();\r
- item.ChmFile = this;\r
- item.ReadDump(ref reader);\r
- _indexKLinks.Add(item);\r
- }\r
- }\r
- else \r
- {\r
- if((_systemFile.BinaryIndex)&&(dmpInfo.DumpBinaryIndex))\r
- {\r
- Debug.WriteLine("Binary index expected but no index in dump !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- } \r
-\r
- if((!_systemFile.BinaryIndex)&&(dmpInfo.DumpTextIndex))\r
- {\r
- Debug.WriteLine("Text-based index expected but no index dump !");\r
- dmpInfo.SaveData(); // closes the dump\r
- _mustWriteDump = true;\r
- return false; // force reload\r
- }\r
- }\r
-\r
- // read information types from dump\r
- int nITCnt = reader.ReadInt32();\r
-\r
- Debug.WriteLine("Reading " + nITCnt.ToString() + " information types from dump !");\r
-\r
- for(nCnt=0; nCnt<nITCnt; nCnt++)\r
- {\r
- InformationType newType = new InformationType();\r
- newType.ReadDump(ref reader);\r
-\r
- if( SystemInstance.GetInformationType( newType.Name ) != null)\r
- {\r
- // information type of this name already exists in the helpsystem\r
- InformationType sysType = SystemInstance.GetInformationType( newType.Name );\r
- _informationTypes.Add(sysType);\r
- } \r
- else \r
- {\r
- _informationTypes.Add( newType );\r
- }\r
- }\r
-\r
- // read categories from dump\r
- int nCCnt = reader.ReadInt32();\r
-\r
- Debug.WriteLine("Reading " + nITCnt.ToString() + " categories from dump !");\r
-\r
- for(nCnt=0; nCnt<nCCnt; nCnt++)\r
- {\r
- Category newCat = new Category();\r
- newCat.ReadDump(ref reader, this);\r
-\r
- if( SystemInstance.GetCategory( newCat.Name ) != null)\r
- {\r
- // category of this name already exists in the helpsystem\r
- Category sysCat = SystemInstance.GetCategory( newCat.Name );\r
-\r
- sysCat.MergeInfoTypes( newCat );\r
- _categories.Add( sysCat );\r
- } \r
- else \r
- {\r
- _categories.Add( newCat );\r
- }\r
- }\r
-\r
- _dumpRead = true;\r
- bRet = true;\r
- }\r
- catch(Exception ex)\r
- {\r
- Debug.WriteLine("###ERROR :" + ex.Message);\r
- _mustWriteDump = true;\r
- }\r
- finally\r
- {\r
- dmpInfo.SaveData(); // closes the dump\r
- }\r
-\r
- return bRet;\r
- }\r
-\r
- #endregion\r
-\r
- #region Internal properties\r
- /// <summary>\r
- /// Gets the current storage wrapper.\r
- /// </summary>\r
- /// <remarks>This property will return not null, if there are currently file read actions running !</remarks>\r
- internal CHMStream.CHMStream CurrentStorageWrapper\r
- {\r
- get { return _currentWrapper;}\r
- }\r
- /// <summary>\r
- /// Gets/sets the hosting HtmlHelpSystem instance\r
- /// </summary>\r
- internal HtmlHelpSystem SystemInstance\r
- {\r
- get { return _systemInstance; }\r
- set { _systemInstance = value; }\r
- }\r
- /// <summary>\r
- /// Gets an arraylist of TOC items which contains merg-links to other CHMs\r
- /// </summary>\r
- internal ArrayList MergLinks\r
- {\r
- get { return _mergeLinks; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal system file instance\r
- /// </summary>\r
- internal CHMSystem SystemFile\r
- {\r
- get { return _systemFile; }\r
- }\r
- \r
- /// <summary>\r
- /// Gets the internal idxhdr file instance\r
- /// </summary>\r
- internal CHMIdxhdr IdxHdrFile\r
- {\r
- get { return _idxhdrFile; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal strings file instance\r
- /// </summary>\r
- internal CHMStrings StringsFile\r
- {\r
- get { return _stringsFile; }\r
- }\r
- \r
- /// <summary>\r
- /// Gets the internal urlstr file instance\r
- /// </summary>\r
- internal CHMUrlstr UrlstrFile\r
- {\r
- get { return _urlstrFile; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal urltbl file instance\r
- /// </summary>\r
- internal CHMUrltable UrltblFile\r
- {\r
- get { return _urltblFile; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal topics file instance\r
- /// </summary>\r
- internal CHMTopics TopicsFile\r
- {\r
- get { return _topicsFile; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal tocidx file instance\r
- /// </summary>\r
- internal CHMTocidx TocidxFile\r
- {\r
- get { return _tocidxFile; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal btree file instance for alinks\r
- /// </summary>\r
- internal CHMBtree ALinksFile\r
- {\r
- get { return _aLinks; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal btree file instance for klinks\r
- /// </summary>\r
- internal CHMBtree KLinksFile\r
- {\r
- get { return _kLinks; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets/Sets the text encoding\r
- /// </summary>\r
- internal Encoding TextEncoding\r
- {\r
- get { return _textEncoding; }\r
- set { _textEncoding = value; }\r
- }\r
-\r
- #endregion\r
-\r
- #region Properties from the #SYSTEM file\r
- /// <summary>\r
- /// Gets the file version of the chm file. \r
- /// 2 for Compatibility=1.0, 3 for Compatibility=1.1\r
- /// </summary>\r
- internal int FileVersion\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return 0;\r
-\r
- return _systemFile.FileVersion; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the contents file name\r
- /// </summary>\r
- internal string ContentsFile\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return String.Empty;\r
-\r
- return _systemFile.ContentsFile; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the index file name\r
- /// </summary>\r
- internal string IndexFile\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return String.Empty;\r
-\r
- return _systemFile.IndexFile; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the default help topic\r
- /// </summary>\r
- internal string DefaultTopic\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return String.Empty;\r
-\r
- return _systemFile.DefaultTopic; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the title of the help window\r
- /// </summary>\r
- internal string HelpWindowTitle\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return String.Empty;\r
-\r
- return _systemFile.Title; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the flag if DBCS is in use\r
- /// </summary>\r
- internal bool DBCS\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return false;\r
-\r
- return _systemFile.DBCS; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the flag if full-text-search is available\r
- /// </summary>\r
- internal bool FullTextSearch\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return false;\r
-\r
- return _systemFile.FullTextSearch; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the flag if the file has ALinks\r
- /// </summary>\r
- internal bool HasALinks\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return false;\r
-\r
- return _systemFile.HasALinks; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the flag if the file has KLinks\r
- /// </summary>\r
- internal bool HasKLinks\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return false;\r
-\r
- return _systemFile.HasKLinks; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the default window name\r
- /// </summary>\r
- internal string DefaultWindow\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return String.Empty;\r
-\r
- return _systemFile.DefaultWindow; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the file name of the compile file\r
- /// </summary>\r
- internal string CompileFile\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return String.Empty;\r
-\r
- return _systemFile.CompileFile; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the flag if the chm has a binary index file\r
- /// </summary>\r
- internal bool BinaryIndex\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return false;\r
-\r
- return _systemFile.BinaryIndex; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the flag if the chm has a binary index file\r
- /// </summary>\r
- internal string CompilerVersion\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return String.Empty;\r
-\r
- return _systemFile.CompilerVersion; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the flag if the chm has a binary toc file\r
- /// </summary>\r
- internal bool BinaryTOC\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return false;\r
-\r
- return _systemFile.BinaryTOC; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the font face of the read font property.\r
- /// Empty string for default font.\r
- /// </summary>\r
- internal string FontFace\r
- {\r
- get\r
- {\r
- if(_systemFile==null)\r
- return "";\r
- \r
- return _systemFile.FontFace; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the font size of the read font property.\r
- /// 0 for default font size\r
- /// </summary>\r
- internal double FontSize\r
- {\r
- get\r
- {\r
- if(_systemFile==null)\r
- return 0;\r
- \r
- return _systemFile.FontSize; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the character set of the read font property\r
- /// 1 for default\r
- /// </summary>\r
- internal int CharacterSet\r
- {\r
- get\r
- {\r
- if(_systemFile==null)\r
- return 1;\r
- \r
- return _systemFile.CharacterSet; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the codepage depending on the read font property\r
- /// </summary>\r
- internal int CodePage\r
- {\r
- get\r
- {\r
- if(_systemFile==null)\r
- return CultureInfo.CurrentCulture.TextInfo.ANSICodePage;\r
- \r
- return _systemFile.CodePage; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the assiciated culture info\r
- /// </summary>\r
- internal CultureInfo Culture\r
- {\r
- get \r
- { \r
- if(_systemFile==null)\r
- return CultureInfo.CurrentCulture;\r
- \r
- return _systemFile.Culture; \r
- }\r
- }\r
-\r
- #endregion \r
-\r
- #region Properties from the #IDXHDR file\r
- /// <summary>\r
- /// Gets the number of topic nodes including the contents and index files\r
- /// </summary>\r
- internal int NumberOfTopicNodes\r
- {\r
- get \r
- {\r
- if(_idxhdrFile==null)\r
- return 0;\r
-\r
- return _idxhdrFile.NumberOfTopicNodes; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the ImageList string specyfied in the #IDXHDR file.\r
- /// </summary>\r
- /// <remarks>This property uses the #STRINGS file to extract the string at a given offset.</remarks>\r
- internal string ImageList\r
- {\r
- get \r
- {\r
- if( (_stringsFile == null) || (_idxhdrFile == null) )\r
- return "";\r
-\r
- return _stringsFile[ _idxhdrFile.ImageListOffset ];\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// True if the value of the ImageType param of the \r
- /// "text/site properties" object of the sitemap contents is "Folder". \r
- /// </summary>\r
- /// <remarks>If this is set to true, the help will display folders instead of books</remarks>\r
- internal bool ImageTypeFolder\r
- {\r
- get \r
- { \r
- if(_idxhdrFile==null)\r
- return false;\r
-\r
- return _idxhdrFile.ImageTypeFolder; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the background setting \r
- /// </summary>\r
- internal int Background\r
- {\r
- get \r
- { \r
- if(_idxhdrFile==null)\r
- return 0;\r
-\r
- return _idxhdrFile.Background; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the foreground setting \r
- /// </summary>\r
- internal int Foreground\r
- {\r
- get \r
- { \r
- if(_idxhdrFile==null)\r
- return 0;\r
-\r
- return _idxhdrFile.Foreground; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the Font string specyfied in the #IDXHDR file.\r
- /// </summary>\r
- /// <remarks>This property uses the #STRINGS file to extract the string at a given offset.</remarks>\r
- internal string FontName\r
- {\r
- get \r
- {\r
- if( (_stringsFile == null) || (_idxhdrFile == null) )\r
- return "";\r
-\r
- return _stringsFile[ _idxhdrFile.FontOffset ];\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the FrameName string specyfied in the #IDXHDR file.\r
- /// </summary>\r
- /// <remarks>This property uses the #STRINGS file to extract the string at a given offset.</remarks>\r
- internal string FrameName\r
- {\r
- get \r
- {\r
- if( (_stringsFile == null) || (_idxhdrFile == null) )\r
- return "";\r
-\r
- return _stringsFile[ _idxhdrFile.FrameNameOffset ];\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the WindowName string specyfied in the #IDXHDR file.\r
- /// </summary>\r
- /// <remarks>This property uses the #STRINGS file to extract the string at a given offset.</remarks>\r
- internal string WindowName\r
- {\r
- get \r
- {\r
- if( (_stringsFile == null) || (_idxhdrFile == null) )\r
- return "";\r
-\r
- return _stringsFile[ _idxhdrFile.WindowNameOffset ];\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets a string array containing the merged file names\r
- /// </summary>\r
- internal string[] MergedFiles\r
- {\r
- get\r
- {\r
- if( (_stringsFile == null) || (_idxhdrFile == null) )\r
- return new string[0];\r
-\r
- string[] saRet = new string[ _idxhdrFile.MergedFileOffsets.Count ];\r
-\r
- for(int i=0; i < _idxhdrFile.MergedFileOffsets.Count; i++)\r
- {\r
- saRet[i] = _stringsFile[ (int)_idxhdrFile.MergedFileOffsets[i] ];\r
- }\r
-\r
- return saRet;\r
- }\r
- }\r
- #endregion\r
-\r
- /// <summary>\r
- /// Gets the file info associated with this instance\r
- /// </summary>\r
- public ChmFileInfo FileInfo\r
- {\r
- get { return _chmFileInfo; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal toc read from the text-based hhc file\r
- /// </summary>\r
- public ArrayList TOC\r
- {\r
- get { return _toc; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal index read from the chm file.\r
- /// </summary>\r
- public ArrayList IndexKLinks\r
- {\r
- get { return _indexKLinks; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the internal index read from the chm file.\r
- /// </summary>\r
- public ArrayList IndexALinks\r
- {\r
- get { return _indexALinks; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the full-text search engine for this file\r
- /// </summary>\r
- internal FullTextEngine FullTextSearchEngine\r
- {\r
- get { return _ftSearcher; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the full pathname of the file\r
- /// </summary>\r
- public string ChmFilePath\r
- {\r
- get { return _chmFileName; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the full pathname of the chi-file\r
- /// The file name is zero-length if there is no chi-file\r
- /// </summary>\r
- public string ChiFilePath\r
- {\r
- get { return _chiFileName; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the full pathname of the chw-file\r
- /// The file name is zero-length if there is no chw-file\r
- /// </summary>\r
- public string ChwFilePath\r
- {\r
- get { return _chwFileName; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the full pathname of the chq-file\r
- /// The file name is zero-length if there is no chq-file\r
- /// </summary>\r
- public string ChqFilePath\r
- {\r
- get { return _chqFileName; }\r
- }\r
-\r
- /// <summary>\r
- /// Forms an URL for the web browser\r
- /// </summary>\r
- /// <param name="local">local resource</param>\r
- /// <returns>a url for the web-browser</returns>\r
- internal string FormURL(string local)\r
- {\r
- if( (local.ToLower().IndexOf("http://") >= 0) ||\r
- (local.ToLower().IndexOf("https://") >= 0) ||\r
- (local.ToLower().IndexOf("mailto:") >= 0) ||\r
- (local.ToLower().IndexOf("ftp://") >= 0) ||\r
- (local.ToLower().IndexOf("ms-its:") >= 0)) \r
- return local;\r
-\r
- return HtmlHelpSystem.UrlPrefix + _chmFileName + "::/" + local;\r
- }\r
-\r
- /// <summary>\r
- /// Implement IDisposable.\r
- /// </summary>\r
- public void Dispose()\r
- {\r
- Dispose(true);\r
- // This object will be cleaned up by the Dispose method.\r
- // Therefore, you should call GC.SupressFinalize to\r
- // take this object off the finalization queue \r
- // and prevent finalization code for this object\r
- // from executing a second time.\r
- GC.SuppressFinalize(this);\r
- }\r
-\r
- /// <summary>\r
- /// Dispose(bool disposing) executes in two distinct scenarios. \r
- /// If disposing equals true, the method has been called directly \r
- /// or indirectly by a user's code. Managed and unmanaged resources \r
- /// can be disposed. \r
- /// If disposing equals false, the method has been called by the \r
- /// runtime from inside the finalizer and you should not reference \r
- /// other objects. Only unmanaged resources can be disposed.\r
- /// </summary>\r
- /// <param name="disposing">disposing flag</param>\r
- private void Dispose(bool disposing)\r
- {\r
- // Check to see if Dispose has already been called.\r
- if(!this.disposed)\r
- {\r
- // If disposing equals true, dispose all managed \r
- // and unmanaged resources.\r
- if(disposing)\r
- {\r
- // Dispose managed resources.\r
- _toc.Clear();\r
- _indexKLinks.Clear();\r
- _indexALinks.Clear();\r
-\r
- if(_systemFile!=null)\r
- _systemFile.Dispose();\r
-\r
- if(_idxhdrFile != null)\r
- _idxhdrFile.Dispose();\r
-\r
- if(_stringsFile != null)\r
- _stringsFile.Dispose();\r
-\r
- if(_urlstrFile != null)\r
- _urlstrFile.Dispose();\r
-\r
- if(_urltblFile != null)\r
- _urltblFile.Dispose();\r
-\r
- if(_topicsFile != null)\r
- _topicsFile.Dispose();\r
-\r
- if(_tocidxFile != null)\r
- _tocidxFile.Dispose();\r
-\r
- if(_kLinks != null)\r
- _kLinks.Dispose();\r
-\r
- if(_aLinks != null)\r
- _aLinks.Dispose();\r
-\r
- if(_ftSearcher != null)\r
- _ftSearcher.Dispose();\r
-\r
- if(_chmFileInfo != null)\r
- _chmFileInfo = null;\r
- }\r
- }\r
- disposed = true; \r
- }\r
-\r
- }\r
-}\r