/// <summary>
        /// This is called to copy the additional content files and build a
        /// list of them for the help file project.
        /// </summary>
        /// <param name="previewing">Pass true to generate the table of content
        /// collection for previewing without actually copying anything.</param>
        /// <remarks>Note that for wilcard content items, the folders are
        /// copied recursively.</remarks>
        protected void CopyAdditionalContent(bool previewing)
        {
            TocEntry tocEntry;
            string   source, filename, dirName, srcLower,
                     rootPath = workingFolder + @"Output\";

            string[] fileList;
            int      idx;

            toc           = new TocEntryCollection();
            exclusionList = new Dictionary <string, string>();

            // Get a list of the exclusions first
            foreach (ContentItem ci in project.AdditionalContent)
            {
                if (!ci.ExcludeItems)
                {
                    continue;
                }

                source = ci.SourcePath;

                if (source.IndexOfAny(new char[] { '*', '?' }) == -1)
                {
                    exclusionList.Add(source, null);
                }
                else
                {
                    idx      = source.LastIndexOf('\\');
                    dirName  = source.Substring(0, idx);
                    filename = source.Substring(idx + 1);

                    fileList = Directory.GetFiles(dirName, filename,
                                                  SearchOption.AllDirectories);

                    foreach (string matchFile in fileList)
                    {
                        exclusionList.Add(matchFile, null);
                    }
                }
            }

            // Now copy the additional content less the excluded files
            foreach (ContentItem ci in project.AdditionalContent)
            {
                if (ci.ExcludeItems)
                {
                    continue;
                }

                source   = ci.SourcePath;
                dirName  = workingFolder + @"Output\" + ci.DestinationPath;
                filename = dirName + Path.GetFileName(source);

                if (source.IndexOfAny(new char[] { '*', '?' }) == -1)
                {
                    if (exclusionList.ContainsKey(source))
                    {
                        continue;
                    }

                    srcLower = source.ToLower(CultureInfo.InvariantCulture);

                    if (srcLower.EndsWith(".htm") || srcLower.EndsWith(".html"))
                    {
                        tocEntry = BuildProcess.GetTocInfo(source);

                        // If not to be included in the TOC, don't add it
                        if (tocEntry.IncludePage)
                        {
                            tocEntry.SourceFile      = source;
                            tocEntry.DestinationFile = filename.Remove(0,
                                                                       rootPath.Length);
                            toc.Add(tocEntry);
                        }

                        if (tocEntry.IsDefaultTopic)
                        {
                            defaultTopic = tocEntry.DestinationFile;
                        }
                    }
                    else
                    {
                        tocEntry = null;
                    }

                    if (!previewing && !Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }

                    // If the file contains links that need to be resolved,
                    // it is handled separately.
                    if (!previewing && tocEntry != null &&
                        (tocEntry.HasLinks || tocEntry.HasCodeBlocks ||
                         tocEntry.NeedsColorizing || tocEntry.HasProjectTags))
                    {
                        // Figure out the path to the root if needed
                        string[] parts = ci.DestinationPath.Split('\\');
                        pathToRoot = String.Empty;

                        for (int part = 0; part < parts.Length - 1; part++)
                        {
                            pathToRoot += "../";
                        }

                        this.ResolveLinksAndCopy(source, filename, tocEntry);
                    }
                    else
                    {
                        this.ReportProgress("{0} -> {1}", source, filename);

                        // All attributes are turned off so that we can delete
                        // it later.
                        if (!previewing)
                        {
                            File.Copy(source, filename, true);
                            File.SetAttributes(filename, FileAttributes.Normal);
                        }
                    }
                }
                else
                {
                    tocEntry = this.RecursiveContentCopy(previewing, source,
                                                         dirName);

                    if (tocEntry != null)
                    {
                        if (ci.DestinationPath.Length != 0)
                        {
                            toc.Add(tocEntry);
                        }
                        else
                        {
                            // If the content is copied to the root, just
                            // add the children to the TOC.
                            foreach (TocEntry te in tocEntry.Children)
                            {
                                toc.Add(te);
                            }
                        }
                    }
                }
            }

            // Sort the additional content entries into the proper order
            toc.Sort();

            codeColorizer = null;
            sharedContent = null;
            exclusionList = null;
        }
Пример #2
0
        //=====================================================================
        // Methods, etc.

        /// <summary>
        /// Constructor
        /// </summary>
        public TocEntry()
        {
            includePage = true;
            sortOrder   = Int32.MaxValue;
            children    = new TocEntryCollection();
        }