Skip to content

Commit 9fd1078

Browse files
authored
Retain non-null installer fields when copying over root values (#491)
1 parent 08baf0e commit 9fd1078

File tree

6 files changed

+252
-87
lines changed

6 files changed

+252
-87
lines changed

src/WingetCreateCLI/Commands/BaseCommand.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ protected static void RemoveEmptyStringFieldsInManifests(Manifests manifests)
422422

423423
/// <summary>
424424
/// Shifts common installer fields from manifest root to installer level.
425+
/// If value is already defined at the installer level, then it should not be overwritten.
425426
/// </summary>
426427
/// <param name="installerManifest">Wrapper object containing the installer manifest object models.</param>
427428
protected static void ShiftRootFieldsToInstallerLevel(InstallerManifest installerManifest)
@@ -439,8 +440,13 @@ protected static void ShiftRootFieldsToInstallerLevel(InstallerManifest installe
439440
{
440441
foreach (var installer in installerManifest.Installers)
441442
{
442-
// Copy the value to installer level
443-
installer.GetType().GetProperty(property.Name).SetValue(installer, rootValue);
443+
var installerProperty = installer.GetType().GetProperty(property.Name);
444+
445+
// Only set the value if it is null at the installer level
446+
if (installerProperty.GetValue(installer) == null)
447+
{
448+
installerProperty.SetValue(installer, rootValue);
449+
}
444450
}
445451

446452
// Set root value to null

src/WingetCreateCLI/Commands/UpdateCommand.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,6 @@ public Manifests DeserializeManifestContentAndApplyInitialUpdate(List<string> la
460460
UpdatePropertyForLocaleManifests(nameof(LocaleManifest.PackageVersion), this.Version, localeManifests);
461461
}
462462

463-
// TODO: Move relevant metadata from root node to installer node.
464-
if (installerManifest.InstallerType != null)
465-
{
466-
installerManifest.Installers.ForEach(i => i.InstallerType = installerManifest.InstallerType);
467-
installerManifest.InstallerType = null;
468-
}
469-
470463
return manifests;
471464
}
472465

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
PackageIdentifier: TestPublisher.OverwriteNullInstallerFields
2+
PackageVersion: 0.1.2
3+
PackageName: Overwrite installer level fields by root fields
4+
Publisher: Test publisher
5+
License: MIT
6+
ShortDescription: A manifest that verifies that installer level fields are overwritten by root fields.
7+
Description: |-
8+
Expected flow:
9+
10+
1) Installer level fields are overwritten by root fields at the start of the update.
11+
2) The update flow modifies the installer level fields if needed. (e.g. ProductCode in case of MSI upgrade)
12+
3) At the end of the update, the common installer fields are moved to the root level.
13+
InstallerLocale: en-US
14+
InstallerType: zip
15+
NestedInstallerType: exe
16+
NestedInstallerFiles:
17+
- RelativeFilePath: WingetCreateTestExeInstaller.exe
18+
PortableCommandAlias: PortableCommandAlias1
19+
AppsAndFeaturesEntries:
20+
- DisplayName: TestDisplayName1
21+
Publisher: TestPublisher1
22+
DisplayVersion: 1.0.1
23+
ProductCode: TestProductCode1
24+
UpgradeCode: TestUpgradeCode1
25+
InstallerType: msi
26+
InstallerSwitches:
27+
Silent: /silent1
28+
SilentWithProgress: /silentwithprogress1
29+
Dependencies:
30+
PackageDependencies:
31+
- PackageIdentifier: TestPackageDependency1
32+
MinimumVersion: 1.0.1
33+
WindowsFeatures:
34+
- TestWindowsFeature1
35+
ExternalDependencies:
36+
- TestExternalDependency1
37+
WindowsLibraries:
38+
- TestWindowsLibrary1
39+
ExpectedReturnCodes:
40+
- InstallerReturnCode: 1001
41+
ReturnResponse: installInProgress
42+
MinimumOSVersion: 10.0.22000.0
43+
PackageFamilyName: TestPackageFamilyName1
44+
Platform:
45+
- Windows.Desktop
46+
Scope: machine
47+
UpgradeBehavior: install
48+
ElevationRequirement: elevationRequired
49+
Commands:
50+
- fakeCommand1
51+
Protocols:
52+
- fakeProtocol1
53+
FileExtensions:
54+
- .exe
55+
# Uncomment when installer model gets updated to support these fields
56+
#Markets:
57+
# AllowedMarkets:
58+
# - fakeAllowedMarket
59+
# ExcludedMarkets:
60+
# - fakeExcludedMarket
61+
InstallerAbortsTerminal: true
62+
InstallLocationRequired: true
63+
RequireExplicitUpgrade: true
64+
UnsupportedOSArchitectures:
65+
- arm64
66+
DisplayInstallWarnings: true
67+
InstallerSuccessCodes:
68+
- 1
69+
UnsupportedArguments:
70+
- log
71+
- location
72+
InstallationMetadata:
73+
DefaultInstallLocation: "%ProgramFiles%\\TestApp1"
74+
Files:
75+
- RelativeFilePath: "main1.exe"
76+
FileSha256: 69D84CA8899800A5575CE31798293CD4FEBAB1D734A07C2E51E56A28E0DF8C82
77+
FileType: launch
78+
InvocationParameter: "/arg1"
79+
Installers:
80+
- Architecture: x64
81+
InstallerUrl: https://fakedomain.com/WingetCreateTestZipInstaller.zip
82+
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
83+
- Architecture: x86
84+
InstallerUrl: https://fakedomain.com/WingetCreateTestZipInstaller.zip
85+
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
86+
PackageLocale: en-US
87+
ManifestType: singleton
88+
ManifestVersion: 1.4.0

