From e8030ca17ff96a794a3fecd66bb01b81581a5451 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 22 May 2020 14:47:36 -0700 Subject: Fix naming of file in a merge module's cabinet The file was stored in the merge module's cabinet with plain FileId, without the modularization GUID. This change fixes the cabinet builder so that it adds the modularization GUID when creating the cabinet. --- .../Bind/BindDatabaseCommand.cs | 7 ++++--- .../Bind/BindSummaryInfoCommand.cs | 6 +++--- .../Bind/CabinetBuilder.cs | 4 ++-- .../Bind/CabinetWorkItem.cs | 7 +++++++ .../Bind/CreateCabinetsCommand.cs | 7 ++++--- .../Bind/ModularizeCommand.cs | 19 +++++++++---------- src/test/WixToolsetTest.CoreIntegration/MsiFixture.cs | 19 ++++++++++++++++++- 7 files changed, 47 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs index c9659287..5c84a82f 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs @@ -134,7 +134,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind bool compressed; bool longNames; int installerVersion; - string modularizationGuid; + string modularizationSuffix; { var command = new BindSummaryInfoCommand(section); command.Execute(); @@ -142,7 +142,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind compressed = command.Compressed; longNames = command.LongNames; installerVersion = command.InstallerVersion; - modularizationGuid = command.ModularizationGuid; + modularizationSuffix = command.ModularizationSuffix; } // Add binder variables for all properties. @@ -362,7 +362,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Modularize identifiers. if (OutputType.Module == output.Type) { - var command = new ModularizeCommand(output, modularizationGuid, section.Tuples.OfType()); + var command = new ModularizeCommand(output, modularizationSuffix, section.Tuples.OfType()); command.Execute(); } else if (output.Type == OutputType.Patch) @@ -448,6 +448,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind command.BackendExtensions = this.BackendExtensions; command.LayoutDirectory = layoutDirectory; command.Compressed = compressed; + command.ModularizationSuffix = modularizationSuffix; command.FileRowsByCabinet = filesByCabinetMedia; command.ResolveMedia = this.ResolveMedia; command.TableDefinitions = tableDefinitions; diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs index 6483f0fc..d5806fee 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs @@ -35,14 +35,14 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// /// Modularization guid, or null if the output is not a module. /// - public string ModularizationGuid { get; private set; } + public string ModularizationSuffix { get; private set; } public void Execute() { this.Compressed = false; this.LongNames = false; this.InstallerVersion = 0; - this.ModularizationGuid = null; + this.ModularizationSuffix = null; var foundCreateDataTime = false; var foundLastSaveDataTime = false; @@ -71,7 +71,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (SectionType.Module == this.Section.Type) { - this.ModularizationGuid = packageCode.Substring(1, 36).Replace('-', '_'); + this.ModularizationSuffix = "." + packageCode.Substring(1, 36).Replace('-', '_'); } else if ("*" == packageCode) { diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CabinetBuilder.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CabinetBuilder.cs index f70548d9..5f19fd2a 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CabinetBuilder.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CabinetBuilder.cs @@ -166,8 +166,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind var files = cabinetWorkItem.FileFacades .Select(facade => facade.Hash == null ? - new CabinetCompressFile(facade.SourcePath, facade.Id) : - new CabinetCompressFile(facade.SourcePath, facade.Id, facade.Hash.HashPart1, facade.Hash.HashPart2, facade.Hash.HashPart3, facade.Hash.HashPart4)) + new CabinetCompressFile(facade.SourcePath, facade.Id + cabinetWorkItem.ModularizationSuffix) : + new CabinetCompressFile(facade.SourcePath, facade.Id + cabinetWorkItem.ModularizationSuffix, facade.Hash.HashPart1, facade.Hash.HashPart2, facade.Hash.HashPart3, facade.Hash.HashPart4)) .ToList(); var cab = new Cabinet(cabinetPath); diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs index 405b840b..760b5fb9 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs @@ -25,9 +25,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// The compression level of the cabinet. /// The binder file manager. public CabinetWorkItem(IEnumerable fileFacades, string cabinetFile, int maxThreshold, CompressionLevel compressionLevel /*, BinderFileManager binderFileManager*/) + public CabinetWorkItem(IEnumerable fileFacades, string cabinetFile, int maxThreshold, CompressionLevel compressionLevel, string modularizationSuffix /*, BinderFileManager binderFileManager*/) { this.cabinetFile = cabinetFile; this.compressionLevel = compressionLevel; + this.ModularizationSuffix = modularizationSuffix; this.FileFacades = fileFacades; //this.binderFileManager = binderFileManager; this.maxThreshold = maxThreshold; @@ -51,6 +53,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind get { return this.compressionLevel; } } + /// + /// Gets the modularization suffix used when building a Merge Module. + /// + public string ModularizationSuffix { get; } + /// /// Gets the collection of files in this cabinet. /// diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs index 2536eeac..6852772e 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs @@ -75,6 +75,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind public bool Compressed { private get; set; } + public string ModularizationSuffix { private get; set; } + public Dictionary> FileRowsByCabinet { private get; set; } public Func ResolveMedia { private get; set; } @@ -214,9 +216,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind // create a cabinet work item if it's not being skipped if (CabinetBuildOption.BuildAndCopy == resolvedCabinet.BuildOption || CabinetBuildOption.BuildAndMove == resolvedCabinet.BuildOption) { - int maxThreshold = 0; // default to the threshold for best smartcabbing (makes smallest cabinet). - - cabinetWorkItem = new CabinetWorkItem(fileFacades, resolvedCabinet.Path, maxThreshold, compressionLevel/*, this.FileManager*/); + // Default to the threshold for best smartcabbing (makes smallest cabinet). + cabinetWorkItem = new CabinetWorkItem(fileFacades, resolvedCabinet.Path, maxThreshold: 0, compressionLevel, this.ModularizationSuffix /*, this.FileManager*/); } else // reuse the cabinet from the cabinet cache. { diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ModularizeCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ModularizeCommand.cs index 64257ccf..8b459d69 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/ModularizeCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ModularizeCommand.cs @@ -15,10 +15,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind internal class ModularizeCommand { - public ModularizeCommand(WindowsInstallerData output, string modularizationGuid, IEnumerable suppressTuples) + public ModularizeCommand(WindowsInstallerData output, string modularizationSuffix, IEnumerable suppressTuples) { this.Output = output; - this.ModularizationGuid = modularizationGuid; + this.ModularizationSuffix = modularizationSuffix; // Gather all the unique suppress modularization identifiers. this.SuppressModularizationIdentifiers = new HashSet(suppressTuples.Select(s => s.Id.Id)); @@ -26,7 +26,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind private WindowsInstallerData Output { get; } - private string ModularizationGuid { get; } + private string ModularizationSuffix { get; } private HashSet SuppressModularizationIdentifiers { get; } @@ -129,7 +129,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // if we're not supposed to suppress modularization of this identifier if (!this.SuppressModularizationIdentifiers.Contains(fieldData)) { - fieldData = String.Concat(fieldData, ".", this.ModularizationGuid); + fieldData = String.Concat(fieldData, this.ModularizationSuffix); } break; @@ -178,8 +178,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind var identifier = group.Value; if (!WindowsInstallerStandard.IsStandardProperty(identifier) && !this.SuppressModularizationIdentifiers.Contains(identifier)) { - sb.Insert(group.Index + group.Length, '.'); - sb.Insert(group.Index + group.Length + 1, this.ModularizationGuid); + sb.Insert(group.Index + group.Length, this.ModularizationSuffix); } } } @@ -193,7 +192,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (!this.SuppressModularizationIdentifiers.Contains(fieldData) && 0 < fieldData.Length && !Char.IsDigit(fieldData, 0)) { - fieldData = String.Concat(fieldData, ".", this.ModularizationGuid); + fieldData = String.Concat(fieldData, this.ModularizationSuffix); } break; @@ -203,11 +202,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind var start = fieldData.LastIndexOf(".", StringComparison.Ordinal); if (-1 == start) { - fieldData = String.Concat(fieldData, ".", this.ModularizationGuid); + fieldData = String.Concat(fieldData, this.ModularizationSuffix); } else { - fieldData = String.Concat(fieldData.Substring(0, start), ".", this.ModularizationGuid, fieldData.Substring(start)); + fieldData = String.Concat(fieldData.Substring(0, start), this.ModularizationSuffix, fieldData.Substring(start)); } } break; @@ -218,7 +217,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { if (!String.IsNullOrEmpty(keys[i])) { - keys[i] = String.Concat(keys[i], ".", this.ModularizationGuid); + keys[i] = String.Concat(keys[i], this.ModularizationSuffix); } } diff --git a/src/test/WixToolsetTest.CoreIntegration/MsiFixture.cs b/src/test/WixToolsetTest.CoreIntegration/MsiFixture.cs index 5af256c1..075f7733 100644 --- a/src/test/WixToolsetTest.CoreIntegration/MsiFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/MsiFixture.cs @@ -346,15 +346,32 @@ namespace WixToolsetTest.CoreIntegration result.AssertSuccess(); - Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.msm"))); + var msmPath = Path.Combine(intermediateFolder, @"bin\test.msm"); + Assert.True(File.Exists(msmPath)); Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\test.wixpdb"))); var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"bin\test.wixpdb")); var section = intermediate.Sections.Single(); var fileTuple = section.Tuples.OfType().Single(); + Assert.Equal("filyIq8rqcxxf903Hsn5K9L0SWV73g", fileTuple.Id.Id); Assert.Equal(Path.Combine(folder, @"data\test.txt"), fileTuple[FileTupleFields.Source].AsPath().Path); Assert.Equal(@"test.txt", fileTuple[FileTupleFields.Source].PreviousValue.AsPath().Path); + + var data = WindowsInstallerData.Load(Path.Combine(intermediateFolder, @"bin\test.wixpdb")); + var fileRows = data.Tables["File"].Rows; + Assert.Equal(new[] + { + "filyIq8rqcxxf903Hsn5K9L0SWV73g.243FB739_4D05_472F_9CFB_EF6B1017B6DE" + }, fileRows.Select(r => r.FieldAsString(0)).ToArray()); + + var cabPath = Path.Combine(intermediateFolder, "msm-test.cab"); + Query.ExtractStream(msmPath, "MergeModule.CABinet", cabPath); + var files = Query.GetCabinetFiles(cabPath); + Assert.Equal(new[] + { + "filyIq8rqcxxf903Hsn5K9L0SWV73g.243FB739_4D05_472F_9CFB_EF6B1017B6DE" + }, files.Select(f => Path.Combine(f.Path, f.Name)).ToArray()); } } -- cgit v1.2.3-55-g6feb