From dbde9e7104b907bbbaea17e21247d8cafc8b3a4c Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 14 Oct 2017 16:12:07 -0700 Subject: Massive refactoring to introduce the concept of IBackend --- .../Bind/ProcessUncompressedFilesCommand.cs | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs') 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 @@ +// 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. + +namespace WixToolset.Core.WindowsInstaller.Databases +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.IO; + using WixToolset.Data; + using WixToolset.Data.Rows; + using WixToolset.Msi; + using WixToolset.Core.Native; + using WixToolset.Bind; + using WixToolset.Core.Bind; + using WixToolset.Data.Bind; + + /// + /// Defines the file transfers necessary to layout the uncompressed files. + /// + internal class ProcessUncompressedFilesCommand + { + public string DatabasePath { private get; set; } + + public IEnumerable FileFacades { private get; set; } + + public RowDictionary MediaRows { private get; set; } + + public string LayoutDirectory { private get; set; } + + public bool Compressed { private get; set; } + + public bool LongNamesInImage { private get; set; } + + public Func ResolveMedia { private get; set; } + + public Table WixMediaTable { private get; set; } + + public IEnumerable FileTransfers { get; private set; } + + public void Execute() + { + List fileTransfers = new List(); + + Hashtable directories = new Hashtable(); + + RowDictionary wixMediaRows = new RowDictionary(this.WixMediaTable); + + using (Database db = new Database(this.DatabasePath, OpenDatabase.ReadOnly)) + { + using (View directoryView = db.OpenExecuteView("SELECT `Directory`, `Directory_Parent`, `DefaultDir` FROM `Directory`")) + { + while (true) + { + using (Record directoryRecord = directoryView.Fetch()) + { + if (null == directoryRecord) + { + break; + } + + string sourceName = Common.GetName(directoryRecord.GetString(3), true, this.LongNamesInImage); + + directories.Add(directoryRecord.GetString(1), new ResolvedDirectory(directoryRecord.GetString(2), sourceName)); + } + } + } + + using (View fileView = db.OpenView("SELECT `Directory_`, `FileName` FROM `Component`, `File` WHERE `Component`.`Component`=`File`.`Component_` AND `File`.`File`=?")) + { + using (Record fileQueryRecord = new Record(1)) + { + // for each file in the array of uncompressed files + foreach (FileFacade facade in this.FileFacades) + { + MediaRow mediaRow = this.MediaRows.Get(facade.WixFile.DiskId); + string relativeFileLayoutPath = null; + + WixMediaRow wixMediaRow = null; + string mediaLayoutFolder = null; + + if (wixMediaRows.TryGetValue(mediaRow.GetKey(), out wixMediaRow)) + { + mediaLayoutFolder = wixMediaRow.Layout; + } + + string mediaLayoutDirectory = this.ResolveMedia(mediaRow, mediaLayoutFolder, this.LayoutDirectory); + + // setup up the query record and find the appropriate file in the + // previously executed file view + fileQueryRecord[1] = facade.File.File; + fileView.Execute(fileQueryRecord); + + using (Record fileRecord = fileView.Fetch()) + { + if (null == fileRecord) + { + throw new WixException(WixErrors.FileIdentifierNotFound(facade.File.SourceLineNumbers, facade.File.File)); + } + + relativeFileLayoutPath = Binder.GetFileSourcePath(directories, fileRecord[1], fileRecord[2], this.Compressed, this.LongNamesInImage); + } + + // finally put together the base media layout path and the relative file layout path + string fileLayoutPath = Path.Combine(mediaLayoutDirectory, relativeFileLayoutPath); + FileTransfer transfer; + if (FileTransfer.TryCreate(facade.WixFile.Source, fileLayoutPath, false, "File", facade.File.SourceLineNumbers, out transfer)) + { + fileTransfers.Add(transfer); + } + } + } + } + } + + this.FileTransfers = fileTransfers; + } + } +} -- cgit v1.2.3-55-g6feb