Пример #1
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));
                }
            }
        }
Пример #2
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
            }
        }