src/WingetCreateTests/WingetCreateTests/Resources/TestPublisher.OverrideInstallerFields.yaml renamed to src/WingetCreateTests/WingetCreateTests/Resources/TestPublisher.RetainInstallerFields.yaml

Lines changed: 13 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
PackageIdentifier: TestPublisher.OverrideInstallerFields
1+
PackageIdentifier: TestPublisher.RetainInstallerFields
22
PackageVersion: 0.1.2
3-
PackageName: Override installer level fields by root fields
3+
PackageName: Retain installer level fields when copying over root values
44
Publisher: Test publisher
55
License: MIT
6-
ShortDescription: A manifest that verifies that installer level fields are overridden by root fields.
6+
ShortDescription: A manifest that verifies that non-null installer level fields are not overwritten by root fields.
77
Description: |-
88
Expected flow:
99
10-
1) Installer level fields are overridden by root fields at the start of the update.
11-
2) The update flow modifies the installer level fields if needed. (e.g. ProductCode in case of MSI upgrade)
12-
3) At the end of the update, the common installer fields are moved to the root level.
10+
1) For the first installer, all root level fields are copied over and root fields are set to null.
11+
2) For the second installer, installer level fields are preserved since they are not null.
12+
3) InstallerType and NestedInstallerType are common across both installers, so they are moved to the root level at the end of the update.
13+
14+
TODO: Use different NestedInstallerType and RelativeFilePath for each installer once logic for handling multiple nested installers is improved.
15+
Reference: https://github.com/microsoft/winget-create/issues/392
1316
InstallerLocale: en-US
1417
InstallerType: zip
1518
NestedInstallerType: exe
1619
NestedInstallerFiles:
1720
- RelativeFilePath: WingetCreateTestExeInstaller.exe
18-
PortableCommandAlias: PortableCommandAlias1
21+
PortableCommandAlias: TestAlias
1922
AppsAndFeaturesEntries:
2023
- DisplayName: TestDisplayName1
2124
Publisher: TestPublisher1
@@ -78,80 +81,16 @@ InstallationMetadata:
7881
InvocationParameter: "/arg1"
7982
Installers:
8083
- Architecture: x64
81-
InstallerType: zip
8284
InstallerUrl: https://fakedomain.com/WingetCreateTestZipInstaller.zip
8385
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
84-
NestedInstallerType: msi
85-
NestedInstallerFiles:
86-
- RelativeFilePath: WingetCreateTestExeInstaller.exe
87-
PortableCommandAlias: PortableCommandAlias2
88-
AppsAndFeaturesEntries:
89-
- DisplayName: TestDisplayName2
90-
Publisher: TestPublisher2
91-
DisplayVersion: 1.0.2
92-
ProductCode: TestProductCode2
93-
UpgradeCode: TestUpgradeCode2
94-
InstallerType: exe
95-
InstallerSwitches:
96-
Silent: /silent2
97-
SilentWithProgress: /silentwithprogress2
98-
Dependencies:
99-
PackageDependencies:
100-
- PackageIdentifier: TestPackageDependency2
101-
MinimumVersion: 1.0.2
102-
WindowsFeatures:
103-
- TestWindowsFeature2
104-
ExternalDependencies:
105-
- TestExternalDependency2
106-
WindowsLibraries:
107-
- TestWindowsLibrary2
108-
ExpectedReturnCodes:
109-
- InstallerReturnCode: 1002
110-
ReturnResponse: installInProgress
111-
MinimumOSVersion: 10.0.17763.0
112-
PackageFamilyName: TestPackageFamilyName2
113-
Platform:
114-
- Windows.Universal
115-
Scope: user
116-
UpgradeBehavior: uninstallPrevious
117-
ElevationRequirement: elevatesSelf
118-
Commands:
119-
- fakeCommand2
120-
Protocols:
121-
- fakeProtocol2
122-
FileExtensions:
123-
- .msi
124-
# Uncomment when installer model gets updated to support these fields
125-
#Markets:
126-
# AllowedMarkets:
127-
# - fakeAllowedMarket
128-
# ExcludedMarkets:
129-
# - fakeExcludedMarket
130-
InstallerAbortsTerminal: false
131-
InstallLocationRequired: false
132-
RequireExplicitUpgrade: false
133-
UnsupportedOSArchitectures:
134-
- arm
135-
DisplayInstallWarnings: false
136-
InstallerSuccessCodes:
137-
- 2
138-
UnsupportedArguments:
139-
- log
140-
InstallationMetadata:
141-
DefaultInstallLocation: "%ProgramFiles%\\TestApp2"
142-
Files:
143-
- RelativeFilePath: "main2.exe"
144-
FileSha256: 69D84CA8899800A5575CE31798293CD4FEBAB1D734A07C2E51E56A28E0DF8C82
145-
FileType: launch
146-
InvocationParameter: "/arg2"
14786
- Architecture: x86
14887
InstallerType: zip
14988
InstallerUrl: https://fakedomain.com/WingetCreateTestZipInstaller.zip
15089
InstallerSha256: 8A052767127A6E2058BAAE03B551A807777BB1B726650E2C7E92C3E92C8DF80D
151-
NestedInstallerType: msi
90+
NestedInstallerType: exe
15291
NestedInstallerFiles:
15392
- RelativeFilePath: WingetCreateTestExeInstaller.exe
154-
PortableCommandAlias: PortableCommandAlias2
93+
PortableCommandAlias: TestAlias
15594
AppsAndFeaturesEntries:
15695
- DisplayName: TestDisplayName2
15796
Publisher: TestPublisher2
@@ -188,7 +127,7 @@ Installers:
188127
- fakeProtocol2
189128
FileExtensions:
190129
- .msi
191-
# Uncomment when installer model gets updated to support these fields
130+
# TODO: Uncomment when installer model gets updated to support these fields
192131
#Markets:
193132
# AllowedMarkets:
194133
# - fakeAllowedMarket

0 commit comments

Comments
 (0)