diff options
author | Rob Mensching <rob@firegiant.com> | 2022-01-08 07:47:13 -0800 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-01-10 17:08:43 -0800 |
commit | ee2bb35228e8d3c12ae0e31748075777e10f9d62 (patch) | |
tree | fec2bca2f1b76e5e621a61557783c93af81fa735 /src | |
parent | 4182d6d594301b88d4780d0222a3d1448b524fde (diff) | |
download | wix-ee2bb35228e8d3c12ae0e31748075777e10f9d62.tar.gz wix-ee2bb35228e8d3c12ae0e31748075777e10f9d62.tar.bz2 wix-ee2bb35228e8d3c12ae0e31748075777e10f9d62.zip |
Modernize GetCabList and GetLooseFileList tasks
Diffstat (limited to 'src')
-rw-r--r-- | src/wix/WixToolset.BuildTasks/GetCabList.cs | 14 | ||||
-rw-r--r-- | src/wix/WixToolset.BuildTasks/GetLooseFileList.cs | 171 | ||||
-rw-r--r-- | src/wix/WixToolset.Sdk/tools/wix.signing.targets | 9 |
3 files changed, 78 insertions, 116 deletions
diff --git a/src/wix/WixToolset.BuildTasks/GetCabList.cs b/src/wix/WixToolset.BuildTasks/GetCabList.cs index 6e8cd991..18623caa 100644 --- a/src/wix/WixToolset.BuildTasks/GetCabList.cs +++ b/src/wix/WixToolset.BuildTasks/GetCabList.cs | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace WixToolset.BuildTasks | 3 | namespace WixToolset.BuildTasks |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | ||
6 | using System.IO; | 7 | using System.IO; |
7 | using Microsoft.Build.Framework; | 8 | using Microsoft.Build.Framework; |
8 | using Microsoft.Build.Utilities; | 9 | using Microsoft.Build.Utilities; |
@@ -32,9 +33,8 @@ namespace WixToolset.BuildTasks | |||
32 | /// <returns>True upon completion of the task execution.</returns> | 33 | /// <returns>True upon completion of the task execution.</returns> |
33 | public override bool Execute() | 34 | public override bool Execute() |
34 | { | 35 | { |
35 | string databaseFile = this.Database.ItemSpec; | 36 | var cabNames = new List<ITaskItem>(); |
36 | object[] args = { }; | 37 | var databaseFile = this.Database.ItemSpec; |
37 | System.Collections.Generic.List<ITaskItem> cabNames = new System.Collections.Generic.List<ITaskItem>(); | ||
38 | 38 | ||
39 | // If the file doesn't exist, no cabs to return, so exit now | 39 | // If the file doesn't exist, no cabs to return, so exit now |
40 | if (!File.Exists(databaseFile)) | 40 | if (!File.Exists(databaseFile)) |
@@ -42,7 +42,7 @@ namespace WixToolset.BuildTasks | |||
42 | return true; | 42 | return true; |
43 | } | 43 | } |
44 | 44 | ||
45 | using (Database database = new Database(databaseFile)) | 45 | using (var database = new Database(databaseFile)) |
46 | { | 46 | { |
47 | // If the media table doesn't exist, no cabs to return, so exit now | 47 | // If the media table doesn't exist, no cabs to return, so exit now |
48 | if (null == database.Tables["Media"]) | 48 | if (null == database.Tables["Media"]) |
@@ -50,16 +50,16 @@ namespace WixToolset.BuildTasks | |||
50 | return true; | 50 | return true; |
51 | } | 51 | } |
52 | 52 | ||
53 | System.Collections.IList records = database.ExecuteQuery("SELECT `Cabinet` FROM `Media`", args); | 53 | var databaseDirectory = Path.GetDirectoryName(databaseFile); |
54 | 54 | ||
55 | foreach (string cabName in records) | 55 | foreach (string cabName in database.ExecuteQuery("SELECT `Cabinet` FROM `Media`")) |
56 | { | 56 | { |
57 | if (String.IsNullOrEmpty(cabName) || cabName.StartsWith("#", StringComparison.Ordinal)) | 57 | if (String.IsNullOrEmpty(cabName) || cabName.StartsWith("#", StringComparison.Ordinal)) |
58 | { | 58 | { |
59 | continue; | 59 | continue; |
60 | } | 60 | } |
61 | 61 | ||
62 | cabNames.Add(new TaskItem(Path.Combine(Path.GetDirectoryName(databaseFile), cabName))); | 62 | cabNames.Add(new TaskItem(Path.Combine(databaseDirectory, cabName))); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
diff --git a/src/wix/WixToolset.BuildTasks/GetLooseFileList.cs b/src/wix/WixToolset.BuildTasks/GetLooseFileList.cs index d1eb62c1..ba04a374 100644 --- a/src/wix/WixToolset.BuildTasks/GetLooseFileList.cs +++ b/src/wix/WixToolset.BuildTasks/GetLooseFileList.cs | |||
@@ -15,9 +15,6 @@ namespace WixToolset.BuildTasks | |||
15 | /// </summary> | 15 | /// </summary> |
16 | public class GetLooseFileList : Task | 16 | public class GetLooseFileList : Task |
17 | { | 17 | { |
18 | private ITaskItem database; | ||
19 | private ITaskItem[] looseFileList; | ||
20 | |||
21 | internal const int MsidbFileAttributesNoncompressed = 8192; | 18 | internal const int MsidbFileAttributesNoncompressed = 8192; |
22 | internal const int MsidbFileAttributesCompressed = 16384; | 19 | internal const int MsidbFileAttributesCompressed = 16384; |
23 | 20 | ||
@@ -25,75 +22,13 @@ namespace WixToolset.BuildTasks | |||
25 | /// The list of database files to find Loose Files in | 22 | /// The list of database files to find Loose Files in |
26 | /// </summary> | 23 | /// </summary> |
27 | [Required] | 24 | [Required] |
28 | public ITaskItem Database | 25 | public ITaskItem Database { get; set; } |
29 | { | ||
30 | get { return this.database; } | ||
31 | set { this.database = value; } | ||
32 | } | ||
33 | 26 | ||
34 | /// <summary> | 27 | /// <summary> |
35 | /// The total list of Loose Files in this database | 28 | /// The total list of Loose Files in this database |
36 | /// </summary> | 29 | /// </summary> |
37 | [Output] | 30 | [Output] |
38 | public ITaskItem[] LooseFileList | 31 | public ITaskItem[] LooseFileList { get; private set; } |
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 | } | ||
97 | 32 | ||
98 | /// <summary> | 33 | /// <summary> |
99 | /// Gets a complete list of external Loose Files referenced by the given installer database file. | 34 | /// Gets a complete list of external Loose Files referenced by the given installer database file. |
@@ -101,15 +36,12 @@ namespace WixToolset.BuildTasks | |||
101 | /// <returns>True upon completion of the task execution.</returns> | 36 | /// <returns>True upon completion of the task execution.</returns> |
102 | public override bool Execute() | 37 | public override bool Execute() |
103 | { | 38 | { |
104 | string databaseFile = this.database.ItemSpec; | 39 | var databaseFile = this.Database.ItemSpec; |
105 | Object []emptyArgs = { }; | 40 | var looseFileNames = new List<ITaskItem>(); |
106 | System.Collections.Generic.List<ITaskItem> looseFileNames = new System.Collections.Generic.List<ITaskItem>(); | 41 | var ComponentFullDirectory = new Dictionary<string, string>(); |
107 | Dictionary<string, string> ComponentFullDirectory = new Dictionary<string, string>(); | 42 | var DirectoryIdDefaultDir = new Dictionary<string, string>(); |
108 | Dictionary<string, string> DirectoryIdDefaultDir = new Dictionary<string, string>(); | 43 | var DirectoryIdParent = new Dictionary<string, string>(); |
109 | Dictionary<string, string> DirectoryIdParent = new Dictionary<string, string>(); | 44 | var DirectoryIdFullSource = new Dictionary<string, string>(); |
110 | Dictionary<string, string> DirectoryIdFullSource = new Dictionary<string, string>(); | ||
111 | int i; | ||
112 | string databaseDir = Path.GetDirectoryName(databaseFile); | ||
113 | 45 | ||
114 | // If the file doesn't exist, no Loose Files to return, so exit now | 46 | // If the file doesn't exist, no Loose Files to return, so exit now |
115 | if (!File.Exists(databaseFile)) | 47 | if (!File.Exists(databaseFile)) |
@@ -117,20 +49,18 @@ namespace WixToolset.BuildTasks | |||
117 | return true; | 49 | return true; |
118 | } | 50 | } |
119 | 51 | ||
120 | using (Database database = new Database(databaseFile)) | 52 | var databaseDir = Path.GetDirectoryName(databaseFile); |
121 | { | ||
122 | bool compressed = false; | ||
123 | if (2 == (database.SummaryInfo.WordCount & 2)) | ||
124 | { | ||
125 | compressed = true; | ||
126 | } | ||
127 | 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 | ||
129 | if (null == database.Tables["File"]) | 57 | if (null == database.Tables["File"]) |
130 | { | 58 | { |
131 | return true; | 59 | return true; |
132 | } | 60 | } |
133 | 61 | ||
62 | var compressed = 2 == (database.SummaryInfo.WordCount & 2); | ||
63 | |||
134 | // 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, | 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, |
135 | // so none of these indexes will be used | 65 | // so none of these indexes will be used |
136 | if (!compressed) | 66 | if (!compressed) |
@@ -140,29 +70,28 @@ namespace WixToolset.BuildTasks | |||
140 | return true; | 70 | return true; |
141 | } | 71 | } |
142 | 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`"); |
144 | 74 | ||
145 | // First setup a simple index from DirectoryId to DefaultDir | 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) |
147 | { | 77 | { |
148 | string directoryId = (string)(directoryRecords[i]); | 78 | var directoryId = (string)directoryRecords[i]; |
149 | string directoryParent = (string)(directoryRecords[i + 1]); | 79 | var directoryParent = (string)directoryRecords[i + 1]; |
150 | string defaultDir = (string)(directoryRecords[i + 2]); | 80 | var defaultDir = (string)directoryRecords[i + 2]; |
151 | 81 | ||
152 | string sourceDir = this.SourceDirFromDefaultDir(defaultDir); | 82 | var sourceDir = this.SourceDirFromDefaultDir(defaultDir); |
153 | 83 | ||
154 | DirectoryIdDefaultDir[directoryId] = sourceDir; | 84 | DirectoryIdDefaultDir[directoryId] = sourceDir; |
155 | DirectoryIdParent[directoryId] = directoryParent; | 85 | DirectoryIdParent[directoryId] = directoryParent; |
156 | } | 86 | } |
157 | 87 | ||
158 | // Setup an index from directory Id to the full source path | 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) |
160 | { | 90 | { |
161 | string directoryId = (string)(directoryRecords[i]); | 91 | var directoryId = (string)directoryRecords[i]; |
162 | string directoryParent = (string)(directoryRecords[i + 1]); | 92 | var directoryParent = (string)directoryRecords[i + 1]; |
163 | string defaultDir = (string)(directoryRecords[i + 2]); | ||
164 | 93 | ||
165 | string sourceDir = DirectoryIdDefaultDir[directoryId]; | 94 | var sourceDir = DirectoryIdDefaultDir[directoryId]; |
166 | 95 | ||
167 | // The TARGETDIR case | 96 | // The TARGETDIR case |
168 | if (String.IsNullOrEmpty(directoryParent)) | 97 | if (String.IsNullOrEmpty(directoryParent)) |
@@ -171,7 +100,7 @@ namespace WixToolset.BuildTasks | |||
171 | } | 100 | } |
172 | else | 101 | else |
173 | { | 102 | { |
174 | string tempDirectoryParent = directoryParent; | 103 | var tempDirectoryParent = directoryParent; |
175 | 104 | ||
176 | while (!String.IsNullOrEmpty(tempDirectoryParent) && !String.IsNullOrEmpty(DirectoryIdParent[tempDirectoryParent])) | 105 | while (!String.IsNullOrEmpty(tempDirectoryParent) && !String.IsNullOrEmpty(DirectoryIdParent[tempDirectoryParent])) |
177 | { | 106 | { |
@@ -185,27 +114,27 @@ namespace WixToolset.BuildTasks | |||
185 | } | 114 | } |
186 | 115 | ||
187 | // Setup an index from component Id to full directory path | 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`"); |
189 | 118 | ||
190 | for (i = 0; i < componentRecords.Count; i += 2) | 119 | for (var i = 0; i < componentRecords.Count; i += 2) |
191 | { | 120 | { |
192 | string componentId = (string)(componentRecords[i]); | 121 | var componentId = (string)componentRecords[i]; |
193 | string componentDir = (string)(componentRecords[i + 1]); | 122 | var componentDir = (string)componentRecords[i + 1]; |
194 | 123 | ||
195 | ComponentFullDirectory[componentId] = DirectoryIdFullSource[componentDir]; | 124 | ComponentFullDirectory[componentId] = DirectoryIdFullSource[componentDir]; |
196 | } | 125 | } |
197 | } | 126 | } |
198 | 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`"); |
200 | 129 | ||
201 | for (i = 0; i < fileRecords.Count; i += 3) | 130 | for (var i = 0; i < fileRecords.Count; i += 3) |
202 | { | 131 | { |
203 | string componentId = (string)(fileRecords[i]); | 132 | var componentId = (string)fileRecords[i]; |
204 | string fileName = this.SourceFileFromFileName((string)(fileRecords[i + 1])); | 133 | var fileName = this.SourceFileFromFileName((string)fileRecords[i + 1]); |
205 | int attributes = (int)(fileRecords[i + 2]); | 134 | var attributes = (int)fileRecords[i + 2]; |
206 | 135 | ||
207 | // If the whole database is marked uncompressed, use the directory layout made above | 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)) |
209 | { | 138 | { |
210 | looseFileNames.Add(new TaskItem(Path.GetFullPath(Path.Combine(ComponentFullDirectory[componentId], fileName)))); | 139 | looseFileNames.Add(new TaskItem(Path.GetFullPath(Path.Combine(ComponentFullDirectory[componentId], fileName)))); |
211 | } | 140 | } |
@@ -217,9 +146,37 @@ namespace WixToolset.BuildTasks | |||
217 | } | 146 | } |
218 | } | 147 | } |
219 | 148 | ||
220 | this.looseFileList = looseFileNames.ToArray(); | 149 | this.LooseFileList = looseFileNames.ToArray(); |
221 | 150 | ||
222 | return true; | 151 | return true; |
223 | } | 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 | } | ||
224 | } | 181 | } |
225 | } | 182 | } |
diff --git a/src/wix/WixToolset.Sdk/tools/wix.signing.targets b/src/wix/WixToolset.Sdk/tools/wix.signing.targets index 3df05d51..45556e23 100644 --- a/src/wix/WixToolset.Sdk/tools/wix.signing.targets +++ b/src/wix/WixToolset.Sdk/tools/wix.signing.targets | |||
@@ -8,8 +8,13 @@ | |||
8 | </PropertyGroup> | 8 | </PropertyGroup> |
9 | 9 | ||
10 | <UsingTask TaskName="Insignia" AssemblyFile="$(WixTasksPath)" /> | 10 | <UsingTask TaskName="Insignia" AssemblyFile="$(WixTasksPath)" /> |
11 | <UsingTask TaskName="GetCabList" AssemblyFile="$(WixTasksPath)" /> | 11 | <UsingTask TaskName="GetCabList" Condition=" '$(WixTasksPath64)' == '' " AssemblyFile="$(WixTasksPath)" /> |
12 | <UsingTask TaskName="GetLooseFileList" 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" /> | ||
13 | 18 | ||
14 | <UsingTask TaskName="InscribeMsiWithCabinetSignatures" Condition=" '$(WixTasksPath64)' == '' " AssemblyFile="$(WixTasksPath)" /> | 19 | <UsingTask TaskName="InscribeMsiWithCabinetSignatures" Condition=" '$(WixTasksPath64)' == '' " AssemblyFile="$(WixTasksPath)" /> |
15 | <UsingTask TaskName="InscribeMsiWithCabinetSignatures" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath)" Architecture="x86" /> | 20 | <UsingTask TaskName="InscribeMsiWithCabinetSignatures" Condition=" '$(WixTasksPath64)' != '' " AssemblyFile="$(WixTasksPath)" Architecture="x86" /> |