/// <summary>
        /// View the last built help output
        /// </summary>
        /// <param name="project">The project to use or null to use the current project</param>
        /// <param name="commandId">The ID of the command that invoked the request which determines the help
        /// file format launched.  Zero is used for markdown content since there is no viewer for it.</param>
        private static void ViewBuiltHelpFile(SandcastleProject project, uint commandId)
        {
            string outputPath;

            if(project == null)
            {
                project = CurrentSandcastleProject;

                if(project == null)
                    return;
            }

            // Make sure we start out in the project's output folder in case the output folder is relative to it
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Path.GetFullPath(project.Filename)));
            outputPath = project.OutputPath;

            if(String.IsNullOrEmpty(outputPath))
                outputPath = Directory.GetCurrentDirectory();
            else
                outputPath = Path.GetFullPath(outputPath);

            if(commandId == PkgCmdIDList.ViewHtmlHelp)
                outputPath += project.HtmlHelpName + ".chm";
            else
                if(commandId == PkgCmdIDList.ViewDocxHelp)
                    outputPath += project.HtmlHelpName + ".docx";
                else
                    if(commandId == 0)
                        outputPath += "_Sidebar.md";
                    else
                        outputPath += "Index.html";

            // If there are substitution tags present, have a go at resolving them
            if(outputPath.IndexOf("{@", StringComparison.Ordinal) != -1)
            {
                try
                {
                    var bp = new SandcastleBuilder.Utils.BuildEngine.BuildProcess(project);
                    outputPath = bp.SubstitutionTags.TransformText(outputPath);
                }
                catch
                {
                    // Ignore errors
                    Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_WARNING, "The help filename appears to " +
                        "contain substitution tags but they could not be resolved to determine the actual " +
                        "file to open for viewing.  Building website output and viewing it can be used to " +
                        "work around this issue.");
                    return;
                }
            }

            if(!File.Exists(outputPath))
            {
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_INFO, "A copy of the help file does not appear " +
                    "to exist yet.  It may need to be built.");
                return;
            }

            try
            {
                if(outputPath.EndsWith(".chm", StringComparison.OrdinalIgnoreCase) ||
                    outputPath.EndsWith(".docx", StringComparison.OrdinalIgnoreCase))
                    System.Diagnostics.Process.Start(outputPath);
                else
                    if(outputPath.EndsWith(".md", StringComparison.OrdinalIgnoreCase))
                    {
                        var dte = Utility.GetServiceFromPackage<DTE, SDTE>(true);

                        if(dte != null)
                        {
                            var doc = dte.ItemOperations.OpenFile(outputPath, EnvDTE.Constants.vsViewKindPrimary);

                            if(doc != null)
                                doc.Activate();
                        }
                    }
                    else
                        Utility.OpenUrl(outputPath);
            }
            catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_CRITICAL, "Unable to open help file '{0}'\r\n" +
                    "Reason: {1}", outputPath, ex.Message);
            }
        }
        /// <summary>
        /// View the last build HTML Help 1 file, MS Help 2 file, or website Index.html page
        /// </summary>
        /// <param name="project">The project to use or null to use the current project</param>
        /// <param name="commandId">The ID of the command that invoked the request which determines the help
        /// file format launched.</param>
        private void ViewBuiltHelpFile(SandcastleProject project, uint commandId)
        {
            string outputPath, help2Viewer = null;

            if(project == null)
            {
                project = CurrentSandcastleProject;

                if(project == null)
                    return;
            }

            var options = this.GeneralOptions;

            if(options != null)
                help2Viewer = options.HxsViewerPath;

            // Make sure we start out in the project's output folder in case the output folder is relative to it
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Path.GetFullPath(project.Filename)));
            outputPath = project.OutputPath;

            if(String.IsNullOrEmpty(outputPath))
                outputPath = Directory.GetCurrentDirectory();
            else
                outputPath = Path.GetFullPath(outputPath);

            if(commandId == PkgCmdIDList.ViewHtmlHelp)
                outputPath += project.HtmlHelpName + ".chm";
            else
                if(commandId == PkgCmdIDList.ViewHxSHelp)
                {
                    outputPath += project.HtmlHelpName + ".hxs";

                    if(String.IsNullOrEmpty(help2Viewer) || !File.Exists(help2Viewer))
                    {
                        Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_WARNING, "MS Help 2 files must be registered in a " +
                            "collection to be viewed or you can use a standalone viewer.  Use Tools | Options | Sandcastle " +
                            "Help File Builder to define a standalone viewer.  See Links to Resources in the help file if " +
                            "you need one.");
                        return;
                    }
                }
                else
                    if(commandId == PkgCmdIDList.ViewDocxHelp)
                        outputPath += project.HtmlHelpName + ".docx";
                    else
                        outputPath += "Index.html";

            // If there are substitution tags present, have a go at resolving them
            if(outputPath.IndexOf("{@", StringComparison.Ordinal) != -1)
            {
                try
                {
                    var bp = new SandcastleBuilder.Utils.BuildEngine.BuildProcess(project);
                    outputPath = bp.TransformText(outputPath);
                }
                catch
                {
                    // Ignore errors
                    Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_WARNING, "The help filename appears to " +
                        "contain substitution tags but they could not be resolved to determine the actual " +
                        "file to open for viewing.  Building website output and viewing it can be used to " +
                        "work around this issue.");
                    return;
                }
            }

            if(!File.Exists(outputPath))
            {
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_INFO, "A copy of the help file does not appear " +
                    "to exist yet.  It may need to be built.");
                return;
            }

            try
            {
                if(outputPath.EndsWith(".hxs", StringComparison.OrdinalIgnoreCase))
                    System.Diagnostics.Process.Start(help2Viewer, outputPath);
                else
                    if(outputPath.EndsWith(".chm", StringComparison.OrdinalIgnoreCase) ||
                      outputPath.EndsWith(".docx", StringComparison.OrdinalIgnoreCase))
                        System.Diagnostics.Process.Start(outputPath);
                    else
                        Utility.OpenUrl(outputPath);
            }
            catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_CRITICAL, "Unable to open help file '{0}'\r\n" +
                    "Reason: {1}", outputPath, ex.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// View the last build HTML Help 1 file, MS Help 2 file, or website Index.html page
        /// </summary>
        /// <param name="project">The project to use or null to use the current project</param>
        /// <param name="commandId">The ID of the command that invoked the request which determines the help
        /// file format launched.</param>
        private void ViewBuiltHelpFile(SandcastleProject project, uint commandId)
        {
            string outputPath, help2Viewer = null;

            if (project == null)
            {
                project = CurrentSandcastleProject;

                if (project == null)
                {
                    return;
                }
            }

            var options = this.GeneralOptions;

            if (options != null)
            {
                help2Viewer = options.HxsViewerPath;
            }

            // Make sure we start out in the project's output folder in case the output folder is relative to it
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Path.GetFullPath(project.Filename)));
            outputPath = project.OutputPath;

            if (String.IsNullOrEmpty(outputPath))
            {
                outputPath = Directory.GetCurrentDirectory();
            }
            else
            {
                outputPath = Path.GetFullPath(outputPath);
            }

            if (commandId == PkgCmdIDList.ViewHtmlHelp)
            {
                outputPath += project.HtmlHelpName + ".chm";
            }
            else
            if (commandId == PkgCmdIDList.ViewHxSHelp)
            {
                outputPath += project.HtmlHelpName + ".hxs";

                if (String.IsNullOrEmpty(help2Viewer) || !File.Exists(help2Viewer))
                {
                    Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_WARNING, "MS Help 2 files must be registered in a " +
                                           "collection to be viewed or you can use a standalone viewer.  Use Tools | Options | Sandcastle " +
                                           "Help File Builder to define a standalone viewer.  See Links to Resources in the help file if " +
                                           "you need one.");
                    return;
                }
            }
            else
            if (commandId == PkgCmdIDList.ViewDocxHelp)
            {
                outputPath += project.HtmlHelpName + ".docx";
            }
            else
            {
                outputPath += "Index.html";
            }

            // If there are substitution tags present, have a go at resolving them
            if (outputPath.IndexOf("{@", StringComparison.Ordinal) != -1)
            {
                try
                {
                    var bp = new SandcastleBuilder.Utils.BuildEngine.BuildProcess(project);
                    outputPath = bp.TransformText(outputPath);
                }
                catch
                {
                    // Ignore errors
                    Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_WARNING, "The help filename appears to " +
                                           "contain substitution tags but they could not be resolved to determine the actual " +
                                           "file to open for viewing.  Building website output and viewing it can be used to " +
                                           "work around this issue.");
                    return;
                }
            }

            if (!File.Exists(outputPath))
            {
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_INFO, "A copy of the help file does not appear " +
                                       "to exist yet.  It may need to be built.");
                return;
            }

            try
            {
                if (outputPath.EndsWith(".hxs", StringComparison.OrdinalIgnoreCase))
                {
                    System.Diagnostics.Process.Start(help2Viewer, outputPath);
                }
                else
                if (outputPath.EndsWith(".chm", StringComparison.OrdinalIgnoreCase) ||
                    outputPath.EndsWith(".docx", StringComparison.OrdinalIgnoreCase))
                {
                    System.Diagnostics.Process.Start(outputPath);
                }
                else
                {
                    Utility.OpenUrl(outputPath);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_CRITICAL, "Unable to open help file '{0}'\r\n" +
                                       "Reason: {1}", outputPath, ex.Message);
            }
        }
