From f66b390b92ca2b2203c1f9c3f28def8a8e4a8634 Mon Sep 17 00:00:00 2001 From: Kaleb Luedtke Date: Tue, 23 Aug 2022 15:31:54 -0500 Subject: [PATCH] Show PurchaseUrl if present in manifest (#2416) --- src/AppInstallerCLICore/Resources.h | 1 + .../Workflows/ShowFlow.cpp | 189 +++++++----------- .../Shared/Strings/en-us/winget.resw | 3 + 3 files changed, 80 insertions(+), 113 deletions(-) diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h index 5a106a5821..be31921a12 100644 --- a/src/AppInstallerCLICore/Resources.h +++ b/src/AppInstallerCLICore/Resources.h @@ -299,6 +299,7 @@ namespace AppInstaller::CLI::Resource WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPublisher); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPublisherSupportUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPublisherUrl); + WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelPurchaseUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelReleaseNotes); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelReleaseNotesUrl); WINGET_DEFINE_RESOURCE_STRINGID(ShowLabelTags); diff --git a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp index 5cb7a910c3..1f81ce974a 100644 --- a/src/AppInstallerCLICore/Workflows/ShowFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/ShowFlow.cpp @@ -12,17 +12,57 @@ using namespace AppInstaller::Utility; using namespace AppInstaller::Utility::literals; namespace { - void ShowMultiLineField(Execution::OutputStream& outputStream, AppInstaller::StringResource::StringId label, std::string& value) + + template + void ShowSingleLineField(Execution::OutputStream outputStream, AppInstaller::StringResource::StringId label, const String& value, bool indent = false) + { + if (value.empty()) + { + return; + } + if (indent) + { + outputStream << " "_liv; + } + outputStream << Execution::ManifestInfoEmphasis << label << ' ' << value << std::endl; + } + + template + void ShowMultiLineField(Execution::OutputStream outputStream, AppInstaller::StringResource::StringId label, const String& value) { - bool isMultiLine = FindAndReplace(value, "\n", "\n "); + if (value.empty()) + { + return; + } + /* + We need to be able to find and replace within the string.However, we don't want to own the original string + Therefore, a copy is created here so we can manipulate it. The memory should be freed again once this method + returns and the string is no longer in scope. + */ + std::string shownValue = value; + bool isMultiLine = FindAndReplace(shownValue, "\n", "\n "); outputStream << Execution::ManifestInfoEmphasis << label; if (isMultiLine) { - outputStream << std::endl << " "_liv << value << std::endl; + outputStream << std::endl << " "_liv << shownValue << std::endl; } else { - outputStream << ' ' << value << std::endl; + outputStream << ' ' << shownValue << std::endl; + } + } + + template + void ShowMultiValueField(Execution::OutputStream outputStream, AppInstaller::StringResource::StringId label, const Enumerable& values) + { + if (values.empty()) + { + return; + } + outputStream << Execution::ManifestInfoEmphasis << label << std::endl; + for (const auto& value : values) + { + outputStream << " "_liv << value << std::endl; } } } @@ -38,80 +78,27 @@ namespace AppInstaller::CLI::Workflow { const auto& manifest = context.Get(); auto info = context.Reporter.Info(); + // Get description from manifest so we can see if it is empty later + auto description = manifest.CurrentLocalization.Get(); // TODO: Come up with a prettier format - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelVersion << ' ' << manifest.Version << std::endl; - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPublisher << ' ' << manifest.CurrentLocalization.Get() << std::endl; - auto publisherUrl = manifest.CurrentLocalization.Get(); - if (!publisherUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPublisherUrl << ' ' << publisherUrl << std::endl; - } - auto publisherSupportUrl = manifest.CurrentLocalization.Get(); - if (!publisherSupportUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPublisherSupportUrl << ' ' << publisherSupportUrl << std::endl; - } - auto author = manifest.CurrentLocalization.Get(); - if (!author.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelAuthor << ' ' << author << std::endl; - } - if (!manifest.Moniker.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelMoniker << ' ' << manifest.Moniker << std::endl; - } - auto description = manifest.CurrentLocalization.Get(); - if (description.empty()) - { - // Fall back to short description - description = manifest.CurrentLocalization.Get(); - } - if (!description.empty()) - { - ShowMultiLineField(info, Resource::String::ShowLabelDescription, description); - } - auto homepage = manifest.CurrentLocalization.Get(); - if (!homepage.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPackageUrl << ' ' << homepage << std::endl; - } - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelLicense << ' ' << manifest.CurrentLocalization.Get() << std::endl; - auto licenseUrl = manifest.CurrentLocalization.Get(); - if (!licenseUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelLicenseUrl << ' ' << licenseUrl << std::endl; - } - auto privacyUrl = manifest.CurrentLocalization.Get(); - if (!privacyUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPrivacyUrl << ' ' << privacyUrl << std::endl; - } - auto copyright = manifest.CurrentLocalization.Get(); - if (!copyright.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelCopyright << ' ' << copyright << std::endl; - } - auto copyrightUrl = manifest.CurrentLocalization.Get(); - if (!copyrightUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelCopyrightUrl << ' ' << copyrightUrl << std::endl; - } - auto releaseNotes = manifest.CurrentLocalization.Get(); - if (!releaseNotes.empty()) - { - ShowMultiLineField(info, Resource::String::ShowLabelReleaseNotes, releaseNotes); - } - auto releaseNotesUrl = manifest.CurrentLocalization.Get(); - if (!releaseNotesUrl.empty()) - { - info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelReleaseNotesUrl << ' ' << releaseNotesUrl << std::endl; - } - auto installationNotes = manifest.CurrentLocalization.Get(); - if (!installationNotes.empty()) - { - ShowMultiLineField(info, Resource::String::ShowLabelInstallationNotes, installationNotes); - } + ShowSingleLineField(info, Resource::String::ShowLabelVersion, manifest.Version); + ShowSingleLineField(info, Resource::String::ShowLabelPublisher, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelPublisherUrl, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelPublisherSupportUrl, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelAuthor, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelMoniker, manifest.Moniker); + ShowMultiLineField(info, Resource::String::ShowLabelDescription, description.empty() ? manifest.CurrentLocalization.Get() : description); + ShowSingleLineField(info, Resource::String::ShowLabelPackageUrl, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelLicense, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelLicenseUrl, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelPrivacyUrl, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelCopyright, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelCopyrightUrl, manifest.CurrentLocalization.Get()); + ShowMultiLineField(info, Resource::String::ShowLabelReleaseNotes, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelReleaseNotesUrl, manifest.CurrentLocalization.Get()); + ShowSingleLineField(info, Resource::String::ShowLabelPurchaseUrl, manifest.CurrentLocalization.Get()); + ShowMultiLineField(info, Resource::String::ShowLabelInstallationNotes, manifest.CurrentLocalization.Get()); const auto& documentations = manifest.CurrentLocalization.Get(); if (!documentations.empty()) { @@ -130,15 +117,7 @@ namespace AppInstaller::CLI::Workflow } } } - const auto& tags = manifest.CurrentLocalization.Get(); - if (!tags.empty()) - { - context.Reporter.Info() << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelTags << std::endl; - for (const auto& tag : tags) - { - info << " "_liv << tag << std::endl; - } - } + ShowMultiValueField(info, Resource::String::ShowLabelTags, manifest.CurrentLocalization.Get()); const auto& agreements = manifest.CurrentLocalization.Get(); if (!agreements.empty()) { @@ -175,36 +154,20 @@ namespace AppInstaller::CLI::Workflow { Manifest::InstallerTypeEnum effectiveInstallerType = installer->EffectiveInstallerType(); Manifest::InstallerTypeEnum baseInstallerType = installer->BaseInstallerType; - if (effectiveInstallerType == baseInstallerType) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerType << ' ' << Manifest::InstallerTypeToString(effectiveInstallerType) << std::endl; - } - else - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerType << ' ' << Manifest::InstallerTypeToString(effectiveInstallerType) << " (" << - Manifest::InstallerTypeToString(baseInstallerType) << ')' << std::endl; - } - - if (!installer->Locale.empty()) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerLocale << ' ' << installer->Locale << std::endl; - } - if (!installer->Url.empty()) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerUrl << ' ' << installer->Url << std::endl; - } - if (!installer->Sha256.empty()) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerSha256 << ' ' << Utility::SHA256::ConvertToString(installer->Sha256) << std::endl; - } - if (!installer->ProductId.empty()) - { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerProductId << ' ' << installer->ProductId << std::endl; - } - if (!installer->ReleaseDate.empty()) + std::string shownInstallerType; + shownInstallerType = Manifest::InstallerTypeToString(effectiveInstallerType); + if (effectiveInstallerType != baseInstallerType) { - info << " "_liv << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstallerReleaseDate << ' ' << installer->ReleaseDate << std::endl; + shownInstallerType += " ("_liv; + shownInstallerType += Manifest::InstallerTypeToString(baseInstallerType); + shownInstallerType += ')'; } + ShowSingleLineField(info, Resource::String::ShowLabelInstallerType, shownInstallerType, true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerLocale, installer->Locale, true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerUrl, installer->Url, true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerSha256, (installer->Sha256.empty()) ? "" : Utility::SHA256::ConvertToString(installer->Sha256), true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerProductId, installer->ProductId, true); + ShowSingleLineField(info, Resource::String::ShowLabelInstallerReleaseDate, installer->ReleaseDate, true); if (Settings::ExperimentalFeature::IsEnabled(Settings::ExperimentalFeature::Feature::Dependencies)) { diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw index 4058653011..ac583d45ae 100644 --- a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw +++ b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw @@ -1127,6 +1127,9 @@ Do you agree to the terms? Publisher Url: + + Purchase Url: + Publisher Support Url: