diff options
author | Rob Mensching <rob@firegiant.com> | 2024-12-28 17:50:50 -0800 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2024-12-29 16:29:07 -0800 |
commit | d9bb1133c2913d7129b3b103bd4a75f01d24625c (patch) | |
tree | 3d2eab94b90bd3eeb8e7fed2dd70ac38132a0d1d /src | |
parent | ae8264ac0df30b1503311af52ed6c615d83a67fc (diff) | |
download | wix-d9bb1133c2913d7129b3b103bd4a75f01d24625c.tar.gz wix-d9bb1133c2913d7129b3b103bd4a75f01d24625c.tar.bz2 wix-d9bb1133c2913d7129b3b103bd4a75f01d24625c.zip |
Use PerUserProgramFilesFolder for default INSTALLFOLDER in a per-user package
Fixes 8101
Diffstat (limited to 'src')
5 files changed, 54 insertions, 17 deletions
diff --git a/src/wix/WixToolset.Core/Link/AddDefaultSymbolsCommand.cs b/src/wix/WixToolset.Core/Link/AddDefaultSymbolsCommand.cs index b433b039..bf5e748c 100644 --- a/src/wix/WixToolset.Core/Link/AddDefaultSymbolsCommand.cs +++ b/src/wix/WixToolset.Core/Link/AddDefaultSymbolsCommand.cs | |||
@@ -11,7 +11,8 @@ namespace WixToolset.Core.Link | |||
11 | internal class AddDefaultSymbolsCommand | 11 | internal class AddDefaultSymbolsCommand |
12 | { | 12 | { |
13 | public static readonly string WixStandardInstallFolder = "INSTALLFOLDER"; | 13 | public static readonly string WixStandardInstallFolder = "INSTALLFOLDER"; |
14 | public static readonly string WixStandardInstallFolderParent = "ProgramFiles6432Folder"; | 14 | public static readonly string WixStandardPerMachineInstallFolderParent = "ProgramFiles6432Folder"; |
15 | public static readonly string WixStandardPerUserInstallFolderParent = "PerUserProgramFilesFolder"; | ||
15 | public static readonly string WixStandardInstallFolderReference = "Directory:INSTALLFOLDER"; | 16 | public static readonly string WixStandardInstallFolderReference = "Directory:INSTALLFOLDER"; |
16 | 17 | ||
17 | public AddDefaultSymbolsCommand(FindEntrySectionAndLoadSymbolsCommand find, IList<IntermediateSection> sections) | 18 | public AddDefaultSymbolsCommand(FindEntrySectionAndLoadSymbolsCommand find, IList<IntermediateSection> sections) |
@@ -26,28 +27,31 @@ namespace WixToolset.Core.Link | |||
26 | 27 | ||
27 | public void Execute() | 28 | public void Execute() |
28 | { | 29 | { |
29 | if (this.Find.EntrySection.Type != SectionType.Package) | 30 | if (this.Find.EntrySection.Type != SectionType.Package || this.Find.EntrySection.Symbols.Count == 0) |
30 | { | 31 | { |
31 | // Only packages...for now. | 32 | // Only packages...for now. |
32 | return; | 33 | return; |
33 | } | 34 | } |
34 | 35 | ||
36 | var packageSymbol = this.Find.EntrySection.Symbols.OfType<WixPackageSymbol>().First(); | ||
37 | |||
35 | // If a directory with id INSTALLFOLDER hasn't been authored, provide a default one. | 38 | // If a directory with id INSTALLFOLDER hasn't been authored, provide a default one. |
36 | if (!this.Find.SymbolsByName.ContainsKey(WixStandardInstallFolderReference)) | 39 | if (!this.Find.SymbolsByName.ContainsKey(WixStandardInstallFolderReference)) |
37 | { | 40 | { |
38 | var sourceLineNumber = new SourceLineNumber("DefaultInstallFolder"); | 41 | var sourceLineNumber = new SourceLineNumber("DefaultInstallFolder"); |
42 | var parentDirectoryRef = (packageSymbol.Scope == WixPackageScope.PerUser) ? WixStandardPerUserInstallFolderParent : WixStandardPerMachineInstallFolderParent; | ||
39 | 43 | ||
40 | this.AddSymbolsToNewSection(WixStandardInstallFolder, | 44 | this.AddSymbolsToNewSection(WixStandardInstallFolder, |
41 | new DirectorySymbol(sourceLineNumber, new Identifier(AccessModifier.Global, WixStandardInstallFolder)) | 45 | new DirectorySymbol(sourceLineNumber, new Identifier(AccessModifier.Global, WixStandardInstallFolder)) |
42 | { | 46 | { |
43 | ParentDirectoryRef = WixStandardInstallFolderParent, | 47 | ParentDirectoryRef = parentDirectoryRef, |
44 | Name = "!(bind.Property.Manufacturer) !(bind.Property.ProductName)", | 48 | Name = "!(bind.Property.Manufacturer) !(bind.Property.ProductName)", |
45 | SourceName = ".", | 49 | SourceName = ".", |
46 | }, | 50 | }, |
47 | new WixSimpleReferenceSymbol(sourceLineNumber, new Identifier(AccessModifier.Global, WixStandardInstallFolder)) | 51 | new WixSimpleReferenceSymbol(sourceLineNumber, new Identifier(AccessModifier.Global, WixStandardInstallFolder)) |
48 | { | 52 | { |
49 | Table = "Directory", | 53 | Table = "Directory", |
50 | PrimaryKeys = WixStandardInstallFolderParent, | 54 | PrimaryKeys = parentDirectoryRef, |
51 | } | 55 | } |
52 | ); | 56 | ); |
53 | } | 57 | } |
@@ -58,10 +62,7 @@ namespace WixToolset.Core.Link | |||
58 | var symbols = this.Sections.SelectMany(section => section.Symbols); | 62 | var symbols = this.Sections.SelectMany(section => section.Symbols); |
59 | if (!symbols.OfType<UpgradeSymbol>().Any(us => !us.OnlyDetect)) | 63 | if (!symbols.OfType<UpgradeSymbol>().Any(us => !us.OnlyDetect)) |
60 | { | 64 | { |
61 | var packageSymbol = this.Find.EntrySection.Symbols.OfType<WixPackageSymbol>().FirstOrDefault(); | 65 | if (packageSymbol.UpgradeStrategy == WixPackageUpgradeStrategy.MajorUpgrade && !String.IsNullOrEmpty(packageSymbol?.UpgradeCode)) |
62 | |||
63 | if (packageSymbol?.UpgradeStrategy == WixPackageUpgradeStrategy.MajorUpgrade | ||
64 | && !String.IsNullOrEmpty(packageSymbol?.UpgradeCode)) | ||
65 | { | 66 | { |
66 | this.AddDefaultMajorUpgrade(packageSymbol); | 67 | this.AddDefaultMajorUpgrade(packageSymbol); |
67 | } | 68 | } |
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs index 7f019692..4781a115 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/DirectoryFixture.cs | |||
@@ -14,15 +14,15 @@ namespace WixToolsetTest.CoreIntegration | |||
14 | public class DirectoryFixture | 14 | public class DirectoryFixture |
15 | { | 15 | { |
16 | [Fact] | 16 | [Fact] |
17 | public void CanGetDefaultInstallFolder() | 17 | public void CanGetDefaultPerMachineInstallFolder() |
18 | { | 18 | { |
19 | var folder = TestData.Get(@"TestData\SingleFile"); | 19 | var folder = TestData.Get("TestData", "SingleFile"); |
20 | 20 | ||
21 | using (var fs = new DisposableFileSystem()) | 21 | using (var fs = new DisposableFileSystem()) |
22 | { | 22 | { |
23 | var baseFolder = fs.GetFolder(); | 23 | var baseFolder = fs.GetFolder(); |
24 | var intermediateFolder = Path.Combine(baseFolder, "obj"); | 24 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
25 | var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); | 25 | var msiPath = Path.Combine(baseFolder, "bin", "test.msi"); |
26 | 26 | ||
27 | var result = WixRunner.Execute(new[] | 27 | var result = WixRunner.Execute(new[] |
28 | { | 28 | { |
@@ -37,7 +37,7 @@ namespace WixToolsetTest.CoreIntegration | |||
37 | 37 | ||
38 | result.AssertSuccess(); | 38 | result.AssertSuccess(); |
39 | 39 | ||
40 | var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"bin\test.wixpdb")); | 40 | var intermediate = Intermediate.Load(Path.Combine(baseFolder, "bin", "test.wixpdb")); |
41 | var section = intermediate.Sections.Single(); | 41 | var section = intermediate.Sections.Single(); |
42 | 42 | ||
43 | var dirSymbols = section.Symbols.OfType<WixToolset.Data.Symbols.DirectorySymbol>().ToList(); | 43 | var dirSymbols = section.Symbols.OfType<WixToolset.Data.Symbols.DirectorySymbol>().ToList(); |
@@ -52,6 +52,42 @@ namespace WixToolsetTest.CoreIntegration | |||
52 | } | 52 | } |
53 | 53 | ||
54 | [Fact] | 54 | [Fact] |
55 | public void CanGetDefaultPerUserInstallFolder() | ||
56 | { | ||
57 | var folder = TestData.Get("TestData", "AllUsers"); | ||
58 | |||
59 | using (var fs = new DisposableFileSystem()) | ||
60 | { | ||
61 | var baseFolder = fs.GetFolder(); | ||
62 | var intermediateFolder = Path.Combine(baseFolder, "obj"); | ||
63 | var msiPath = Path.Combine(baseFolder, "bin", "test.msi"); | ||
64 | |||
65 | var result = WixRunner.Execute(new[] | ||
66 | { | ||
67 | "build", | ||
68 | Path.Combine(folder, "PerUser.wxs"), | ||
69 | "-bindpath", folder, | ||
70 | "-intermediateFolder", intermediateFolder, | ||
71 | "-o", msiPath | ||
72 | }); | ||
73 | |||
74 | result.AssertSuccess(); | ||
75 | |||
76 | var intermediate = Intermediate.Load(Path.Combine(baseFolder, "bin", "test.wixpdb")); | ||
77 | var section = intermediate.Sections.Single(); | ||
78 | |||
79 | var dirSymbols = section.Symbols.OfType<WixToolset.Data.Symbols.DirectorySymbol>().ToList(); | ||
80 | WixAssert.CompareLineByLine(new[] | ||
81 | { | ||
82 | "INSTALLFOLDER:PerUserProgramFilesFolder:Example Corporation MsiPackage", | ||
83 | "LocalAppDataFolder:TARGETDIR:LocalApp", | ||
84 | "PerUserProgramFilesFolder:LocalAppDataFolder:Programs", | ||
85 | "TARGETDIR::SourceDir", | ||
86 | }, dirSymbols.OrderBy(d => d.Id.Id).Select(d => d.Id.Id + ":" + d.ParentDirectoryRef + ":" + d.Name).ToArray()); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | [Fact] | ||
55 | public void CanGet32bitProgramFiles6432Folder() | 91 | public void CanGet32bitProgramFiles6432Folder() |
56 | { | 92 | { |
57 | var folder = TestData.Get(@"TestData"); | 93 | var folder = TestData.Get(@"TestData"); |
@@ -60,7 +96,7 @@ namespace WixToolsetTest.CoreIntegration | |||
60 | { | 96 | { |
61 | var baseFolder = fs.GetFolder(); | 97 | var baseFolder = fs.GetFolder(); |
62 | var intermediateFolder = Path.Combine(baseFolder, "obj"); | 98 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
63 | var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); | 99 | var msiPath = Path.Combine(baseFolder, "bin", "test.msi"); |
64 | 100 | ||
65 | var result = WixRunner.Execute(new[] | 101 | var result = WixRunner.Execute(new[] |
66 | { | 102 | { |
@@ -74,7 +110,7 @@ namespace WixToolsetTest.CoreIntegration | |||
74 | 110 | ||
75 | result.AssertSuccess(); | 111 | result.AssertSuccess(); |
76 | 112 | ||
77 | var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"bin\test.wixpdb")); | 113 | var intermediate = Intermediate.Load(Path.Combine(baseFolder, "bin", "test.wixpdb")); |
78 | var section = intermediate.Sections.Single(); | 114 | var section = intermediate.Sections.Single(); |
79 | 115 | ||
80 | var dirSymbols = section.Symbols.OfType<WixToolset.Data.Symbols.DirectorySymbol>().ToList(); | 116 | var dirSymbols = section.Symbols.OfType<WixToolset.Data.Symbols.DirectorySymbol>().ToList(); |
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerMachine.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerMachine.wxs index 3f19277b..ee243815 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerMachine.wxs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerMachine.wxs | |||
@@ -7,7 +7,7 @@ | |||
7 | <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" /> | 7 | <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" /> |
8 | 8 | ||
9 | <Feature Id="ProductFeature" Title="Feature title"> | 9 | <Feature Id="ProductFeature" Title="Feature title"> |
10 | <Component Directory="DesktopFolder"> | 10 | <Component> |
11 | <File Source="PerUser.wxs" /> | 11 | <File Source="PerUser.wxs" /> |
12 | </Component> | 12 | </Component> |
13 | </Feature> | 13 | </Feature> |
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUser.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUser.wxs index 12ba9c59..cc8f7bcd 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUser.wxs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUser.wxs | |||
@@ -7,7 +7,7 @@ | |||
7 | <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" /> | 7 | <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" /> |
8 | 8 | ||
9 | <Feature Id="ProductFeature" Title="Feature title"> | 9 | <Feature Id="ProductFeature" Title="Feature title"> |
10 | <Component Directory="DesktopFolder"> | 10 | <Component> |
11 | <File Source="PerUser.wxs" /> | 11 | <File Source="PerUser.wxs" /> |
12 | </Component> | 12 | </Component> |
13 | </Feature> | 13 | </Feature> |
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUserOrMachine.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUserOrMachine.wxs index 293cf1fa..19c2cb6e 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUserOrMachine.wxs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/AllUsers/PerUserOrMachine.wxs | |||
@@ -7,7 +7,7 @@ | |||
7 | <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" /> | 7 | <MajorUpgrade DowngradeErrorMessage="Downgrade not allowed" /> |
8 | 8 | ||
9 | <Feature Id="ProductFeature" Title="Feature title"> | 9 | <Feature Id="ProductFeature" Title="Feature title"> |
10 | <Component Directory="DesktopFolder"> | 10 | <Component> |
11 | <File Source="PerUser.wxs" /> | 11 | <File Source="PerUser.wxs" /> |
12 | </Component> | 12 | </Component> |
13 | </Feature> | 13 | </Feature> |