/Main/Source/SandcastleInstaller/SandcastleInstaller.SHFB/SandcastleHelpFileBuilderPage.cs
C# | 282 lines | 181 code | 36 blank | 65 comment | 18 complexity | eba63a9ff116f7effcdb619ef9d1768d MD5 | raw file
Possible License(s): CC-BY-SA-3.0
- //=============================================================================
- // System : Sandcastle Guided Installation - Sandcastle Help File Builder
- // File : SandcastleHelpFileBuilderPage.cs
- // Author : Eric Woodruff
- // Updated : 04/23/2011
- // Note : Copyright 2011, Eric Woodruff, All rights reserved
- // Compiler: Microsoft Visual C#
- //
- // This file contains a page used to help the user install the Sandcastle Help
- // File Builder.
- //
- // This code is published under the Microsoft Public License (Ms-PL). A copy
- // of the license should be distributed with the code. It can also be found
- // at the project website: http://SandcastleStyles.CodePlex.com. This
- // notice, the author's name, and all copyright notices must remain intact in
- // all applications, documentation, and source files.
- //
- // Version Date Who Comments
- // ============================================================================
- // 1.0.0.0 02/12/2011 EFW Created the code
- //=============================================================================
-
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Windows.Forms;
- using System.Xml.Linq;
-
- using Sandcastle.Installer.InstallerPages;
-
- using Sandcastle.Installer.SHFB.Properties;
-
- namespace Sandcastle.Installer.SHFB
- {
- /// <summary>
- /// This page is used to help the user install the Sandcastle Help File
- /// Builder.
- /// </summary>
- public partial class SandcastleHelpFileBuilderPage : Sandcastle.Installer.InstallerPages.BasePage
- {
- #region Private data members
- //=====================================================================
-
- private string shfbFolder, installerName;
- private bool searchPerformed, suggestReboot;
- private Version frameworkVersion, shfbVersion;
- #endregion
-
- #region Properties
- //=====================================================================
-
- /// <inheritdoc />
- public override string PageTitle
- {
- get { return "Sandcastle Help File Builder"; }
- }
-
- /// <inheritdoc />
- /// <remarks>This returns the .NET Framework version required by the
- /// Sandcastle Help File Builder installed by this release of the
- /// package.</remarks>
- public override Version RequiredFrameworkVersion
- {
- get { return frameworkVersion; }
- }
-
- /// <summary>
- /// This is overridden to prevent continuing until the Sandcastle
- /// tools are installed.
- /// </summary>
- public override bool CanContinue
- {
- get
- {
- if(String.IsNullOrEmpty(shfbFolder))
- {
- MessageBox.Show("The Sandcastle Help File Builder must be installed in order to install " +
- "the remainder of the tools in this package. Follow the instructions on this " +
- "page to install them.", this.PageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return false;
- }
-
- return base.CanContinue;
- }
- }
-
- /// <summary>
- /// This is overridden to return true if the installer was executed.
- /// </summary>
- public override bool SuggestReboot
- {
- get { return suggestReboot; }
- }
-
- /// <summary>
- /// This is overridden to return a completion action that offers to
- /// open the SHFB help file.
- /// </summary>
- public override IEnumerable<CompletionAction> CompletionActions
- {
- get
- {
- if(!String.IsNullOrEmpty(shfbFolder))
- yield return new CompletionAction
- {
- Description = "Open the Sandcastle Help File Builder help file",
- Action = new Action(() =>
- {
- Utility.Open(Path.Combine(shfbFolder, "SandcastleBuilder.chm"));
- })
- };
- }
- }
-
- /// <summary>
- /// This is used to retrieve the help file builder version
- /// </summary>
- public Version HelpFileBuilderVersion
- {
- get { return shfbVersion; }
- }
- #endregion
-
- #region Constructor
- //=====================================================================
-
- /// <summary>
- /// Constructor
- /// </summary>
- public SandcastleHelpFileBuilderPage()
- {
- InitializeComponent();
- }
- #endregion
-
- #region Method overrides
- //=====================================================================
-
- /// <inheritdoc />
- public override void Initialize(XElement configuration)
- {
- if(configuration.Attribute("frameworkVersion") == null)
- throw new InvalidOperationException("A frameworkVersion attribute value is required");
-
- if(configuration.Attribute("shfbVersion") == null)
- throw new InvalidOperationException("A shfbVersion attribute value is required");
-
- if(configuration.Attribute("installerName") == null)
- throw new InvalidOperationException("An installer attribute value is required");
-
- frameworkVersion = new Version(configuration.Attribute("frameworkVersion").Value);
- shfbVersion = new Version(configuration.Attribute("shfbVersion").Value);
- installerName = configuration.Attribute("installerName").Value;
-
- base.Initialize(configuration);
- }
-
- /// <summary>
- /// This is overridden to figure out if the Sandcastle Help File
- /// Builder is installed.
- /// </summary>
- public override void ShowPage()
- {
- FileVersionInfo fvi;
- Version installedVersion;
- string body = Resources.HelpFileBuilderPageBody, errorMessage = null;
-
- if(searchPerformed)
- return;
-
- btnInstallSHFB.Visible = false;
-
- try
- {
- Cursor.Current = Cursors.WaitCursor;
- searchPerformed = false;
-
- // SHFBROOT will exist as a system environment variable if it is installed correctly
- shfbFolder = Environment.GetEnvironmentVariable("SHFBROOT", EnvironmentVariableTarget.Machine);
-
- if(!String.IsNullOrEmpty(shfbFolder))
- {
- // If there is an installed version, make sure it is older than what we expect
- if(!Directory.Exists(shfbFolder) || !File.Exists(Path.Combine(shfbFolder,
- "SHFBProjectLauncher.exe")))
- installedVersion = new Version(0, 0, 0, 0);
- else
- {
- fvi = FileVersionInfo.GetVersionInfo(Path.Combine(shfbFolder, "SHFBProjectLauncher.exe"));
-
- installedVersion = new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart,
- fvi.FilePrivatePart);
- }
-
- if(installedVersion < shfbVersion)
- shfbFolder = null;
- else
- {
- // If the version is greater, we can't go on as this package is out of date
- if(installedVersion > shfbVersion)
- {
- shfbFolder = null;
- this.scSplitter.Panel2Collapsed = true;
- this.DisplayHtml(body + "<h2>Newer Version Detected</h2><p />It has been determined " +
- "that a newer version of the Sandcastle Help File Builder is installed on this " +
- "system. You will need to download a newer version of this package that is " +
- "compatible with this more recent release of it.");
- return;
- }
- }
- }
- }
- catch(Exception ex)
- {
- errorMessage = "An error occurred while searching for the Sandcastle Help File Builder:<br /><br /> " +
- ex.Message;
- }
- finally
- {
- Cursor.Current = Cursors.Default;
- searchPerformed = true;
- }
-
- if(errorMessage != null)
- {
- this.DisplayHtml(body + "<div class='Error'><p />" + errorMessage + "</div>");
- return;
- }
-
- if(!String.IsNullOrEmpty(shfbFolder))
- {
- this.scSplitter.Panel2Collapsed = true;
- this.DisplayHtml(body + "<h2>Sandcastle Help File Builder Found</h2><p />It has been " +
- "determined that the Sandcastle Help File Builder is installed on this system (Location: " +
- "<i>" + shfbFolder + "</i>). No further action is required in this step.\r\n<p />Click " +
- "the <b>Next</b> button to continue.");
- return;
- }
-
- btnInstallSHFB.Visible = btnInstallSHFB.Enabled = true;
- this.DisplayHtml(body + "<p />The Sandcastle Help File Builder could not be found on this system. " +
- "Please click the <b>Install SHFB</b> button below. A separate installer will be launched to " +
- "perform the installation. Once it has completed, return to this application to continue " +
- "installing the remainder of the tools. You may need to reboot when done so that changes to " +
- "the system environment variables take effect.");
- }
- #endregion
-
- #region Event handlers
- //=====================================================================
-
- /// <summary>
- /// Install the Sandcastle Help File Builder and show the results
- /// </summary>
- /// <param name="sender">The sender of the event</param>
- /// <param name="e">The event arguments</param>
- private void btnInstallSHFB_Click(object sender, EventArgs e)
- {
- searchPerformed = suggestReboot = false;
- btnInstallSHFB.Enabled = false;
-
- bool launched = Utility.RunInstaller(Path.Combine(Utility.InstallResourcesPath, installerName), null,
- (exitCode) =>
- {
- suggestReboot = true;
- pbWait.Visible = lblInstalling.Visible = false;
- this.ShowPage();
- },
- (ex) =>
- {
- pbWait.Visible = lblInstalling.Visible = false;
- MessageBox.Show("Unable to execute installer: " + ex.Message, this.PageTitle,
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- });
-
- if(launched)
- pbWait.Visible = lblInstalling.Visible = true;
- }
- #endregion
- }
- }