@@ -1043,7 +1043,7 @@ public virtual ConcurrentDictionary<string, PackageResult> Upgrade(ChocolateyCon
10431043 continue ;
10441044 }
10451045
1046- SetConfigFromRememberedArguments ( config , pkgInfo ) ;
1046+ config = GetPackageConfigFromRememberedArguments ( config , pkgInfo ) ;
10471047 var pathResolver = NugetCommon . GetPathResolver ( _fileSystem ) ;
10481048 var nugetProject = new FolderNuGetProject ( ApplicationParameters . PackagesLocation , pathResolver , NuGetFramework . AnyFramework ) ;
10491049
@@ -1574,12 +1574,7 @@ public virtual ConcurrentDictionary<string, PackageResult> GetOutdated(Chocolate
15741574 return outdatedPackages ;
15751575 }
15761576
1577- /// <summary>
1578- /// Sets the configuration for the package upgrade
1579- /// </summary>
1580- /// <param name="config">The configuration.</param>
1581- /// <param name="packageInfo">The package information.</param>
1582- /// <returns>The original unmodified configuration, so it can be reset after upgrade</returns>
1577+ [ Obsolete ( "This method is deprecated and will be removed in v3." ) ]
15831578 protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments ( ChocolateyConfiguration config , ChocolateyPackageInformation packageInfo )
15841579 {
15851580 if ( ! config . Features . UseRememberedArgumentsForUpgrades || string . IsNullOrWhiteSpace ( packageInfo . Arguments ) ) return config ;
@@ -1628,6 +1623,122 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco
16281623 return originalConfig ;
16291624 }
16301625
1626+ /// <summary>
1627+ /// Gets the configuration from remembered arguments
1628+ /// </summary>
1629+ /// <param name="config">The original configuration.</param>
1630+ /// <param name="packageInfo">The package information.</param>
1631+ /// <returns>The modified configuration, so it can be used</returns>
1632+ public virtual ChocolateyConfiguration GetPackageConfigFromRememberedArguments ( ChocolateyConfiguration config , ChocolateyPackageInformation packageInfo )
1633+ {
1634+ if ( ! config . Features . UseRememberedArgumentsForUpgrades || string . IsNullOrWhiteSpace ( packageInfo . Arguments ) ) return config ;
1635+
1636+ var packageArgumentsUnencrypted = packageInfo . Arguments . ContainsSafe ( " --" ) && packageInfo . Arguments . ToStringSafe ( ) . Length > 4 ? packageInfo . Arguments : NugetEncryptionUtility . DecryptString ( packageInfo . Arguments ) ;
1637+
1638+ var sensitiveArgs = true ;
1639+ if ( ! ArgumentsUtility . SensitiveArgumentsProvided ( packageArgumentsUnencrypted ) )
1640+ {
1641+ sensitiveArgs = false ;
1642+ this . Log ( ) . Debug ( ChocolateyLoggers . Verbose , "{0} - Adding remembered arguments: {1}" . FormatWith ( packageInfo . Package . Id , packageArgumentsUnencrypted . EscapeCurlyBraces ( ) ) ) ;
1643+ }
1644+
1645+ var packageArgumentsSplit = packageArgumentsUnencrypted . Split ( new [ ] { " --" } , StringSplitOptions . RemoveEmptyEntries ) ;
1646+ var packageArguments = new List < string > ( ) ;
1647+ foreach ( var packageArgument in packageArgumentsSplit . OrEmpty ( ) )
1648+ {
1649+ var packageArgumentSplit = packageArgument . Split ( new [ ] { '=' } , 2 , StringSplitOptions . RemoveEmptyEntries ) ;
1650+ var optionName = packageArgumentSplit [ 0 ] . ToStringSafe ( ) ;
1651+ var optionValue = string . Empty ;
1652+ if ( packageArgumentSplit . Length == 2 )
1653+ {
1654+ optionValue = packageArgumentSplit [ 1 ] . ToStringSafe ( ) . UnquoteSafe ( ) ;
1655+ if ( optionValue . StartsWith ( "'" ) ) optionValue . UnquoteSafe ( ) ;
1656+ }
1657+
1658+ if ( sensitiveArgs )
1659+ {
1660+ this . Log ( ) . Debug ( ChocolateyLoggers . Verbose , "{0} - Adding '{1}' to arguments. Values not shown due to detected sensitive arguments" . FormatWith ( packageInfo . Package . Id , optionName . EscapeCurlyBraces ( ) ) ) ;
1661+ }
1662+ packageArguments . Add ( "--{0}{1}" . FormatWith ( optionName , string . IsNullOrWhiteSpace ( optionValue ) ? string . Empty : "=" + optionValue ) ) ;
1663+ }
1664+
1665+ var originalConfig = config . DeepCopy ( ) ;
1666+ var rememberedOptionSet = new OptionSet ( ) ;
1667+
1668+ rememberedOptionSet
1669+ . Add ( "pre|prerelease" ,
1670+ "Prerelease - Include Prereleases? Defaults to false." ,
1671+ option => config . Prerelease = option != null )
1672+ . Add ( "i|ignoredependencies|ignore-dependencies" ,
1673+ "IgnoreDependencies - Ignore dependencies when installing package(s). Defaults to false." ,
1674+ option => config . IgnoreDependencies = option != null )
1675+ . Add ( "x86|forcex86" ,
1676+ "ForceX86 - Force x86 (32bit) installation on 64 bit systems. Defaults to false." ,
1677+ option => config . ForceX86 = option != null )
1678+ . Add ( "ia=|installargs=|install-args=|installarguments=|install-arguments=" ,
1679+ "InstallArguments - Install Arguments to pass to the native installer in the package. Defaults to unspecified." ,
1680+ option => config . InstallArguments = option . remove_surrounding_quotes ( ) )
1681+ . Add ( "o|override|overrideargs|overridearguments|override-arguments" ,
1682+ "OverrideArguments - Should install arguments be used exclusively without appending to current package passed arguments? Defaults to false." ,
1683+ option => config . OverrideArguments = option != null )
1684+ . Add ( "argsglobal|args-global|installargsglobal|install-args-global|applyargstodependencies|apply-args-to-dependencies|apply-install-arguments-to-dependencies" ,
1685+ "Apply Install Arguments To Dependencies - Should install arguments be applied to dependent packages? Defaults to false." ,
1686+ option => config . ApplyInstallArgumentsToDependencies = option != null )
1687+ . Add ( "params=|parameters=|pkgparameters=|packageparameters=|package-parameters=" ,
1688+ "PackageParameters - Parameters to pass to the package. Defaults to unspecified." ,
1689+ option => config . PackageParameters = option . remove_surrounding_quotes ( ) )
1690+ . Add ( "paramsglobal|params-global|packageparametersglobal|package-parameters-global|applyparamstodependencies|apply-params-to-dependencies|apply-package-parameters-to-dependencies" ,
1691+ "Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false." ,
1692+ option => config . ApplyPackageParametersToDependencies = option != null )
1693+ . Add ( "allowdowngrade|allow-downgrade" ,
1694+ "AllowDowngrade - Should an attempt at downgrading be allowed? Defaults to false." ,
1695+ option => config . AllowDowngrade = option != null )
1696+ . Add ( "u=|user=" ,
1697+ "User - used with authenticated feeds. Defaults to empty." ,
1698+ option => config . SourceCommand . Username = option . remove_surrounding_quotes ( ) )
1699+ . Add ( "p=|password=" ,
1700+ "Password - the user's password to the source. Defaults to empty." ,
1701+ option => config . SourceCommand . Password = option . remove_surrounding_quotes ( ) )
1702+ . Add ( "cert=" ,
1703+ "Client certificate - PFX pathname for an x509 authenticated feeds. Defaults to empty. Available in 0.9.10+." ,
1704+ option => config . SourceCommand . Certificate = option . remove_surrounding_quotes ( ) )
1705+ . Add ( "cp=|certpassword=" ,
1706+ "Certificate Password - the client certificate's password to the source. Defaults to empty. Available in 0.9.10+." ,
1707+ option => config . SourceCommand . CertificatePassword = option . remove_surrounding_quotes ( ) )
1708+ . Add ( "timeout=|execution-timeout=" ,
1709+ "CommandExecutionTimeout (in seconds) - The time to allow a command to finish before timing out. Overrides the default execution timeout in the configuration of {0} seconds. '0' for infinite starting in 0.10.4." . format_with ( config . CommandExecutionTimeoutSeconds . to_string ( ) ) ,
1710+ option =>
1711+ {
1712+ int timeout = 0 ;
1713+ var timeoutString = option . remove_surrounding_quotes ( ) ;
1714+ int . TryParse ( timeoutString , out timeout ) ;
1715+ if ( timeout > 0 || timeoutString . is_equal_to ( "0" ) )
1716+ {
1717+ config . CommandExecutionTimeoutSeconds = timeout ;
1718+ }
1719+ } )
1720+ . Add ( "c=|cache=|cachelocation=|cache-location=" ,
1721+ "CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file." ,
1722+ option => config . CacheLocation = option . remove_surrounding_quotes ( ) )
1723+ . Add ( "use-system-powershell" ,
1724+ "UseSystemPowerShell - Execute PowerShell using an external process instead of the built-in PowerShell host. Should only be used when internal host is failing. Available in 0.9.10+." ,
1725+ option => config . Features . UsePowerShellHost = option != null ) ;
1726+
1727+ rememberedOptionSet . Parse ( packageArguments ) ;
1728+
1729+ // there may be overrides from the user running upgrade
1730+ if ( ! string . IsNullOrWhiteSpace ( originalConfig . PackageParameters ) ) config . PackageParameters = originalConfig . PackageParameters ;
1731+ if ( ! string . IsNullOrWhiteSpace ( originalConfig . InstallArguments ) ) config . InstallArguments = originalConfig . InstallArguments ;
1732+ if ( ! string . IsNullOrWhiteSpace ( originalConfig . SourceCommand . Username ) ) config . SourceCommand . Username = originalConfig . SourceCommand . Username ;
1733+ if ( ! string . IsNullOrWhiteSpace ( originalConfig . SourceCommand . Password ) ) config . SourceCommand . Password = originalConfig . SourceCommand . Password ;
1734+ if ( ! string . IsNullOrWhiteSpace ( originalConfig . SourceCommand . Certificate ) ) config . SourceCommand . Certificate = originalConfig . SourceCommand . Certificate ;
1735+ if ( ! string . IsNullOrWhiteSpace ( originalConfig . SourceCommand . CertificatePassword ) ) config . SourceCommand . CertificatePassword = originalConfig . SourceCommand . CertificatePassword ;
1736+
1737+ // We can't override cache location, execution timeout, or the switches because we don't know here if they were set on the command line
1738+
1739+ return config ;
1740+ }
1741+
16311742 private bool HasMissingDependency ( PackageResult package , List < PackageResult > allLocalPackages )
16321743 {
16331744 foreach ( var dependency in package . PackageMetadata . DependencyGroups . SelectMany ( d => d . Packages ) )
0 commit comments