@joebigelow / wix / commits / ee2bb352

Modernize GetCabList and GetLooseFileList tasks

Rob Mensching committed Jan 8, 2022 at 07:47 UTC ee2bb35228e8d3c12ae0e31748075777e10f9d62
3 files changed +78 -116
src/wix/WixToolset.BuildTasks/GetCabList.cs
+7 -7
@@ -3,6 +3,7 @@
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;
@@ -32,9 +33,8 @@ namespace WixToolset.BuildTasks
33 /// <returns>True upon completion of the task execution.</returns>
34 public override bool Execute()
35 {
35 - string databaseFile = this.Database.ItemSpec;
36 - object[] args = { };
37 - System.Collections.Generic.List<ITaskItem> cabNames = new System.Collections.Generic.List<ITaskItem>();
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))
@@ -42,7 +42,7 @@ namespace WixToolset.BuildTasks
42 return true;
43 }
44
45 - using (Database database = new Database(databaseFile))
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"])
@@ -50,16 +50,16 @@ namespace WixToolset.BuildTasks
50 return true;
51 }
52
53 - System.Collections.IList records = database.ExecuteQuery("SELECT `Cabinet` FROM `Media`", args);
53 + var databaseDirectory = Path.GetDirectoryName(databaseFile);
54
55 - foreach (string cabName in records)
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(Path.GetDirectoryName(databaseFile), cabName)));
62 + cabNames.Add(new TaskItem(Path.Combine(databaseDirectory, cabName)));
63 }
64 }
65
src/wix/WixToolset.BuildTasks/GetLooseFileList.cs
+64 -107
@@ -15,9 +15,6 @@ namespace WixToolset.BuildTasks
15 /// </summary>
16 public class GetLooseFileList : Task
17 {
18 - private ITaskItem database;
19 - private ITaskItem[] looseFileList;
20 -
18 internal const int MsidbFileAttributesNoncompressed = 8192;
19 internal const int MsidbFileAttributesCompressed = 16384;
20
@@ -25,75 +22,13 @@ namespace WixToolset.BuildTasks
22 /// The list of database files to find Loose Files in
23 /// </summary>
24 [Required]
28 - public ITaskItem Database
29 - {
30 - get { return this.database; }
31 - set { this.database = value; }
32 - }
25 + public ITaskItem Database { get; set; }
26
27 /// <summary>
28 /// The total list of Loose Files in this database
29 /// </summary>
30 [Output]
38 - public ITaskItem[] LooseFileList
39 - {
40 - get { return this.looseFileList; }
41 - }
42 -
43 - /// <summary>
44 - /// Takes the "defaultDir" column
45 - /// </summary>
46 - /// <returns>Returns the corresponding sourceDir.</returns>
47 - public string SourceDirFromDefaultDir(string defaultDir)
48 - {
49 - string sourceDir;
50 -
51 - string[] splitted = defaultDir.Split(':');
52 -
53 - if (1 == splitted.Length)
54 - {
55 - sourceDir = splitted[0];
56 - }
57 - else
58 - {
59 - sourceDir = splitted[1];
60 - }
61 -
62 - splitted = sourceDir.Split('|');
63 -
64 - if (1 == splitted.Length)
65 - {
66 - sourceDir = splitted[0];
67 - }
68 - else
69 - {
70 - sourceDir = splitted[1];
71 - }
72 -
73 - return sourceDir;
74 - }
75 -
76 - /// <summary>
77 - /// Takes the "FileName" column
78 - /// </summary>
79 - /// <returns>Returns the corresponding source file name.</returns>
80 - public string SourceFileFromFileName(string fileName)
81 - {
82 - string sourceFile;
83 -
84 - string[] splitted = fileName.Split('|');
85 -
86 - if (1 == splitted.Length)
87 - {
88 - sourceFile = splitted[0];
89 - }
90 - else
91 - {
92 - sourceFile = splitted[1];
93 - }
94 -
95 - return sourceFile;
96 - }
31 + public ITaskItem[] LooseFileList { get; private set; }
32
33 /// <summary>
34 /// Gets a complete list of external Loose Files referenced by the given installer database file.
@@ -101,15 +36,12 @@ namespace WixToolset.BuildTasks
36 /// <returns>True upon completion of the task execution.</returns>
37 public override bool Execute()
38 {
104 - string databaseFile = this.database.ItemSpec;
105 - Object []emptyArgs = { };
106 - System.Collections.Generic.List<ITaskItem> looseFileNames = new System.Collections.Generic.List<ITaskItem>();
107 - Dictionary<string, string> ComponentFullDirectory = new Dictionary<string, string>();
108 - Dictionary<string, string> DirectoryIdDefaultDir = new Dictionary<string, string>();
109 - Dictionary<string, string> DirectoryIdParent = new Dictionary<string, string>();
110 - Dictionary<string, string> DirectoryIdFullSource = new Dictionary<string, string>();
111 - int i;
112 - string databaseDir = Path.GetDirectoryName(databaseFile);
39 + var databaseFile = this.Database.ItemSpec;
40 + var looseFileNames = new List<ITaskItem>();
41 + var ComponentFullDirectory = new Dictionary<string, string>();
42 + var DirectoryIdDefaultDir = new Dictionary<string, string>();
43 + var DirectoryIdParent = new Dictionary<string, string>();
44 + var DirectoryIdFullSource = new Dictionary<string, string>();
45
46 // If the file doesn't exist, no Loose Files to return, so exit now
47 if (!File.Exists(databaseFile))
@@ -117,20 +49,18 @@ namespace WixToolset.BuildTasks
49 return true;
50 }
51
120 - using (Database database = new Database(databaseFile))
121 - {
122 - bool compressed = false;
123 - if (2 == (database.SummaryInfo.WordCount & 2))
124 - {
125 - compressed = true;
126 - }
52 + var databaseDir = Path.GetDirectoryName(databaseFile);
53
128 - // If the media table doesn't exist, no Loose Files to return, so exit now
54 + using (var database = new Database(databaseFile))
55 + {
56 + // If the File table doesn't exist, no Loose Files to return, so exit now
57 if (null == database.Tables["File"])
58 {
59 return true;
60 }
61
62 + var compressed = 2 == (database.SummaryInfo.WordCount & 2);
63 +
64 // Only setup all these helpful indexes if the database is marked as uncompressed. If it's marked as compressed, files are stored at the root,
65 // so none of these indexes will be used
66 if (!compressed)
@@ -140,29 +70,28 @@ namespace WixToolset.BuildTasks
70 return true;
71 }
72
143 - System.Collections.IList directoryRecords = database.ExecuteQuery("SELECT `Directory`,`Directory_Parent`,`DefaultDir` FROM `Directory`", emptyArgs);
73 + var directoryRecords = database.ExecuteQuery("SELECT `Directory`,`Directory_Parent`,`DefaultDir` FROM `Directory`");
74
75 // First setup a simple index from DirectoryId to DefaultDir
146 - for (i = 0; i < directoryRecords.Count; i += 3)
76 + for (var i = 0; i < directoryRecords.Count; i += 3)
77 {
148 - string directoryId = (string)(directoryRecords[i]);
149 - string directoryParent = (string)(directoryRecords[i + 1]);
150 - string defaultDir = (string)(directoryRecords[i + 2]);
78 + var directoryId = (string)directoryRecords[i];
79 + var directoryParent = (string)directoryRecords[i + 1];
80 + var defaultDir = (string)directoryRecords[i + 2];
81
152 - string sourceDir = this.SourceDirFromDefaultDir(defaultDir);
82 + var sourceDir = this.SourceDirFromDefaultDir(defaultDir);
83
84 DirectoryIdDefaultDir[directoryId] = sourceDir;
85 DirectoryIdParent[directoryId] = directoryParent;
86 }
87
88 // Setup an index from directory Id to the full source path
159 - for (i = 0; i < directoryRecords.Count; i += 3)
89 + for (var i = 0; i < directoryRecords.Count; i += 3)
90 {
161 - string directoryId = (string)(directoryRecords[i]);
162 - string directoryParent = (string)(directoryRecords[i + 1]);
163 - string defaultDir = (string)(directoryRecords[i + 2]);
91 + var directoryId = (string)directoryRecords[i];
92 + var directoryParent = (string)directoryRecords[i + 1];
93
165 - string sourceDir = DirectoryIdDefaultDir[directoryId];
94 + var sourceDir = DirectoryIdDefaultDir[directoryId];
95
96 // The TARGETDIR case
97 if (String.IsNullOrEmpty(directoryParent))
@@ -171,7 +100,7 @@ namespace WixToolset.BuildTasks
100 }
101 else
102 {
174 - string tempDirectoryParent = directoryParent;
103 + var tempDirectoryParent = directoryParent;
104
105 while (!String.IsNullOrEmpty(tempDirectoryParent) && !String.IsNullOrEmpty(DirectoryIdParent[tempDirectoryParent]))
106 {
@@ -185,27 +114,27 @@ namespace WixToolset.BuildTasks
114 }
115
116 // Setup an index from component Id to full directory path
188 - System.Collections.IList componentRecords = database.ExecuteQuery("SELECT `Component`,`Directory_` FROM `Component`", emptyArgs);
117 + var componentRecords = database.ExecuteQuery("SELECT `Component`,`Directory_` FROM `Component`");
118
190 - for (i = 0; i < componentRecords.Count; i += 2)
119 + for (var i = 0; i < componentRecords.Count; i += 2)
120 {
192 - string componentId = (string)(componentRecords[i]);
193 - string componentDir = (string)(componentRecords[i + 1]);
121 + var componentId = (string)componentRecords[i];
122 + var componentDir = (string)componentRecords[i + 1];
123
124 ComponentFullDirectory[componentId] = DirectoryIdFullSource[componentDir];
125 }
126 }
127
199 - System.Collections.IList fileRecords = database.ExecuteQuery("SELECT `Component_`,`FileName`,`Attributes` FROM `File`", emptyArgs);
128 + var fileRecords = database.ExecuteQuery("SELECT `Component_`,`FileName`,`Attributes` FROM `File`");
129
201 - for (i = 0; i < fileRecords.Count; i += 3)
130 + for (var i = 0; i < fileRecords.Count; i += 3)
131 {
203 - string componentId = (string)(fileRecords[i]);
204 - string fileName = this.SourceFileFromFileName((string)(fileRecords[i + 1]));
205 - int attributes = (int)(fileRecords[i + 2]);
132 + var componentId = (string)fileRecords[i];
133 + var fileName = this.SourceFileFromFileName((string)fileRecords[i + 1]);
134 + var attributes = (int)fileRecords[i + 2];
135
136 // If the whole database is marked uncompressed, use the directory layout made above
208 - if ((!compressed && MsidbFileAttributesCompressed != (attributes & MsidbFileAttributesCompressed)))
137 + if (!compressed && MsidbFileAttributesCompressed != (attributes & MsidbFileAttributesCompressed))
138 {
139 looseFileNames.Add(new TaskItem(Path.GetFullPath(Path.Combine(ComponentFullDirectory[componentId], fileName))));
140 }
@@ -217,9 +146,37 @@ namespace WixToolset.BuildTasks
146 }
147 }
148
220 - this.looseFileList = looseFileNames.ToArray();
149 + this.LooseFileList = looseFileNames.ToArray();
150
151 return true;
152 }
153 +
154 + /// <summary>
155 + /// Takes the "defaultDir" column
156 + /// </summary>
157 + /// <returns>Returns the corresponding sourceDir.</returns>
158 + public string SourceDirFromDefaultDir(string defaultDir)
159 + {
160 + var split = defaultDir.Split(':');
161 +
162 + var sourceDir = (1 == split.Length) ? split[0] : split[1];
163 +
164 + split = sourceDir.Split('|');
165 +
166 + sourceDir = (1 == split.Length) ? split[0] : split[1];
167 +
168 + return sourceDir;
169 + }
170 +
171 + /// <summary>
172 + /// Takes the "FileName" column
173 + /// </summary>
174 + /// <returns>Returns the corresponding source file name.</returns>
175 + private string SourceFileFromFileName(string fileName)
176 + {
177 + var split = fileName.Split('|');
178 +
179 + return (1 == split.Length) ? split[0] : split[1];
180 + }
181 }
182 }
src/wix/WixToolset.Sdk/tools/wix.signing.targets
+7 -2
@@ -8,8 +8,13 @@
8 </PropertyGroup>
9
10 <UsingTask TaskName="Insignia" AssemblyFile="$(WixTasksPath)" />
11 - <UsingTask TaskName="GetCabList" AssemblyFile="$(WixTasksPath)" />
12 - <UsingTask TaskName="GetLooseFileList" AssemblyFile="$(WixTasksPath)" />
11 + <UsingTask TaskName="GetCabList" Condition=" '$(WixTasksPath64)' == '' " AssemblyFile="$(WixTasksPath)" />
12 + <UsingTask TaskName="GetCabList" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath)" Architecture="x86" />
13 + <UsingTask TaskName="GetCabList" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath64)" Architecture="x64" />
14 +
15 + <UsingTask TaskName="GetLooseFileList" Condition=" '$(WixTasksPath64)' == '' " AssemblyFile="$(WixTasksPath)" />
16 + <UsingTask TaskName="GetLooseFileList" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath)" Architecture="x86" />
17 + <UsingTask TaskName="GetLooseFileList" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath64)" Architecture="x64" />
18
19 <UsingTask TaskName="InscribeMsiWithCabinetSignatures" Condition=" '$(WixTasksPath64)' == '' " AssemblyFile="$(WixTasksPath)" />
20 <UsingTask TaskName="InscribeMsiWithCabinetSignatures" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath)" Architecture="x86" />