PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  1. //=============================================================================
  2. // System : Sandcastle Guided Installation - Sandcastle Help File Builder
  3. // File : SandcastleHelpFileBuilderPage.cs
  4. // Author : Eric Woodruff
  5. // Updated : 04/23/2011
  6. // Note : Copyright 2011, Eric Woodruff, All rights reserved
  7. // Compiler: Microsoft Visual C#
  8. //
  9. // This file contains a page used to help the user install the Sandcastle Help
  10. // File Builder.
  11. //
  12. // This code is published under the Microsoft Public License (Ms-PL). A copy
  13. // of the license should be distributed with the code. It can also be found
  14. // at the project website: http://SandcastleStyles.CodePlex.com. This
  15. // notice, the author's name, and all copyright notices must remain intact in
  16. // all applications, documentation, and source files.
  17. //
  18. // Version Date Who Comments
  19. // ============================================================================
  20. // 1.0.0.0 02/12/2011 EFW Created the code
  21. //=============================================================================
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Diagnostics;
  25. using System.IO;
  26. using System.Windows.Forms;
  27. using System.Xml.Linq;
  28. using Sandcastle.Installer.InstallerPages;
  29. using Sandcastle.Installer.SHFB.Properties;
  30. namespace Sandcastle.Installer.SHFB
  31. {
  32. /// <summary>
  33. /// This page is used to help the user install the Sandcastle Help File
  34. /// Builder.
  35. /// </summary>
  36. public partial class SandcastleHelpFileBuilderPage : Sandcastle.Installer.InstallerPages.BasePage
  37. {
  38. #region Private data members
  39. //=====================================================================
  40. private string shfbFolder, installerName;
  41. private bool searchPerformed, suggestReboot;
  42. private Version frameworkVersion, shfbVersion;
  43. #endregion
  44. #region Properties
  45. //=====================================================================
  46. /// <inheritdoc />
  47. public override string PageTitle
  48. {
  49. get { return "Sandcastle Help File Builder"; }
  50. }
  51. /// <inheritdoc />
  52. /// <remarks>This returns the .NET Framework version required by the
  53. /// Sandcastle Help File Builder installed by this release of the
  54. /// package.</remarks>
  55. public override Version RequiredFrameworkVersion
  56. {
  57. get { return frameworkVersion; }
  58. }
  59. /// <summary>
  60. /// This is overridden to prevent continuing until the Sandcastle
  61. /// tools are installed.
  62. /// </summary>
  63. public override bool CanContinue
  64. {
  65. get
  66. {
  67. if(String.IsNullOrEmpty(shfbFolder))
  68. {
  69. MessageBox.Show("The Sandcastle Help File Builder must be installed in order to install " +
  70. "the remainder of the tools in this package. Follow the instructions on this " +
  71. "page to install them.", this.PageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  72. return false;
  73. }
  74. return base.CanContinue;
  75. }
  76. }
  77. /// <summary>
  78. /// This is overridden to return true if the installer was executed.
  79. /// </summary>
  80. public override bool SuggestReboot
  81. {
  82. get { return suggestReboot; }
  83. }
  84. /// <summary>
  85. /// This is overridden to return a completion action that offers to
  86. /// open the SHFB help file.
  87. /// </summary>
  88. public override IEnumerable<CompletionAction> CompletionActions
  89. {
  90. get
  91. {
  92. if(!String.IsNullOrEmpty(shfbFolder))
  93. yield return new CompletionAction
  94. {
  95. Description = "Open the Sandcastle Help File Builder help file",
  96. Action = new Action(() =>
  97. {
  98. Utility.Open(Path.Combine(shfbFolder, "SandcastleBuilder.chm"));
  99. })
  100. };
  101. }
  102. }
  103. /// <summary>
  104. /// This is used to retrieve the help file builder version
  105. /// </summary>
  106. public Version HelpFileBuilderVersion
  107. {
  108. get { return shfbVersion; }
  109. }
  110. #endregion
  111. #region Constructor
  112. //=====================================================================
  113. /// <summary>
  114. /// Constructor
  115. /// </summary>
  116. public SandcastleHelpFileBuilderPage()
  117. {
  118. InitializeComponent();
  119. }
  120. #endregion
  121. #region Method overrides
  122. //=====================================================================
  123. /// <inheritdoc />
  124. public override void Initialize(XElement configuration)
  125. {
  126. if(configuration.Attribute("frameworkVersion") == null)
  127. throw new InvalidOperationException("A frameworkVersion attribute value is required");
  128. if(configuration.Attribute("shfbVersion") == null)
  129. throw new InvalidOperationException("A shfbVersion attribute value is required");
  130. if(configuration.Attribute("installerName") == null)
  131. throw new InvalidOperationException("An installer attribute value is required");
  132. frameworkVersion = new Version(configuration.Attribute("frameworkVersion").Value);
  133. shfbVersion = new Version(configuration.Attribute("shfbVersion").Value);
  134. installerName = configuration.Attribute("installerName").Value;
  135. base.Initialize(configuration);
  136. }
  137. /// <summary>
  138. /// This is overridden to figure out if the Sandcastle Help File
  139. /// Builder is installed.
  140. /// </summary>
  141. public override void ShowPage()
  142. {
  143. FileVersionInfo fvi;
  144. Version installedVersion;
  145. string body = Resources.HelpFileBuilderPageBody, errorMessage = null;
  146. if(searchPerformed)
  147. return;
  148. btnInstallSHFB.Visible = false;
  149. try
  150. {
  151. Cursor.Current = Cursors.WaitCursor;
  152. searchPerformed = false;
  153. // SHFBROOT will exist as a system environment variable if it is installed correctly
  154. shfbFolder = Environment.GetEnvironmentVariable("SHFBROOT", EnvironmentVariableTarget.Machine);
  155. if(!String.IsNullOrEmpty(shfbFolder))
  156. {
  157. // If there is an installed version, make sure it is older than what we expect
  158. if(!Directory.Exists(shfbFolder) || !File.Exists(Path.Combine(shfbFolder,
  159. "SHFBProjectLauncher.exe")))
  160. installedVersion = new Version(0, 0, 0, 0);
  161. else
  162. {
  163. fvi = FileVersionInfo.GetVersionInfo(Path.Combine(shfbFolder, "SHFBProjectLauncher.exe"));
  164. installedVersion = new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart,
  165. fvi.FilePrivatePart);
  166. }
  167. if(installedVersion < shfbVersion)
  168. shfbFolder = null;
  169. else
  170. {
  171. // If the version is greater, we can't go on as this package is out of date
  172. if(installedVersion > shfbVersion)
  173. {
  174. shfbFolder = null;
  175. this.scSplitter.Panel2Collapsed = true;
  176. this.DisplayHtml(body + "<h2>Newer Version Detected</h2><p />It has been determined " +
  177. "that a newer version of the Sandcastle Help File Builder is installed on this " +
  178. "system. You will need to download a newer version of this package that is " +
  179. "compatible with this more recent release of it.");
  180. return;
  181. }
  182. }
  183. }
  184. }
  185. catch(Exception ex)
  186. {
  187. errorMessage = "An error occurred while searching for the Sandcastle Help File Builder:<br /><br /> " +
  188. ex.Message;
  189. }
  190. finally
  191. {
  192. Cursor.Current = Cursors.Default;
  193. searchPerformed = true;
  194. }
  195. if(errorMessage != null)
  196. {
  197. this.DisplayHtml(body + "<div class='Error'><p />" + errorMessage + "</div>");
  198. return;
  199. }
  200. if(!String.IsNullOrEmpty(shfbFolder))
  201. {
  202. this.scSplitter.Panel2Collapsed = true;
  203. this.DisplayHtml(body + "<h2>Sandcastle Help File Builder Found</h2><p />It has been " +
  204. "determined that the Sandcastle Help File Builder is installed on this system (Location: " +
  205. "<i>" + shfbFolder + "</i>). No further action is required in this step.\r\n<p />Click " +
  206. "the <b>Next</b> button to continue.");
  207. return;
  208. }
  209. btnInstallSHFB.Visible = btnInstallSHFB.Enabled = true;
  210. this.DisplayHtml(body + "<p />The Sandcastle Help File Builder could not be found on this system. " +
  211. "Please click the <b>Install SHFB</b> button below. A separate installer will be launched to " +
  212. "perform the installation. Once it has completed, return to this application to continue " +
  213. "installing the remainder of the tools. You may need to reboot when done so that changes to " +
  214. "the system environment variables take effect.");
  215. }
  216. #endregion
  217. #region Event handlers
  218. //=====================================================================
  219. /// <summary>
  220. /// Install the Sandcastle Help File Builder and show the results
  221. /// </summary>
  222. /// <param name="sender">The sender of the event</param>
  223. /// <param name="e">The event arguments</param>
  224. private void btnInstallSHFB_Click(object sender, EventArgs e)
  225. {
  226. searchPerformed = suggestReboot = false;
  227. btnInstallSHFB.Enabled = false;
  228. bool launched = Utility.RunInstaller(Path.Combine(Utility.InstallResourcesPath, installerName), null,
  229. (exitCode) =>
  230. {
  231. suggestReboot = true;
  232. pbWait.Visible = lblInstalling.Visible = false;
  233. this.ShowPage();
  234. },
  235. (ex) =>
  236. {
  237. pbWait.Visible = lblInstalling.Visible = false;
  238. MessageBox.Show("Unable to execute installer: " + ex.Message, this.PageTitle,
  239. MessageBoxButtons.OK, MessageBoxIcon.Error);
  240. });
  241. if(launched)
  242. pbWait.Visible = lblInstalling.Visible = true;
  243. }
  244. #endregion
  245. }
  246. }