Пример #4
0
        /// <summary>
        /// This is used to determine the state of the help content and set the form options when a help viewer
        /// version is selected.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void cboHelpViewerVersion_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtInfo.Text = null;

            grpOptions.Enabled = rbInstall.Enabled = true;
            lastVersionSelected = cboHelpViewerVersion.SelectedIndex;

            // If there are substitution tags present, have a go at resolving them
            if(helpFilePath.IndexOf("{@", StringComparison.Ordinal) != -1)
            {
                try
                {
                    var bp = new SandcastleBuilder.Utils.BuildEngine.BuildProcess(project);
                    helpFilePath = bp.SubstitutionTags.TransformText(helpFilePath);
                    setupFile = Path.ChangeExtension(helpFilePath, ".msha");
                }
                catch
                {
                    // Ignore errors
                    txtInfo.AppendText("The help filename appears to contain substitution tags but they could " +
                        "not be resolved to determine the actual file to use for installation.  Building " +
                        "website output and viewing it can be used to work around this issue.\r\n\r\n");
                    rbInstall.Enabled = false;
                }
            }

            if(rbInstall.Enabled && (!File.Exists(helpFilePath) || !File.Exists(setupFile)))
            {
                txtInfo.AppendText("A copy of the help file does not appear to exist yet.  It may need to be built.\r\n\r\n");
                rbInstall.Enabled = false;
            }

            try
            {
                viewerVersion = new Version((string)cboHelpViewerVersion.SelectedItem);

                HelpLibraryManager hlm = new HelpLibraryManager(viewerVersion);

                // Can't do anything if the Help Library Manager is not installed
                if(hlm.HelpLibraryManagerPath == null)
                    throw new HelpLibraryManagerException(viewerVersion,
                        HelpLibraryManagerException.HelpLibraryManagerNotFound);

                // Can't do anything if the Help Library Manager is already running
                if(Process.GetProcessesByName(Path.GetFileNameWithoutExtension(hlm.HelpLibraryManagerPath)).Length > 0)
                    throw new HelpLibraryManagerException(viewerVersion,
                        HelpLibraryManagerException.HelpLibraryManagerAlreadyRunning);

                // Can't do anything if the local store is not initialized
                if(!hlm.LocalStoreInitialized)
                    throw new HelpLibraryManagerException(viewerVersion,
                        HelpLibraryManagerException.LocalStoreNotInitialized);

                if(hlm.HelpContentFileInstalled(helpFilePath))
                    rbOpenCurrent.Enabled = rbRemove.Enabled = true;
                else
                {
                    txtInfo.AppendText("The help file does not appear to be installed yet.\r\n");
                    rbOpenCurrent.Enabled = rbRemove.Enabled = false;
                }
            }
            catch(Exception ex)
            {
                txtInfo.AppendText("Problem: " + ex.Message + "\r\n");
                rbOpenCurrent.Enabled = rbRemove.Enabled = false;
            }

            if(rbOpenCurrent.Enabled)
                rbOpenCurrent.Checked = true;
            else
                if(rbInstall.Enabled)
                    rbInstall.Checked = true;
                else
                    rbLaunchContentManager.Checked = true;

            if(!rbOpenCurrent.Enabled && !rbInstall.Enabled && !rbRemove.Enabled)
                txtInfo.AppendText("\r\nNo action can be taken with the help content.");

            // Determine the catalog name here as it's used in a lot of places and varies by version if not
            // defined in the project.
            catalogName = !String.IsNullOrWhiteSpace(project.CatalogName) ? project.CatalogName :
                HelpLibraryManager.DefaultCatalogName(viewerVersion);

            // If it looks like a default value, warn the user if it doesn't match.  It may need to be cleared.
            if(!String.IsNullOrWhiteSpace(project.CatalogName) && project.CatalogName.StartsWith("VisualStudio",
              StringComparison.Ordinal) && project.CatalogName != HelpLibraryManager.DefaultCatalogName(viewerVersion))
                txtInfo.AppendText("\r\n\r\nWARNING:  The project's catalog name property is set to '" +
                    project.CatalogName + "' which does not match the default catalog name for the selected " +
                    "version of the help viewer.  If necessary, clear the catalog name property value.");
        }
        /// <summary>
        /// This is used to determine the state of the help content and set the form options when a help viewer
        /// version is selected.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void cboHelpViewerVersion_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtInfo.Text = null;

            grpOptions.Enabled  = rbInstall.Enabled = true;
            lastVersionSelected = cboHelpViewerVersion.SelectedIndex;

            // If there are substitution tags present, have a go at resolving them
            if (helpFilePath.IndexOf("{@", StringComparison.Ordinal) != -1)
            {
                try
                {
                    var bp = new SandcastleBuilder.Utils.BuildEngine.BuildProcess(project);
                    helpFilePath = bp.TransformText(helpFilePath);
                    setupFile    = Path.ChangeExtension(helpFilePath, ".msha");
                }
                catch
                {
                    // Ignore errors
                    txtInfo.AppendText("The help filename appears to contain substitution tags but they could " +
                                       "not be resolved to determine the actual file to use for installation.  Building " +
                                       "website output and viewing it can be used to work around this issue.\r\n\r\n");
                    rbInstall.Enabled = false;
                }
            }

            if (rbInstall.Enabled && (!File.Exists(helpFilePath) || !File.Exists(setupFile)))
            {
                txtInfo.AppendText("A copy of the help file does not appear to exist yet.  It may need to be built.\r\n\r\n");
                rbInstall.Enabled = false;
            }

            try
            {
                viewerVersion = new Version((string)cboHelpViewerVersion.SelectedItem);

                HelpLibraryManager hlm = new HelpLibraryManager(viewerVersion);

                // Can't do anything if the Help Library Manager is not installed
                if (hlm.HelpLibraryManagerPath == null)
                {
                    throw new HelpLibraryManagerException(viewerVersion,
                                                          HelpLibraryManagerException.HelpLibraryManagerNotFound);
                }

                // Can't do anything if the Help Library Manager is already running
                if (Process.GetProcessesByName(Path.GetFileNameWithoutExtension(hlm.HelpLibraryManagerPath)).Length > 0)
                {
                    throw new HelpLibraryManagerException(viewerVersion,
                                                          HelpLibraryManagerException.HelpLibraryManagerAlreadyRunning);
                }

                // Can't do anything if the local store is not initialized
                if (!hlm.LocalStoreInitialized)
                {
                    throw new HelpLibraryManagerException(viewerVersion,
                                                          HelpLibraryManagerException.LocalStoreNotInitialized);
                }

                if (hlm.HelpContentFileInstalled(helpFilePath))
                {
                    rbOpenCurrent.Enabled = rbRemove.Enabled = true;
                }
                else
                {
                    txtInfo.AppendText("The help file does not appear to be installed yet.\r\n");
                    rbOpenCurrent.Enabled = rbRemove.Enabled = false;
                }

                if (rbOpenCurrent.Enabled)
                {
                    rbOpenCurrent.Checked = true;
                }
                else
                if (rbInstall.Enabled)
                {
                    rbInstall.Checked = true;
                }

                btnOK.Enabled = (rbOpenCurrent.Enabled || rbInstall.Enabled || rbRemove.Enabled);
            }
            catch (Exception ex)
            {
                txtInfo.AppendText("Problem: " + ex.Message + "\r\n");
                btnOK.Enabled = false;
            }

            if (!btnOK.Enabled)
            {
                txtInfo.AppendText("\r\nNo action can be taken.");
            }
        }
