Esempio n. 1
0
        /// <summary>
        /// Merges a chm file to the current help contents
        /// </summary>
        /// <param name="chmFile">full file path of the chm file to merge</param>
        /// <param name="dmpInfo">dumping info</param>
        /// <param name="mergedFileList">true if the merge is done because a merged file list
        /// was found in the previously loaded CHM.</param>
        internal void MergeFile(string chmFile, DumpingInfo dmpInfo, bool mergedFileList)
        {
            if (File.Exists(chmFile))
            {
                if (_chmFiles.Count == 1)
                {
                    // if we open the first file, we directly point into the toc and index of this file.
                    // So that we don't merge the new toc's indexe's into the first file, we have to
                    // clone the internal arraylists first to a new instance of the toc/index holder classes.
                    ArrayList atoc   = _toc.TOC;
                    ArrayList alinks = _index.ALinks;
                    ArrayList klinks = _index.KLinks;

                    _toc   = new TableOfContents();
                    _index = new Index();

                    _toc.MergeToC(atoc);
                    _index.MergeIndex(alinks, IndexType.AssiciativeLinks);
                    _index.MergeIndex(klinks, IndexType.KeywordLinks);
                }

                CHMFile newFile = new CHMFile(this, chmFile, dmpInfo);

                if (mergedFileList)                // if we've called this method due to a merged file list merge
                {
                    RecalculateMergeLinks(newFile);

                    _toc.MergeToC(newFile.TOC, _chmFiles);
                    _index.MergeIndex(newFile.IndexALinks, IndexType.AssiciativeLinks);
                    _index.MergeIndex(newFile.IndexKLinks, IndexType.KeywordLinks);

                    _chmFiles.Add(newFile);

                    // add all infotypes and categories of the read file to this system instance
                    MergeFileInfoTypesCategories(newFile);
                }
                else
                {
                    _toc.MergeToC(newFile.TOC, _chmFiles);
                    _index.MergeIndex(newFile.IndexALinks, IndexType.AssiciativeLinks);
                    _index.MergeIndex(newFile.IndexKLinks, IndexType.KeywordLinks);

                    _chmFiles.Add(newFile);

                    // add all infotypes and categories of the read file to this system instance
                    MergeFileInfoTypesCategories(newFile);

                    // check if the file has a merged files list
                    if (newFile.MergedFiles.Length > 0)
                    {
                        // extract the path of the chm file (usually merged files are in the same path)
                        FileInfo fi    = new FileInfo(chmFile);
                        string   sPath = fi.DirectoryName;

                        for (int i = 0; i < newFile.MergedFiles.Length; i++)
                        {
                            string sFile = newFile.MergedFiles[i];

                            if (sFile.Length > 0)
                            {
                                if (sFile[1] != ':')                                // no full path setting
                                {
                                    sFile = Path.Combine(sPath, sFile);
                                }

                                MergeFile(sFile, dmpInfo, true);
                            }
                        }

                        //if(newFile.MergLinks.Count > 0)
                        //	RecalculateMergeLinks(newFile);

                        RemoveMergeLinks();                         // clear all merge-links which have no target !
                    }
                }
            }
        }