diff options
| author | Rob Mensching <rob@firegiant.com> | 2018-08-11 01:06:40 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2018-08-11 01:06:40 -0700 |
| commit | 2a27f9032aa115bc2f88d9be695d9b049db1a894 (patch) | |
| tree | 7882bd4c94da118a6fc655a3c22e1dd0cf3b60e1 /src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs | |
| parent | b54516035b4ebbfbd8899b26de501bfa13f53e8b (diff) | |
| download | wix-2a27f9032aa115bc2f88d9be695d9b049db1a894.tar.gz wix-2a27f9032aa115bc2f88d9be695d9b049db1a894.tar.bz2 wix-2a27f9032aa115bc2f88d9be695d9b049db1a894.zip | |
Track files to enable clean builds in MSBuild
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs')
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs index ed8f0ece..a85312c4 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs | |||
| @@ -28,6 +28,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 28 | 28 | ||
| 29 | private List<IFileTransfer> fileTransfers; | 29 | private List<IFileTransfer> fileTransfers; |
| 30 | 30 | ||
| 31 | private List<ITrackedFile> trackedFiles; | ||
| 32 | |||
| 31 | private FileSplitCabNamesCallback newCabNamesCallBack; | 33 | private FileSplitCabNamesCallback newCabNamesCallBack; |
| 32 | 34 | ||
| 33 | private Dictionary<string, string> lastCabinetAddedToMediaTable; // Key is First Cabinet Name, Value is Last Cabinet Added in the Split Sequence | 35 | private Dictionary<string, string> lastCabinetAddedToMediaTable; // Key is First Cabinet Name, Value is Last Cabinet Added in the Split Sequence |
| @@ -36,6 +38,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 36 | { | 38 | { |
| 37 | this.fileTransfers = new List<IFileTransfer>(); | 39 | this.fileTransfers = new List<IFileTransfer>(); |
| 38 | 40 | ||
| 41 | this.trackedFiles = new List<ITrackedFile>(); | ||
| 42 | |||
| 39 | this.newCabNamesCallBack = this.NewCabNamesCallBack; | 43 | this.newCabNamesCallBack = this.NewCabNamesCallBack; |
| 40 | 44 | ||
| 41 | this.BackendHelper = backendHelper; | 45 | this.BackendHelper = backendHelper; |
| @@ -78,8 +82,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 78 | 82 | ||
| 79 | public IEnumerable<IFileTransfer> FileTransfers => this.fileTransfers; | 83 | public IEnumerable<IFileTransfer> FileTransfers => this.fileTransfers; |
| 80 | 84 | ||
| 85 | public IEnumerable<ITrackedFile> TrackedFiles => this.trackedFiles; | ||
| 86 | |||
| 81 | /// <param name="output">Output to generate image for.</param> | 87 | /// <param name="output">Output to generate image for.</param> |
| 82 | /// <param name="fileTransfers">Array of files to be transfered.</param> | ||
| 83 | /// <param name="layoutDirectory">The directory in which the image should be layed out.</param> | 88 | /// <param name="layoutDirectory">The directory in which the image should be layed out.</param> |
| 84 | /// <param name="compressed">Flag if source image should be compressed.</param> | 89 | /// <param name="compressed">Flag if source image should be compressed.</param> |
| 85 | /// <returns>The uncompressed file rows.</returns> | 90 | /// <returns>The uncompressed file rows.</returns> |
| @@ -119,7 +124,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 119 | 124 | ||
| 120 | string cabinetDir = this.ResolveMedia(mediaTuple, mediaLayoutFolder, this.LayoutDirectory); | 125 | string cabinetDir = this.ResolveMedia(mediaTuple, mediaLayoutFolder, this.LayoutDirectory); |
| 121 | 126 | ||
| 122 | CabinetWorkItem cabinetWorkItem = this.CreateCabinetWorkItem(this.Output, cabinetDir, mediaTuple, compressionLevel, files, this.fileTransfers); | 127 | var cabinetWorkItem = this.CreateCabinetWorkItem(this.Output, cabinetDir, mediaTuple, compressionLevel, files); |
| 123 | if (null != cabinetWorkItem) | 128 | if (null != cabinetWorkItem) |
| 124 | { | 129 | { |
| 125 | cabinetBuilder.Enqueue(cabinetWorkItem); | 130 | cabinetBuilder.Enqueue(cabinetWorkItem); |
| @@ -188,9 +193,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 188 | /// <param name="cabinetDir">Directory to create cabinet in.</param> | 193 | /// <param name="cabinetDir">Directory to create cabinet in.</param> |
| 189 | /// <param name="mediaRow">MediaRow containing information about the cabinet.</param> | 194 | /// <param name="mediaRow">MediaRow containing information about the cabinet.</param> |
| 190 | /// <param name="fileFacades">Collection of files in this cabinet.</param> | 195 | /// <param name="fileFacades">Collection of files in this cabinet.</param> |
| 191 | /// <param name="fileTransfers">Array of files to be transfered.</param> | ||
| 192 | /// <returns>created CabinetWorkItem object</returns> | 196 | /// <returns>created CabinetWorkItem object</returns> |
| 193 | private CabinetWorkItem CreateCabinetWorkItem(Output output, string cabinetDir, MediaTuple mediaRow, CompressionLevel compressionLevel, IEnumerable<FileFacade> fileFacades, List<IFileTransfer> fileTransfers) | 197 | private CabinetWorkItem CreateCabinetWorkItem(Output output, string cabinetDir, MediaTuple mediaRow, CompressionLevel compressionLevel, IEnumerable<FileFacade> fileFacades) |
| 194 | { | 198 | { |
| 195 | CabinetWorkItem cabinetWorkItem = null; | 199 | CabinetWorkItem cabinetWorkItem = null; |
| 196 | string tempCabinetFileX = Path.Combine(this.TempFilesLocation, mediaRow.Cabinet); | 200 | string tempCabinetFileX = Path.Combine(this.TempFilesLocation, mediaRow.Cabinet); |
| @@ -219,7 +223,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 219 | 223 | ||
| 220 | var cabinetResolver = new CabinetResolver(this.CabCachePath, this.BackendExtensions); | 224 | var cabinetResolver = new CabinetResolver(this.CabCachePath, this.BackendExtensions); |
| 221 | 225 | ||
| 222 | ResolvedCabinet resolvedCabinet = cabinetResolver.ResolveCabinet(tempCabinetFileX, fileFacades); | 226 | var resolvedCabinet = cabinetResolver.ResolveCabinet(tempCabinetFileX, fileFacades); |
| 223 | 227 | ||
| 224 | // create a cabinet work item if it's not being skipped | 228 | // create a cabinet work item if it's not being skipped |
| 225 | if (CabinetBuildOption.BuildAndCopy == resolvedCabinet.BuildOption || CabinetBuildOption.BuildAndMove == resolvedCabinet.BuildOption) | 229 | if (CabinetBuildOption.BuildAndCopy == resolvedCabinet.BuildOption || CabinetBuildOption.BuildAndMove == resolvedCabinet.BuildOption) |
| @@ -248,19 +252,24 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 248 | } | 252 | } |
| 249 | } | 253 | } |
| 250 | 254 | ||
| 255 | var trackResolvedCabinet = this.BackendHelper.TrackFile(resolvedCabinet.Path, TrackedFileType.Intermediate, mediaRow.SourceLineNumbers); | ||
| 256 | this.trackedFiles.Add(trackResolvedCabinet); | ||
| 257 | |||
| 251 | if (mediaRow.Cabinet.StartsWith("#", StringComparison.Ordinal)) | 258 | if (mediaRow.Cabinet.StartsWith("#", StringComparison.Ordinal)) |
| 252 | { | 259 | { |
| 253 | Table streamsTable = output.EnsureTable(this.TableDefinitions["_Streams"]); | 260 | var streamsTable = output.EnsureTable(this.TableDefinitions["_Streams"]); |
| 254 | 261 | ||
| 255 | Row streamRow = streamsTable.CreateRow(mediaRow.SourceLineNumbers); | 262 | var streamRow = streamsTable.CreateRow(mediaRow.SourceLineNumbers); |
| 256 | streamRow[0] = mediaRow.Cabinet.Substring(1); | 263 | streamRow[0] = mediaRow.Cabinet.Substring(1); |
| 257 | streamRow[1] = resolvedCabinet.Path; | 264 | streamRow[1] = resolvedCabinet.Path; |
| 258 | } | 265 | } |
| 259 | else | 266 | else |
| 260 | { | 267 | { |
| 261 | var destinationPath = Path.Combine(cabinetDir, mediaRow.Cabinet); | 268 | var trackDestination = this.BackendHelper.TrackFile(Path.Combine(cabinetDir, mediaRow.Cabinet), TrackedFileType.Final, mediaRow.SourceLineNumbers); |
| 262 | var transfer = this.BackendHelper.CreateFileTransfer(resolvedCabinet.Path, destinationPath, CabinetBuildOption.BuildAndMove == resolvedCabinet.BuildOption, FileTransferType.Built, mediaRow.SourceLineNumbers); | 269 | this.trackedFiles.Add(trackDestination); |
| 263 | fileTransfers.Add(transfer); | 270 | |
| 271 | var transfer = this.BackendHelper.CreateFileTransfer(resolvedCabinet.Path, trackDestination.Path, resolvedCabinet.BuildOption == CabinetBuildOption.BuildAndMove, mediaRow.SourceLineNumbers); | ||
| 272 | this.fileTransfers.Add(transfer); | ||
| 264 | } | 273 | } |
| 265 | 274 | ||
| 266 | return cabinetWorkItem; | 275 | return cabinetWorkItem; |
| @@ -298,10 +307,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 298 | /// <param name="firstCabName">The name of splitting cabinet without extention e.g. "cab1".</param> | 307 | /// <param name="firstCabName">The name of splitting cabinet without extention e.g. "cab1".</param> |
| 299 | /// <param name="newCabName">The name of the new cabinet that would be formed by splitting e.g. "cab1b.cab"</param> | 308 | /// <param name="newCabName">The name of the new cabinet that would be formed by splitting e.g. "cab1b.cab"</param> |
| 300 | /// <param name="fileToken">The file token of the first file present in the splitting cabinet</param> | 309 | /// <param name="fileToken">The file token of the first file present in the splitting cabinet</param> |
| 301 | internal void NewCabNamesCallBack([MarshalAs(UnmanagedType.LPWStr)]string firstCabName, [MarshalAs(UnmanagedType.LPWStr)]string newCabName, [MarshalAs(UnmanagedType.LPWStr)]string fileToken) | 310 | internal void NewCabNamesCallBack([MarshalAs(UnmanagedType.LPWStr)]string firstCabName, [MarshalAs(UnmanagedType.LPWStr)]string newCabinetName, [MarshalAs(UnmanagedType.LPWStr)]string fileToken) |
| 302 | { | 311 | { |
| 303 | // Locking Mutex here as this callback can come from Multiple Cabinet Builder Threads | 312 | // Locking Mutex here as this callback can come from Multiple Cabinet Builder Threads |
| 304 | Mutex mutex = new Mutex(false, "WixCabinetSplitBinderCallback"); | 313 | var mutex = new Mutex(false, "WixCabinetSplitBinderCallback"); |
| 305 | try | 314 | try |
| 306 | { | 315 | { |
| 307 | if (!mutex.WaitOne(0, false)) // Check if you can get the lock | 316 | if (!mutex.WaitOne(0, false)) // Check if you can get the lock |
| @@ -311,19 +320,24 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 311 | mutex.WaitOne(); // Wait on other thread | 320 | mutex.WaitOne(); // Wait on other thread |
| 312 | } | 321 | } |
| 313 | 322 | ||
| 314 | string firstCabinetName = firstCabName + ".cab"; | 323 | var firstCabinetName = firstCabName + ".cab"; |
| 315 | string newCabinetName = newCabName; | 324 | var transferAdded = false; // Used for Error Handling |
| 316 | bool transferAdded = false; // Used for Error Handling | ||
| 317 | 325 | ||
| 318 | // Create File Transfer for new Cabinet using transfer of Base Cabinet | 326 | // Create File Transfer for new Cabinet using transfer of Base Cabinet |
| 319 | foreach (var transfer in this.FileTransfers) | 327 | foreach (var transfer in this.FileTransfers) |
| 320 | { | 328 | { |
| 321 | if (firstCabinetName.Equals(Path.GetFileName(transfer.Source), StringComparison.InvariantCultureIgnoreCase)) | 329 | if (firstCabinetName.Equals(Path.GetFileName(transfer.Source), StringComparison.InvariantCultureIgnoreCase)) |
| 322 | { | 330 | { |
| 323 | string newCabSourcePath = Path.Combine(Path.GetDirectoryName(transfer.Source), newCabinetName); | 331 | var newCabSourcePath = Path.Combine(Path.GetDirectoryName(transfer.Source), newCabinetName); |
| 324 | string newCabTargetPath = Path.Combine(Path.GetDirectoryName(transfer.Destination), newCabinetName); | 332 | var newCabTargetPath = Path.Combine(Path.GetDirectoryName(transfer.Destination), newCabinetName); |
| 333 | |||
| 334 | var trackSource = this.BackendHelper.TrackFile(newCabSourcePath, TrackedFileType.Intermediate, transfer.SourceLineNumbers); | ||
| 335 | this.trackedFiles.Add(trackSource); | ||
| 336 | |||
| 337 | var trackTarget = this.BackendHelper.TrackFile(newCabTargetPath, TrackedFileType.Final, transfer.SourceLineNumbers); | ||
| 338 | this.trackedFiles.Add(trackTarget); | ||
| 325 | 339 | ||
| 326 | var newTransfer = this.BackendHelper.CreateFileTransfer(newCabSourcePath, newCabTargetPath, transfer.Move, FileTransferType.Built, transfer.SourceLineNumbers); | 340 | var newTransfer = this.BackendHelper.CreateFileTransfer(trackSource.Path, trackTarget.Path, transfer.Move, transfer.SourceLineNumbers); |
| 327 | this.fileTransfers.Add(newTransfer); | 341 | this.fileTransfers.Add(newTransfer); |
| 328 | 342 | ||
| 329 | transferAdded = true; | 343 | transferAdded = true; |
| @@ -338,13 +352,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 338 | } | 352 | } |
| 339 | 353 | ||
| 340 | // Add the new Cabinets to media table using LastSequence of Base Cabinet | 354 | // Add the new Cabinets to media table using LastSequence of Base Cabinet |
| 341 | Table mediaTable = this.Output.Tables["Media"]; | 355 | var mediaTable = this.Output.Tables["Media"]; |
| 342 | Table wixFileTable = this.Output.Tables["WixFile"]; | 356 | var wixFileTable = this.Output.Tables["WixFile"]; |
| 343 | int diskIDForLastSplitCabAdded = 0; // The DiskID value for the first cab in this cabinet split chain | 357 | var diskIDForLastSplitCabAdded = 0; // The DiskID value for the first cab in this cabinet split chain |
| 344 | int lastSequenceForLastSplitCabAdded = 0; // The LastSequence value for the first cab in this cabinet split chain | 358 | var lastSequenceForLastSplitCabAdded = 0; // The LastSequence value for the first cab in this cabinet split chain |
| 345 | bool lastSplitCabinetFound = false; // Used for Error Handling | 359 | var lastSplitCabinetFound = false; // Used for Error Handling |
| 346 | 360 | ||
| 347 | string lastCabinetOfThisSequence = String.Empty; | 361 | var lastCabinetOfThisSequence = String.Empty; |
| 348 | // Get the Value of Last Cabinet Added in this split Sequence from Dictionary | 362 | // Get the Value of Last Cabinet Added in this split Sequence from Dictionary |
| 349 | if (!this.lastCabinetAddedToMediaTable.TryGetValue(firstCabinetName, out lastCabinetOfThisSequence)) | 363 | if (!this.lastCabinetAddedToMediaTable.TryGetValue(firstCabinetName, out lastCabinetOfThisSequence)) |
| 350 | { | 364 | { |
