| @@ -27,10 +27,13 @@ using System; · 26 unmodified lines |
| 27 | using System.Collections.Generic; | 27 | using System.Collections.Generic; |
| 28 | using System.Diagnostics; | 28 | using System.Diagnostics; |
| 29 | using System.IO; | 29 | using System.IO; |
| | 30 | using System.IO.Compression; |
| 30 | using System.Linq; | 31 | using System.Linq; |
| 31 | using System.Runtime.InteropServices; | 32 | using System.Runtime.InteropServices; |
| 32 | using System.Security.Principal; | 33 | using System.Security.Principal; |
| 33 | using System.Text; | 34 | using System.Text; |
| | 35 | using System.Threading; |
| | 36 | using System.Windows.Forms; |
| 34 | using System.Xml.Linq; | 37 | using System.Xml.Linq; |
| 35 | using GSF.Data; | 38 | using GSF.Data; |
| 36 | using GSF.Identity; | 39 | using GSF.Identity; |
| @@ -264,6 +267,109 @@ namespace GSF.InstallerActions · 227 unmodified lines |
| 264 | return ActionResult.Success; | 267 | return ActionResult.Success; |
| 265 | } | 268 | } |
| 266 | | 269 | |
| | 270 | /// <summary> |
| | 271 | /// Prompts the user to select a file via the open file dialog. |
| | 272 | /// </summary> |
| | 273 | /// <param name="session">Session object containing data from the installer.</param> |
| | 274 | /// <returns>Result of the custom action.</returns> |
| | 275 | [CustomAction] |
| | 276 | public static ActionResult BrowseFileAction(Session session) |
| | 277 | { |
| | 278 | Thread staThread; |
| | 279 | |
| | 280 | session.Log("Begin BrowseFileAction"); |
| | 281 | |
| | 282 | staThread = new Thread(() => |
| | 283 | { |
| | 284 | using (OpenFileDialog openFileDialog = new OpenFileDialog()) |
| | 285 | { |
| | 286 | openFileDialog.CheckFileExists = true; |
| | 287 | openFileDialog.FileName = session["SELECTEDFILE"]; |
| | 288 | openFileDialog.DefaultExt = session["BROWSEFILEEXTENSION"]; |
| | 289 | openFileDialog.Filter = string.Format("{0} Files|*.{1}|All Files|*.*", session["BROWSEFILEEXTENSION"].ToUpper(), session["BROWSEFILEEXTENSION"]); |
| | 290 | |
| | 291 | if (openFileDialog.ShowDialog() == DialogResult.OK) |
| | 292 | session["SELECTEDFILE"] = openFileDialog.FileName; |
| | 293 | else |
| | 294 | session["SELECTEDFILE"] = null; |
| | 295 | } |
| | 296 | }); |
| | 297 | |
| | 298 | staThread.SetApartmentState(ApartmentState.STA); |
| | 299 | staThread.Start(); |
| | 300 | staThread.Join(); |
| | 301 | |
| | 302 | session.Log("End BrowseFileAction"); |
| | 303 | |
| | 304 | return ActionResult.Success; |
| | 305 | } |
| | 306 | |
| | 307 | /// <summary> |
| | 308 | /// Determines whether a file exists. |
| | 309 | /// </summary> |
| | 310 | /// <param name="session">Session object containing data from the installer.</param> |
| | 311 | /// <returns>Result of the custom action.</returns> |
| | 312 | [CustomAction] |
| | 313 | public static ActionResult CheckFileExistenceAction(Session session) |
| | 314 | { |
| | 315 | session.Log("Begin CheckFileExistenceAction"); |
| | 316 | session["FILEEXISTS"] = File.Exists(session["FILEPATH"]) ? "yes" : null; |
| | 317 | session.Log("End CheckFileExistenceAction"); |
| | 318 | return ActionResult.Success; |
| | 319 | } |
| | 320 | |
| | 321 | /// <summary> |
| | 322 | /// Extracts a zip file to a destination folder. |
| | 323 | /// </summary> |
| | 324 | /// <param name="session">Session object containing data from the installer.</param> |
| | 325 | /// <returns>Result of the custom action.</returns> |
| | 326 | [CustomAction] |
| | 327 | public static ActionResult UnzipAction(Session session) |
| | 328 | { |
| | 329 | string zipFile; |
| | 330 | string sourceDir; |
| | 331 | string destinationDir; |
| | 332 | |
| | 333 | ZipArchive archive; |
| | 334 | string directoryPath; |
| | 335 | string filePath; |
| | 336 | |
| | 337 | session.Log("Begin UnzipAction"); |
| | 338 | |
| | 339 | zipFile = session.CustomActionData["ZIPFILE"]; |
| | 340 | sourceDir = session.CustomActionData["SOURCEDIR"] ?? string.Empty; |
| | 341 | destinationDir = session.CustomActionData["DESTINATIONDIR"] ?? string.Empty; |
| | 342 | |
| | 343 | sourceDir = sourceDir.Replace('\\', '/').EnsureEnd('/'); |
| | 344 | |
| | 345 | archive = ZipFile.OpenRead(zipFile); |
| | 346 | |
| | 347 | foreach (ZipArchiveEntry entry in archive.Entries.Where(entry => entry.FullName.StartsWith(sourceDir))) |
| | 348 | { |
| | 349 | if (entry.FullName.EndsWith("/")) |
| | 350 | continue; |
| | 351 | |
| | 352 | filePath = Path.Combine(destinationDir, entry.FullName.Substring(sourceDir.Length).Replace('/', '\\')); |
| | 353 | directoryPath = Path.GetDirectoryName(filePath); |
| | 354 | |
| | 355 | if ((object)directoryPath == null) |
| | 356 | continue; |
| | 357 | |
| | 358 | if (!Directory.Exists(directoryPath)) |
| | 359 | Directory.CreateDirectory(directoryPath); |
| | 360 | |
| | 361 | using (Stream stream = entry.Open()) |
| | 362 | using (FileStream fileStream = File.Create(filePath)) |
| | 363 | { |
| | 364 | stream.CopyTo(fileStream); |
| | 365 | } |
| | 366 | } |
| | 367 | |
| | 368 | session.Log("End UnzipAction"); |
| | 369 | |
| | 370 | return ActionResult.Success; |
| | 371 | } |
| | 372 | |
| 267 | /// <summary> | 373 | /// <summary> |
| 268 | /// Tests a connection to a database server. | 374 | /// Tests a connection to a database server. |
| 269 | /// </summary> | 375 | /// </summary> |
| @@ -275,7 +381,7 @@ namespace GSF.InstallerActions · 5 unmodified lines |
| 275 | string connectionString; | 381 | string connectionString; |
| 276 | string dataProviderString; | 382 | string dataProviderString; |
| 277 | | 383 | |
| 278 | session.Log("Begin TestDatabaseConnection"); | 384 | session.Log("Begin TestDatabaseConnectionAction"); |
| 279 | | 385 | |
| 280 | // Get properties from the installer session | 386 | // Get properties from the installer session |
| 281 | connectionString = session["CONNECTIONSTRING"]; | 387 | connectionString = session["CONNECTIONSTRING"]; |
| @@ -300,7 +406,7 @@ namespace GSF.InstallerActions · 18 unmodified lines |
| 300 | session["DATABASECONNECTED"] = null; | 406 | session["DATABASECONNECTED"] = null; |
| 301 | } | 407 | } |
| 302 | | 408 | |
| 303 | session.Log("End TestDatabaseConnection"); | 409 | session.Log("End TestDatabaseConnectionAction"); |
| 304 | | 410 | |
| 305 | return ActionResult.Success; | 411 | return ActionResult.Success; |
| 306 | } | 412 | } |