diff --git a/doc/update.md b/doc/update.md index 34dd377f..94003216 100644 --- a/doc/update.md +++ b/doc/update.md @@ -111,6 +111,7 @@ The following arguments are available: | **-u, --urls** | Installer Url(s) used to extract relevant metadata for generating a manifest | | **-v, --version** | Version to be used when updating the package version field. | | **-d, --display-version** | Version to be used when updating the display version field. Version provided in the installer URL arguments will take precedence over this value. | +| **--display-name** | Name to be used when updating the display name field. | | **--release-notes-url** | URL to be used when updating the release notes url field. | | **--release-date** | Date to be used when updating the release date field. Expected format is "YYYY-MM-DD". | | **-o, --out** | The output directory where the newly created manifests will be saved locally | diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index 94604cc2..f53696fe 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -73,6 +73,12 @@ public static IEnumerable Examples [Option('d', "display-version", Required = false, HelpText = "DisplayVersion_HelpText", ResourceType = typeof(Resources))] public string DisplayVersion { get; set; } + /// + /// Gets or sets the new value used to update the display name field in the manifest. + /// + [Option("display-name", Required = false, HelpText = "DisplayName_HelpText", ResourceType = typeof(Resources))] + public string DisplayName { get; set; } + /// /// Gets or sets the release notes URL for the manifest. /// @@ -367,6 +373,18 @@ public async Task UpdateManifestsAutonomously(Manifests manifests) } } + if (!string.IsNullOrEmpty(this.DisplayName)) + { + // Use --display-name value if provided as an argument. + foreach (InstallerMetadata installerUpdate in installerMetadataList) + { + if (string.IsNullOrEmpty(installerUpdate.DisplayName)) + { + installerUpdate.DisplayName = this.DisplayName; + } + } + } + var originalAppsAndFeaturesEntries = installerManifest.Installers .Where(i => i.AppsAndFeaturesEntries != null) .SelectMany(i => i.AppsAndFeaturesEntries); diff --git a/src/WingetCreateCLI/Properties/Resources.Designer.cs b/src/WingetCreateCLI/Properties/Resources.Designer.cs index 50974bd2..4239e97b 100644 --- a/src/WingetCreateCLI/Properties/Resources.Designer.cs +++ b/src/WingetCreateCLI/Properties/Resources.Designer.cs @@ -618,6 +618,15 @@ public static string DisplayInstallWarnings_KeywordDescription { } } + /// + /// Looks up a localized string similar to Name to be used when updating the display name field.. + /// + public static string DisplayName_HelpText { + get { + return ResourceManager.GetString("DisplayName_HelpText", resourceCulture); + } + } + /// /// Looks up a localized string similar to The DisplayName of the package or file. /// diff --git a/src/WingetCreateCLI/Properties/Resources.resx b/src/WingetCreateCLI/Properties/Resources.resx index cb842ae3..987e0e32 100644 --- a/src/WingetCreateCLI/Properties/Resources.resx +++ b/src/WingetCreateCLI/Properties/Resources.resx @@ -1365,6 +1365,9 @@ Warning: Using this argument may result in the token being logged. Consider an a Base manifest contains DisplayVersion that has not been updated. Use --display-version CLI arg or provide the version in the installer URL. + + Name to be used when updating the display name field. + Version to be used when updating the display version field. Version provided in the installer URL arguments will take precedence over this value. diff --git a/src/WingetCreateCore/Common/PackageParser.cs b/src/WingetCreateCore/Common/PackageParser.cs index 984650c2..9bad4972 100644 --- a/src/WingetCreateCore/Common/PackageParser.cs +++ b/src/WingetCreateCore/Common/PackageParser.cs @@ -270,6 +270,25 @@ public static void UpdateInstallerNodesAsync(List installerMe } } + // Update DisplayName for each AppsAndFeaturesEntry + if (!string.IsNullOrEmpty(installerUpdate.DisplayName)) + { + if (newInstaller.AppsAndFeaturesEntries != null) + { + newInstaller.AppsAndFeaturesEntries[0].DisplayName = installerUpdate.DisplayName; + } + else + { + newInstaller.AppsAndFeaturesEntries = new List + { + new AppsAndFeaturesEntry + { + DisplayName = installerUpdate.DisplayName, + }, + }; + } + } + // if the installerUpdate does not have a binary or url architecture specified, then just use what is specified in the installer. Installer existingInstallerMatch = FindInstallerMatch( newInstaller, diff --git a/src/WingetCreateCore/Models/InstallerMetadata.cs b/src/WingetCreateCore/Models/InstallerMetadata.cs index e260b37c..266287a1 100644 --- a/src/WingetCreateCore/Models/InstallerMetadata.cs +++ b/src/WingetCreateCore/Models/InstallerMetadata.cs @@ -46,6 +46,11 @@ public class InstallerMetadata /// public Scope? OverrideScope { get; set; } + /// + /// Gets or sets the display name specified as a CLI arg. + /// + public string DisplayName { get; set; } + /// /// Gets or sets the display version specified as a CLI arg or an installer url argument. /// diff --git a/src/WingetCreateTests/WingetCreateTests/Resources/TestPublisher.UpdateDisplayName.yaml b/src/WingetCreateTests/WingetCreateTests/Resources/TestPublisher.UpdateDisplayName.yaml new file mode 100644 index 00000000..5fd7d217 --- /dev/null +++ b/src/WingetCreateTests/WingetCreateTests/Resources/TestPublisher.UpdateDisplayName.yaml @@ -0,0 +1,23 @@ +PackageIdentifier: TestPublisher.UpdateDisplayName +PackageVersion: 0.1.2 +PackageName: Test for updating display name through CLI arg +Publisher: Test publisher +License: MIT +ShortDescription: A manifest used to test whether the display name is correctly updated with the CLI arg +InstallerLocale: en-US +Installers: + # DisplayVersion: 1.0.0 + - Architecture: x64 + InstallerUrl: https://fakedomain.com/WingetCreateTestExeInstaller.exe + InstallerType: exe + AppsAndFeaturesEntries: + - DisplayName: FooApp 1.0.0 + InstallerSha256: A7803233EEDB6A4B59B3024CCF9292A6FFFB94507DC998AA67C5B745D197A5DC + # No DisplayVersion + - Architecture: arm64 + InstallerUrl: https://fakedomain.com/WingetCreateTestExeInstaller.exe + InstallerType: exe + InstallerSha256: A7803233EEDB6A4B59B3024CCF9292A6FFFB94507DC998AA67C5B745D197A5DC +PackageLocale: en-US +ManifestType: singleton +ManifestVersion: 1.4.0 \ No newline at end of file diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs index 7951e56a..0c042991 100644 --- a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs +++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs @@ -584,6 +584,54 @@ public async Task UpdateWithAllUrlArguments() ClassicAssert.AreNotEqual(initialSecondDisplayVersion, updatedSecondDisplayVersion, "DisplayVersion should be updated"); } + /// + /// Verifies that display name provided as CLI arg correctly updates the display name in the manifest. + /// + /// A representing the result of the asynchronous operation. + [Test] + public async Task UpdateDisplayName() + { + TestUtils.InitializeMockDownload(); + TestUtils.SetMockHttpResponseContent(TestConstants.TestExeInstaller); + string testInstallerUrl = $"https://fakedomain.com/{TestConstants.TestExeInstaller}"; + string displayNameForCLIArg = "FooApp 2.3.4.5"; + + var initialManifestContent = TestUtils.GetInitialManifestContent("TestPublisher.UpdateDisplayName.yaml"); + UpdateCommand command = new UpdateCommand + { + Id = "TestPublisher.UpdateDisplayName", + Version = "1.2.3.4", + InstallerUrls = new[] + { + $"{testInstallerUrl}|x64", + $"{testInstallerUrl}|arm64", + }, + DisplayName = displayNameForCLIArg, + }; + var initialManifests = Serialization.DeserializeManifestContents(initialManifestContent); + var updatedManifests = await RunUpdateCommand(command, initialManifestContent); + ClassicAssert.IsNotNull(updatedManifests, "Command should have succeeded."); + + // Initial installers + var initialFirstInstaller = initialManifests.SingletonManifest.Installers[0]; + + // Initial display names (second installer does not have a display name) + var initialFirstDisplayName = initialFirstInstaller.AppsAndFeaturesEntries.FirstOrDefault().DisplayName; + + // Updated installers + var updatedFirstInstaller = updatedManifests.InstallerManifest.Installers[0]; + var updatedSecondInstaller = updatedManifests.InstallerManifest.Installers[1]; + + // Updated display names (second installer does not have a display name) + var updatedFirstDisplayName = updatedFirstInstaller.AppsAndFeaturesEntries.FirstOrDefault().DisplayName; + + ClassicAssert.AreEqual(displayNameForCLIArg, updatedFirstDisplayName, "DisplayName should be updated by the value in the CLI arg"); + ClassicAssert.IsNull(updatedSecondInstaller.AppsAndFeaturesEntries); + + ClassicAssert.AreNotEqual(initialFirstInstaller.InstallerSha256, updatedFirstInstaller.InstallerSha256, "InstallerSha256 should be updated"); + ClassicAssert.AreNotEqual(initialFirstDisplayName, updatedFirstDisplayName, "DisplayName should be updated"); + } + /// /// Verifies that display version provided as CLI arg and in the URL arguments correctly updates the display version in the manifest. /// diff --git a/src/WingetCreateTests/WingetCreateTests/WingetCreateTests.csproj b/src/WingetCreateTests/WingetCreateTests/WingetCreateTests.csproj index a075e7b9..029f9d00 100644 --- a/src/WingetCreateTests/WingetCreateTests/WingetCreateTests.csproj +++ b/src/WingetCreateTests/WingetCreateTests/WingetCreateTests.csproj @@ -96,6 +96,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest