diff options
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs')
-rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs new file mode 100644 index 00000000..b3c09b9e --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs | |||
@@ -0,0 +1,118 @@ | |||
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.Core.WindowsInstaller.Databases | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections; | ||
7 | using System.Collections.Generic; | ||
8 | using System.IO; | ||
9 | using WixToolset.Data; | ||
10 | using WixToolset.Data.Rows; | ||
11 | using WixToolset.Msi; | ||
12 | using WixToolset.Core.Native; | ||
13 | using WixToolset.Bind; | ||
14 | using WixToolset.Core.Bind; | ||
15 | using WixToolset.Data.Bind; | ||
16 | |||
17 | /// <summary> | ||
18 | /// Defines the file transfers necessary to layout the uncompressed files. | ||
19 | /// </summary> | ||
20 | internal class ProcessUncompressedFilesCommand | ||
21 | { | ||
22 | public string DatabasePath { private get; set; } | ||
23 | |||
24 | public IEnumerable<FileFacade> FileFacades { private get; set; } | ||
25 | |||
26 | public RowDictionary<MediaRow> MediaRows { private get; set; } | ||
27 | |||
28 | public string LayoutDirectory { private get; set; } | ||
29 | |||
30 | public bool Compressed { private get; set; } | ||
31 | |||
32 | public bool LongNamesInImage { private get; set; } | ||
33 | |||
34 | public Func<MediaRow, string, string, string> ResolveMedia { private get; set; } | ||
35 | |||
36 | public Table WixMediaTable { private get; set; } | ||
37 | |||
38 | public IEnumerable<FileTransfer> FileTransfers { get; private set; } | ||
39 | |||
40 | public void Execute() | ||
41 | { | ||
42 | List<FileTransfer> fileTransfers = new List<FileTransfer>(); | ||
43 | |||
44 | Hashtable directories = new Hashtable(); | ||
45 | |||
46 | RowDictionary<WixMediaRow> wixMediaRows = new RowDictionary<WixMediaRow>(this.WixMediaTable); | ||
47 | |||
48 | using (Database db = new Database(this.DatabasePath, OpenDatabase.ReadOnly)) | ||
49 | { | ||
50 | using (View directoryView = db.OpenExecuteView("SELECT `Directory`, `Directory_Parent`, `DefaultDir` FROM `Directory`")) | ||
51 | { | ||
52 | while (true) | ||
53 | { | ||
54 | using (Record directoryRecord = directoryView.Fetch()) | ||
55 | { | ||
56 | if (null == directoryRecord) | ||
57 | { | ||
58 | break; | ||
59 | } | ||
60 | |||
61 | string sourceName = Common.GetName(directoryRecord.GetString(3), true, this.LongNamesInImage); | ||
62 | |||
63 | directories.Add(directoryRecord.GetString(1), new ResolvedDirectory(directoryRecord.GetString(2), sourceName)); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | using (View fileView = db.OpenView("SELECT `Directory_`, `FileName` FROM `Component`, `File` WHERE `Component`.`Component`=`File`.`Component_` AND `File`.`File`=?")) | ||
69 | { | ||
70 | using (Record fileQueryRecord = new Record(1)) | ||
71 | { | ||
72 | // for each file in the array of uncompressed files | ||
73 | foreach (FileFacade facade in this.FileFacades) | ||
74 | { | ||
75 | MediaRow mediaRow = this.MediaRows.Get(facade.WixFile.DiskId); | ||
76 | string relativeFileLayoutPath = null; | ||
77 | |||
78 | WixMediaRow wixMediaRow = null; | ||
79 | string mediaLayoutFolder = null; | ||
80 | |||
81 | if (wixMediaRows.TryGetValue(mediaRow.GetKey(), out wixMediaRow)) | ||
82 | { | ||
83 | mediaLayoutFolder = wixMediaRow.Layout; | ||
84 | } | ||
85 | |||
86 | string mediaLayoutDirectory = this.ResolveMedia(mediaRow, mediaLayoutFolder, this.LayoutDirectory); | ||
87 | |||
88 | // setup up the query record and find the appropriate file in the | ||
89 | // previously executed file view | ||
90 | fileQueryRecord[1] = facade.File.File; | ||
91 | fileView.Execute(fileQueryRecord); | ||
92 | |||
93 | using (Record fileRecord = fileView.Fetch()) | ||
94 | { | ||
95 | if (null == fileRecord) | ||
96 | { | ||
97 | throw new WixException(WixErrors.FileIdentifierNotFound(facade.File.SourceLineNumbers, facade.File.File)); | ||
98 | } | ||
99 | |||
100 | relativeFileLayoutPath = Binder.GetFileSourcePath(directories, fileRecord[1], fileRecord[2], this.Compressed, this.LongNamesInImage); | ||
101 | } | ||
102 | |||
103 | // finally put together the base media layout path and the relative file layout path | ||
104 | string fileLayoutPath = Path.Combine(mediaLayoutDirectory, relativeFileLayoutPath); | ||
105 | FileTransfer transfer; | ||
106 | if (FileTransfer.TryCreate(facade.WixFile.Source, fileLayoutPath, false, "File", facade.File.SourceLineNumbers, out transfer)) | ||
107 | { | ||
108 | fileTransfers.Add(transfer); | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | |||
115 | this.FileTransfers = fileTransfers; | ||
116 | } | ||
117 | } | ||
118 | } | ||