diff --git a/src/chocolatey.console/Properties/AssemblyInfo.cs b/src/chocolatey.console/Properties/AssemblyInfo.cs
index a959c0e14d..c092409150 100644
--- a/src/chocolatey.console/Properties/AssemblyInfo.cs
+++ b/src/chocolatey.console/Properties/AssemblyInfo.cs
@@ -14,8 +14,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2f406051-3fe2-45f4-97bf-40968b86c5a9")]
+
+// TODO: Make internals visible to Chocolatey Licensed Extension. This section is commented out as it will cause problems upstream when ilmerged.
+// We allow the officially built chocolatey.extension to always see the internals.
+//[assembly: InternalsVisibleTo("chocolatey.licensed, PublicKey=002400000480000094000000060200000024000052534131000400000100010001f55d4a9065e32d5e9854e592ffa5f7b3a707f55a17796937faf70f3ade21346dcf735216015d20304acd25d260d01202a390ac648ace0e93f6c4d6ac7cbede5b3e8f66e536d03ffa2d09594ac8de7bd147419c17e0fa1fa112b81b1b65a9e8b0ca148dc3a77e7b2917f448455ce9dbad266351710d097424692be8854704e8")]
+//[assembly: InternalsVisibleTo("chocolatey.interfaces, PublicKey=002400000480000094000000060200000024000052534131000400000100010001f55d4a9065e32d5e9854e592ffa5f7b3a707f55a17796937faf70f3ade21346dcf735216015d20304acd25d260d01202a390ac648ace0e93f6c4d6ac7cbede5b3e8f66e536d03ffa2d09594ac8de7bd147419c17e0fa1fa112b81b1b65a9e8b0ca148dc3a77e7b2917f448455ce9dbad266351710d097424692be8854704e8")]
+
+//#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
+//[assembly: InternalsVisibleTo("chocolatey.licensed, PublicKey=00240000048000009400000006020000002400005253413100040000010001003f70732af6adf3f525d983852cc7049878c498e4f8a413bd7685c9edc503ed6c6e4087354c7c1797b7c9f6d9bd3c25cdd5f97b0e810b7dd1aaba2e489f60d17d1f03c0f4db27c63146ee64ce797e4c92d591a750d8c342f5b67775710f6f9b3d9d10b4121522779a1ff72776bcce3962ca66f1755919972fb70ffb289bc082b3")]
+//[assembly: InternalsVisibleTo("chocolatey.interfaces, PublicKey=00240000048000009400000006020000002400005253413100040000010001003f70732af6adf3f525d983852cc7049878c498e4f8a413bd7685c9edc503ed6c6e4087354c7c1797b7c9f6d9bd3c25cdd5f97b0e810b7dd1aaba2e489f60d17d1f03c0f4db27c63146ee64ce797e4c92d591a750d8c342f5b67775710f6f9b3d9d10b4121522779a1ff72776bcce3962ca66f1755919972fb70ffb289bc082b3")]
+//#endif
\ No newline at end of file
diff --git a/src/chocolatey.tests.integration/TestKey.snk b/src/chocolatey.tests.integration/TestKey.snk
new file mode 100644
index 0000000000..78ce6512e5
Binary files /dev/null and b/src/chocolatey.tests.integration/TestKey.snk differ
diff --git a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj
index e1e64db302..23061ea637 100644
--- a/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj
+++ b/src/chocolatey.tests.integration/chocolatey.tests.integration.csproj
@@ -78,6 +78,12 @@
prompt
MinimumRecommendedRules.ruleset
+
+ true
+
+
+ TestKey.snk
+
..\packages\Chocolatey.NuGet.Common.3.3.0\lib\net472\Chocolatey.NuGet.Common.dll
@@ -176,6 +182,7 @@
Designer
+
diff --git a/src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs b/src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs
index 5ae1872b49..46238614e2 100644
--- a/src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs
+++ b/src/chocolatey.tests.integration/infrastructure.app/builders/ConfigurationBuilderSpecs.cs
@@ -34,6 +34,7 @@ namespace chocolatey.tests.integration.infrastructure.app.builders
using Microsoft.Win32;
using scenarios;
using FluentAssertions;
+ using static chocolatey.StringResources;
public class ConfigurationBuilderSpecs
{
@@ -116,11 +117,11 @@ public override void Context()
if (EnvironmentVariableSet)
{
- Environment.Setup(e => e.GetEnvironmentVariable(It.IsIn("http_proxy", "https_proxy"))).Returns(EnvironmentVariableProxyValue);
+ Environment.Setup(e => e.GetEnvironmentVariable(It.IsIn(EnvironmentVariables.System.HttpProxy, EnvironmentVariables.System.HttpsProxy))).Returns(EnvironmentVariableProxyValue);
}
else
{
- Environment.Setup(e => e.GetEnvironmentVariable(It.IsIn("http_proxy", "https_proxy"))).Returns(string.Empty);
+ Environment.Setup(e => e.GetEnvironmentVariable(It.IsIn(EnvironmentVariables.System.HttpProxy, EnvironmentVariables.System.HttpsProxy))).Returns(string.Empty);
}
if (ConfigSet)
@@ -192,11 +193,11 @@ public override void Context()
if (EnvironmentVariableSet)
{
- Environment.Setup(e => e.GetEnvironmentVariable("no_proxy")).Returns(EnvironmentVariableProxyValue);
+ Environment.Setup(e => e.GetEnvironmentVariable(EnvironmentVariables.System.NoProxy)).Returns(EnvironmentVariableProxyValue);
}
else
{
- Environment.Setup(e => e.GetEnvironmentVariable("no_proxy")).Returns(string.Empty);
+ Environment.Setup(e => e.GetEnvironmentVariable(EnvironmentVariables.System.NoProxy)).Returns(string.Empty);
}
if (ArgumentSet)
diff --git a/src/chocolatey.tests/TestKey.snk b/src/chocolatey.tests/TestKey.snk
new file mode 100644
index 0000000000..78ce6512e5
Binary files /dev/null and b/src/chocolatey.tests/TestKey.snk differ
diff --git a/src/chocolatey.tests/TinySpec.cs b/src/chocolatey.tests/TinySpec.cs
index f072a37cf2..bc79c6279e 100644
--- a/src/chocolatey.tests/TinySpec.cs
+++ b/src/chocolatey.tests/TinySpec.cs
@@ -24,6 +24,7 @@ namespace chocolatey.tests
using chocolatey.infrastructure.logging;
using System.IO;
using chocolatey.infrastructure.app.nuget;
+ using static chocolatey.StringResources;
// ReSharper disable InconsistentNaming
@@ -32,12 +33,12 @@ public class NUnitSetup
{
public static MockLogger MockLogger { get; set; }
- private static readonly string _installLocationVariable = Environment.GetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName);
+ private static readonly string _installLocationVariable = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall);
[OneTimeSetUp]
public virtual void BeforeEverything()
{
- Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, string.Empty);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, string.Empty);
MockLogger = new MockLogger();
Log.InitializeWith(MockLogger);
// do not log trace messages
@@ -48,7 +49,7 @@ public virtual void BeforeEverything()
[OneTimeTearDown]
public void AfterEverything()
{
- Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, _installLocationVariable);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, _installLocationVariable);
}
}
diff --git a/src/chocolatey.tests/chocolatey.tests.csproj b/src/chocolatey.tests/chocolatey.tests.csproj
index 6d9fc89608..e832ba68f0 100644
--- a/src/chocolatey.tests/chocolatey.tests.csproj
+++ b/src/chocolatey.tests/chocolatey.tests.csproj
@@ -77,6 +77,12 @@
prompt
MinimumRecommendedRules.ruleset
+
+ true
+
+
+ TestKey.snk
+
..\packages\Chocolatey.NuGet.Commands.3.3.0\lib\net472\Chocolatey.NuGet.Commands.dll
@@ -223,6 +229,7 @@
Designer
+
diff --git a/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs b/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs
index 1a17273cce..38ed3d8ef6 100644
--- a/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs
+++ b/src/chocolatey.tests/infrastructure/filesystem/DotNetFileSystemSpecs.cs
@@ -25,6 +25,7 @@ namespace chocolatey.tests.infrastructure.filesystem
using Moq;
using NUnit.Framework;
using FluentAssertions;
+ using static chocolatey.StringResources;
public class DotNetFileSystemSpecs
{
@@ -135,8 +136,8 @@ public class When_finding_paths_to_executables_with_dotNetFileSystem : DotNetFil
public override void Context()
{
base.Context();
- Environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.PathExtensions)).Returns(".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL");
- Environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.Path)).Returns(
+ Environment.Setup(x => x.GetEnvironmentVariable(EnvironmentVariables.System.PathExtensions)).Returns(".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL");
+ Environment.Setup(x => x.GetEnvironmentVariable(EnvironmentVariables.System.Path)).Returns(
@"C:\ProgramData\Chocolatey\bin{0}C:\Program Files\Microsoft\Web Platform Installer\{0}C:\Users\yes\AppData\Roaming\Boxstarter{0}C:\tools\ChocolateyPackageUpdater{0}C:\Windows\system32{0}C:\Windows{0}C:\Windows\System32\Wbem{0}C:\Windows\System32\WindowsPowerShell\v1.0\{0}"
.FormatWith(Path.PathSeparator)
);
@@ -192,8 +193,8 @@ public class When_finding_paths_to_executables_with_dotNetFileSystem_with_empty_
public override void Context()
{
base.Context();
- Environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.PathExtensions)).Returns(string.Empty);
- Environment.Setup(x => x.GetEnvironmentVariable(ApplicationParameters.Environment.Path)).Returns(
+ Environment.Setup(x => x.GetEnvironmentVariable(EnvironmentVariables.System.PathExtensions)).Returns(string.Empty);
+ Environment.Setup(x => x.GetEnvironmentVariable(EnvironmentVariables.System.Path)).Returns(
"/usr/local/bin{0}/usr/bin/{0}/bin{0}/usr/sbin{0}/sbin"
.FormatWith(Path.PathSeparator)
);
diff --git a/src/chocolatey/GetChocolatey.cs b/src/chocolatey/GetChocolatey.cs
index c4f2814062..da3ab6edb7 100644
--- a/src/chocolatey/GetChocolatey.cs
+++ b/src/chocolatey/GetChocolatey.cs
@@ -43,6 +43,7 @@ namespace chocolatey
using IFileSystem = infrastructure.filesystem.IFileSystem;
using ILog = infrastructure.logging.ILog;
using System.Linq;
+ using static chocolatey.StringResources;
///
/// Entry point for API
@@ -490,19 +491,19 @@ private void EnsureEnvironment()
string chocolateyInstall = string.Empty;
#if !DEBUG
- chocolateyInstall = Environment.GetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, EnvironmentVariableTarget.Machine);
+ chocolateyInstall = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, EnvironmentVariableTarget.Machine);
if (string.IsNullOrWhiteSpace(chocolateyInstall))
{
- chocolateyInstall = Environment.GetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, EnvironmentVariableTarget.User);
+ chocolateyInstall = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, EnvironmentVariableTarget.User);
}
#endif
if (string.IsNullOrWhiteSpace(chocolateyInstall))
{
- chocolateyInstall = Environment.GetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName);
+ chocolateyInstall = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall);
}
- Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, chocolateyInstall);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, chocolateyInstall);
}
private void ExtractResources()
diff --git a/src/chocolatey/Properties/AssemblyInfo.cs b/src/chocolatey/Properties/AssemblyInfo.cs
index b580b39064..ac35fa927f 100644
--- a/src/chocolatey/Properties/AssemblyInfo.cs
+++ b/src/chocolatey/Properties/AssemblyInfo.cs
@@ -14,8 +14,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bd59231e-97d1-4fc0-a975-80c3fed498b7")]
+
+[assembly: InternalsVisibleTo("chocolatey.tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010059b0331d79eca3ed9087221c6252d3383087f35fa7c54f2ce6223c40905ed2c44e2de8576ae81bcd2f0471961bdbc083a8457d564912d3d3263477756337565ac8ce8dfe912b15cd762ac9e5c4641d82768d9da09265cde5b414ed08e654a3ebf48b9c70b34ebeab0adcb145c439289b5fa8790ef218a6d8123c8d02251c33cf")]
+
+[assembly: InternalsVisibleTo("chocolatey.tests.integration, PublicKey=002400000480000094000000060200000024000052534131000400000100010059b0331d79eca3ed9087221c6252d3383087f35fa7c54f2ce6223c40905ed2c44e2de8576ae81bcd2f0471961bdbc083a8457d564912d3d3263477756337565ac8ce8dfe912b15cd762ac9e5c4641d82768d9da09265cde5b414ed08e654a3ebf48b9c70b34ebeab0adcb145c439289b5fa8790ef218a6d8123c8d02251c33cf")]
+
+// TODO: Make internals visible to Chocolatey Licensed Extension. This section is commented out as it will cause problems upstream when ilmerged.
+// We allow the officially built chocolatey.extension to always see the internals.
+//[assembly: InternalsVisibleTo("chocolatey.licensed, PublicKey=002400000480000094000000060200000024000052534131000400000100010001f55d4a9065e32d5e9854e592ffa5f7b3a707f55a17796937faf70f3ade21346dcf735216015d20304acd25d260d01202a390ac648ace0e93f6c4d6ac7cbede5b3e8f66e536d03ffa2d09594ac8de7bd147419c17e0fa1fa112b81b1b65a9e8b0ca148dc3a77e7b2917f448455ce9dbad266351710d097424692be8854704e8")]
+//[assembly: InternalsVisibleTo("chocolatey.interfaces, PublicKey=002400000480000094000000060200000024000052534131000400000100010001f55d4a9065e32d5e9854e592ffa5f7b3a707f55a17796937faf70f3ade21346dcf735216015d20304acd25d260d01202a390ac648ace0e93f6c4d6ac7cbede5b3e8f66e536d03ffa2d09594ac8de7bd147419c17e0fa1fa112b81b1b65a9e8b0ca148dc3a77e7b2917f448455ce9dbad266351710d097424692be8854704e8")]
+
+//#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
+//[assembly: InternalsVisibleTo("chocolatey.licensed, PublicKey=00240000048000009400000006020000002400005253413100040000010001003f70732af6adf3f525d983852cc7049878c498e4f8a413bd7685c9edc503ed6c6e4087354c7c1797b7c9f6d9bd3c25cdd5f97b0e810b7dd1aaba2e489f60d17d1f03c0f4db27c63146ee64ce797e4c92d591a750d8c342f5b67775710f6f9b3d9d10b4121522779a1ff72776bcce3962ca66f1755919972fb70ffb289bc082b3")]
+//[assembly: InternalsVisibleTo("chocolatey.interfaces, PublicKey=00240000048000009400000006020000002400005253413100040000010001003f70732af6adf3f525d983852cc7049878c498e4f8a413bd7685c9edc503ed6c6e4087354c7c1797b7c9f6d9bd3c25cdd5f97b0e810b7dd1aaba2e489f60d17d1f03c0f4db27c63146ee64ce797e4c92d591a750d8c342f5b67775710f6f9b3d9d10b4121522779a1ff72776bcce3962ca66f1755919972fb70ffb289bc082b3")]
+//#endif
\ No newline at end of file
diff --git a/src/chocolatey/StringResources.cs b/src/chocolatey/StringResources.cs
index 4bbf0f6c99..7ee7bf130a 100644
--- a/src/chocolatey/StringResources.cs
+++ b/src/chocolatey/StringResources.cs
@@ -20,41 +20,585 @@ namespace chocolatey
public static class StringResources
{
///
- /// Resources for the names of available environment variables
- /// that will be created or used as part of executing
- /// Chocolatey CLI.
+ /// Resources for the names of available environment variables that will be created or used
+ /// as part of executing Chocolatey CLI.
///
///
- /// DEV NOTICE: Mark anything that is not meant for public consumption as
- /// internal constants and not browsable, even if used in other projects.
+ /// DEV NOTICE: Mark anything that is not meant for public consumption as internal constants
+ /// and not browsable, even if used in other projects.
///
public static class EnvironmentVariables
{
///
- /// The version of the package that is being handled as it is defined in the embedded
- /// nuspec file.
+ /// Environment variables that will be set before running any PowerShell scripts, or by
+ /// one PowerShell helpers that a user can use.
///
- ///
- /// Will be sets during package installs, upgrades and uninstalls.
- /// Environment variable is only for internal uses.
- ///
- ///
- [EditorBrowsable(EditorBrowsableState.Never)]
- [Browsable(false)]
- internal const string ChocolateyPackageNuspecVersion = "chocolateyPackageNuspecVersion";
+ public static class Package
+ {
+ ///
+ /// Whether debug output should be enabled when running PowerShell scripts.
+ ///
+ /// In most scenarios this environment variable will always be true
+ public const string ChocolateyEnvironmentDebug = nameof(ChocolateyEnvironmentDebug);
+
+ ///
+ /// Whether verbose output should be enabled when running PowerShell scripts.
+ ///
+ /// In most scenarios this environment variable will always be true
+ public const string ChocolateyEnvironmentVerbose = nameof(ChocolateyEnvironmentVerbose);
+
+ ///
+ /// Whether we should detect if a reboot is required or not, and exit if a reboot is required.
+ ///
+ public const string ChocolateyExitOnRebootDetected = "ChocolateyExitOnRebootDetected";
+
+ ///
+ /// Whether the user has specified that the package should be forced to install
+ /// again, even if it is installed.
+ ///
+ public const string ChocolateyForce = "ChocolateyForce";
+
+ ///
+ /// Whether the user has requested to install 32bit version of binaries or not.
+ ///
+ public const string ChocolateyForceX86 = "chocolateyForceX86";
+
+ ///
+ /// The type of the license that the user currently has installed on their system
+ /// (business, professional, msp, architect, etc).
+ ///
+ /// Business Edition Only Variable
+ public const string ChocolateyLicenseType = nameof(ChocolateyLicenseType);
+
+ ///
+ /// The location that the package was found to be installed to. When found will be
+ /// outputted by Chocolatey CLI at the end of its execution.
+ ///
+ public const string ChocolateyPackageInstallLocation = "ChocolateyPackageInstallLocation";
+
+ ///
+ /// The name or identifier of the package that is being handled.
+ ///
+ ///
+ public const string ChocolateyPackageName = "chocolateyPackageName";
+
+ ///
+ /// The package parameters that was passed in by the user during install, upgrade or uninstalls.
+ ///
+ ///
+ public const string ChocolateyPackageParameters = "chocolateyPackageParameters";
+
+ ///
+ /// The title of the package that is being handled.
+ ///
+ ///
+ public const string ChocolateyPackageTitle = "chocolateyPackageTitle";
+
+ ///
+ /// The normalized version of the package that is being handled.
+ ///
+ ///
+ public const string ChocolateyPackageVersion = "chocolateyPackageVersion";
+
+ ///
+ /// Whether the user has specified that we should use the built-in PowerShell Host
+ /// or the Host that is available on the system.
+ ///
+ public const string ChocolateyPowerShellHost = nameof(ChocolateyPowerShellHost);
+
+ ///
+ /// The full semantic version of the currently running Chocolatey CLI product.
+ ///
+ ///
+ /// This environment variable is experimental, and is not recommended for public consumption.
+ ///
+ public const string ChocolateyProductVersion = "CHOCOLATEY_VERSION_PRODUCT";
+
+ ///
+ /// How long before a web request will timeout.
+ ///
+ public const string ChocolateyRequestTimeout = "chocolateyRequestTimeout";
+
+ ///
+ /// How long to wait for a download to complete.
+ ///
+ public const string ChocolateyResponseTimeout = "chocolateyResponseTimeout";
+
+ ///
+ /// The 4-part assembly version number of Chocolatey CLI that the user is currently using.
+ ///
+ public const string ChocolateyVersion = "CHOCOLATEY_VERSION";
+
+ ///
+ /// Whether the user in an administrator. Even if we are not running in an elevated state.
+ ///
+ /// This environment variable is experimental.
+ public const string IsAdmin = "IS_ADMIN";
+
+ ///
+ /// Whether the current process is running in an elevated state.
+ ///
+ public const string IsProcessElevated = "IS_PROCESSELEVATED";
+
+ ///
+ /// Whether the running operating system is a 64bit system.
+ ///
+ /// This environment variable is experimental.
+ public const string OsIs64Bit = "OS_IS64BIT";
+
+ ///
+ /// The name of the running operating system as it is being reported.
+ ///
+ public const string OsName = "OS_NAME";
+
+ ///
+ /// The platform that Chocolatey CLI is currently running on. This will typically
+ /// be Windows, macOS or Linux.
+ ///
+ public const string OsPlatform = "OS_PLATFORM";
+
+ ///
+ /// The version of the running operating system.
+ ///
+ public const string OsVersion = "OS_VERSION";
+
+ ///
+ /// The location where temporary files should be stored during PowerShell execution.
+ ///
+ ///
+ ///
+ /// When PowerShell scripts are executed, this variable will be set to the
+ /// configured .
+ ///
+ ///
+ ///
+ public const string Tmp = "TMP";
+
+ ///
+ /// The checksum of the cached file that is stored on the private CDN.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string CacheChecksumFormat = "CacheChecksum_{0}";
+
+ ///
+ /// The checksum type of the cached file that is stored on the private CDN.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string CacheChecksumTypeFormat = "CacheChecksumType_{0}";
+
+ ///
+ /// The name of the cached file that is stored on the private CDN.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string CacheFileFormat = "CacheFile_{0}";
+
+ ///
+ /// Whether the user has specified that packages are allowed to not validate
+ /// checksums for non-https sources.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyAllowEmptyChecksums = nameof(ChocolateyAllowEmptyChecksums);
+
+ ///
+ /// Whether the user has specified that packages are allowed to not validate
+ /// checksums for https sources.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyAllowEmptyChecksumsSecure = nameof(ChocolateyAllowEmptyChecksumsSecure);
+
+ ///
+ /// Whether the argument `--download-checksum` was passed by the user.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyChecksum32 = "chocolateyChecksum32";
+
+ ///
+ /// Whether the argument `--download-checksum-x64` was passed by the user.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyChecksum64 = "chocolateyChecksum64";
+
+ ///
+ /// Whether the argument `--download-checksum-type` was passed by the user.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyChecksumType32 = "chocolateyChecksumType32";
+
+ ///
+ /// Whether the argument `--download-checksum-type-x64` was passed by the user.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyChecksumType64 = "chocolateyChecksumType64";
+
+ ///
+ /// The exit code that the installation, upgrade or uninstall ended up reporting.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyExitCode = "ChocolateyExitCode";
+
+ ///
+ /// Whether the user has specified that checksums should be ignored.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyIgnoreChecksums = "ChocolateyIgnoreChecksums";
+
+ ///
+ /// The arguments that the user has passed to the commandline that should be added
+ /// when launching an installer.
+ ///
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyInstallArguments = "chocolateyInstallArguments";
+
+ ///
+ /// The identified type of the installer the package uses during installation.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyInstallerType = nameof(ChocolateyInstallerType);
+
+ ///
+ /// A true or false value of whether custom installer arguments was
+ /// passed in by the user or not.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyInstallOverride = "chocolateyInstallOverride";
+
+ ///
+ /// The version of the package that is being handled as it is defined in the
+ /// embedded nuspec file.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyNuspecVersion = "chocolateyPackageNuspecVersion";
+
+ ///
+ /// The location of the package content that is being handled.
+ ///
+ /// Normally set to `%ChocolateyInstall\lib\PACKAGE_NAME`.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyPackageFolder = "chocolateyPackageFolder";
+
+ ///
+ /// The full pre-release label of the package that is being handled.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyPackageVersionPrerelease = "chocolateyPackageVersionPrerelease";
+
+ ///
+ /// The domains that should bypass any proxies that is configured on the system.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyProxyBypassList = "chocolateyProxyBypassList";
+
+ ///
+ /// Whether local requests should bypass any configured proxy.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyProxyBypassOnLocal = "chocolateyProxyBypassOnLocal";
+
+ ///
+ /// The URL to the proxy that should be used when downloading binary files and other
+ /// web requests.
+ ///
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyProxyLocation = "chocolateyProxyLocation";
+
+ ///
+ /// The password of the user that is configured to be used for the proxy.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyProxyPassword = "chocolateyProxyPassword";
+
+ ///
+ /// The username of the user that is configured to be used for the proxy.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyProxyUser = "chocolateyProxyUser";
+
+ ///
+ /// Whether the package being handled has download cache available in the private CDN.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string DownloadCacheAvailable = "DownloadCacheAvailable";
+
+ ///
+ /// The arguments that the user has passed to the commandline that should be added
+ /// when launching an installer.
+ ///
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string InstallArguments = "installArguments";
+
+ ///
+ /// The arguments that the user has passed to the commandline that should be added
+ /// when launching an installer.
+ ///
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string InstallerArguments = "installerArguments";
+
+ ///
+ /// Whether the current execution is running in a remote context.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string IsRemote = "IS_REMOTE";
+
+ ///
+ /// Whether the current execution is running in the context of a remote desktop.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string IsRemoteDesktop = "IS_REMOTEDESKTOP";
+
+ ///
+ /// Whether the user account we are running under is a system account or not.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string IsUserSystemAccount = "IS_SYSTEM";
+
+ ///
+ /// The location of the package content that is being handled.
+ ///
+ /// Normally set to `%ChocolateyInstall\lib\PACKAGE_NAME`.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string PackageFolder = "packageFolder";
+
+ ///
+ /// The name or identifier of the package that is being handled.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string PackageName = "packageName";
+
+ ///
+ /// The version of the package that is being handled as it is defined in the
+ /// embedded nuspec file.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string PackageNuspecVersion = "packageNuspecVersion";
+
+ ///
+ /// The package parameters that was passed in by the user during install, upgrade or uninstalls.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string PackageParameters = "packageParameters";
+
+ ///
+ /// The title of the package that is being handled.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string PackageTitle = "PackageTitle";
+
+ ///
+ /// The normalized version of the package that is being handled.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string PackageVersion = "packageVersion";
+
+ ///
+ /// Whether we are running in a 64bit process context.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ProcessIs64Bit = "PROCESS_IS64BIT";
+
+ ///
+ /// The name of the domain the user we are running under is registered to.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string UserDomainName = "USER_DOMAIN";
+
+ ///
+ /// The username of the user that Chocolatey CLI is running under.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string Username = "USER_NAME";
+ }
///
- /// The version of the package that is being handled as it is defined in the embedded
- /// nuspec file.
+ /// Environment variables that are part of the Operating System itself. Either by
+ /// default, or read when user has specified the environment variable manually.
///
///
- /// Will be sets during package installs, upgrades and uninstalls.
- /// Environment variable is only for internal uses.
+ /// These environment variables will also be available in packages. They may have a
+ /// different value than the system environment variable in that case.
///
- ///
- [EditorBrowsable(EditorBrowsableState.Never)]
- [Browsable(false)]
- internal const string PackageNuspecVersion = "packageNuspecVersion";
+ public static class System
+ {
+ ///
+ /// The location of where Chocolatey CLI is expected to be installed to.
+ ///
+ public const string ChocolateyInstall = nameof(ChocolateyInstall);
+
+ ///
+ /// The location where temporary files should be stored.
+ ///
+ ///
+ ///
+ /// When PowerShell scripts are executed, this variable will be set to the
+ /// configured .
+ ///
+ ///
+ ///
+ public const string Temp = "TEMP";
+
+ ///
+ /// Where tools should end up being installed to.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ChocolateyToolsLocation = nameof(ChocolateyToolsLocation);
+
+ ///
+ /// The name of the environment variable that should be used when looking up
+ /// binaries, or when adding binaries to PATH.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string Path = nameof(Path);
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string PathExtensions = "PATHEXT";
+
+ ///
+ /// Where tools should end up being installed to.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string ProcessorArchitecture = "PROCESSOR_ARCHITECTURE";
+
+ ///
+ /// The paths where PowerShell modules are expected to be located.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string PSModulePath = "PSModulePath";
+
+ ///
+ /// The username of the user that Chocolatey CLI is running under.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal const string Username = "USERNAME";
+
+ ///
+ /// The root of the chocolatey bin (legacy name for ).
+ ///
+ ///
+ /// This environment variable is only used by the alternative sources to determine
+ /// the executable location.
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal static string ChocolateyBinRoot = "ChocolateyBinRoot";
+
+ ///
+ /// One of the possible system environment variables available to set a system proxy.
+ ///
+ ///
+ /// This variable will also be set as part of running PowerShell scripts when a
+ /// proxy has been configured.
+ ///
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal static string HttpProxy = "http_proxy";
+
+ ///
+ /// One of the possible system environment variables available to set a system proxy.
+ ///
+ ///
+ /// This variable will also be set as part of running PowerShell scripts when a
+ /// proxy has been configured.
+ ///
+ ///
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal static string HttpsProxy = "https_proxy";
+
+ ///
+ /// The system defined environment variable with the same name.
+ ///
+ ///
+ /// This variable will also be set as part of running PowerShell scripts by using
+ /// the system no_proxy variable, or it will be set to the .
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal static string NoProxy = "no_proxy";
+
+ ///
+ /// The name of the session we are running underneath.
+ ///
+ ///
+ /// This will commonly be console for normal users through the CLI, and
+ /// rdp-something for remote users.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal static string SessionName = "SESSIONNAME";
+
+ ///
+ /// A common environment variable defined by Windows OS on what drive is being used
+ /// for the windows installation.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Browsable(false)]
+ internal static string SystemDrive = "SystemDrive";
+ }
}
}
}
\ No newline at end of file
diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs
index 122e6ddfa9..8602b5e208 100644
--- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs
+++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs
@@ -23,6 +23,7 @@ namespace chocolatey.infrastructure.app
using Environment = System.Environment;
using chocolatey.infrastructure.platforms;
using chocolatey.infrastructure.information;
+ using static chocolatey.StringResources;
///
/// Application constants and settings for the application
@@ -30,12 +31,13 @@ namespace chocolatey.infrastructure.app
public static class ApplicationParameters
{
private static readonly IFileSystem _fileSystem = new DotNetFileSystem();
- public static readonly string ChocolateyInstallEnvironmentVariableName = "ChocolateyInstall";
+ [Obsolete("Use StringResources.EnvironmentVariables.System.ChocolateyInstall instead", error: true)]
+ public static readonly string ChocolateyInstallEnvironmentVariableName = EnvironmentVariables.System.ChocolateyInstall;
public static readonly string Name = "Chocolatey";
#if FORCE_CHOCOLATEY_OFFICIAL_KEY
// always look at the official location of the machine installation
- public static readonly string InstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.GetDirectoryName(_fileSystem.GetCurrentAssemblyPath());
+ public static readonly string InstallLocation = System.Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall) ?? _fileSystem.GetDirectoryName(_fileSystem.GetCurrentAssemblyPath());
public static readonly string LicensedAssemblyLocation = _fileSystem.CombinePaths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll");
#elif DEBUG
// Install location is choco.exe or chocolatey.dll
@@ -51,8 +53,8 @@ public static class ApplicationParameters
public static readonly string InstallLocation = _fileSystem.FileExists(_fileSystem.CombinePaths(_fileSystem.GetDirectoryName(_assemblyForLocation.CodeBase.Replace(Platform.GetPlatform() == PlatformType.Windows ? "file:///" : "file://", string.Empty)), "chocolatey.dll")) ||
_fileSystem.FileExists(_fileSystem.CombinePaths(_fileSystem.GetDirectoryName(_assemblyForLocation.CodeBase.Replace(Platform.GetPlatform() == PlatformType.Windows ? "file:///" : "file://", string.Empty)), "choco.exe")) ?
_fileSystem.GetDirectoryName(_assemblyForLocation.CodeBase.Replace(Platform.GetPlatform() == PlatformType.Windows ? "file:///" : "file://", string.Empty)) :
- !string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName)) ?
- System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) :
+ !string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall)) ?
+ System.Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall) :
@"C:\ProgramData\Chocolatey"
;
@@ -124,26 +126,57 @@ private static string GetHttpCacheLocation()
public static class Environment
{
- public static readonly string Path = "Path";
- public static readonly string PathExtensions = "PATHEXT";
- public static readonly string PsModulePath = "PSModulePath";
- public static readonly string Temp = "TEMP";
public static readonly string SystemUserName = "SYSTEM";
- public static readonly string Username = "USERNAME";
- public static readonly string ProcessorArchitecture = "PROCESSOR_ARCHITECTURE";
public const string Arm64ProcessorArchitecture = "ARM64";
public static readonly string EnvironmentSeparator = ";";
- public static readonly string ChocolateyToolsLocation = "ChocolateyToolsLocation";
- public static readonly string ChocolateyPackageInstallLocation = "ChocolateyPackageInstallLocation";
- public static readonly string ChocolateyPackageInstallerType = "ChocolateyInstallerType";
- public static readonly string ChocolateyPackageExitCode = "ChocolateyExitCode";
- public static readonly string ChocolateyIgnoreChecksums = "ChocolateyIgnoreChecksums";
- public static readonly string ChocolateyAllowEmptyChecksums = "ChocolateyAllowEmptyChecksums";
- public static readonly string ChocolateyAllowEmptyChecksumsSecure = "ChocolateyAllowEmptyChecksumsSecure";
- public static readonly string ChocolateyPowerShellHost = "ChocolateyPowerShellHost";
- public static readonly string ChocolateyForce = "ChocolateyForce";
- public static readonly string ChocolateyExitOnRebootDetected = "ChocolateyExitOnRebootDetected";
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.System.Path instead", error: true)]
+ public static readonly string Path = EnvironmentVariables.System.Path;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.System.Path instead", error: true)]
+ public static readonly string PathExtensions = EnvironmentVariables.System.PathExtensions;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.System.Path instead", error: true)]
+ public static readonly string PsModulePath = EnvironmentVariables.System.PSModulePath;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.System.Temp instead", error: true)]
+ public static readonly string Temp = EnvironmentVariables.System.Temp;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.System.Username instead", error: true)]
+ public static readonly string Username = EnvironmentVariables.System.Username;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.System.ProcessorArchitecture instead", error: true)]
+ public static readonly string ProcessorArchitecture = EnvironmentVariables.System.ProcessorArchitecture;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.System.ChocolateyToolsLocation instead", error: true)]
+ public static readonly string ChocolateyToolsLocation = EnvironmentVariables.System.ChocolateyToolsLocation;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.Package.ChocolateyPackageInstallLocation instead", error: true)]
+ public static readonly string ChocolateyPackageInstallLocation = EnvironmentVariables.Package.ChocolateyPackageInstallLocation;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.Package.ChocolateyInstallerType instead", error: true)]
+ public static readonly string ChocolateyPackageInstallerType = EnvironmentVariables.Package.ChocolateyInstallerType;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.Package.ChocolateyExitCode instead", error: true)]
+ public static readonly string ChocolateyPackageExitCode = EnvironmentVariables.Package.ChocolateyExitCode;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.Package.ChocolateyIgnoreChecksums instead", error: true)]
+ public static readonly string ChocolateyIgnoreChecksums = EnvironmentVariables.Package.ChocolateyIgnoreChecksums;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.Package.ChocolateyAllowEmptyChecksums instead", error: true)]
+ public static readonly string ChocolateyAllowEmptyChecksums = EnvironmentVariables.Package.ChocolateyAllowEmptyChecksums;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.Package.ChocolateyAllowEmptyChecksumsSecure instead", error: true)]
+ public static readonly string ChocolateyAllowEmptyChecksumsSecure = EnvironmentVariables.Package.ChocolateyAllowEmptyChecksumsSecure;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.Package.ChocolateyPowerShellHost instead", error: true)]
+ public static readonly string ChocolateyPowerShellHost = EnvironmentVariables.Package.ChocolateyPowerShellHost;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.Package.ChocolateyForce instead", error: true)]
+ public static readonly string ChocolateyForce = EnvironmentVariables.Package.ChocolateyForce;
+
+ [Obsolete("Use alternative variable in StringResources.EnvironmentVariables.Package.ChocolateyExitOnRebootDetected instead", error: true)]
+ public static readonly string ChocolateyExitOnRebootDetected = EnvironmentVariables.Package.ChocolateyExitOnRebootDetected;
}
///
diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
index a82d647c48..7fbb078414 100644
--- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
+++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
@@ -37,6 +37,7 @@ namespace chocolatey.infrastructure.app.builders
using platforms;
using services;
using tolerance;
+ using static chocolatey.StringResources;
using Assembly = adapters.Assembly;
using Container = SimpleInjector.Container;
using Environment = adapters.Environment;
@@ -503,19 +504,19 @@ private static void SetEnvironmentOptions(ChocolateyConfiguration config)
config.Information.IsUserRemote = ProcessInformation.UserIsRemote();
config.Information.IsProcessElevated = ProcessInformation.IsElevated();
- if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("https_proxy")) && string.IsNullOrWhiteSpace(config.Proxy.Location))
+ if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(EnvironmentVariables.System.HttpsProxy)) && string.IsNullOrWhiteSpace(config.Proxy.Location))
{
- config.Proxy.Location = Environment.GetEnvironmentVariable("https_proxy");
+ config.Proxy.Location = Environment.GetEnvironmentVariable(EnvironmentVariables.System.HttpsProxy);
}
- if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("http_proxy")) && string.IsNullOrWhiteSpace(config.Proxy.Location))
+ if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(EnvironmentVariables.System.HttpProxy)) && string.IsNullOrWhiteSpace(config.Proxy.Location))
{
- config.Proxy.Location = Environment.GetEnvironmentVariable("http_proxy");
+ config.Proxy.Location = Environment.GetEnvironmentVariable(EnvironmentVariables.System.HttpProxy);
}
- if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("no_proxy")) && string.IsNullOrWhiteSpace(config.Proxy.BypassList))
+ if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(EnvironmentVariables.System.NoProxy)) && string.IsNullOrWhiteSpace(config.Proxy.BypassList))
{
- config.Proxy.BypassList = Environment.GetEnvironmentVariable("no_proxy");
+ config.Proxy.BypassList = Environment.GetEnvironmentVariable(EnvironmentVariables.System.NoProxy);
}
}
diff --git a/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs b/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs
index 6f1decbde3..9c60347733 100644
--- a/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs
+++ b/src/chocolatey/infrastructure.app/configuration/EnvironmentSettings.cs
@@ -27,6 +27,7 @@ namespace chocolatey.infrastructure.app.configuration
using adapters;
using logging;
using nuget;
+ using static chocolatey.StringResources;
using Environment = adapters.Environment;
public static class EnvironmentSettings
@@ -47,56 +48,56 @@ private static IEnvironment Environment
public static void ResetEnvironmentVariables(ChocolateyConfiguration config)
{
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation, null);
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallerType, null);
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageExitCode, null);
-
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyIgnoreChecksums, null);
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyAllowEmptyChecksums, null);
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyAllowEmptyChecksumsSecure, null);
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPowerShellHost, null);
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyForce, null);
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyExitOnRebootDetected, null);
-
- Environment.SetEnvironmentVariable("chocolateyProxyLocation", null);
- Environment.SetEnvironmentVariable("chocolateyProxyBypassList", null);
- Environment.SetEnvironmentVariable("chocolateyProxyBypassOnLocal", null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyInstallerType, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyExitCode, null);
+
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyIgnoreChecksums, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyAllowEmptyChecksums, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyAllowEmptyChecksumsSecure, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPowerShellHost, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyForce, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyExitOnRebootDetected, null);
+
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyProxyLocation, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyProxyBypassList, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyProxyBypassOnLocal, null);
}
public static void SetEnvironmentVariables(ChocolateyConfiguration config)
{
ResetEnvironmentVariables(config);
- Environment.SetEnvironmentVariable(ApplicationParameters.ChocolateyInstallEnvironmentVariableName, ApplicationParameters.InstallLocation);
- Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION", config.Information.ChocolateyVersion);
- Environment.SetEnvironmentVariable("CHOCOLATEY_VERSION_PRODUCT", config.Information.ChocolateyProductVersion);
- Environment.SetEnvironmentVariable("OS_PLATFORM", config.Information.PlatformType.DescriptionOrValue());
- Environment.SetEnvironmentVariable("OS_VERSION", config.Information.PlatformVersion.ToStringSafe());
- Environment.SetEnvironmentVariable("OS_NAME", config.Information.PlatformName.ToStringSafe());
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.ChocolateyInstall, ApplicationParameters.InstallLocation);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyVersion, config.Information.ChocolateyVersion);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyProductVersion, config.Information.ChocolateyProductVersion);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.OsPlatform, config.Information.PlatformType.DescriptionOrValue());
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.OsVersion, config.Information.PlatformVersion.ToStringSafe());
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.OsName, config.Information.PlatformName.ToStringSafe());
// experimental until we know if this value returns correctly based on the OS and not the current process.
- Environment.SetEnvironmentVariable("OS_IS64BIT", config.Information.Is64BitOperatingSystem ? "true" : "false");
- Environment.SetEnvironmentVariable("PROCESS_IS64BIT", config.Information.Is64BitProcess ? "true" : "false");
- Environment.SetEnvironmentVariable("USER_NAME", config.Information.UserName);
- Environment.SetEnvironmentVariable("USER_DOMAIN", config.Information.UserDomainName);
- Environment.SetEnvironmentVariable("IS_ADMIN", config.Information.IsUserAdministrator ? "true" : "false");
- Environment.SetEnvironmentVariable("IS_SYSTEM", config.Information.IsUserSystemAccount ? "true" : "false");
- Environment.SetEnvironmentVariable("IS_REMOTEDESKTOP", config.Information.IsUserRemoteDesktop ? "true" : "false");
- Environment.SetEnvironmentVariable("IS_REMOTE", config.Information.IsUserRemote ? "true" : "false");
- Environment.SetEnvironmentVariable("IS_PROCESSELEVATED", config.Information.IsProcessElevated ? "true" : "false");
- Environment.SetEnvironmentVariable("TEMP", config.CacheLocation);
- Environment.SetEnvironmentVariable("TMP", config.CacheLocation);
-
- if (config.Debug) Environment.SetEnvironmentVariable("ChocolateyEnvironmentDebug", "true");
- if (config.Verbose) Environment.SetEnvironmentVariable("ChocolateyEnvironmentVerbose", "true");
- if (!config.Features.ChecksumFiles) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyIgnoreChecksums, "true");
- if (config.Features.AllowEmptyChecksums) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyAllowEmptyChecksums, "true");
- if (config.Features.AllowEmptyChecksumsSecure) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyAllowEmptyChecksumsSecure, "true");
-
- Environment.SetEnvironmentVariable("chocolateyRequestTimeout", config.WebRequestTimeoutSeconds.ToStringSafe() + "000");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.OsIs64Bit, config.Information.Is64BitOperatingSystem ? "true" : "false");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ProcessIs64Bit, config.Information.Is64BitProcess ? "true" : "false");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.Username, config.Information.UserName);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.UserDomainName, config.Information.UserDomainName);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.IsAdmin, config.Information.IsUserAdministrator ? "true" : "false");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.IsUserSystemAccount, config.Information.IsUserSystemAccount ? "true" : "false");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.IsRemoteDesktop, config.Information.IsUserRemoteDesktop ? "true" : "false");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.IsRemote, config.Information.IsUserRemote ? "true" : "false");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.IsProcessElevated, config.Information.IsProcessElevated ? "true" : "false");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.Temp, config.CacheLocation);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.Tmp, config.CacheLocation);
+
+ if (config.Debug) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyEnvironmentDebug, "true");
+ if (config.Verbose) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyEnvironmentVerbose, "true");
+ if (!config.Features.ChecksumFiles) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyIgnoreChecksums, "true");
+ if (config.Features.AllowEmptyChecksums) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyAllowEmptyChecksums, "true");
+ if (config.Features.AllowEmptyChecksumsSecure) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPowerShellHost, "true");
+
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyRequestTimeout, config.WebRequestTimeoutSeconds.ToStringSafe() + "000");
if (config.CommandExecutionTimeoutSeconds != 0)
{
- Environment.SetEnvironmentVariable("chocolateyResponseTimeout", config.CommandExecutionTimeoutSeconds.ToStringSafe() + "000");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyResponseTimeout, config.CommandExecutionTimeoutSeconds.ToStringSafe() + "000");
}
if (!string.IsNullOrWhiteSpace(config.Proxy.Location))
@@ -108,33 +109,33 @@ public static void SetEnvironmentVariables(ChocolateyConfiguration config)
{
proxyCreds = "{0}:{1}@".FormatWith(config.Proxy.User, NugetEncryptionUtility.DecryptString(config.Proxy.EncryptedPassword));
- Environment.SetEnvironmentVariable("chocolateyProxyUser", config.Proxy.User);
- Environment.SetEnvironmentVariable("chocolateyProxyPassword", NugetEncryptionUtility.DecryptString(config.Proxy.EncryptedPassword));
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyProxyUser, config.Proxy.User);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyProxyPassword, NugetEncryptionUtility.DecryptString(config.Proxy.EncryptedPassword));
}
- Environment.SetEnvironmentVariable("http_proxy", "{0}{1}".FormatWith(proxyCreds, config.Proxy.Location));
- Environment.SetEnvironmentVariable("https_proxy", "{0}{1}".FormatWith(proxyCreds, config.Proxy.Location));
- Environment.SetEnvironmentVariable("chocolateyProxyLocation", config.Proxy.Location);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.HttpProxy, "{0}{1}".FormatWith(proxyCreds, config.Proxy.Location));
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.HttpsProxy, "{0}{1}".FormatWith(proxyCreds, config.Proxy.Location));
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyProxyLocation, config.Proxy.Location);
if (!string.IsNullOrWhiteSpace(config.Proxy.BypassList))
{
- Environment.SetEnvironmentVariable("chocolateyProxyBypassList", config.Proxy.BypassList);
- Environment.SetEnvironmentVariable("no_proxy", config.Proxy.BypassList);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyProxyBypassList, config.Proxy.BypassList);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.NoProxy , config.Proxy.BypassList);
}
- if (config.Proxy.BypassOnLocal) Environment.SetEnvironmentVariable("chocolateyProxyBypassOnLocal", "true");
+ if (config.Proxy.BypassOnLocal) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyProxyBypassOnLocal, "true");
}
- if (config.Features.UsePowerShellHost) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPowerShellHost, "true");
- if (config.Force) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyForce, "true");
- if (config.Features.ExitOnRebootDetected) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyExitOnRebootDetected, "true");
+ if (config.Features.UsePowerShellHost) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPowerShellHost, "true");
+ if (config.Force) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyForce, "true");
+ if (config.Features.ExitOnRebootDetected) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyExitOnRebootDetected, "true");
SetLicensedEnvironment(config);
}
private static void SetLicensedEnvironment(ChocolateyConfiguration config)
{
- Environment.SetEnvironmentVariable("ChocolateyLicenseType", config.Information.LicenseType);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyLicenseType, config.Information.LicenseType);
if (!(config.Information.IsLicensedVersion && config.Information.IsLicensedAssemblyLoaded))
{
@@ -200,15 +201,15 @@ public static void UpdateEnvironmentVariables()
{
// grab original values
var originalEnvironmentVariables = ConvertToCaseInsensitiveDictionary(Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process));
- var userName = originalEnvironmentVariables[ApplicationParameters.Environment.Username].ToStringSafe();
- var architecture = originalEnvironmentVariables[ApplicationParameters.Environment.ProcessorArchitecture].ToStringSafe();
- var originalPath = originalEnvironmentVariables[ApplicationParameters.Environment.Path]
+ var userName = originalEnvironmentVariables[EnvironmentVariables.System.Username].ToStringSafe();
+ var architecture = originalEnvironmentVariables[EnvironmentVariables.System.ProcessorArchitecture].ToStringSafe();
+ var originalPath = originalEnvironmentVariables[EnvironmentVariables.System.Path]
.ToStringSafe()
.Split(new[] { ApplicationParameters.Environment.EnvironmentSeparator }, StringSplitOptions.RemoveEmptyEntries);
- var originalPathExt = originalEnvironmentVariables[ApplicationParameters.Environment.PathExtensions]
+ var originalPathExt = originalEnvironmentVariables[EnvironmentVariables.System.PathExtensions]
.ToStringSafe()
.Split(new[] { ApplicationParameters.Environment.EnvironmentSeparator }, StringSplitOptions.RemoveEmptyEntries);
- var originalPsModulePath = originalEnvironmentVariables[ApplicationParameters.Environment.PsModulePath]
+ var originalPsModulePath = originalEnvironmentVariables[EnvironmentVariables.System.PSModulePath]
.ToStringSafe()
.Split(new[] { ApplicationParameters.Environment.EnvironmentSeparator }, StringSplitOptions.RemoveEmptyEntries);
@@ -237,21 +238,25 @@ public static void UpdateEnvironmentVariables()
if (setUserEnvironmentVariables) RefreshEnvironmentVariables(userVariables);
// restore process overridden variables
- if (originalEnvironmentVariables.Contains(ApplicationParameters.Environment.Username)) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.Username, userName);
- if (originalEnvironmentVariables.Contains(ApplicationParameters.Environment.ProcessorArchitecture)) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ProcessorArchitecture, architecture);
+ if (originalEnvironmentVariables.Contains(EnvironmentVariables.System.Username))
+ {
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.Username, userName);
+ }
+
+ if (originalEnvironmentVariables.Contains(EnvironmentVariables.System.ProcessorArchitecture)) Environment.SetEnvironmentVariable(EnvironmentVariables.System.ProcessorArchitecture, architecture);
// combine environment values that append together
var updatedPath = "{0};{1};".FormatWith(
- machineVariables[ApplicationParameters.Environment.Path].ToStringSafe(),
- userVariables[ApplicationParameters.Environment.Path].ToStringSafe()
+ machineVariables[EnvironmentVariables.System.Path].ToStringSafe(),
+ userVariables[EnvironmentVariables.System.Path].ToStringSafe()
).Replace(";;", ";");
var updatedPathExt = "{0};{1};".FormatWith(
- machineVariables[ApplicationParameters.Environment.PathExtensions].ToStringSafe(),
- userVariables[ApplicationParameters.Environment.PathExtensions].ToStringSafe()
+ machineVariables[EnvironmentVariables.System.PathExtensions].ToStringSafe(),
+ userVariables[EnvironmentVariables.System.PathExtensions].ToStringSafe()
).Replace(";;", ";");
var updatedPsModulePath = "{0};{1};".FormatWith(
- userVariables[ApplicationParameters.Environment.PsModulePath].ToStringSafe(),
- machineVariables[ApplicationParameters.Environment.PsModulePath].ToStringSafe()
+ userVariables[EnvironmentVariables.System.PSModulePath].ToStringSafe(),
+ machineVariables[EnvironmentVariables.System.PSModulePath].ToStringSafe()
).Replace(";;", ";");
// add back in process items
@@ -274,9 +279,9 @@ public static void UpdateEnvironmentVariables()
updatedPsModulePath = updatedPsModulePath.Remove(0, 1);
}
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.Path, updatedPath);
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.PathExtensions, updatedPathExt);
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.PsModulePath, updatedPsModulePath);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.Path, updatedPath);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.PathExtensions, updatedPathExt);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.System.PSModulePath, updatedPsModulePath);
}
private static IDictionary ConvertToCaseInsensitiveDictionary(IDictionary originalDictionary)
diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs
index e79199659d..a33ecfb66c 100644
--- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs
+++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs
@@ -41,6 +41,7 @@ namespace chocolatey.infrastructure.app.services
using results;
using SimpleInjector;
using tolerance;
+ using static chocolatey.StringResources;
using IFileSystem = filesystem.IFileSystem;
public class ChocolateyPackageService : IChocolateyPackageService
@@ -522,25 +523,25 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC
pkgInfo.IsPinned = config.PinPackage;
}
- var toolsLocation = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyToolsLocation);
- if (!string.IsNullOrWhiteSpace(toolsLocation) && string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation)))
+ var toolsLocation = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyToolsLocation);
+ if (!string.IsNullOrWhiteSpace(toolsLocation) && string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation)))
{
toolsLocation = _fileSystem.CombinePaths(toolsLocation, packageResult.Name);
if (_fileSystem.DirectoryExists(toolsLocation))
{
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation, toolsLocation, EnvironmentVariableTarget.Process);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation, toolsLocation, EnvironmentVariableTarget.Process);
}
}
- if (!powerShellRan && string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation)))
+ if (!powerShellRan && string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation)))
{
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation, packageResult.InstallLocation, EnvironmentVariableTarget.Process);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation, packageResult.InstallLocation, EnvironmentVariableTarget.Process);
}
if (pkgInfo.RegistrySnapshot != null && pkgInfo.RegistrySnapshot.RegistryKeys.Any(k => !string.IsNullOrWhiteSpace(k.InstallLocation)))
{
var key = pkgInfo.RegistrySnapshot.RegistryKeys.FirstOrDefault(k => !string.IsNullOrWhiteSpace(k.InstallLocation));
- if (key != null) Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation, key.InstallLocation, EnvironmentVariableTarget.Process);
+ if (key != null) Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation, key.InstallLocation, EnvironmentVariableTarget.Process);
}
UpdatePackageInformation(pkgInfo);
@@ -578,8 +579,8 @@ public virtual void HandlePackageResult(PackageResult packageResult, ChocolateyC
this.Log().Info(ChocolateyLoggers.Important, " The {0} of {1} was successful.".FormatWith(commandName.ToStringSafe(), packageResult.Name));
- var installLocation = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation);
- var installerDetected = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallerType);
+ var installLocation = Environment.GetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation);
+ var installerDetected = Environment.GetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyInstallerType);
if (!string.IsNullOrWhiteSpace(installLocation))
{
this.Log().Info(ChocolateyLoggers.Important, " Software installed to '{0}'".FormatWith(installLocation.EscapeCurlyBraces()));
@@ -1432,7 +1433,7 @@ private void HandleExtensionPackages(ChocolateyConfiguration config, PackageResu
this.Log().Warn(logMessage);
packageResult.Messages.Add(new ResultMessage(ResultType.Note, logMessage));
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation, packageExtensionsInstallDirectory, EnvironmentVariableTarget.Process);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation, packageExtensionsInstallDirectory, EnvironmentVariableTarget.Process);
}
else
{
@@ -1518,7 +1519,7 @@ private void HandleTemplatePackages(ChocolateyConfiguration config, PackageResul
this.Log().Warn(logMessage);
packageResult.Messages.Add(new ResultMessage(ResultType.Note, logMessage));
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation, installTemplatePath, EnvironmentVariableTarget.Process);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation, installTemplatePath, EnvironmentVariableTarget.Process);
}
else
{
@@ -1837,7 +1838,7 @@ private void HandleHookPackages(ChocolateyConfiguration config, PackageResult pa
this.Log().Warn(logMessage);
packageResult.Messages.Add(new ResultMessage(ResultType.Note, logMessage));
- Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation, installHookPath, EnvironmentVariableTarget.Process);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageInstallLocation, installHookPath, EnvironmentVariableTarget.Process);
}
else
{
diff --git a/src/chocolatey/infrastructure.app/services/CygwinService.cs b/src/chocolatey/infrastructure.app/services/CygwinService.cs
index 252d24cc0d..819551ebc0 100644
--- a/src/chocolatey/infrastructure.app/services/CygwinService.cs
+++ b/src/chocolatey/infrastructure.app/services/CygwinService.cs
@@ -29,6 +29,7 @@ namespace chocolatey.infrastructure.app.services
using logging;
using results;
using platforms;
+ using static chocolatey.StringResources;
///
/// Alternative Source for Cygwin
@@ -179,7 +180,7 @@ private string GetRootDirectory()
return setupKey.GetValue("rootdir", string.Empty).ToStringSafe();
}
- var binRoot = Environment.GetEnvironmentVariable("ChocolateyBinRoot");
+ var binRoot = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyBinRoot);
if (string.IsNullOrWhiteSpace(binRoot)) binRoot = "c:\\tools";
return _fileSystem.CombinePaths(binRoot, "cygwin");
diff --git a/src/chocolatey/infrastructure.app/services/PowershellService.cs b/src/chocolatey/infrastructure.app/services/PowershellService.cs
index b80dce5ba8..eb56dc8fbe 100644
--- a/src/chocolatey/infrastructure.app/services/PowershellService.cs
+++ b/src/chocolatey/infrastructure.app/services/PowershellService.cs
@@ -37,6 +37,7 @@ namespace chocolatey.infrastructure.app.services
using powershell;
using results;
using utility;
+ using static chocolatey.StringResources;
using CryptoHashProvider = cryptography.CryptoHashProvider;
using Environment = System.Environment;
using IFileSystem = filesystem.IFileSystem;
@@ -440,34 +441,34 @@ public void PreparePowerShellEnvironment(IPackageSearchMetadata package, Chocola
EnvironmentSettings.UpdateEnvironmentVariables();
EnvironmentSettings.SetEnvironmentVariables(configuration);
- Environment.SetEnvironmentVariable("chocolateyPackageName", package.Identity.Id);
- Environment.SetEnvironmentVariable("packageName", package.Identity.Id);
- Environment.SetEnvironmentVariable("chocolateyPackageTitle", package.Title);
- Environment.SetEnvironmentVariable("packageTitle", package.Title);
- Environment.SetEnvironmentVariable("chocolateyPackageVersion", package.Identity.Version.ToNormalizedStringChecked());
- Environment.SetEnvironmentVariable("packageVersion", package.Identity.Version.ToNormalizedStringChecked());
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageName, package.Identity.Id);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.PackageName, package.Identity.Id);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageTitle, package.Title);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.PackageTitle, package.Title);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageVersion, package.Identity.Version.ToNormalizedStringChecked());
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.PackageVersion, package.Identity.Version.ToNormalizedStringChecked());
// We use ToStringSafe on purpose here. There is a need for the version
// the package specified, not the normalized version we want users to use.
- Environment.SetEnvironmentVariable(StringResources.EnvironmentVariables.ChocolateyPackageNuspecVersion, package.Identity.Version.ToStringSafe());
- Environment.SetEnvironmentVariable(StringResources.EnvironmentVariables.PackageNuspecVersion, package.Identity.Version.ToStringSafe());
- Environment.SetEnvironmentVariable("chocolateyPackageVersionPrerelease", package.Identity.Version.Release.ToStringSafe());
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyNuspecVersion, package.Identity.Version.ToStringSafe());
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.PackageNuspecVersion, package.Identity.Version.ToStringSafe());
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageVersionPrerelease, package.Identity.Version.Release.ToStringSafe());
- Environment.SetEnvironmentVariable("chocolateyPackageFolder", packageDirectory);
- Environment.SetEnvironmentVariable("packageFolder", packageDirectory);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageFolder, packageDirectory);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.PackageFolder, packageDirectory);
// unset variables that may not be updated so they don't get passed again
- Environment.SetEnvironmentVariable("installArguments", null);
- Environment.SetEnvironmentVariable("installerArguments", null);
- Environment.SetEnvironmentVariable("chocolateyInstallArguments", null);
- Environment.SetEnvironmentVariable("chocolateyInstallOverride", null);
- Environment.SetEnvironmentVariable("packageParameters", null);
- Environment.SetEnvironmentVariable("chocolateyPackageParameters", null);
- Environment.SetEnvironmentVariable("chocolateyChecksum32", null);
- Environment.SetEnvironmentVariable("chocolateyChecksum64", null);
- Environment.SetEnvironmentVariable("chocolateyChecksumType32", null);
- Environment.SetEnvironmentVariable("chocolateyChecksumType64", null);
- Environment.SetEnvironmentVariable("chocolateyForceX86", null);
- Environment.SetEnvironmentVariable("DownloadCacheAvailable", null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.InstallArguments, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.InstallerArguments, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.InstallArguments, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyInstallOverride, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.PackageParameters, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.PackageParameters, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksum32, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksum64, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksumType32, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksumType64, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyForceX86, null);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.DownloadCacheAvailable, null);
// we only want to pass the following args to packages that would apply.
// like choco install git --params '' should pass those params to git.install,
@@ -475,13 +476,13 @@ public void PreparePowerShellEnvironment(IPackageSearchMetadata package, Chocola
if (!PackageUtility.PackageIdHasDependencySuffix(configuration, package.Identity.Id) || configuration.ApplyInstallArgumentsToDependencies)
{
this.Log().Debug(ChocolateyLoggers.Verbose, "Setting installer args for {0}".FormatWith(package.Identity.Id));
- Environment.SetEnvironmentVariable("installArguments", configuration.InstallArguments);
- Environment.SetEnvironmentVariable("installerArguments", configuration.InstallArguments);
- Environment.SetEnvironmentVariable("chocolateyInstallArguments", configuration.InstallArguments);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.InstallArguments, configuration.InstallArguments);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.InstallerArguments, configuration.InstallArguments);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyInstallArguments, configuration.InstallArguments);
if (configuration.OverrideArguments)
{
- Environment.SetEnvironmentVariable("chocolateyInstallOverride", "true");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyInstallOverride, "true");
}
}
@@ -490,40 +491,40 @@ public void PreparePowerShellEnvironment(IPackageSearchMetadata package, Chocola
if (!PackageUtility.PackageIdHasDependencySuffix(configuration, package.Identity.Id) || configuration.ApplyPackageParametersToDependencies)
{
this.Log().Debug(ChocolateyLoggers.Verbose, "Setting package parameters for {0}".FormatWith(package.Identity.Id));
- Environment.SetEnvironmentVariable("packageParameters", configuration.PackageParameters);
- Environment.SetEnvironmentVariable("chocolateyPackageParameters", configuration.PackageParameters);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.PackageParameters, configuration.PackageParameters);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyPackageParameters, configuration.PackageParameters);
}
if (!string.IsNullOrWhiteSpace(configuration.DownloadChecksum))
{
- Environment.SetEnvironmentVariable("chocolateyChecksum32", configuration.DownloadChecksum);
- Environment.SetEnvironmentVariable("chocolateyChecksum64", configuration.DownloadChecksum);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksum32, configuration.DownloadChecksum);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksum64, configuration.DownloadChecksum);
}
if (!string.IsNullOrWhiteSpace(configuration.DownloadChecksumType))
{
- Environment.SetEnvironmentVariable("chocolateyChecksumType32", configuration.DownloadChecksumType);
- Environment.SetEnvironmentVariable("chocolateyChecksumType64", configuration.DownloadChecksumType);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksumType32, configuration.DownloadChecksumType);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksumType64, configuration.DownloadChecksumType);
}
if (!string.IsNullOrWhiteSpace(configuration.DownloadChecksum64))
{
- Environment.SetEnvironmentVariable("chocolateyChecksum64", configuration.DownloadChecksum64);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksum64, configuration.DownloadChecksum64);
}
if (!string.IsNullOrWhiteSpace(configuration.DownloadChecksumType64))
{
- Environment.SetEnvironmentVariable("chocolateyChecksumType64", configuration.DownloadChecksumType64);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyChecksumType64, configuration.DownloadChecksumType64);
}
if (configuration.ForceX86)
{
- Environment.SetEnvironmentVariable("chocolateyForceX86", "true");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyForceX86, "true");
}
if (configuration.NotSilent)
{
- Environment.SetEnvironmentVariable("chocolateyInstallOverride", "true");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyInstallOverride, "true");
}
//todo:if (configuration.NoOutput)
@@ -533,14 +534,14 @@ public void PreparePowerShellEnvironment(IPackageSearchMetadata package, Chocola
if (package.IsDownloadCacheAvailable)
{
- Environment.SetEnvironmentVariable("DownloadCacheAvailable", "true");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.DownloadCacheAvailable, "true");
foreach (var downloadCache in package.DownloadCache.OrEmpty())
{
var urlKey = CryptoHashProvider.ComputeStringHash(downloadCache.OriginalUrl, CryptoHashProviderType.Sha256).Replace("=", string.Empty);
- Environment.SetEnvironmentVariable("CacheFile_{0}".FormatWith(urlKey), downloadCache.FileName);
- Environment.SetEnvironmentVariable("CacheChecksum_{0}".FormatWith(urlKey), downloadCache.Checksum);
- Environment.SetEnvironmentVariable("CacheChecksumType_{0}".FormatWith(urlKey), "sha512");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.CacheFileFormat.FormatWith(urlKey), downloadCache.FileName);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.CacheChecksumFormat.FormatWith(urlKey), downloadCache.Checksum);
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.CacheChecksumTypeFormat.FormatWith(urlKey), "sha512");
}
}
@@ -606,8 +607,8 @@ private void RemoveAssemblyResolver()
public PowerShellExecutionResults RunHost(ChocolateyConfiguration config, string chocoPowerShellScript, Action additionalActionsBeforeScript, IEnumerable hookPreScriptPathList, IEnumerable hookPostScriptPathList)
{
// since we control output in the host, always set these true
- Environment.SetEnvironmentVariable("ChocolateyEnvironmentDebug", "true");
- Environment.SetEnvironmentVariable("ChocolateyEnvironmentVerbose", "true");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyEnvironmentDebug, "true");
+ Environment.SetEnvironmentVariable(EnvironmentVariables.Package.ChocolateyEnvironmentVerbose, "true");
var result = new PowerShellExecutionResults();
diff --git a/src/chocolatey/infrastructure.app/services/PythonService.cs b/src/chocolatey/infrastructure.app/services/PythonService.cs
index 718bbccae3..af12710c27 100644
--- a/src/chocolatey/infrastructure.app/services/PythonService.cs
+++ b/src/chocolatey/infrastructure.app/services/PythonService.cs
@@ -30,6 +30,7 @@ namespace chocolatey.infrastructure.app.services
using logging;
using results;
using platforms;
+ using static chocolatey.StringResources;
///
/// Alternative Source for Installing Python packages
@@ -244,7 +245,7 @@ private void EnsureExecutablePathSet()
if (string.IsNullOrWhiteSpace(topLevelPath))
{
- var binRoot = Environment.GetEnvironmentVariable("ChocolateyBinRoot");
+ var binRoot = Environment.GetEnvironmentVariable(EnvironmentVariables.System.ChocolateyBinRoot);
if (string.IsNullOrWhiteSpace(binRoot)) binRoot = "c:\\tools";
topLevelPath = _fileSystem.CombinePaths(binRoot, "python");
diff --git a/src/chocolatey/infrastructure/adapters/Environment.cs b/src/chocolatey/infrastructure/adapters/Environment.cs
index 26df791377..f6c81e5648 100644
--- a/src/chocolatey/infrastructure/adapters/Environment.cs
+++ b/src/chocolatey/infrastructure/adapters/Environment.cs
@@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.adapters
using System;
using System.Collections;
using app;
+ using static chocolatey.StringResources;
public sealed class Environment : IEnvironment
{
@@ -37,7 +38,7 @@ public bool Is64BitProcess
get
{
// ARM64 bit architecture has a x86-32 emulator, so return false
- if (System.Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ProcessorArchitecture).ToStringSafe().IsEqualTo(ApplicationParameters.Environment.Arm64ProcessorArchitecture))
+ if (System.Environment.GetEnvironmentVariable(EnvironmentVariables.System.ProcessorArchitecture).ToStringSafe().IsEqualTo(ApplicationParameters.Environment.Arm64ProcessorArchitecture))
{
return false;
}
diff --git a/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs b/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs
index 410b765340..98720d2564 100644
--- a/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs
+++ b/src/chocolatey/infrastructure/filesystem/DotNetFileSystem.cs
@@ -30,6 +30,7 @@ namespace chocolatey.infrastructure.filesystem
using logging;
using platforms;
using tolerance;
+ using static chocolatey.StringResources;
using Assembly = adapters.Assembly;
using Environment = adapters.Environment;
@@ -116,7 +117,7 @@ public string GetTempPath()
if (System.Environment.UserName.ContainsSafe(ApplicationParameters.Environment.SystemUserName) || path.ContainsSafe("config\\systemprofile"))
{
- path = System.Environment.ExpandEnvironmentVariables(System.Environment.GetEnvironmentVariable(ApplicationParameters.Environment.Temp, EnvironmentVariableTarget.Machine).ToStringSafe());
+ path = System.Environment.ExpandEnvironmentVariables(System.Environment.GetEnvironmentVariable(EnvironmentVariables.System.Username, EnvironmentVariableTarget.Machine).ToStringSafe());
}
return path;
@@ -141,7 +142,7 @@ public string GetExecutablePath(string executableName)
if (GetFilenameWithoutExtension(executableName).IsEqualTo(executableName) && isWindows)
{
- var pathExtensions = Environment.GetEnvironmentVariable(ApplicationParameters.Environment.PathExtensions).ToStringSafe().Split(new[] { ApplicationParameters.Environment.EnvironmentSeparator }, StringSplitOptions.RemoveEmptyEntries);
+ var pathExtensions = Environment.GetEnvironmentVariable(EnvironmentVariables.System.PathExtensions).ToStringSafe().Split(new[] { ApplicationParameters.Environment.EnvironmentSeparator }, StringSplitOptions.RemoveEmptyEntries);
foreach (var extension in pathExtensions.OrEmpty())
{
extensions.Add(extension.StartsWith(".") ? extension : ".{0}".FormatWith(extension));
@@ -157,7 +158,7 @@ public string GetExecutablePath(string executableName)
var searchPaths = new List();
searchPaths.Add(GetCurrentDirectory());
searchPaths.Add(GetDirectoryName(GetCurrentAssemblyPath()));
- searchPaths.AddRange(Environment.GetEnvironmentVariable(ApplicationParameters.Environment.Path).ToStringSafe().Split(new[] { GetPathSeparator() }, StringSplitOptions.RemoveEmptyEntries));
+ searchPaths.AddRange(Environment.GetEnvironmentVariable(EnvironmentVariables.System.Path).ToStringSafe().Split(new[] { GetPathSeparator() }, StringSplitOptions.RemoveEmptyEntries));
foreach (var path in searchPaths.OrEmpty())
{
@@ -671,7 +672,7 @@ public void MoveDirectory(string directoryPath, string newDirectoryPath, bool us
if (string.IsNullOrWhiteSpace(directoryPath) || string.IsNullOrWhiteSpace(newDirectoryPath)) throw new ApplicationException("You must provide a directory to move from or to.");
// Linux / macOS do not have a SystemDrive environment variable, instead, everything is under "/"
- var systemDrive = Platform.GetPlatform() == PlatformType.Windows ? Environment.GetEnvironmentVariable("SystemDrive") : "/";
+ var systemDrive = Platform.GetPlatform() == PlatformType.Windows ? Environment.GetEnvironmentVariable(EnvironmentVariables.System.SystemDrive) : "/";
if (CombinePaths(directoryPath, "").IsEqualTo(CombinePaths(systemDrive, ""))) throw new ApplicationException("Cannot move or delete the root of the system drive");
try
@@ -796,7 +797,7 @@ public void DeleteDirectory(string directoryPath, bool recursive, bool overrideA
if (string.IsNullOrWhiteSpace(directoryPath)) throw new ApplicationException("You must provide a directory to delete.");
// Linux / macOS do not have a SystemDrive environment variable, instead, everything is under "/"
- var systemDrive = Platform.GetPlatform() == PlatformType.Windows ? Environment.GetEnvironmentVariable("SystemDrive") : "/";
+ var systemDrive = Platform.GetPlatform() == PlatformType.Windows ? Environment.GetEnvironmentVariable(EnvironmentVariables.System.SystemDrive) : "/";
if (CombinePaths(directoryPath, "").IsEqualTo(CombinePaths(systemDrive, ""))) throw new ApplicationException("Cannot move or delete the root of the system drive");
if (overrideAttributes)
diff --git a/src/chocolatey/infrastructure/information/ProcessInformation.cs b/src/chocolatey/infrastructure/information/ProcessInformation.cs
index e70e1b253e..c0cb32dc04 100644
--- a/src/chocolatey/infrastructure/information/ProcessInformation.cs
+++ b/src/chocolatey/infrastructure/information/ProcessInformation.cs
@@ -20,6 +20,7 @@ namespace chocolatey.infrastructure.information
using System.Runtime.InteropServices;
using System.Security.Principal;
using platforms;
+ using static chocolatey.StringResources;
public sealed class ProcessInformation
{
@@ -118,12 +119,12 @@ public static bool IsElevated()
public static bool UserIsTerminalServices()
{
- return Environment.GetEnvironmentVariable("SESSIONNAME").ToStringSafe().ContainsSafe("rdp-");
+ return Environment.GetEnvironmentVariable(EnvironmentVariables.System.SessionName).ToStringSafe().ContainsSafe("rdp-");
}
public static bool UserIsRemote()
{
- return UserIsTerminalServices() || Environment.GetEnvironmentVariable("SESSIONNAME").ToStringSafe() == string.Empty;
+ return UserIsTerminalServices() || Environment.GetEnvironmentVariable(EnvironmentVariables.System.SessionName).ToStringSafe() == string.Empty;
}
public static bool UserIsSystem()