Пример #6
0
        /// <summary>
        /// View the last built help output
        /// </summary>
        /// <param name="project">The project to use or null to use the current project</param>
        /// <param name="commandId">The ID of the command that invoked the request which determines the help
        /// file format launched.  Zero is used for markdown content since there is no viewer for it.</param>
        private static void ViewBuiltHelpFile(SandcastleProject project, uint commandId)
        {
            string outputPath;

            if (project == null)
            {
                project = CurrentSandcastleProject;

                if (project == null)
                {
                    return;
                }
            }

            // Make sure we start out in the project's output folder in case the output folder is relative to it
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Path.GetFullPath(project.Filename)));
            outputPath = project.OutputPath;

            if (String.IsNullOrEmpty(outputPath))
            {
                outputPath = Directory.GetCurrentDirectory();
            }
            else
            {
                outputPath = Path.GetFullPath(outputPath);
            }

            if (commandId == PkgCmdIDList.ViewHtmlHelp)
            {
                outputPath += project.HtmlHelpName + ".chm";
            }
            else
            if (commandId == PkgCmdIDList.ViewDocxHelp)
            {
                outputPath += project.HtmlHelpName + ".docx";
            }
            else
            if (commandId == 0)
            {
                outputPath += "_Sidebar.md";
            }
            else
            {
                outputPath += "Index.html";
            }

            // If there are substitution tags present, have a go at resolving them
            if (outputPath.IndexOf("{@", StringComparison.Ordinal) != -1)
            {
                try
                {
                    var bp = new SandcastleBuilder.Utils.BuildEngine.BuildProcess(project);
                    outputPath = bp.SubstitutionTags.TransformText(outputPath);
                }
                catch
                {
                    // Ignore errors
                    Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_WARNING, "The help filename appears to " +
                                           "contain substitution tags but they could not be resolved to determine the actual " +
                                           "file to open for viewing.  Building website output and viewing it can be used to " +
                                           "work around this issue.");
                    return;
                }
            }

            if (!File.Exists(outputPath))
            {
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_INFO, "A copy of the help file does not appear " +
                                       "to exist yet.  It may need to be built.");
                return;
            }

            try
            {
                if (outputPath.EndsWith(".chm", StringComparison.OrdinalIgnoreCase) ||
                    outputPath.EndsWith(".docx", StringComparison.OrdinalIgnoreCase))
                {
                    System.Diagnostics.Process.Start(outputPath);
                }
                else
                if (outputPath.EndsWith(".md", StringComparison.OrdinalIgnoreCase))
                {
                    var dte = Utility.GetServiceFromPackage <DTE, SDTE>(true);

                    if (dte != null)
                    {
                        var doc = dte.ItemOperations.OpenFile(outputPath, EnvDTE.Constants.vsViewKindPrimary);

                        if (doc != null)
                        {
                            doc.Activate();
                        }
                    }
                }
                else
                {
                    Utility.OpenUrl(outputPath);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_CRITICAL, "Unable to open help file '{0}'\r\n" +
                                       "Reason: {1}", outputPath, ex.Message);
            }
        }
