예제 #1
0
 public FormatChmEncoding(FormatChmOptions options)
 {
     _options        = options;
     _listEncoders   = new List <FormatChmEncoder>();
     _outputEncoding = Encoding.UTF8;
     _appSettings    = new BuildProperties();
 }
예제 #2
0
        public FormatChmHelper(FormatChmOptions options)
        {
            _defaultTopic = String.Empty;

            _options = options;
            _options.HtmlDirectory = StripEndBackSlash(Path.GetFullPath(
                                                           _options.HtmlDirectory));
            if (String.IsNullOrEmpty(_options.TocFile))
            {
                _hasToc = false;
            }
            else
            {
                _hasToc = File.Exists(_options.TocFile);
            }
            _options.OutputDirectory = StripEndBackSlash(Path.GetFullPath(
                                                             _options.OutputDirectory));
            _config = new XPathDocument(options.ConfigFile);

            LoadLanginfo(_options.LangID);
        }
예제 #3
0
        public override BuildStep CreateStep(BuildContext context,
                                             BuildStage stage, string workingDir)
        {
            if (context == null || context.Settings == null)
            {
                return(null);
            }

            // Accessing the property will force a lookup for the compiler...
            BuildFilePath helpCompiler = this.CompilerFile;

            if (helpCompiler == null || !helpCompiler.Exists)
            {
                throw new BuildException(
                          "The CHM format compiler cannot be found. If installed, manually set its path.");
            }

            BuildSettings settings = context.Settings;

            string helpDirectory = context.OutputDirectory;

            if (String.IsNullOrEmpty(workingDir))
            {
                workingDir = context.WorkingDirectory;
            }

            string helpName = settings.HelpName;

            if (String.IsNullOrEmpty(helpName))
            {
                helpName = "Documentation";
            }
            string helpTitle = settings.HelpTitle;

            if (String.IsNullOrEmpty(helpTitle))
            {
                helpTitle = helpName;
            }
            string helpFolder = this.OutputFolder;
            string helpPath   = Path.Combine(helpDirectory,
                                             String.Format(@"{0}\{1}.chm", helpFolder, helpName));

            // Case 1: Closing the HtmlHelp 1.x viewer...
            if (stage == BuildStage.CloseViewer)
            {
                StepChmViewerClose chmClose = new StepChmViewerClose(
                    helpDirectory, helpPath, helpTitle);

                return(chmClose);
            }

            // Case 2: Starting the HtmlHelp 1.x viewer...
            if (stage == BuildStage.StartViewer)
            {
                StepChmViewerStart chmStart = new StepChmViewerStart(
                    helpDirectory, helpPath);

                return(chmStart);
            }

            // Case 3: Compiling the HtmlHelp 1.x help file...
            if (stage == BuildStage.Compilation)
            {
                string      sandassistDir = settings.SandAssistDirectory;
                CultureInfo culture       = settings.CultureInfo;
                int         lcid          = 1033;
                if (culture != null)
                {
                    lcid = culture.LCID;
                }
                string appLocale = null;
                if (lcid != 1033)
                {
                    string toolsDir = Path.Combine(sandassistDir, "Tools");
                    if (Directory.Exists(toolsDir))
                    {
                        appLocale = Path.Combine(toolsDir, "SBAppLocale.exe");
                    }
                }

                // If there is a customized or format specific TOC use it,
                // otherwise, use the default...
                string tocFile = context["$HelpTocFile"];

                FormatChmOptions options = new FormatChmOptions();
                options.ConfigFile       = Path.Combine(workingDir, "ChmBuilder.config");
                options.HtmlDirectory    = Path.Combine(workingDir, @"Output\html");
                options.LangID           = lcid;
                options.Metadata         = false;
                options.WorkingDirectory = workingDir;
                options.OutputDirectory  = Path.Combine(workingDir, helpFolder);
                options.ProjectName      = helpName;
                options.TocFile          = Path.Combine(workingDir, tocFile);

                BuildMultiStep listSteps = new BuildMultiStep();
                listSteps.LogTitle    = "Building document output format - " + this.Name;
                listSteps.LogTimeSpan = true;

                // 1. Prepare the help html files, and create the html project
                // ChmBuilder.exe
                // /project:Manual /html:Output\html
                //   /lcid:1041 /toc:Toc.xml /out:Help
                string application = Path.Combine(context.SandcastleToolsDirectory,
                                                  "ChmBuilder.exe");
                string arguments = String.Format(
                    "/project:{0} /html:Output\\html /lcid:{1} /toc:{2} /out:{3} /config:ChmBuilder.config",
                    helpName, lcid, tocFile, helpFolder);
                StepChmBuilder chmProcess = new StepChmBuilder(workingDir,
                                                               application, arguments);
                chmProcess.LogTitle        = String.Empty;
                chmProcess.Message         = "Creating project and HTML files for the compiler";
                chmProcess.CopyrightNotice = 2;
                chmProcess.HelpName        = helpName;
                chmProcess.HelpFolder      = helpFolder;
                chmProcess.HelpDirectory   = helpDirectory;
                chmProcess.Options         = options;
                chmProcess.OptimizeStyle   = this.OptimizeStyle;
                chmProcess.Format          = this;

                listSteps.Add(chmProcess);

                // 2. Fix the file encoding: DBCSFix.exe /d:Help /l:1033
                application = Path.Combine(context.SandcastleToolsDirectory,
                                           "DBCSFix.exe");
                arguments = String.Format("/d:{0} /l:{1}", helpFolder + @"\html", lcid);
                StepChmDbcsFix dbcsFixProcess = new StepChmDbcsFix(workingDir,
                                                                   application, arguments);
                dbcsFixProcess.LogTitle        = String.Empty;
                dbcsFixProcess.Message         = "Fixing the DBCS for the non-Unicode compiler";
                dbcsFixProcess.CopyrightNotice = 2;
                dbcsFixProcess.Options         = options;

                listSteps.Add(dbcsFixProcess);

                // 3. Compile the Html help files: hhc Help\Manual.hhp
                application = helpCompiler.Path;
                arguments   = String.Format(@"{0}\{1}.hhp", helpFolder, helpName);
                if (String.IsNullOrEmpty(appLocale) == false &&
                    File.Exists(appLocale))
                {
                    arguments = String.Format("$({0}) \"{1}\" {2}", lcid, application,
                                              arguments);
                    application = appLocale;
                }
                StepChmCompiler hhcProcess = new StepChmCompiler(workingDir,
                                                                 application, arguments);
                hhcProcess.LogTitle        = String.Empty;
                hhcProcess.Message         = "Compiling HtmlHelp 1.x help file";
                hhcProcess.CopyrightNotice = 2;
                hhcProcess.KeepSources     = _keepSources;
                hhcProcess.HelpName        = helpName;
                hhcProcess.HelpFolder      = helpFolder;
                hhcProcess.HelpDirectory   = helpDirectory;

                listSteps.Add(hhcProcess);

                return(listSteps);
            }

            return(null);
        }