Reducing duplication of Environment variable extraction

This commit is contained in:
Mike Richmond committed 2016-08-04 13:15:34 -07:00
1 parent d3625f7662
commit 1e4615114c
3 files changed
+7 -14

No files matched your search

@@ -641,7 +641,7 @@ namespace System.Management.Automation
return null;
}
private static string GetExpandedEnvironmentVariable(string name, EnvironmentVariableTarget target)
internal static string GetExpandedEnvironmentVariable(string name, EnvironmentVariableTarget target)
{
string result = Environment.GetEnvironmentVariable(name, target);
if (!string.IsNullOrEmpty(result))
@@ -507,28 +507,20 @@ namespace System.Management.Automation
}
/// <summary>
/// This method is not supported for systems when reading from the registry. Its value is
/// known at compile time for inbox PowerShell.
/// Gets the specified module path from the appropriate Environment entry in the registry.
/// </summary>
/// <param name="scope"></param>
/// <returns>The specified module path. Null if not present.</returns>
internal override string GetModulePath(PropertyScope scope)
{
RegistryKey scopedKey = Registry.LocalMachine;
string regKeyName = @"System\CurrentControlSet\Control\Session Manager\Environment";
if (scope == PropertyScope.CurrentUser)
if (PropertyScope.CurrentUser == scope)
{
scopedKey = Registry.CurrentUser;
regKeyName = "Environment";
return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.User);
}
string modulePath = GetRegistryString(scopedKey, regKeyName, "PSMODULEPATH");
if ( ! string.IsNullOrEmpty(modulePath))
else
{
modulePath = Environment.ExpandEnvironmentVariables(modulePath);
return ModuleIntrinsics.GetExpandedEnvironmentVariable("PSMODULEPATH", EnvironmentVariableTarget.Machine);
}
return modulePath;
}
/// <summary>
@@ -211,6 +211,7 @@ namespace System.Management.Automation.Internal
private static void CleanKeyParents(RegistryKey baseKey, string keyPath)
{
#if CORECLR
// if ( ! Platform.Inbox) // Modify this to support registry checks for inbox CoreCLR
return;
#else // Windows && FullCLR
using (RegistryKey key = baseKey.OpenSubKey(keyPath, true))