Skip to content

Commit

Permalink
Show PurchaseUrl if present in manifest (#2416)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trenly authored Aug 23, 2022
1 parent 45a3867 commit f66b390
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 113 deletions.
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
189 changes: 76 additions & 113 deletions src/AppInstallerCLICore/Workflows/ShowFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename String>
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 <typename String>
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 <typename Enumerable>
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;
}
}
}
Expand All @@ -38,80 +78,27 @@ namespace AppInstaller::CLI::Workflow
{
const auto& manifest = context.Get<Execution::Data::Manifest>();
auto info = context.Reporter.Info();
// Get description from manifest so we can see if it is empty later
auto description = manifest.CurrentLocalization.Get<Manifest::Localization::Description>();

// 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<Manifest::Localization::Publisher>() << std::endl;
auto publisherUrl = manifest.CurrentLocalization.Get<Manifest::Localization::PublisherUrl>();
if (!publisherUrl.empty())
{
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPublisherUrl << ' ' << publisherUrl << std::endl;
}
auto publisherSupportUrl = manifest.CurrentLocalization.Get<Manifest::Localization::PublisherSupportUrl>();
if (!publisherSupportUrl.empty())
{
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPublisherSupportUrl << ' ' << publisherSupportUrl << std::endl;
}
auto author = manifest.CurrentLocalization.Get<Manifest::Localization::Author>();
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<Manifest::Localization::Description>();
if (description.empty())
{
// Fall back to short description
description = manifest.CurrentLocalization.Get<Manifest::Localization::ShortDescription>();
}
if (!description.empty())
{
ShowMultiLineField(info, Resource::String::ShowLabelDescription, description);
}
auto homepage = manifest.CurrentLocalization.Get<Manifest::Localization::PackageUrl>();
if (!homepage.empty())
{
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPackageUrl << ' ' << homepage << std::endl;
}
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelLicense << ' ' << manifest.CurrentLocalization.Get<Manifest::Localization::License>() << std::endl;
auto licenseUrl = manifest.CurrentLocalization.Get<Manifest::Localization::LicenseUrl>();
if (!licenseUrl.empty())
{
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelLicenseUrl << ' ' << licenseUrl << std::endl;
}
auto privacyUrl = manifest.CurrentLocalization.Get<Manifest::Localization::PrivacyUrl>();
if (!privacyUrl.empty())
{
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelPrivacyUrl << ' ' << privacyUrl << std::endl;
}
auto copyright = manifest.CurrentLocalization.Get<Manifest::Localization::Copyright>();
if (!copyright.empty())
{
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelCopyright << ' ' << copyright << std::endl;
}
auto copyrightUrl = manifest.CurrentLocalization.Get<Manifest::Localization::CopyrightUrl>();
if (!copyrightUrl.empty())
{
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelCopyrightUrl << ' ' << copyrightUrl << std::endl;
}
auto releaseNotes = manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotes>();
if (!releaseNotes.empty())
{
ShowMultiLineField(info, Resource::String::ShowLabelReleaseNotes, releaseNotes);
}
auto releaseNotesUrl = manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotesUrl>();
if (!releaseNotesUrl.empty())
{
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelReleaseNotesUrl << ' ' << releaseNotesUrl << std::endl;
}
auto installationNotes = manifest.CurrentLocalization.Get<Manifest::Localization::InstallationNotes>();
if (!installationNotes.empty())
{
ShowMultiLineField(info, Resource::String::ShowLabelInstallationNotes, installationNotes);
}
ShowSingleLineField(info, Resource::String::ShowLabelVersion, manifest.Version);
ShowSingleLineField(info, Resource::String::ShowLabelPublisher, manifest.CurrentLocalization.Get<Manifest::Localization::Publisher>());
ShowSingleLineField(info, Resource::String::ShowLabelPublisherUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PublisherUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelPublisherSupportUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PublisherSupportUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelAuthor, manifest.CurrentLocalization.Get<Manifest::Localization::Author>());
ShowSingleLineField(info, Resource::String::ShowLabelMoniker, manifest.Moniker);
ShowMultiLineField(info, Resource::String::ShowLabelDescription, description.empty() ? manifest.CurrentLocalization.Get<Manifest::Localization::ShortDescription>() : description);
ShowSingleLineField(info, Resource::String::ShowLabelPackageUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PackageUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelLicense, manifest.CurrentLocalization.Get<Manifest::Localization::License>());
ShowSingleLineField(info, Resource::String::ShowLabelLicenseUrl, manifest.CurrentLocalization.Get<Manifest::Localization::LicenseUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelPrivacyUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PrivacyUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelCopyright, manifest.CurrentLocalization.Get<Manifest::Localization::Copyright>());
ShowSingleLineField(info, Resource::String::ShowLabelCopyrightUrl, manifest.CurrentLocalization.Get<Manifest::Localization::CopyrightUrl>());
ShowMultiLineField(info, Resource::String::ShowLabelReleaseNotes, manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotes>());
ShowSingleLineField(info, Resource::String::ShowLabelReleaseNotesUrl, manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotesUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelPurchaseUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PurchaseUrl>());
ShowMultiLineField(info, Resource::String::ShowLabelInstallationNotes, manifest.CurrentLocalization.Get<Manifest::Localization::InstallationNotes>());
const auto& documentations = manifest.CurrentLocalization.Get<Manifest::Localization::Documentations>();
if (!documentations.empty())
{
Expand All @@ -130,15 +117,7 @@ namespace AppInstaller::CLI::Workflow
}
}
}
const auto& tags = manifest.CurrentLocalization.Get<Manifest::Localization::Tags>();
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<Manifest::Localization::Tags>());
const auto& agreements = manifest.CurrentLocalization.Get<Manifest::Localization::Agreements>();
if (!agreements.empty())
{
Expand Down Expand Up @@ -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))
{
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,9 @@ Do you agree to the terms?</value>
<data name="ShowLabelPublisherUrl" xml:space="preserve">
<value>Publisher Url:</value>
</data>
<data name="ShowLabelPurchaseUrl" xml:space="preserve">
<value>Purchase Url:</value>
</data>
<data name="ShowLabelPublisherSupportUrl" xml:space="preserve">
<value>Publisher Support Url:</value>
</data>
Expand Down

0 comments on commit f66b390

Please sign in to comment.