Пример #7
0
        /// <summary>
        /// This is used to determine the state of the help content and set the form options when a help viewer
        /// version is selected.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void cboHelpViewerVersion_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtInfo.Text = null;

            grpOptions.Enabled = rbInstall.Enabled = true;
            lastVersionSelected = cboHelpViewerVersion.SelectedIndex;

            // If there are substitution tags present, have a go at resolving them
            if(helpFilePath.IndexOf("{@", StringComparison.Ordinal) != -1)
            {
                try
                {
                    var bp = new SandcastleBuilder.Utils.BuildEngine.BuildProcess(project);
                    helpFilePath = bp.TransformText(helpFilePath);
                    setupFile = Path.ChangeExtension(helpFilePath, ".msha");
                }
                catch
                {
                    // Ignore errors
                    txtInfo.AppendText("The help filename appears to contain substitution tags but they could " +
                        "not be resolved to determine the actual file to use for installation.  Building " +
                        "website output and viewing it can be used to work around this issue.\r\n\r\n");
                    rbInstall.Enabled = false;
                }
            }

            if(rbInstall.Enabled && (!File.Exists(helpFilePath) || !File.Exists(setupFile)))
            {
                txtInfo.AppendText("A copy of the help file does not appear to exist yet.  It may need to be built.\r\n\r\n");
                rbInstall.Enabled = false;
            }

            try
            {
                viewerVersion = new Version((string)cboHelpViewerVersion.SelectedItem);

                HelpLibraryManager hlm = new HelpLibraryManager(viewerVersion);

                // Can't do anything if the Help Library Manager is not installed
                if(hlm.HelpLibraryManagerPath == null)
                    throw new HelpLibraryManagerException(viewerVersion,
                        HelpLibraryManagerException.HelpLibraryManagerNotFound);

                // Can't do anything if the Help Library Manager is already running
                if(Process.GetProcessesByName(Path.GetFileNameWithoutExtension(hlm.HelpLibraryManagerPath)).Length > 0)
                    throw new HelpLibraryManagerException(viewerVersion,
                        HelpLibraryManagerException.HelpLibraryManagerAlreadyRunning);

                // Can't do anything if the local store is not initialized
                if(!hlm.LocalStoreInitialized)
                    throw new HelpLibraryManagerException(viewerVersion,
                        HelpLibraryManagerException.LocalStoreNotInitialized);

                if(hlm.HelpContentFileInstalled(helpFilePath))
                    rbOpenCurrent.Enabled = rbRemove.Enabled = true;
                else
                {
                    txtInfo.AppendText("The help file does not appear to be installed yet.\r\n");
                    rbOpenCurrent.Enabled = rbRemove.Enabled = false;
                }

                if(rbOpenCurrent.Enabled)
                    rbOpenCurrent.Checked = true;
                else
                    if(rbInstall.Enabled)
                        rbInstall.Checked = true;

                btnOK.Enabled = (rbOpenCurrent.Enabled || rbInstall.Enabled || rbRemove.Enabled);
            }
            catch(Exception ex)
            {
                txtInfo.AppendText("Problem: " + ex.Message + "\r\n");
                btnOK.Enabled = false;
            }

            if(!btnOK.Enabled)
                txtInfo.AppendText("\r\nNo action can be taken.");
        }
