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