+++ /dev/null
-using System;\r
-using System.IO;\r
-using System.Collections;\r
-using System.Data;\r
-\r
-using HtmlHelp.ChmDecoding;\r
-\r
-namespace HtmlHelp\r
-{\r
- /// <summary>\r
- /// The class <c>HtmlHelpSystem</c> implements the main object for reading chm files\r
- /// </summary>\r
- public sealed class HtmlHelpSystem\r
- {\r
- /// <summary>\r
- /// Private shared instance of current HtmlHelpSystem class\r
- /// </summary>\r
- private static HtmlHelpSystem _current=null;\r
- /// <summary>\r
- /// Internal member storing the attached files\r
- /// </summary>\r
- private ArrayList _chmFiles = new ArrayList();\r
- /// <summary>\r
- /// Internal member storing a merged table of contents\r
- /// </summary>\r
- private TableOfContents _toc = new TableOfContents();\r
- /// <summary>\r
- /// Internal member storing a merged index\r
- /// </summary>\r
- private Index _index = new Index();\r
- /// <summary>\r
- /// URL prefix for specifying a chm destination\r
- /// </summary>\r
- private static string _urlPrefix = "ms-its:";\r
- /// <summary>\r
- /// Internal flag specifying if the system should use the tree-images list\r
- /// from HtmlHelp2. If false the standard CHM-Viewer pics will be used.\r
- /// </summary>\r
- private static bool _useHH2TreePics = false;\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
-\r
- /// <summary>\r
- /// Gets/Sets the url prefix for specifying a chm destination\r
- /// </summary>\r
- public static string UrlPrefix\r
- {\r
- get { return _urlPrefix; }\r
- set { _urlPrefix = value; }\r
- }\r
-\r
- public CHMStream.CHMStream BaseStream\r
- {\r
- get \r
- {\r
- CHMFile chm=(CHMFile)_chmFiles[0];\r
- return chm.BaseStream; \r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets/Sets the flag specifying if the system should use the tree-images list\r
- /// from HtmlHelp2. If false the standard CHM-Viewer pics will be used.\r
- /// </summary>\r
- public static bool UseHH2TreePics\r
- {\r
- get { return _useHH2TreePics; }\r
- set { _useHH2TreePics = value; }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the current HtmlHelpSystem instance\r
- /// </summary>\r
- public static HtmlHelpSystem Current\r
- {\r
- get \r
- {\r
- return _current;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Standard constructor\r
- /// </summary>\r
- public HtmlHelpSystem() : this("")\r
- {\r
- }\r
-\r
- /// <summary>\r
- /// Constructor of the reader class\r
- /// </summary>\r
- /// <param name="chmFile">chm file to attach with the reader</param>\r
- public HtmlHelpSystem(string chmFile)\r
- {\r
- _current = this;\r
- OpenFile(chmFile);\r
- }\r
-\r
-\r
- /// <summary>\r
- /// Opens a chm file and creates\r
- /// </summary>\r
- /// <param name="chmFile">full file path of the chm file to open</param>\r
- /// <remarks>If you call this method, all existing merged files will be cleared.</remarks>\r
- public void OpenFile(string chmFile)\r
- {\r
- OpenFile(chmFile, null);\r
- }\r
-\r
- /// <summary>\r
- /// Opens a chm file and creates\r
- /// </summary>\r
- /// <param name="chmFile">full file path of the chm file to open</param>\r
- /// <param name="dmpInfo">dumping info</param>\r
- /// <remarks>If you call this method, all existing merged files will be cleared.</remarks>\r
- public void OpenFile(string chmFile, DumpingInfo dmpInfo)\r
- {\r
- if( File.Exists(chmFile ) )\r
- {\r
- _chmFiles.Clear();\r
- _toc.Clear();\r
- _index.Clear();\r
- _informationTypes.Clear();\r
- _categories.Clear();\r
-\r
- CHMFile newFile = new CHMFile(this, chmFile, dmpInfo);\r
-\r
- _toc = new TableOfContents( newFile.TOC );\r
- _index = new Index( newFile.IndexKLinks, newFile.IndexALinks );\r
-\r
- _chmFiles.Add(newFile);\r
- // add all infotypes and categories of the read file to this system instance\r
- MergeFileInfoTypesCategories(newFile);\r
-\r
- // check if the file has a merged files list\r
- if( newFile.MergedFiles.Length > 0 )\r
- {\r
- // extract the path of the chm file (usually merged files are in the same path)\r
- FileInfo fi = new FileInfo(chmFile);\r
- string sPath = fi.DirectoryName;\r
-\r
- for(int i=0; i<newFile.MergedFiles.Length; i++)\r
- {\r
- string sFile = newFile.MergedFiles[i];\r
-\r
- if(sFile.Length > 0)\r
- {\r
- if(sFile[1] != ':') // no full path setting\r
- {\r
- sFile = Path.Combine(sPath, sFile);\r
- }\r
-\r
- MergeFile(sFile, dmpInfo, true);\r
- }\r
- }\r
-\r
- // if (newFile.MergLinks.Count>0)\r
- // RecalculateMergeLinks(newFile);\r
-\r
- RemoveMergeLinks(); // clear all merge-links which have no target !\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Merges a chm file to the current help contents\r
- /// </summary>\r
- /// <param name="chmFile">full file path of the chm file to merge</param>\r
- public void MergeFile(string chmFile)\r
- {\r
- MergeFile(chmFile, null);\r
- }\r
-\r
- /// <summary>\r
- /// Merges a chm file to the current help contents\r
- /// </summary>\r
- /// <param name="chmFile">full file path of the chm file to merge</param>\r
- /// <param name="dmpInfo">dumping info</param>\r
- public void MergeFile(string chmFile, DumpingInfo dmpInfo)\r
- {\r
- MergeFile(chmFile, dmpInfo, false);\r
- }\r
-\r
- /// <summary>\r
- /// Merges a chm file to the current help contents\r
- /// </summary>\r
- /// <param name="chmFile">full file path of the chm file to merge</param>\r
- /// <param name="dmpInfo">dumping info</param>\r
- /// <param name="mergedFileList">true if the merge is done because a merged file list \r
- /// was found in the previously loaded CHM.</param>\r
- internal void MergeFile(string chmFile, DumpingInfo dmpInfo, bool mergedFileList)\r
- {\r
- if( File.Exists(chmFile ) )\r
- {\r
- if( _chmFiles.Count == 1)\r
- {\r
- // if we open the first file, we directly point into the toc and index of this file.\r
- // So that we don't merge the new toc's indexe's into the first file, we have to \r
- // clone the internal arraylists first to a new instance of the toc/index holder classes.\r
- ArrayList atoc = _toc.TOC;\r
- ArrayList alinks = _index.ALinks;\r
- ArrayList klinks = _index.KLinks;\r
-\r
- _toc = new TableOfContents();\r
- _index = new Index();\r
-\r
- _toc.MergeToC( atoc );\r
- _index.MergeIndex( alinks, IndexType.AssiciativeLinks );\r
- _index.MergeIndex( klinks, IndexType.KeywordLinks );\r
- }\r
-\r
- CHMFile newFile = new CHMFile(this, chmFile, dmpInfo);\r
-\r
- if(mergedFileList) // if we've called this method due to a merged file list merge\r
- {\r
- RecalculateMergeLinks(newFile);\r
-\r
- _toc.MergeToC( newFile.TOC, _chmFiles );\r
- _index.MergeIndex( newFile.IndexALinks, IndexType.AssiciativeLinks );\r
- _index.MergeIndex( newFile.IndexKLinks, IndexType.KeywordLinks );\r
-\r
- _chmFiles.Add(newFile);\r
-\r
- // add all infotypes and categories of the read file to this system instance\r
- MergeFileInfoTypesCategories(newFile);\r
- } \r
- else \r
- {\r
- _toc.MergeToC( newFile.TOC, _chmFiles );\r
- _index.MergeIndex( newFile.IndexALinks, IndexType.AssiciativeLinks );\r
- _index.MergeIndex( newFile.IndexKLinks, IndexType.KeywordLinks );\r
-\r
- _chmFiles.Add(newFile);\r
-\r
- // add all infotypes and categories of the read file to this system instance\r
- MergeFileInfoTypesCategories(newFile);\r
-\r
- // check if the file has a merged files list\r
- if( newFile.MergedFiles.Length > 0 )\r
- {\r
- // extract the path of the chm file (usually merged files are in the same path)\r
- FileInfo fi = new FileInfo(chmFile);\r
- string sPath = fi.DirectoryName;\r
-\r
- for(int i=0; i<newFile.MergedFiles.Length; i++)\r
- {\r
- string sFile = newFile.MergedFiles[i];\r
-\r
- if(sFile.Length > 0)\r
- {\r
- if(sFile[1] != ':') // no full path setting\r
- {\r
- sFile = Path.Combine(sPath, sFile);\r
- }\r
-\r
- MergeFile(sFile, dmpInfo, true);\r
- }\r
- }\r
-\r
- RemoveMergeLinks(); // clear all merge-links which have no target !\r
- }\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Checks all Merg-links read till now. Checks if the merg-link points to the \r
- /// file <c>currentFile</c>. If yes the link will be replaced by the contents of the \r
- /// merged file.\r
- /// </summary>\r
- /// <param name="currentFile">Current CHMFile instance</param>\r
- internal void RecalculateMergeLinks(CHMFile currentFile)\r
- {\r
- foreach(CHMFile curFile in _chmFiles)\r
- {\r
- if( curFile.MergLinks.Count > 0)\r
- {\r
- for(int i=0; i<curFile.MergLinks.Count; i++)\r
- {\r
- TOCItem curItem = curFile.MergLinks[i] as TOCItem;\r
-\r
- string sMerge = curItem.MergeLink;\r
- string [] sSplit = sMerge.Split( new char[]{':'} );\r
-\r
- string sFName = "";\r
- string sTarget = "";\r
-\r
- if( sSplit.Length > 3) // merge info contains path name\r
- {\r
- sFName = sSplit[0] + ":" + sSplit[1];\r
- sTarget = sSplit[3];\r
- } \r
- else if( sSplit.Length == 3)// merge info contains only file name\r
- {\r
- FileInfo fi = new FileInfo(currentFile.ChmFilePath);\r
- string sPath = fi.DirectoryName;\r
-\r
- string sFile = sSplit[0];\r
-\r
- if(sFile.Length > 0)\r
- {\r
- if(sFile[1] != ':') // no full path setting\r
- {\r
- sFile = Path.Combine(sPath, sFile);\r
- }\r
- }\r
-\r
- sFName = sFile;\r
- sTarget = sSplit[2];\r
- }\r
-\r
- ArrayList arrToc = null;\r
- if( (sFName.Length>0) && (sTarget.Length>0) )\r
- {\r
- // if this link points into the current file\r
- if( sFName.ToLower() == currentFile.ChmFilePath.ToLower() )\r
- {\r
- if(sTarget.ToLower().IndexOf(".hhc") >= 0)\r
- {\r
- string sfCheck = sTarget;\r
-\r
- // remove prefixing ./\r
- while( (sfCheck[0]=='.') || (sfCheck[0]=='/') )\r
- {\r
- sfCheck = sfCheck.Substring(1);\r
- }\r
-\r
- if( currentFile.ContentsFile.ToLower() != sfCheck )\r
- {\r
- arrToc = currentFile.ParseHHC( sTarget );\r
-\r
- if( arrToc.Count > 0)\r
- {\r
- }\r
- } \r
- else \r
- {\r
- arrToc = currentFile.TOC;\r
- }\r
-\r
- // target points to a complete TOC\r
- int nCnt = 0;\r
-\r
- foreach(TOCItem chkItem in arrToc)\r
- {\r
- if(nCnt == 0)\r
- {\r
- curItem.AssociatedFile = currentFile;\r
- curItem.Children = chkItem.Children;\r
- curItem.ChmFile = currentFile.ChmFilePath;\r
- curItem.ImageIndex = chkItem.ImageIndex;\r
- curItem.Local = chkItem.Local;\r
- curItem.MergeLink = chkItem.MergeLink;\r
- curItem.Name = chkItem.Name;\r
- curItem.TocMode = chkItem.TocMode;\r
- curItem.TopicOffset = chkItem.TopicOffset;\r
-\r
- MarkChildrenAdded(chkItem.Children, curFile.MergLinks);\r
- } \r
- else \r
- {\r
- ArrayList checkList = null;\r
-\r
- if(curItem.Parent != null)\r
- checkList = curItem.Parent.Children;\r
- else\r
- checkList = curFile.TOC;\r
- \r
- int nIdx = checkList.IndexOf(curItem);\r
- if((nIdx+nCnt)>checkList.Count)\r
- checkList.Add(chkItem);\r
- else\r
- checkList.Insert(nIdx+nCnt, chkItem);\r
- \r
- curFile.MergLinks.Add(chkItem);\r
- MarkChildrenAdded(chkItem.Children, curFile.MergLinks);\r
- }\r
-\r
- nCnt++;\r
- }\r
- } \r
- else \r
- {\r
- \r
- // target points to a single topic\r
- TOCItem chkItem = currentFile.GetTOCItemByLocal(sTarget);\r
- if(chkItem != null)\r
- {\r
- curItem.AssociatedFile = currentFile;\r
- curItem.Children = chkItem.Children;\r
- curItem.ChmFile = currentFile.ChmFilePath;\r
- curItem.ImageIndex = chkItem.ImageIndex;\r
- curItem.Local = chkItem.Local;\r
- curItem.MergeLink = chkItem.MergeLink;\r
- curItem.Name = chkItem.Name;\r
- curItem.TocMode = chkItem.TocMode;\r
- curItem.TopicOffset = chkItem.TopicOffset;\r
-\r
- curFile.MergLinks.Add(chkItem);\r
- MarkChildrenAdded(chkItem.Children, curFile.MergLinks);\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Adds sub-items of an TOC-entry to the merg-linked list. \r
- /// This will mark this item as "added" during the extra merge run \r
- /// of the HtmlHelpSystem class.\r
- /// </summary>\r
- /// <param name="tocs">TOCItem list</param>\r
- /// <param name="merged">Arraylist which holds the merged-items</param>\r
- internal void MarkChildrenAdded(ArrayList tocs, ArrayList merged)\r
- {\r
- foreach(TOCItem curItem in tocs)\r
- {\r
- if(!merged.Contains(curItem))\r
- {\r
- merged.Add(curItem);\r
-\r
- MarkChildrenAdded(curItem.Children, merged);\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Removes merge-links from the toc of files which were not loaded\r
- /// </summary>\r
- internal void RemoveMergeLinks()\r
- {\r
- foreach(CHMFile curFile in _chmFiles)\r
- {\r
- if( curFile.MergLinks.Count > 0)\r
- {\r
- while(curFile.MergLinks.Count > 0)\r
- {\r
- TOCItem curItem = curFile.MergLinks[0] as TOCItem;\r
- if(curItem.MergeLink.Length > 0)\r
- curFile.RemoveTOCItem(curItem);\r
-\r
- curFile.MergLinks.RemoveAt(0);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Merges the information types and categories read by the CHMFile instance \r
- /// into the system instance\r
- /// </summary>\r
- /// <param name="chmFile">file instance</param>\r
- private void MergeFileInfoTypesCategories(CHMFile chmFile)\r
- {\r
- if(chmFile.HasInformationTypes)\r
- {\r
- for(int i=0; i<chmFile.InformationTypes.Count;i++)\r
- {\r
- InformationType curType = chmFile.InformationTypes[i] as InformationType;\r
- InformationType sysType = GetInformationType( curType.Name );\r
-\r
- if( sysType == null)\r
- _informationTypes.Add(curType);\r
- else\r
- curType.ReferenceCount++;\r
- }\r
- }\r
-\r
- if(chmFile.HasCategories)\r
- {\r
- for(int i=0; i<chmFile.Categories.Count;i++)\r
- {\r
- Category curCat = chmFile.Categories[i] as Category;\r
- Category sysCat = GetCategory( curCat.Name );\r
-\r
- if(sysCat == null)\r
- _categories.Add(curCat);\r
- else\r
- curCat.ReferenceCount++;\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Removes the information types and categories read by the CHMFile instance \r
- /// </summary>\r
- /// <param name="chmFile">file instance</param>\r
- private void RemoveFileInfoTypesCategories(CHMFile chmFile)\r
- {\r
- if(chmFile.HasInformationTypes)\r
- {\r
- for(int i=0; i<chmFile.InformationTypes.Count;i++)\r
- {\r
- InformationType curType = chmFile.InformationTypes[i] as InformationType;\r
- InformationType sysType = GetInformationType( curType.Name );\r
-\r
- if(sysType != null)\r
- {\r
- sysType.ReferenceCount--;\r
-\r
- if(sysType.ReferenceCount<=0)\r
- _informationTypes.Remove(sysType);\r
- }\r
- }\r
- }\r
-\r
- if(chmFile.HasCategories)\r
- {\r
- for(int i=0; i<chmFile.Categories.Count;i++)\r
- {\r
- Category curCat = chmFile.Categories[i] as Category;\r
- Category sysCat = GetCategory( curCat.Name );\r
-\r
- if(sysCat != null)\r
- {\r
- sysCat.ReferenceCount--;\r
-\r
- if(sysCat.ReferenceCount<=0)\r
- _categories.Remove(sysCat);\r
- }\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Removes a chm file from the internal file collection\r
- /// </summary>\r
- /// <param name="chmFile">full file path of the chm file to remove</param>\r
- public void RemoveFile(string chmFile)\r
- {\r
- int nIdx = -1;\r
- CHMFile removeInstance=null;\r
-\r
- foreach(CHMFile curFile in _chmFiles)\r
- {\r
- nIdx++;\r
-\r
- if( curFile.ChmFilePath.ToLower() == chmFile.ToLower() )\r
- {\r
- removeInstance = curFile;\r
- break;\r
- }\r
- }\r
-\r
- if(nIdx >= 0)\r
- {\r
- _toc.Clear(); // forces a rebuild of the merged toc\r
- _index.Clear(); // force a rebuild of the merged index\r
- \r
- RemoveFileInfoTypesCategories(removeInstance);\r
- _chmFiles.RemoveAt(nIdx);\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Closes all files and destroys TOC/index\r
- /// </summary>\r
- public void CloseAllFiles()\r
- {\r
- for(int i=0; i < _chmFiles.Count; i++)\r
- {\r
- CHMFile curFile = _chmFiles[i] as CHMFile;\r
-\r
- _chmFiles.RemoveAt(i);\r
- curFile.Dispose();\r
- i--;\r
- }\r
-\r
- _chmFiles.Clear();\r
- _toc.Clear();\r
- _index.Clear();\r
- _informationTypes.Clear();\r
- _categories.Clear();\r
- }\r
-\r
- /// <summary>\r
- /// Gets an array of loaded chm files. \r
- /// </summary>\r
- public CHMFile[] FileList\r
- {\r
- get\r
- {\r
- CHMFile[] ret = new CHMFile[ _chmFiles.Count ];\r
- for(int i=0;i<_chmFiles.Count;i++)\r
- ret[i] = (CHMFile)_chmFiles[i];\r
-\r
- return ret;\r
- }\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
- /// <summary>\r
- /// Gets the default topic\r
- /// </summary>\r
- public string DefaultTopic\r
- {\r
- get\r
- {\r
- if( _chmFiles.Count > 0 )\r
- {\r
- foreach(CHMFile curFile in _chmFiles)\r
- {\r
- if( curFile.DefaultTopic.Length > 0)\r
- {\r
- return curFile.FormURL( curFile.DefaultTopic );\r
- }\r
- }\r
- }\r
-\r
- return "about:blank";\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets a merged table of contents of all opened chm files\r
- /// </summary>\r
- public TableOfContents TableOfContents\r
- {\r
- get\r
- {\r
- if( _chmFiles.Count > 0 )\r
- {\r
- if( _toc.Count() <= 0)\r
- {\r
- // merge toc of files\r
- foreach(CHMFile curFile in _chmFiles)\r
- {\r
- _toc.MergeToC( curFile.TOC );\r
- }\r
- }\r
- }\r
-\r
- return _toc;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets a merged index of all opened chm files\r
- /// </summary>\r
- public Index Index\r
- {\r
- get\r
- {\r
- if( _chmFiles.Count > 0 )\r
- {\r
- if( (_index.Count(IndexType.KeywordLinks)+_index.Count(IndexType.AssiciativeLinks)) <= 0)\r
- {\r
- // merge index files\r
- foreach(CHMFile curFile in _chmFiles)\r
- {\r
- _index.MergeIndex( curFile.IndexKLinks, IndexType.KeywordLinks);\r
- _index.MergeIndex( curFile.IndexALinks, IndexType.AssiciativeLinks);\r
- }\r
- }\r
- }\r
-\r
- return _index;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets a flag if the current instance offers a table of contents\r
- /// </summary>\r
- public bool HasTableOfContents\r
- {\r
- get \r
- {\r
- return (TableOfContents.Count() > 0);\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets a flag if the current instance offers an index\r
- /// </summary>\r
- public bool HasIndex\r
- {\r
- get \r
- {\r
- return (HasALinks || HasKLinks);\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets a flag if the index holds klinks\r
- /// </summary>\r
- public bool HasKLinks\r
- {\r
- get\r
- {\r
- return (_index.Count(IndexType.KeywordLinks) > 0);\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets a flag if the index holds alinks\r
- /// </summary>\r
- public bool HasALinks\r
- {\r
- get\r
- {\r
- return (_index.Count(IndexType.AssiciativeLinks) > 0);\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets a flag if the current instance supports fulltext searching\r
- /// </summary>\r
- public bool FullTextSearch\r
- {\r
- get \r
- {\r
- bool bRet = false;\r
-\r
- foreach(CHMFile curFile in _chmFiles)\r
- {\r
- bRet |= curFile.FullTextSearch;\r
- }\r
-\r
- return bRet;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Performs a full-text search over the chm files\r
- /// </summary>\r
- /// <param name="words">words to search</param>\r
- /// <param name="partialMatches">true if partial word should be matched also \r
- /// ( if this is true a search of 'support' will match 'supports', otherwise not )</param>\r
- /// <param name="titleOnly">true if titles only</param>\r
- /// <returns>A DataTable containing the search hits</returns>\r
- public DataTable PerformSearch(string words, bool partialMatches, bool titleOnly)\r
- {\r
- return PerformSearch(words, -1, partialMatches, titleOnly);\r
- }\r
-\r
- /// <summary>\r
- /// Performs a full-text search over the chm files\r
- /// </summary>\r
- /// <param name="words">words to search</param>\r
- /// <param name="MaxResults">maximal number of hits to return</param>\r
- /// <param name="partialMatches">true if partial word should be matched also \r
- /// ( if this is true a search of 'support' will match 'supports', otherwise not )</param>\r
- /// <param name="titleOnly">true if titles only</param>\r
- /// <returns>A DataTable containing the search hits</returns>\r
- public DataTable PerformSearch(string words, int MaxResults, bool partialMatches, bool titleOnly)\r
- {\r
- if( ! FullTextSearch )\r
- return null;\r
-\r
- DataTable dtResult = null;\r
-\r
- int nCnt = 0;\r
-\r
- foreach(CHMFile curFile in _chmFiles)\r
- {\r
- if(nCnt == 0)\r
- {\r
- if(curFile.FullTextSearchEngine.CanSearch)\r
- {\r
- if(curFile.FullTextSearchEngine.Search(words, MaxResults, partialMatches, titleOnly))\r
- {\r
- dtResult = curFile.FullTextSearchEngine.Hits;\r
- dtResult.DefaultView.Sort = "Rating DESC";\r
- }\r
- }\r
- }\r
- else\r
- {\r
- if(curFile.FullTextSearchEngine.CanSearch)\r
- {\r
- if(curFile.FullTextSearchEngine.Search(words, MaxResults, partialMatches, titleOnly))\r
- {\r
- DataTable table = curFile.FullTextSearchEngine.Hits;\r
- \r
- // append rows from 2nd file\r
- foreach(DataRow curRow in table.Rows)\r
- {\r
- dtResult.ImportRow( curRow );\r
- }\r
-\r
- dtResult.DefaultView.Sort = "Rating DESC";\r
-\r
- // adjust max hits\r
- if(MaxResults >= 0)\r
- {\r
- if(dtResult.DefaultView.Count > MaxResults)\r
- {\r
- for(int i=MaxResults-1; i<dtResult.DefaultView.Count-1;i++)\r
- {\r
- if(dtResult.DefaultView[i].Row.RowState != DataRowState.Deleted)\r
- {\r
- dtResult.DefaultView[i].Row.Delete();\r
- dtResult.DefaultView[i].Row.AcceptChanges();\r
- i--;\r
- }\r
- }\r
-\r
- dtResult.AcceptChanges();\r
- dtResult.DefaultView.Sort = "Rating DESC";\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- nCnt++;\r
- }\r
-\r
- return dtResult;\r
- }\r
- }\r
-}\r