Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block elevated process from overriding hash mismatch #482

Merged
merged 2 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ namespace AppInstaller::CLI

Argument Argument::ForType(Execution::Args::Type type)
{
constexpr char None = APPINSTALLER_CLI_ARGUMENT_NO_SHORT_VER;

switch (type)
{
case Args::Type::Query:
return Argument{ "query", 'q', Args::Type::Query, Resource::String::QueryArgumentDescription, ArgumentType::Positional};
case Args::Type::Manifest:
return Argument{ "manifest", 'm', Args::Type::Manifest, Resource::String::ManifestArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
case Args::Type::Id:
return Argument{ "id", None, Args::Type::Id,Resource::String::IdArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
return Argument{ "id", NoAlias, Args::Type::Id,Resource::String::IdArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
case Args::Type::Name:
return Argument{ "name", None, Args::Type::Name, Resource::String::NameArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
return Argument{ "name", NoAlias, Args::Type::Name, Resource::String::NameArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
case Args::Type::Moniker:
return Argument{ "moniker", None, Args::Type::Moniker, Resource::String::MonikerArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
return Argument{ "moniker", NoAlias, Args::Type::Moniker, Resource::String::MonikerArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
case Args::Type::Tag:
return Argument{ "tag", None, Args::Type::Tag, Resource::String::TagArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
return Argument{ "tag", NoAlias, Args::Type::Tag, Resource::String::TagArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
case Args::Type::Command:
return Argument{ "command", None, Args::Type::Command, Resource::String::CommandArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
return Argument{ "command", NoAlias, Args::Type::Command, Resource::String::CommandArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
case Args::Type::Source:
return Argument{ "source", 's', Args::Type::Source, Resource::String::SourceArgumentDescription, ArgumentType::Standard };
case Args::Type::Count:
Expand All @@ -50,15 +48,15 @@ namespace AppInstaller::CLI
case Args::Type::Log:
return Argument{ "log", 'o', Args::Type::Log, Resource::String::LogArgumentDescription, ArgumentType::Standard };
case Args::Type::Override:
return Argument{ "override", None, Args::Type::Override, Resource::String::OverrideArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
return Argument{ "override", NoAlias, Args::Type::Override, Resource::String::OverrideArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
case Args::Type::InstallLocation:
return Argument{ "location", 'l', Args::Type::InstallLocation, Resource::String::LocationArgumentDescription, ArgumentType::Standard };
case Args::Type::HashFile:
return Argument{ "file", 'f', Args::Type::HashFile, Resource::String::FileArgumentDescription, ArgumentType::Positional, true };
case Args::Type::Msix:
return Argument{ "msix", 'm', Args::Type::Msix, Resource::String::MsixArgumentDescription, ArgumentType::Flag };
case Args::Type::ListVersions:
return Argument{ "versions", None, Args::Type::ListVersions, Resource::String::VersionsArgumentDescription, ArgumentType::Flag };
return Argument{ "versions", NoAlias, Args::Type::ListVersions, Resource::String::VersionsArgumentDescription, ArgumentType::Flag };
case Args::Type::Help:
return Argument{ "help", APPINSTALLER_CLI_HELP_ARGUMENT_TEXT_CHAR, Args::Type::Help, Resource::String::HelpArgumentDescription, ArgumentType::Flag };
case Args::Type::SourceName:
Expand All @@ -68,19 +66,17 @@ namespace AppInstaller::CLI
case Args::Type::SourceType:
return Argument{ "type", 't', Args::Type::SourceType, Resource::String::SourceTypeArgumentDescription, ArgumentType::Positional };
case Args::Type::ValidateManifest:
return Argument{ "manifest", None, Args::Type::ValidateManifest, Resource::String::ValidateManifestArgumentDescription, ArgumentType::Positional, true };
return Argument{ "manifest", NoAlias, Args::Type::ValidateManifest, Resource::String::ValidateManifestArgumentDescription, ArgumentType::Positional, true };
case Args::Type::NoVT:
return Argument{ "no-vt", None, Args::Type::NoVT, Resource::String::NoVTArgumentDescription, ArgumentType::Flag, Argument::Visibility::Hidden };
return Argument{ "no-vt", NoAlias, Args::Type::NoVT, Resource::String::NoVTArgumentDescription, ArgumentType::Flag, Argument::Visibility::Hidden };
case Args::Type::RainbowStyle:
return Argument{ "rainbow", None, Args::Type::RainbowStyle, Resource::String::RainbowArgumentDescription, ArgumentType::Flag, Argument::Visibility::Hidden };
return Argument{ "rainbow", NoAlias, Args::Type::RainbowStyle, Resource::String::RainbowArgumentDescription, ArgumentType::Flag, Argument::Visibility::Hidden };
case Args::Type::RetroStyle:
return Argument{ "retro", None, Args::Type::RetroStyle, Resource::String::RetroArgumentDescription, ArgumentType::Flag, Argument::Visibility::Hidden };
case Args::Type::Force:
return Argument{ "force", None, Args::Type::Force, Resource::String::ForceArgumentDescription, ArgumentType::Flag };
return Argument{ "retro", NoAlias, Args::Type::RetroStyle, Resource::String::RetroArgumentDescription, ArgumentType::Flag, Argument::Visibility::Hidden };
case Args::Type::VerboseLogs:
return Argument{ "verbose-logs", None, Args::Type::VerboseLogs, Resource::String::VerboseLogsArgumentDescription, ArgumentType::Flag };
return Argument{ "verbose-logs", NoAlias, Args::Type::VerboseLogs, Resource::String::VerboseLogsArgumentDescription, ArgumentType::Flag };
case Args::Type::ExperimentalArg:
return Argument{ "arg", None, Args::Type::ExperimentalArg, Resource::String::ExperimentalArgumentDescription, ArgumentType::Flag, ExperimentalFeature::Feature::ExperimentalArg };
return Argument{ "arg", NoAlias, Args::Type::ExperimentalArg, Resource::String::ExperimentalArgumentDescription, ArgumentType::Flag, ExperimentalFeature::Feature::ExperimentalArg };
default:
THROW_HR(E_UNEXPECTED);
}
Expand Down
5 changes: 3 additions & 2 deletions src/AppInstallerCLICore/Argument.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#define APPINSTALLER_CLI_HELP_ARGUMENT_TEXT_STRING "?"
#define APPINSTALLER_CLI_HELP_ARGUMENT APPINSTALLER_CLI_ARGUMENT_IDENTIFIER_STRING APPINSTALLER_CLI_HELP_ARGUMENT_TEXT_STRING

#define APPINSTALLER_CLI_ARGUMENT_NO_SHORT_VER '\0'

namespace AppInstaller::CLI
{
// The type of argument.
Expand Down Expand Up @@ -46,6 +44,9 @@ namespace AppInstaller::CLI
Hidden,
};

// Defines an argument with no alias.
constexpr static char NoAlias = '\0';

Argument(std::string_view name, char alias, Execution::Args::Type execArgType, Resource::StringId desc) :
m_name(name), m_alias(alias), m_execArgType(execArgType), m_desc(std::move(desc)) {}

Expand Down
4 changes: 2 additions & 2 deletions src/AppInstallerCLICore/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace AppInstaller::CLI

infoOut << '[';

if (arg.Alias() == APPINSTALLER_CLI_ARGUMENT_NO_SHORT_VER)
if (arg.Alias() == Argument::NoAlias)
{
infoOut << APPINSTALLER_CLI_ARGUMENT_IDENTIFIER_CHAR << APPINSTALLER_CLI_ARGUMENT_IDENTIFIER_CHAR << arg.Name();
}
Expand Down Expand Up @@ -186,7 +186,7 @@ namespace AppInstaller::CLI
for (const auto& arg : arguments)
{
std::ostringstream strstr;
if (arg.Alias() != APPINSTALLER_CLI_ARGUMENT_NO_SHORT_VER)
if (arg.Alias() != Argument::NoAlias)
{
strstr << APPINSTALLER_CLI_ARGUMENT_IDENTIFIER_CHAR << arg.Alias() << ',';
}
Expand Down
12 changes: 10 additions & 2 deletions src/AppInstallerCLICore/Commands/FeaturesCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@ namespace AppInstaller::CLI

if (!features.empty())
{
Execution::TableOutput<4> table(context.Reporter, { "Feature", "Status", "Property", "Link" });
Execution::TableOutput<4> table(context.Reporter, {
Resource::String::FeaturesFeature,
Resource::String::FeaturesStatus,
Resource::String::FeaturesProperty,
Resource::String::FeaturesLink });
for (const auto& feature : features)
{
table.OutputLine({ std::string{ feature.Name() }, ExperimentalFeature::IsEnabled(feature.GetFeature()) ? "Enabled" : "Disabled", std::string { feature.JsonName() }, std::string{ feature.Link() } });
table.OutputLine({
std::string{ feature.Name() },
Resource::Loader::Instance().ResolveString(ExperimentalFeature::IsEnabled(feature.GetFeature()) ? Resource::String::FeaturesEnabled : Resource::String::FeaturesDisabled),
std::string { feature.JsonName() },
std::string{ feature.Link() } });
}
table.Complete();
}
Expand Down
32 changes: 17 additions & 15 deletions src/AppInstallerCLICore/Commands/InstallCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Workflows/WorkflowBase.h"
#include "Resources.h"

using namespace AppInstaller::CLI::Execution;
using namespace AppInstaller::Manifest;
using namespace AppInstaller::CLI::Workflow;

Expand All @@ -18,21 +19,22 @@ namespace AppInstaller::CLI
std::vector<Argument> InstallCommand::GetArguments() const
{
return {
Argument::ForType(Execution::Args::Type::Query),
Argument::ForType(Execution::Args::Type::Manifest),
Argument::ForType(Execution::Args::Type::Id),
Argument::ForType(Execution::Args::Type::Name),
Argument::ForType(Execution::Args::Type::Moniker),
Argument::ForType(Execution::Args::Type::Version),
Argument::ForType(Execution::Args::Type::Channel),
Argument::ForType(Execution::Args::Type::Source),
Argument::ForType(Execution::Args::Type::Exact),
Argument::ForType(Execution::Args::Type::Interactive),
Argument::ForType(Execution::Args::Type::Silent),
Argument::ForType(Execution::Args::Type::Language),
Argument::ForType(Execution::Args::Type::Log),
Argument::ForType(Execution::Args::Type::Override),
Argument::ForType(Execution::Args::Type::InstallLocation),
Argument::ForType(Args::Type::Query),
Argument::ForType(Args::Type::Manifest),
Argument::ForType(Args::Type::Id),
Argument::ForType(Args::Type::Name),
Argument::ForType(Args::Type::Moniker),
Argument::ForType(Args::Type::Version),
Argument::ForType(Args::Type::Channel),
Argument::ForType(Args::Type::Source),
Argument::ForType(Args::Type::Exact),
Argument::ForType(Args::Type::Interactive),
Argument::ForType(Args::Type::Silent),
Argument::ForType(Args::Type::Language),
Argument::ForType(Args::Type::Log),
Argument::ForType(Args::Type::Override),
Argument::ForType(Args::Type::InstallLocation),
Argument{ "force", Argument::NoAlias, Args::Type::Force, Resource::String::InstallForceArgumentDescription, ArgumentType::Flag },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument [](start = 12, length = 8)

Curious why is this one not added to ForType?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses different help text for each case. Honestly, now that we have the resource strings that whole function could be done away with.


In reply to: 451283891 [](ancestors = 451283891)

};
}

Expand Down
4 changes: 2 additions & 2 deletions src/AppInstallerCLICore/Commands/RootCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace AppInstaller::CLI
return
{
Argument{ "version", 'v', Execution::Args::Type::ListVersions, Resource::String::ToolVersionArgumentDescription, ArgumentType::Flag, Argument::Visibility::Help },
Argument{ "info", APPINSTALLER_CLI_ARGUMENT_NO_SHORT_VER, Execution::Args::Type::Info, Resource::String::ToolInfoArgumentDescription, ArgumentType::Flag, Argument::Visibility::Help },
Argument{ "info", Argument::NoAlias, Execution::Args::Type::Info, Resource::String::ToolInfoArgumentDescription, ArgumentType::Flag, Argument::Visibility::Help },
};
}

Expand Down Expand Up @@ -72,7 +72,7 @@ namespace AppInstaller::CLI

info << std::endl;

Execution::TableOutput<2> links{ context.Reporter, { Resource::LocString(Resource::String::Links).get(), "" } };
Execution::TableOutput<2> links{ context.Reporter, { Resource::String::Links, {} } };

links.OutputLine({ Resource::LocString(Resource::String::PrivacyStatement).get(), "https://aka.ms/winget-privacy" });
links.OutputLine({ Resource::LocString(Resource::String::LicenseAgreement).get(), "https://aka.ms/winget-license" });
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Commands/SourceCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace AppInstaller::CLI
{
return {
Argument::ForType(Args::Type::SourceName),
Argument::ForType(Args::Type::Force),
Argument{ "force", Argument::NoAlias, Args::Type::Force, Resource::String::SourceResetForceArgumentDescription, ArgumentType::Flag },
};
}

Expand Down
12 changes: 0 additions & 12 deletions src/AppInstallerCLICore/ExecutionReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,6 @@ namespace AppInstaller::CLI::Execution
}
}

bool Reporter::PromptForBoolResponse(const std::string& msg, Level level)
{
UNREFERENCED_PARAMETER(level);

m_out << msg << " (Y|N)" << std::endl;

char response;
m_in.get(response);

return tolower(response) == 'y';
}

void Reporter::ShowIndefiniteProgress(bool running)
{
if (running)
Expand Down
3 changes: 0 additions & 3 deletions src/AppInstallerCLICore/ExecutionReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ namespace AppInstaller::CLI::Execution
// Sets the visual style (mostly for progress currently)
void SetStyle(AppInstaller::Settings::VisualStyle style);

// Prompts the user, return true if they consented.
bool PromptForBoolResponse(const std::string& msg, Level level = Level::Info);

// Used to show indefinite progress. Currently an indefinite spinner is the form of
// showing indefinite progress.
// running: shows indefinite progress if set to true, stops indefinite progress if set to false
Expand Down
Loading