Пример #8
0
        /// <summary>
        /// This is used to determine the state of the help content and set the form options when a help viewer
        /// version is selected.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void cboHelpViewerVersion_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtInfo.Text = null;

            grpOptions.Enabled  = rbInstall.Enabled = true;
            lastVersionSelected = cboHelpViewerVersion.SelectedIndex;

            // If there are substitution tags present, have a go at resolving them
            if (helpFilePath.IndexOf("{@", StringComparison.Ordinal) != -1)
            {
                try
                {
                    var bp = new SandcastleBuilder.Utils.BuildEngine.BuildProcess(project);
                    helpFilePath = bp.TransformText(helpFilePath);
                    setupFile    = Path.ChangeExtension(helpFilePath, ".msha");
                }
                catch
                {
                    // Ignore errors
                    txtInfo.AppendText("The help filename appears to contain substitution tags but they could " +
                                       "not be resolved to determine the actual file to use for installation.  Building " +
                                       "website output and viewing it can be used to work around this issue.\r\n\r\n");
                    rbInstall.Enabled = false;
                }
            }

            if (rbInstall.Enabled && (!File.Exists(helpFilePath) || !File.Exists(setupFile)))
            {
                txtInfo.AppendText("A copy of the help file does not appear to exist yet.  It may need to be built.\r\n\r\n");
                rbInstall.Enabled = false;
            }

            try
            {
                viewerVersion = new Version((string)cboHelpViewerVersion.SelectedItem);

                HelpLibraryManager hlm = new HelpLibraryManager(viewerVersion);

                // Can't do anything if the Help Library Manager is not installed
                if (hlm.HelpLibraryManagerPath == null)
                {
                    throw new HelpLibraryManagerException(viewerVersion,
                                                          HelpLibraryManagerException.HelpLibraryManagerNotFound);
                }

                // Can't do anything if the Help Library Manager is already running
                if (Process.GetProcessesByName(Path.GetFileNameWithoutExtension(hlm.HelpLibraryManagerPath)).Length > 0)
                {
                    throw new HelpLibraryManagerException(viewerVersion,
                                                          HelpLibraryManagerException.HelpLibraryManagerAlreadyRunning);
                }

                // Can't do anything if the local store is not initialized
                if (!hlm.LocalStoreInitialized)
                {
                    throw new HelpLibraryManagerException(viewerVersion,
                                                          HelpLibraryManagerException.LocalStoreNotInitialized);
                }

                if (hlm.HelpContentFileInstalled(helpFilePath))
                {
                    rbOpenCurrent.Enabled = rbRemove.Enabled = true;
                }
                else
                {
                    txtInfo.AppendText("The help file does not appear to be installed yet.\r\n");
                    rbOpenCurrent.Enabled = rbRemove.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                txtInfo.AppendText("Problem: " + ex.Message + "\r\n");
                rbOpenCurrent.Enabled = rbRemove.Enabled = false;
            }

            if (rbOpenCurrent.Enabled)
            {
                rbOpenCurrent.Checked = true;
            }
            else
            if (rbInstall.Enabled)
            {
                rbInstall.Checked = true;
            }
            else
            {
                rbLaunchContentManager.Checked = true;
            }

            if (!rbOpenCurrent.Enabled && !rbInstall.Enabled && !rbRemove.Enabled)
            {
                txtInfo.AppendText("\r\nNo action can be taken with the help content.");
            }

            // Determine the catalog name here as it's used in a lot of places and varies by version if not
            // defined in the project.
            catalogName = !String.IsNullOrWhiteSpace(project.CatalogName) ? project.CatalogName :
                          HelpLibraryManager.DefaultCatalogName(viewerVersion);

            // If it looks like a default value, warn the user if it doesn't match.  It may need to be cleared.
            if (!String.IsNullOrWhiteSpace(project.CatalogName) && project.CatalogName.StartsWith("VisualStudio",
                                                                                                  StringComparison.Ordinal) && project.CatalogName != HelpLibraryManager.DefaultCatalogName(viewerVersion))
            {
                txtInfo.AppendText("\r\n\r\nWARNING:  The project's catalog name property is set to '" +
                                   project.CatalogName + "' which does not match the default catalog name for the selected " +
                                   "version of the help viewer.  If necessary, clear the catalog name property value.");
            }
        }