aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.BuildTasks/GetLooseFileList.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.BuildTasks/GetLooseFileList.cs')
-rw-r--r--src/WixToolset.BuildTasks/GetLooseFileList.cs230
1 files changed, 0 insertions, 230 deletions
diff --git a/src/WixToolset.BuildTasks/GetLooseFileList.cs b/src/WixToolset.BuildTasks/GetLooseFileList.cs
deleted file mode 100644
index bd403426..00000000
--- a/src/WixToolset.BuildTasks/GetLooseFileList.cs
+++ /dev/null
@@ -1,230 +0,0 @@
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
3namespace WixToolset.BuildTasks
4{
5 using System;
6 using System.Collections;
7 using System.Collections.Generic;
8 using System.Diagnostics;
9 using System.IO;
10 using System.Reflection;
11 using System.Xml;
12 using Microsoft.Build.Framework;
13 using Microsoft.Build.Utilities;
14 using WixToolset.Dtf.WindowsInstaller;
15 using Microsoft.Win32;
16
17 /// <summary>
18 /// This task assigns Culture metadata to files based on the value of the Culture attribute on the
19 /// WixLocalization element inside the file.
20 /// </summary>
21 public class GetLooseFileList : Task
22 {
23 private ITaskItem database;
24 private ITaskItem[] looseFileList;
25
26 internal const int MsidbFileAttributesNoncompressed = 8192;
27 internal const int MsidbFileAttributesCompressed = 16384;
28
29 /// <summary>
30 /// The list of database files to find Loose Files in
31 /// </summary>
32 [Required]
33 public ITaskItem Database
34 {
35 get { return this.database; }
36 set { this.database = value; }
37 }
38
39 /// <summary>
40 /// The total list of Loose Files in this database
41 /// </summary>
42 [Output]
43 public ITaskItem[] LooseFileList
44 {
45 get { return this.looseFileList; }
46 }
47
48 /// <summary>
49 /// Takes the "defaultDir" column
50 /// </summary>
51 /// <returns>Returns the corresponding sourceDir.</returns>
52 public string SourceDirFromDefaultDir(string defaultDir)
53 {
54 string sourceDir;
55
56 string[] splitted = defaultDir.Split(':');
57
58 if (1 == splitted.Length)
59 {
60 sourceDir = splitted[0];
61 }
62 else
63 {
64 sourceDir = splitted[1];
65 }
66
67 splitted = sourceDir.Split('|');
68
69 if (1 == splitted.Length)
70 {
71 sourceDir = splitted[0];
72 }
73 else
74 {
75 sourceDir = splitted[1];
76 }
77
78 return sourceDir;
79 }
80
81 /// <summary>
82 /// Takes the "FileName" column
83 /// </summary>
84 /// <returns>Returns the corresponding source file name.</returns>
85 public string SourceFileFromFileName(string fileName)
86 {
87 string sourceFile;
88
89 string[] splitted = fileName.Split('|');
90
91 if (1 == splitted.Length)
92 {
93 sourceFile = splitted[0];
94 }
95 else
96 {
97 sourceFile = splitted[1];
98 }
99
100 return sourceFile;
101 }
102
103 /// <summary>
104 /// Gets a complete list of external Loose Files referenced by the given installer database file.
105 /// </summary>
106 /// <returns>True upon completion of the task execution.</returns>
107 public override bool Execute()
108 {
109 string databaseFile = this.database.ItemSpec;
110 Object []emptyArgs = { };
111 System.Collections.Generic.List<ITaskItem> looseFileNames = new System.Collections.Generic.List<ITaskItem>();
112 Dictionary<string, string> ComponentFullDirectory = new Dictionary<string, string>();
113 Dictionary<string, string> DirectoryIdDefaultDir = new Dictionary<string, string>();
114 Dictionary<string, string> DirectoryIdParent = new Dictionary<string, string>();
115 Dictionary<string, string> DirectoryIdFullSource = new Dictionary<string, string>();
116 int i;
117 string databaseDir = Path.GetDirectoryName(databaseFile);
118
119 // If the file doesn't exist, no Loose Files to return, so exit now
120 if (!File.Exists(databaseFile))
121 {
122 return true;
123 }
124
125 using (Database database = new Database(databaseFile))
126 {
127 bool compressed = false;
128 if (2 == (database.SummaryInfo.WordCount & 2))
129 {
130 compressed = true;
131 }
132
133 // If the media table doesn't exist, no Loose Files to return, so exit now
134 if (null == database.Tables["File"])
135 {
136 return true;
137 }
138
139 // 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,
140 // so none of these indexes will be used
141 if (!compressed)
142 {
143 if (null == database.Tables["Directory"] || null == database.Tables["Component"])
144 {
145 return true;
146 }
147
148 System.Collections.IList directoryRecords = database.ExecuteQuery("SELECT `Directory`,`Directory_Parent`,`DefaultDir` FROM `Directory`", emptyArgs);
149
150 // First setup a simple index from DirectoryId to DefaultDir
151 for (i = 0; i < directoryRecords.Count; i += 3)
152 {
153 string directoryId = (string)(directoryRecords[i]);
154 string directoryParent = (string)(directoryRecords[i + 1]);
155 string defaultDir = (string)(directoryRecords[i + 2]);
156
157 string sourceDir = SourceDirFromDefaultDir(defaultDir);
158
159 DirectoryIdDefaultDir[directoryId] = sourceDir;
160 DirectoryIdParent[directoryId] = directoryParent;
161 }
162
163 // Setup an index from directory Id to the full source path
164 for (i = 0; i < directoryRecords.Count; i += 3)
165 {
166 string directoryId = (string)(directoryRecords[i]);
167 string directoryParent = (string)(directoryRecords[i + 1]);
168 string defaultDir = (string)(directoryRecords[i + 2]);
169
170 string sourceDir = DirectoryIdDefaultDir[directoryId];
171
172 // The TARGETDIR case
173 if (String.IsNullOrEmpty(directoryParent))
174 {
175 DirectoryIdFullSource[directoryId] = databaseDir;
176 }
177 else
178 {
179 string tempDirectoryParent = directoryParent;
180
181 while (!String.IsNullOrEmpty(tempDirectoryParent) && !String.IsNullOrEmpty(DirectoryIdParent[tempDirectoryParent]))
182 {
183 sourceDir = Path.Combine(DirectoryIdDefaultDir[tempDirectoryParent], sourceDir);
184
185 tempDirectoryParent = DirectoryIdParent[tempDirectoryParent];
186 }
187
188 DirectoryIdFullSource[directoryId] = Path.Combine(databaseDir, sourceDir);
189 }
190 }
191
192 // Setup an index from component Id to full directory path
193 System.Collections.IList componentRecords = database.ExecuteQuery("SELECT `Component`,`Directory_` FROM `Component`", emptyArgs);
194
195 for (i = 0; i < componentRecords.Count; i += 2)
196 {
197 string componentId = (string)(componentRecords[i]);
198 string componentDir = (string)(componentRecords[i + 1]);
199
200 ComponentFullDirectory[componentId] = DirectoryIdFullSource[componentDir];
201 }
202 }
203
204 System.Collections.IList fileRecords = database.ExecuteQuery("SELECT `Component_`,`FileName`,`Attributes` FROM `File`", emptyArgs);
205
206 for (i = 0; i < fileRecords.Count; i += 3)
207 {
208 string componentId = (string)(fileRecords[i]);
209 string fileName = SourceFileFromFileName((string)(fileRecords[i + 1]));
210 int attributes = (int)(fileRecords[i + 2]);
211
212 // If the whole database is marked uncompressed, use the directory layout made above
213 if ((!compressed && MsidbFileAttributesCompressed != (attributes & MsidbFileAttributesCompressed)))
214 {
215 looseFileNames.Add(new TaskItem(Path.GetFullPath(Path.Combine(ComponentFullDirectory[componentId], fileName))));
216 }
217 // If the database is marked as compressed, put files at the root
218 else if (compressed && (MsidbFileAttributesNoncompressed == (attributes & MsidbFileAttributesNoncompressed)))
219 {
220 looseFileNames.Add(new TaskItem(Path.GetFullPath(Path.Combine(databaseDir, fileName))));
221 }
222 }
223 }
224
225 this.looseFileList = looseFileNames.ToArray();
226
227 return true;
228 }
229 }
230}