Пример #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
 public override void Run()
 {
     if (string.IsNullOrEmpty(HelpLibraryManager.Manager))
     {
         using (HelpLibraryManagerNotFoundForm form = new HelpLibraryManagerNotFoundForm()) {
             form.ShowDialog(SD.WinForms.MainWin32Window);
         }
         return;
     }
     HelpLibraryManager.Start();
 }
Пример #3
0
        /// <summary>
        /// This is used to determine the state of the help content and set
        /// the form options.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void LaunchMSHelpViewerDlg_Load(object sender, EventArgs e)
        {
            if (!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");
                rbInstall.Enabled = false;
            }

            try
            {
                HelpLibraryManager hlm = new HelpLibraryManager();

                // Can't do anything if the Help Library Manager is not installed
                if (hlm.HelpLibraryManagerPath == null)
                {
                    throw new HelpLibraryManagerException(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(HelpLibraryManagerException.HelpLibraryManagerAlreadyRunning);
                }

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

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

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

            if (!btnOK.Enabled)
            {
                txtInfo.AppendText("\r\nNo action can be taken.");
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
        /// <summary>
        /// Execute the selected action
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private async void btnOK_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            HelpViewerAction action;

            txtInfo.Text = null;

            try
            {
                HelpLibraryManager hlm = new HelpLibraryManager(viewerVersion);

                // 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);
                }
            }
            catch (Exception ex)
            {
                txtInfo.AppendText("Problem: " + ex.Message + "\r\n");
                return;
            }

            try
            {
                cancellationTokenSource = new CancellationTokenSource();

                lblAction.Text                 = "Please wait...";
                grdAction.Visibility           = Visibility.Visible;
                cboHelpViewerVersion.IsEnabled = grpOptions.IsEnabled = btnOK.IsEnabled = false;

                if (rbOpenCurrent.IsChecked ?? false)
                {
                    action = HelpViewerAction.OpenCurrent;
                }
                else
                if (rbInstall.IsChecked ?? false)
                {
                    action = HelpViewerAction.Install;
                }
                else
                if (rbRemove.IsChecked ?? false)
                {
                    action = HelpViewerAction.Remove;
                }
                else
                {
                    action = HelpViewerAction.OpenContentManager;
                }

                await Task.Run(() => this.PerformHelpViewerAction(action), cancellationTokenSource.Token);

                if (rbRemove.IsChecked ?? false)
                {
                    txtInfo.AppendText("The operation completed successfully");
                    rbRemove.IsEnabled = rbOpenCurrent.IsEnabled = false;

                    if (rbInstall.IsEnabled)
                    {
                        rbInstall.IsChecked = true;
                    }
                    else
                    {
                        rbLaunchContentManager.IsChecked = true;
                    }
                }
                else
                {
                    this.Close();   // Close if content was opened
                }
            }
            catch (OperationCanceledException)
            {
                // Ignore cancellation exceptions
                txtInfo.AppendText("\r\n\r\nOperation canceled");
            }
            catch (Exception ex)
            {
                do
                {
                    txtInfo.AppendText("ERROR: " + ex.Message);
                    ex = ex.InnerException;
                } while(ex != null);
            }
            finally
            {
                if (!cancellationTokenSource.IsCancellationRequested)
                {
                    grdAction.Visibility           = Visibility.Hidden;
                    cboHelpViewerVersion.IsEnabled = grpOptions.IsEnabled = btnOK.IsEnabled = true;
                }

                cancellationTokenSource.Dispose();
                cancellationTokenSource = null;
            }
        }
Пример #6
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_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            txtInfo.Text = null;

            grpOptions.IsEnabled = rbInstall.IsEnabled = 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 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.IsEnabled = false;
                }
            }

            if (rbInstall.IsEnabled && (!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.IsEnabled = false;
            }

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

                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.IsEnabled = rbRemove.IsEnabled = true;
                }
                else
                {
                    txtInfo.AppendText("The help file does not appear to be installed yet.\r\n");
                    rbOpenCurrent.IsEnabled = rbRemove.IsEnabled = false;
                }
            }
            catch (Exception ex)
            {
                txtInfo.AppendText("Problem: " + ex.Message + "\r\n");
                rbOpenCurrent.IsEnabled = rbRemove.IsEnabled = false;
            }

            if (rbOpenCurrent.IsEnabled)
            {
                rbOpenCurrent.IsChecked = true;
            }
            else
            if (rbInstall.IsEnabled)
            {
                rbInstall.IsChecked = true;
            }
            else
            {
                rbLaunchContentManager.IsChecked = true;
            }

            if (!rbOpenCurrent.IsEnabled && !rbInstall.IsEnabled && !rbRemove.IsEnabled)
            {
                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.");
            }
        }
Пример #7
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));
                }
            }
        }
Пример #8
0
        //=====================================================================

        /// <summary>
        /// This performs the requested task
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void actionThread_DoWork(object sender, DoWorkEventArgs e)
        {
            ThreadAction action = (ThreadAction)e.Argument;
            string       arguments, contentSetupFile;
            int          errorCode;

            runningThread = Thread.CurrentThread;

            try
            {
                HelpLibraryManager hlm = new HelpLibraryManager();

                // Remove old content.  We'll remove it if installing to be sure that
                // the latest copy is installed.
                if (action == ThreadAction.Install || action == ThreadAction.Remove)
                {
                    if (action == ThreadAction.Install)
                    {
                        actionThread.ReportProgress(0, (int)ThreadState.RemovingOldContent);
                    }
                    else
                    {
                        actionThread.ReportProgress(0, (int)ThreadState.RemovingContent);
                    }

                    arguments = String.Format(CultureInfo.InvariantCulture,
                                              "/product \"{0}\" /version \"{1}\" /locale {2} /uninstall /silent /vendor " +
                                              "\"{3}\" /mediaBookList \"{4}\" /productName \"{5}\"",
                                              project.CatalogProductId, project.CatalogVersion, project.Language.Name,
                                              project.VendorName, project.HelpTitle, project.ProductTitle);

                    // 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 == ThreadAction.Remove))
                    {
                        throw new HelpLibraryManagerException(errorCode);
                    }
                }

                if (action == ThreadAction.Install)
                {
                    // Install the new content
                    actionThread.ReportProgress(0, (int)ThreadState.InstallingContent);

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

                    arguments = String.Format(CultureInfo.InvariantCulture,
                                              "/product \"{0}\" /version \"{1}\" /locale {2} /brandingPackage Dev10.mshc " +
                                              "/sourceMedia \"{3}", project.CatalogProductId, project.CatalogVersion, 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(errorCode);
                    }

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

                if (action == ThreadAction.OpenCurrent)
                {
                    actionThread.ReportProgress(0, (int)ThreadState.OpeningContent);
                    System.Diagnostics.Process.Start(msHelpViewer);
                }
            }
            catch (ThreadAbortException)
            {
                // Ignore thread abort exceptions
            }
        }