Skip to content

Commit

Permalink
Use PerUserProgramFilesFolder for default INSTALLFOLDER in a per-user…
Browse files Browse the repository at this point in the history
… package

Fixes 8101
  • Loading branch information
robmen committed Dec 30, 2024
1 parent ae8264a commit d9bb113
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 17 deletions.
17 changes: 9 additions & 8 deletions src/wix/WixToolset.Core/Link/AddDefaultSymbolsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace WixToolset.Core.Link
internal class AddDefaultSymbolsCommand
{
public static readonly string WixStandardInstallFolder = "INSTALLFOLDER";
public static readonly string WixStandardInstallFolderParent = "ProgramFiles6432Folder";
public static readonly string WixStandardPerMachineInstallFolderParent = "ProgramFiles6432Folder";
public static readonly string WixStandardPerUserInstallFolderParent = "PerUserProgramFilesFolder";
public static readonly string WixStandardInstallFolderReference = "Directory:INSTALLFOLDER";

public AddDefaultSymbolsCommand(FindEntrySectionAndLoadSymbolsCommand find, IList<IntermediateSection> sections)
Expand All @@ -26,28 +27,31 @@ public AddDefaultSymbolsCommand(FindEntrySectionAndLoadSymbolsCommand find, ILis

public void Execute()
{
if (this.Find.EntrySection.Type != SectionType.Package)
if (this.Find.EntrySection.Type != SectionType.Package || this.Find.EntrySection.Symbols.Count == 0)
{
// Only packages...for now.
return;
}

var packageSymbol = this.Find.EntrySection.Symbols.OfType<WixPackageSymbol>().First();

// If a directory with id INSTALLFOLDER hasn't been authored, provide a default one.
if (!this.Find.SymbolsByName.ContainsKey(WixStandardInstallFolderReference))
{
var sourceLineNumber = new SourceLineNumber("DefaultInstallFolder");
var parentDirectoryRef = (packageSymbol.Scope == WixPackageScope.PerUser) ? WixStandardPerUserInstallFolderParent : WixStandardPerMachineInstallFolderParent;

this.AddSymbolsToNewSection(WixStandardInstallFolder,
new DirectorySymbol(sourceLineNumber, new Identifier(AccessModifier.Global, WixStandardInstallFolder))
{
ParentDirectoryRef = WixStandardInstallFolderParent,
ParentDirectoryRef = parentDirectoryRef,
Name = "!(bind.Property.Manufacturer) !(bind.Property.ProductName)",
SourceName = ".",
},
new WixSimpleReferenceSymbol(sourceLineNumber, new Identifier(AccessModifier.Global, WixStandardInstallFolder))
{
Table = "Directory",
PrimaryKeys = WixStandardInstallFolderParent,
PrimaryKeys = parentDirectoryRef,
}
);
}
Expand All @@ -58,10 +62,7 @@ public void Execute()
var symbols = this.Sections.SelectMany(section => section.Symbols);
if (!symbols.OfType<UpgradeSymbol>().Any(us => !us.OnlyDetect))
{
var packageSymbol = this.Find.EntrySection.Symbols.OfType<WixPackageSymbol>().FirstOrDefault();

if (packageSymbol?.UpgradeStrategy == WixPackageUpgradeStrategy.MajorUpgrade
&& !String.IsNullOrEmpty(packageSymbol?.UpgradeCode))
if (packageSymbol.UpgradeStrategy == WixPackageUpgradeStrategy.MajorUpgrade && !String.IsNullOrEmpty(packageSymbol?.UpgradeCode))
{
this.AddDefaultMajorUpgrade(packageSymbol);
}
Expand Down
48 changes: 42 additions & 6 deletions src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace WixToolsetTest.CoreIntegration
public class DirectoryFixture
{
[Fact]
public void CanGetDefaultInstallFolder()
public void CanGetDefaultPerMachineInstallFolder()
{
var folder = TestData.Get(@"TestData\SingleFile");
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 msiPath = Path.Combine(baseFolder, "bin", "test.msi");

var result = WixRunner.Execute(new[]
{
Expand All @@ -37,7 +37,7 @@ public void CanGetDefaultInstallFolder()

result.AssertSuccess();

var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"bin\test.wixpdb"));
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();
Expand All @@ -51,6 +51,42 @@ public void CanGetDefaultInstallFolder()
}
}

[Fact]
public void CanGetDefaultPerUserInstallFolder()
{
var folder = TestData.Get("TestData", "AllUsers");

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, "PerUser.wxs"),
"-bindpath", folder,
"-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:PerUserProgramFilesFolder:Example Corporation MsiPackage",
"LocalAppDataFolder:TARGETDIR:LocalApp",
"PerUserProgramFilesFolder:LocalAppDataFolder:Programs",
"TARGETDIR::SourceDir",
}, dirSymbols.OrderBy(d => d.Id.Id).Select(d => d.Id.Id + ":" + d.ParentDirectoryRef + ":" + d.Name).ToArray());
}
}

[Fact]
public void CanGet32bitProgramFiles6432Folder()
{
Expand All @@ -60,7 +96,7 @@ public void CanGet32bitProgramFiles6432Folder()
{
var baseFolder = fs.GetFolder();
var intermediateFolder = Path.Combine(baseFolder, "obj");
var msiPath = Path.Combine(baseFolder, @"bin\test.msi");
var msiPath = Path.Combine(baseFolder, "bin", "test.msi");

var result = WixRunner.Execute(new[]
{
Expand All @@ -74,7 +110,7 @@ public void CanGet32bitProgramFiles6432Folder()

result.AssertSuccess();

var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"bin\test.wixpdb"));
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />

<Feature Id="ProductFeature" Title="Feature title">
<Component Directory="DesktopFolder">
<Component>
<File Source="PerUser.wxs" />
</Component>
</Feature>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />

<Feature Id="ProductFeature" Title="Feature title">
<Component Directory="DesktopFolder">
<Component>
<File Source="PerUser.wxs" />
</Component>
</Feature>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" />

<Feature Id="ProductFeature" Title="Feature title">
<Component Directory="DesktopFolder">
<Component>
<File Source="PerUser.wxs" />
</Component>
</Feature>
Expand Down

0 comments on commit d9bb113

Please sign in to comment.