예제 #1
0
        /// <summary>
        /// Launch the Launch Help Viewer 2.x Content Manager for interactive use based on the current project's
        /// settings.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void LaunchContentMgrExecuteHandler(object sender, EventArgs e)
        {
            Version version;

            try
            {
                SandcastleProject project = CurrentSandcastleProject;

                if (project != null)
                {
                    if (project.CatalogName == "VisualStudio11")
                    {
                        version = new Version(2, 0);
                    }
                    else
                    {
                        version = new Version(2, 1);
                    }

                    HelpLibraryManager hlm = new HelpLibraryManager(version);

                    hlm.LaunchInteractive(String.Format(CultureInfo.InvariantCulture,
                                                        "/catalogName \"{0}\" /locale {1} /manage", project.CatalogName, project.Language.Name));
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_CRITICAL, "Unable to launch Help Viewer 2.x " +
                                       "Content Manager.  Reason:\r\n{0}\r\n\r\nIs the catalog name correct in the project?",
                                       ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Launch the Help Library Manager 1.0 for interactive use based on the current project's settings
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void LaunchHelpLibMgrExecuteHandler(object sender, EventArgs e)
        {
            try
            {
                SandcastleProject project = CurrentSandcastleProject;

                if (project != null)
                {
                    HelpLibraryManager hlm = new HelpLibraryManager();

                    hlm.LaunchInteractive(String.Format(CultureInfo.InvariantCulture,
                                                        "/product \"{0}\" /version \"{1}\" /locale {2}", project.CatalogProductId,
                                                        project.CatalogVersion, project.Language.Name));
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Utility.ShowMessageBox(OLEMSGICON.OLEMSGICON_CRITICAL,
                                       "Unable to launch Help Library Manager.  Reason:\r\n{0}", ex.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// This performs the requested task
        /// </summary>
        /// <param name="action">The action to perform</param>
        private void PerformHelpViewerAction(HelpViewerAction action)
        {
            string arguments, contentSetupFile;
            int    errorCode;

            HelpLibraryManager hlm = new HelpLibraryManager(viewerVersion);

            cancellationTokenSource.Token.ThrowIfCancellationRequested();

            // Remove old content.  We'll remove it if installing to be sure that the latest copy is
            // installed.
            if (action == HelpViewerAction.Install || action == HelpViewerAction.Remove)
            {
                if (action == HelpViewerAction.Install)
                {
                    helpViewerProgress.Report("Removing old help content...");
                }
                else
                {
                    helpViewerProgress.Report("Removing help content...");
                }

                if (viewerVersion.Major == 1)
                {
                    arguments = String.Format(CultureInfo.InvariantCulture,
                                              "/product \"{0}\" /version \"{1}\" /locale {2} /uninstall /silent /vendor " +
                                              "\"{3}\" /productName \"{4}\" /mediaBookList \"{5}\"",
                                              project.CatalogProductId, project.CatalogVersion, project.Language.Name,
                                              !String.IsNullOrEmpty(project.VendorName) ? project.VendorName : "Vendor Name",
                                              !String.IsNullOrEmpty(project.ProductTitle) ? project.ProductTitle : project.HelpTitle,
                                              project.HelpTitle);
                }
                else
                {
                    arguments = String.Format(CultureInfo.InvariantCulture,
                                              "/catalogName \"{0}\" /locale {1} /wait 0 /operation uninstall /vendor \"{2}\" " +
                                              "/productName \"{3}\" /bookList \"{4}\" ", catalogName, project.Language.Name,
                                              !String.IsNullOrEmpty(project.VendorName) ? project.VendorName : "Vendor Name",
                                              !String.IsNullOrEmpty(project.ProductTitle) ? project.ProductTitle : project.HelpTitle,
                                              project.HelpTitle);
                }

                // If there are substitution tags present, have a go at resolving them
                if (arguments.IndexOf("{@", StringComparison.Ordinal) != -1)
                {
                    try
                    {
                        var bp = new BuildProcess(project);
                        arguments = bp.SubstitutionTags.TransformText(arguments);
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException("Unable to transform substitution tags: " +
                                                            ex.Message, ex);
                    }
                }

                // This doesn't have to run as an administrator
                errorCode = hlm.RunAsNormalUser(arguments, ProcessWindowStyle.Minimized);

                // Ignore it if not found and we are installing
                if (errorCode != HelpLibraryManagerException.Success &&
                    (errorCode != HelpLibraryManagerException.NoBooksToInstall || action == HelpViewerAction.Remove))
                {
                    throw new HelpLibraryManagerException(viewerVersion, errorCode);
                }
            }

            cancellationTokenSource.Token.ThrowIfCancellationRequested();

            if (action == HelpViewerAction.Install)
            {
                // Install the new content
                helpViewerProgress.Report("Installing help content...");

                // Copy the MSHA file to the required name
                contentSetupFile = Path.Combine(Path.GetDirectoryName(setupFile), "HelpContentSetup.msha");
                File.Copy(setupFile, contentSetupFile, true);

                if (viewerVersion.Major == 1)
                {
                    arguments = String.Format(CultureInfo.InvariantCulture, "/product \"{0}\" " +
                                              "/version \"{1}\" /locale {2} /sourceMedia \"{3}\"", project.CatalogProductId,
                                              project.CatalogVersion, project.Language.Name, contentSetupFile);
                }
                else
                {
                    arguments = String.Format(CultureInfo.InvariantCulture, "/catalogName \"{0}\" " +
                                              "/locale {1} /wait 0 /operation install /sourceUri \"{2}\"", catalogName,
                                              project.Language.Name, contentSetupFile);
                }

                // Always interactive and must run as administrator.  We can't run silently as we don't have
                // a signed cabinet file.
                errorCode = hlm.RunAsAdministrator(arguments, ProcessWindowStyle.Normal);

                if (errorCode != HelpLibraryManagerException.Success)
                {
                    throw new HelpLibraryManagerException(viewerVersion, errorCode);
                }

                // Open it if installed successfully
                action = HelpViewerAction.OpenCurrent;
            }

            if (action == HelpViewerAction.OpenCurrent)
            {
                arguments = null;

                if (msHelpViewer == null)
                {
                    msHelpViewer = hlm.HelpViewerPath;

                    if (msHelpViewer == null)
                    {
                        msHelpViewer = "ms-xhelp:///?method=page&id=-1";
                    }
                    else
                    if (viewerVersion.Major == 2)
                    {
                        arguments = "/catalogname \"" + catalogName + "\"";
                    }
                }

                helpViewerProgress.Report("Opening help content...");
                System.Diagnostics.Process.Start(msHelpViewer, arguments);
            }

            cancellationTokenSource.Token.ThrowIfCancellationRequested();

            if (action == HelpViewerAction.OpenContentManager)
            {
                helpViewerProgress.Report("Opening help content manager...");

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

                if (viewerVersion.Major == 1)
                {
                    hlm.LaunchInteractive(String.Format(CultureInfo.InvariantCulture,
                                                        "/product \"{0}\" /version \"{1}\" /locale {2}", project.CatalogProductId,
                                                        project.CatalogVersion, project.Language.Name));
                }
                else
                {
                    hlm.LaunchInteractive(String.Format(CultureInfo.InvariantCulture,
                                                        "/catalogName \"{0}\" /locale {1} /manage", catalogName, project.Language.Name));
                }
            }
        }