| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.BuildTasks |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.IO; |
| 8 | using Microsoft.Build.Framework; |
| 9 | using Microsoft.Build.Utilities; |
| 10 | using WixToolset.Dtf.WindowsInstaller; |
| 11 | |
| 12 | /// <summary> |
| 13 | /// This task assigns Culture metadata to files based on the value of the Culture attribute on the |
| 14 | /// WixLocalization element inside the file. |
| 15 | /// </summary> |
| 16 | public class GetCabList : Task |
| 17 | { |
| 18 | /// <summary> |
| 19 | /// The list of database files to find cabs in |
| 20 | /// </summary> |
| 21 | [Required] |
| 22 | public ITaskItem Database { get; set; } |
| 23 | |
| 24 | /// <summary> |
| 25 | /// The total list of cabs in this database |
| 26 | /// </summary> |
| 27 | [Output] |
| 28 | public ITaskItem[] CabList { get; private set; } |
| 29 | |
| 30 | /// <summary> |
| 31 | /// Gets a complete list of external cabs referenced by the given installer database file. |
| 32 | /// </summary> |
| 33 | /// <returns>True upon completion of the task execution.</returns> |
| 34 | public override bool Execute() |
| 35 | { |
| 36 | var cabNames = new List<ITaskItem>(); |
| 37 | var databaseFile = this.Database.ItemSpec; |
| 38 | |
| 39 | // If the file doesn't exist, no cabs to return, so exit now |
| 40 | if (!File.Exists(databaseFile)) |
| 41 | { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | using (var database = new Database(databaseFile)) |
| 46 | { |
| 47 | // If the media table doesn't exist, no cabs to return, so exit now |
| 48 | if (null == database.Tables["Media"]) |
| 49 | { |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | var databaseDirectory = Path.GetDirectoryName(databaseFile); |
| 54 | |
| 55 | foreach (string cabName in database.ExecuteQuery("SELECT `Cabinet` FROM `Media`")) |
| 56 | { |
| 57 | if (String.IsNullOrEmpty(cabName) || cabName.StartsWith("#", StringComparison.Ordinal)) |
| 58 | { |
| 59 | continue; |
| 60 | } |
| 61 | |
| 62 | cabNames.Add(new TaskItem(Path.Combine(databaseDirectory, cabName))); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | this.CabList = cabNames.ToArray(); |
| 67 | |
| 68 | return true; |
| 69 | } |
| 70 | } |
| 71 | } |