Example #1
0
        private void StartHelpAgent(BuildContext context)
        {
            if (ProcessRunner.IsProcessOpen("HelpLibAgent"))
            {
                return;
            }

            BuildLogger logger = context.Logger;

            if (logger != null)
            {
                logger.WriteLine("Starting: Microsoft Help Library Agent",
                                 BuildLoggerLevel.Info);
            }

            using (Process proc = new Process())
            {
                proc.EnableRaisingEvents = false;
                proc.StartInfo.FileName  = GetAgentLocation();
                proc.Start();
            }
        }
Example #2
0
        private bool OpenHelpFile(BuildContext context)
        {
            // 1. Start the Microsoft Help Library Agent process...
            StartHelpAgent(context);

            // 2. Wait for the help library service to be available...
            int waitCount = 0;

            while (!ProcessRunner.IsProcessOpen("HelpLibAgent"))
            {
                // We wait for a max of 5 times, should be enough on even slow
                // systems...
                if (waitCount >= 5)
                {
                    break;
                }

                waitCount++;
                Thread.Sleep(100);
            }

            BuildLogger logger = context.Logger;

            if (logger != null)
            {
                logger.WriteLine("Opening: " + _helpPath,
                                 BuildLoggerLevel.Info);
            }

            string helpUrlFormat =
                "ms-xhelp:///?method=page&id={0}&product={1}&productversion={2}&locale={3}";

            string helpUrl = null;
            // 3. The startup help ID will normally be saved in the context, get it...
            string helpStartId = context["$HelpTocRoot"];
            string tempText    = context["$HelpHierarchicalToc"];
            // If there is a custom format TOC, we use its root...
            BuildTocContext tocContext = context.TocContext;
            BuildFormatList formatList = context.Settings.Formats;
            FormatMhv       mhvFormat  = formatList[BuildFormatType.HtmlHelp3]
                                         as FormatMhv;
            string formatTocFile = tocContext.GetValue("$" + mhvFormat.Name);
            string formatTocRoot = tocContext.GetValue("$" + mhvFormat.Name +
                                                       "-HelpTocRoot");

            if (!(String.IsNullOrEmpty(formatTocFile) && File.Exists(formatTocFile)) &&
                !String.IsNullOrEmpty(formatTocRoot))
            {
                helpStartId = formatTocRoot;
            }
            else if (!String.IsNullOrEmpty(tempText) && String.Equals(tempText,
                                                                      Boolean.TrueString, StringComparison.OrdinalIgnoreCase))
            {
                helpStartId = context["$HelpHierarchicalTocRoot"];
            }

            if (String.IsNullOrEmpty(helpStartId))
            {
                helpUrl = String.Format(
                    "ms-xhelp:///?method=page&id=-1&format=html&product={0}&productVersion={1}",
                    _catalogProductId, _catalogVersion);
            }
            else
            {
                helpUrl = String.Format(helpUrlFormat,
                                        helpStartId, _catalogProductId, _catalogVersion, _catalogLocale);
            }

            try
            {
                // 4. Request the Microsoft Help Library Agent to open the page...
                Process startHelp = Process.Start(helpUrl);
                // The return could be null, if no process resource is started
                // (for example, if an existing process is reused as in browsers).
                if (startHelp != null)
                {
                    startHelp.Close();
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (logger != null)
                {
                    logger.WriteLine(ex, BuildLoggerLevel.Error);
                }

                return(false);
            }
        }
Example #3
0
        protected override bool OnExecute(BuildContext context)
        {
            BuildLogger logger = context.Logger;

            // 1. Perform the initial sanity checks...
            if (String.IsNullOrEmpty(_helpPath) || String.IsNullOrEmpty(_helpSetup) ||
                !File.Exists(_helpPath) || !File.Exists(_helpSetup))
            {
                if (logger != null)
                {
                    logger.WriteLine("The Microsoft Help Viewer help or setup file path is not provided or does not exist.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            // 2. Validate the Microsoft Help Viewer installation...
            this.ValidViewerInstallation(context);

            _helpLibAgentPath = GetAgentLocation();
            if (!File.Exists(_helpLibAgentPath))
            {
                if (logger != null)
                {
                    logger.WriteLine("The installed location of the Microsoft Help Viewer cannot be found.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            string viewerDir = Path.GetDirectoryName(_helpLibAgentPath);

            _helpLibManagerPath = Path.Combine(viewerDir, "HelpLibManager.exe");
            if (!File.Exists(_helpLibManagerPath))
            {
                if (logger != null)
                {
                    logger.WriteLine("The installed location of the Microsoft Help Viewer cannot be found.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            if (ProcessRunner.IsProcessOpen("HelpLibManager"))
            {
                if (logger != null)
                {
                    logger.WriteLine("The Microsoft Help Library Manager tool is currently running. The help cannot be installed.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            // Start the Microsoft Help Library Agent process.
            // This will ensure that it is ready and listening by the time we
            // opening the help page...
            StartHelpAgent(context);

            if (!this.UninstallHelpFile(context))
            {
                return(false);
            }
            if (!this.InstallHelpFile(context))
            {
                return(false);
            }

            return(OpenHelpFile(context));
        }