Skip to content

Commit

Permalink
Provide a default INSTALLFOLDER.
Browse files Browse the repository at this point in the history
If INSTALLFOLDER is referenced and not defined, define one with
reasonable default values.

Implements WIP wixtoolset/issues#7588.
  • Loading branch information
barnson committed Jul 29, 2023
1 parent 5e9901d commit f922afb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
28 changes: 27 additions & 1 deletion src/wix/WixToolset.Core/Link/ResolveReferencesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ private void RecursivelyResolveReferences(IntermediateSection section)
return;
}

DirectorySymbol defaultInstallFolderSymbol = null;

// Process all of the references contained in this section using the collection of
// symbols provided. Then recursively call this method to process the
// located symbol's section. All in all this is a very simple depth-first
Expand Down Expand Up @@ -110,9 +112,33 @@ private void RecursivelyResolveReferences(IntermediateSection section)
}
else
{
this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName));
// If the authoring references a directory with id `INSTALLFOLDER` and
// the authoring does not _define_ it, conjure such a symbol with appropriate
// default values.
if (wixSimpleReferenceRow.SymbolicName == "Directory:INSTALLFOLDER"
&& defaultInstallFolderSymbol == null)
{
defaultInstallFolderSymbol = new DirectorySymbol(wixSimpleReferenceRow.SourceLineNumbers,
new Identifier(AccessModifier.Global, "INSTALLFOLDER"))
{
ParentDirectoryRef = "ProgramFiles6432Folder",
Name = "!(bind.Property.Manufacturer) !(bind.Property.ProductName)",
SourceName = ".",
};

this.referencedSymbols.Add(new SymbolWithSection(null, defaultInstallFolderSymbol));
}
else
{
this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName));
}
}
}

if (defaultInstallFolderSymbol != null)
{
section.AddSymbol(defaultInstallFolderSymbol);
}
}

/// <summary>
Expand Down
38 changes: 38 additions & 0 deletions src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,44 @@ namespace WixToolsetTest.CoreIntegration

public class DirectoryFixture
{
[Fact]
public void CanGetDefaultInstallFolder()
{
var folder = TestData.Get(@"TestData\SingleFile");

using (var fs = new DisposableFileSystem())
{
var baseFolder = fs.GetFolder();
var intermediateFolder = Path.Combine(baseFolder, "obj");
var msiPath = Path.Combine(baseFolder, @"bin\test.msi");

var result = WixRunner.Execute(new[]
{
"build",
Path.Combine(folder, "Package.wxs"),
Path.Combine(folder, "PackageComponents.wxs"),
"-loc", Path.Combine(folder, "Package.en-us.wxl"),
"-bindpath", Path.Combine(folder, "data"),
"-intermediateFolder", intermediateFolder,
"-o", msiPath
});

result.AssertSuccess();

var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"bin\test.wixpdb"));
var section = intermediate.Sections.Single();

var dirSymbols = section.Symbols.OfType<WixToolset.Data.Symbols.DirectorySymbol>().ToList();
WixAssert.CompareLineByLine(new[]
{
"INSTALLFOLDER:ProgramFiles6432Folder:Example Corporation MsiPackage",
"ProgramFiles6432Folder:ProgramFilesFolder:.",
"ProgramFilesFolder:TARGETDIR:PFiles",
"TARGETDIR::SourceDir"
}, dirSymbols.OrderBy(d => d.Id.Id).Select(d => d.Id.Id + ":" + d.ParentDirectoryRef + ":" + d.Name).ToArray());
}
}

[Fact]
public void CanGet32bitProgramFiles6432Folder()
{
Expand Down
2 changes: 1 addition & 1 deletion src/wix/test/WixToolsetTest.CoreIntegration/MsiFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void CanBuildSingleFile()

Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.msi")));
Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.wixpdb")));
Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\PFiles\MsiPackage\test.txt")));
Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\PFiles\Example Corporation MsiPackage\test.txt")));

var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"bin\test.wixpdb"));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="MsiPackage" Codepage="1252" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a" Compressed="no" InstallerVersion="200" Scope="perMachine">


<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />

<Feature Id="ProductFeature" Title="!(loc.FeatureTitle)">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Package>

<Fragment>
<StandardDirectory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MsiPackage" SourceName="." />
</StandardDirectory>
</Fragment>
</Wix>

0 comments on commit f922afb

Please sign in to comment.