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