Skip to content

Commit

Permalink
Add Experimental Argument for UninstallPrevious in Upgrade Flow (#2755)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trenly authored Jan 10, 2023
1 parent ce4d40c commit 5c6ba96
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 2 deletions.
11 changes: 11 additions & 0 deletions doc/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ You can enable the feature as shown below.
},
```

### uninstallPreviousArgument

This feature enables the Windows Package Manager to override the upgrade behavior to UninstallPrevious by passing the `--uninstall-previous` argument with the upgrade or install command.
You can enable the feature as shown below.

```json
"experimentalFeatures": {
"uninstallPreviousArgument": true
},
```

### dependencies

Experimental feature with the aim of managing dependencies, as of now it only shows package dependency information. You can enable the feature as shown below.
Expand Down
5 changes: 5 additions & 0 deletions schemas/JSON/settings/settings.schema.0.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@
"description": "Enable argument to open default logs location",
"type": "boolean",
"default": false
},
"uninstallPreviousArgument": {
"description": "Enable argument to override upgrade behavior to UninstallPrevious",
"type": "boolean",
"default": false
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ namespace AppInstaller::CLI
return Argument{ "product-code"_liv, NoAlias, Args::Type::ProductCode, Resource::String::ProductCodeArgumentDescription, ArgumentType::Standard, false };
case Args::Type::OpenLogs:
return Argument{ "open-logs"_liv, NoAlias, "logs"_liv, Args::Type::OpenLogs, Resource::String::OpenLogsArgumentDescription, ArgumentType::Flag, ExperimentalFeature::Feature::OpenLogsArgument};
case Args::Type::UninstallPrevious:
return Argument{ "uninstall-previous"_liv, NoAlias, Args::Type::UninstallPrevious, Resource::String::UninstallPreviousArgumentDescription, ArgumentType::Flag, ExperimentalFeature::Feature::UninstallPreviousArgument };
case Args::Type::Force:
return Argument{ "force"_liv, NoAlias, Args::Type::Force, Resource::String::ForceArgumentDescription, ArgumentType::Flag, false };
default:
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Commands/InstallCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace AppInstaller::CLI
Argument::ForType(Args::Type::CustomHeader),
Argument::ForType(Args::Type::AcceptSourceAgreements),
Argument::ForType(Args::Type::Rename),
Argument::ForType(Args::Type::UninstallPrevious),
Argument::ForType(Args::Type::Force),
};
}
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Commands/UpgradeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace AppInstaller::CLI
Argument::ForType(Execution::Args::Type::CustomHeader),
Argument{ "all"_liv, 'r', "recurse"_liv, Args::Type::All, Resource::String::UpdateAllArgumentDescription, ArgumentType::Flag },
Argument{ "include-unknown"_liv, 'u', "unknown"_liv, Args::Type::IncludeUnknown, Resource::String::IncludeUnknownArgumentDescription, ArgumentType::Flag },
Argument::ForType(Args::Type::UninstallPrevious),
Argument::ForType(Args::Type::Force),
};
}
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/ExecutionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace AppInstaller::CLI::Execution
// Upgrade command
All, // Used in Update command to update all installed packages to latest
IncludeUnknown, // Used in Upgrade command to allow upgrades of packages with unknown versions
UninstallPrevious, // Used in Upgrade command to override the default manifest behavior to UninstallPrevious

// Show command
ListVersions, // Used in Show command to list all available versions of an app
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(UninstallFailedWithCode);
WINGET_DEFINE_RESOURCE_STRINGID(UninstallFlowStartingPackageUninstall);
WINGET_DEFINE_RESOURCE_STRINGID(UninstallFlowUninstallSuccess);
WINGET_DEFINE_RESOURCE_STRINGID(UninstallPreviousArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(UnrecognizedCommand);
WINGET_DEFINE_RESOURCE_STRINGID(UnsupportedArgument);
WINGET_DEFINE_RESOURCE_STRINGID(UpdateAllArgumentDescription);
Expand Down
5 changes: 3 additions & 2 deletions src/AppInstallerCLICore/Workflows/InstallFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ namespace AppInstaller::CLI::Workflow
{
bool isUpdate = WI_IsFlagSet(context.GetFlags(), Execution::ContextFlag::InstallerExecutionUseUpdate);
UpdateBehaviorEnum updateBehavior = context.Get<Execution::Data::Installer>().value().UpdateBehavior;
bool doUninstallPrevious = isUpdate && (updateBehavior == UpdateBehaviorEnum::UninstallPrevious || context.Args.Contains(Execution::Args::Type::UninstallPrevious));

switch (m_installerType)
{
Expand All @@ -255,7 +256,7 @@ namespace AppInstaller::CLI::Workflow
case InstallerTypeEnum::Msi:
case InstallerTypeEnum::Nullsoft:
case InstallerTypeEnum::Wix:
if (isUpdate && updateBehavior == UpdateBehaviorEnum::UninstallPrevious)
if (doUninstallPrevious)
{
context <<
GetUninstallInfo <<
Expand All @@ -280,7 +281,7 @@ namespace AppInstaller::CLI::Workflow
(isUpdate ? MSStoreUpdate : MSStoreInstall);
break;
case InstallerTypeEnum::Portable:
if (isUpdate && updateBehavior == UpdateBehaviorEnum::UninstallPrevious)
if (doUninstallPrevious)
{
context <<
GetUninstallInfo <<
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLIE2ETests/FeaturesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void EnableExperimentalFeatures()
WinGetSettingsHelper.ConfigureFeature("experimentalCmd", true);
WinGetSettingsHelper.ConfigureFeature("directMSI", true);
WinGetSettingsHelper.ConfigureFeature("openLogsArgument", true);
WinGetSettingsHelper.ConfigureFeature("uninstallPreviousArgument", true);
var result = TestCommon.RunAICLICommand("features", string.Empty);
Assert.True(result.StdOut.Contains("Enabled"));
}
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 @@ -688,6 +688,9 @@ They can be configured through the settings file 'winget settings'.</value>
<data name="UnexpectedErrorExecutingCommand" xml:space="preserve">
<value>An unexpected error occurred while executing the command:</value>
</data>
<data name="UninstallPreviousArgumentDescription" xml:space="preserve">
<value>Uninstall the previous version of the package during upgrade</value>
</data>
<data name="UnrecognizedCommand" xml:space="preserve">
<value>Unrecognized command: '{0}'</value>
<comment>{Locked="{0}"} Error message displayed when the user provides an unrecognized command. {0} is a placeholder replaced by the user input.</comment>
Expand Down
4 changes: 4 additions & 0 deletions src/AppInstallerCommonCore/ExperimentalFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace AppInstaller::Settings
return userSettings.Get<Setting::EFOpenLogsArgument>();
case ExperimentalFeature::Feature::Pinning:
return userSettings.Get<Setting::EFPinning>();
case ExperimentalFeature::Feature::UninstallPreviousArgument:
return userSettings.Get<Setting::EFUninstallPreviousArgument>();
default:
THROW_HR(E_UNEXPECTED);
}
Expand Down Expand Up @@ -81,6 +83,8 @@ namespace AppInstaller::Settings
return ExperimentalFeature{ "Open Logs Argument", "openLogsArgument", "https://aka.ms/winget-settings", Feature::OpenLogsArgument };
case Feature::Pinning:
return ExperimentalFeature{ "Package Pinning", "pinning", "https://aka.ms/winget-settings", Feature::Pinning};
case Feature::UninstallPreviousArgument:
return ExperimentalFeature{ "Uninstall Previous Argument", "uninstallPreviousArgument", "https://aka.ms/winget-settings", Feature::UninstallPreviousArgument };
default:
THROW_HR(E_UNEXPECTED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace AppInstaller::Settings
DirectMSI = 0x2,
OpenLogsArgument = 0x4,
Pinning = 0x8,
UninstallPreviousArgument = 0x10,
Max, // This MUST always be after all experimental features

// Features listed after Max will not be shown with the features command
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerCommonCore/Public/winget/UserSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace AppInstaller::Settings
EFDirectMSI,
EFOpenLogsArgument,
EFPinning,
EFUninstallPreviousArgument,
// Telemetry
TelemetryDisable,
// Install behavior
Expand Down Expand Up @@ -148,6 +149,7 @@ namespace AppInstaller::Settings
SETTINGMAPPING_SPECIALIZATION(Setting::EFDirectMSI, bool, bool, false, ".experimentalFeatures.directMSI"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::EFOpenLogsArgument, bool, bool, false, ".experimentalFeatures.openLogsArgument"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::EFPinning, bool, bool, false, ".experimentalFeatures.pinning"sv);
SETTINGMAPPING_SPECIALIZATION(Setting::EFUninstallPreviousArgument, bool, bool, false, ".experimentalFeatures.uninstallPreviousArgument"sv);
// Telemetry
SETTINGMAPPING_SPECIALIZATION(Setting::TelemetryDisable, bool, bool, false, ".telemetry.disable"sv);
// Install behavior
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCommonCore/UserSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ namespace AppInstaller::Settings
WINGET_VALIDATE_PASS_THROUGH(EFDirectMSI)
WINGET_VALIDATE_PASS_THROUGH(EFOpenLogsArgument)
WINGET_VALIDATE_PASS_THROUGH(EFPinning)
WINGET_VALIDATE_PASS_THROUGH(EFUninstallPreviousArgument)
WINGET_VALIDATE_PASS_THROUGH(TelemetryDisable)
WINGET_VALIDATE_PASS_THROUGH(InteractivityDisable)
WINGET_VALIDATE_PASS_THROUGH(EnableSelfInitiatedMinidump)
Expand Down

0 comments on commit 5c6ba96

Please sign in to comment.