mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Remove Platform.HasRegistry query
This commit is contained in:
1 parent
c2cd059aa8
commit
73a1a51f69
9 files changed
+29
-59
No files matched your search
@@ -893,13 +893,10 @@ namespace System.Management.Automation
|
|||||||
return GetEnvironmentVariables();
|
return GetEnvironmentVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Platform.HasRegistrySupport())
|
#if LINUX
|
||||||
{
|
return null;
|
||||||
// Porting note: Does not throw a PlatformUnsupported because
|
#else
|
||||||
// GetEnvironmentVariable cannot throw, and we want the same interface.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( target == EnvironmentVariableTarget.Machine)
|
if( target == EnvironmentVariableTarget.Machine)
|
||||||
{
|
{
|
||||||
using (RegistryKey environmentKey =
|
using (RegistryKey environmentKey =
|
||||||
@@ -916,6 +913,7 @@ namespace System.Management.Automation
|
|||||||
return GetRegistryKeyNameValuePairs(environmentKey);
|
return GetRegistryKeyNameValuePairs(environmentKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -956,13 +954,9 @@ namespace System.Management.Automation
|
|||||||
return System.Environment.GetEnvironmentVariable(variable);
|
return System.Environment.GetEnvironmentVariable(variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Platform.HasRegistrySupport())
|
#if LINUX
|
||||||
{
|
return null;
|
||||||
// Porting note: This cannot throw since it would otherwise throw while
|
#else
|
||||||
// creating a runspace. Returning null is appropriate to signal that there
|
|
||||||
// is no value for a registry key with no registry.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target == EnvironmentVariableTarget.Machine)
|
if (target == EnvironmentVariableTarget.Machine)
|
||||||
{
|
{
|
||||||
@@ -985,6 +979,7 @@ namespace System.Management.Automation
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion EnvironmentVariable_Extensions
|
#endregion EnvironmentVariable_Extensions
|
||||||
|
|||||||
@@ -217,12 +217,6 @@ namespace System.Management.Automation
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux does not have a registry
|
|
||||||
internal static bool HasRegistrySupport()
|
|
||||||
{
|
|
||||||
return IsWindows;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Linux does not have PowerShell execution policies
|
// Linux does not have PowerShell execution policies
|
||||||
internal static bool HasExecutionPolicy()
|
internal static bool HasExecutionPolicy()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1903,13 +1903,9 @@ namespace System.Management.Automation
|
|||||||
///
|
///
|
||||||
internal static string GetShellPathFromRegistry(string shellID)
|
internal static string GetShellPathFromRegistry(string shellID)
|
||||||
{
|
{
|
||||||
if (!Platform.HasRegistrySupport())
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
string result = null;
|
string result = null;
|
||||||
|
|
||||||
|
#if !LINUX
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RegistryKey shellKey = Registry.LocalMachine.OpenSubKey(Utils.GetRegistryConfigurationPath(shellID));
|
RegistryKey shellKey = Registry.LocalMachine.OpenSubKey(Utils.GetRegistryConfigurationPath(shellID));
|
||||||
@@ -1935,6 +1931,7 @@ namespace System.Management.Automation
|
|||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,13 +103,9 @@ namespace System.Management.Automation
|
|||||||
// Gets the current WSMan stack version from the registry.
|
// Gets the current WSMan stack version from the registry.
|
||||||
private static Version GetWSManStackVersion()
|
private static Version GetWSManStackVersion()
|
||||||
{
|
{
|
||||||
if (!Platform.HasRegistrySupport())
|
|
||||||
{
|
|
||||||
return new Version(1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Version version = null;
|
Version version = null;
|
||||||
|
|
||||||
|
#if !LINUX
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (RegistryKey wsManStackVersionKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\WSMAN"))
|
using (RegistryKey wsManStackVersionKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\WSMAN"))
|
||||||
@@ -133,6 +129,7 @@ namespace System.Management.Automation
|
|||||||
catch (FormatException) { }
|
catch (FormatException) { }
|
||||||
catch (OverflowException) { }
|
catch (OverflowException) { }
|
||||||
catch (InvalidCastException) { }
|
catch (InvalidCastException) { }
|
||||||
|
#endif
|
||||||
|
|
||||||
return version ?? System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STACK_VERSION;
|
return version ?? System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STACK_VERSION;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -368,14 +368,11 @@ namespace System.Management.Automation
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static bool IsWinPEHost()
|
internal static bool IsWinPEHost()
|
||||||
{
|
{
|
||||||
if (Platform.HasRegistrySupport())
|
#if LINUX
|
||||||
{
|
return false;
|
||||||
return WinIsWinPEHost();
|
#else
|
||||||
}
|
return WinIsWinPEHost();
|
||||||
else
|
#endif
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool WinIsWinPEHost()
|
internal static bool WinIsWinPEHost()
|
||||||
|
|||||||
@@ -96,12 +96,10 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static void CheckRemotingCmdletPrerequisites()
|
internal static void CheckRemotingCmdletPrerequisites()
|
||||||
{
|
{
|
||||||
//If the operating system (ie Linux) does not support the registry, simply return to avoid calls to the Windows registry.
|
#if LINUX
|
||||||
if (!Platform.HasRegistrySupport())
|
// TODO: check that PSRP requirements are installed
|
||||||
{
|
return;
|
||||||
return;
|
#else
|
||||||
}
|
|
||||||
|
|
||||||
bool notSupported = true;
|
bool notSupported = true;
|
||||||
String WSManKeyPath = "Software\\Microsoft\\Windows\\CurrentVersion\\WSMAN\\";
|
String WSManKeyPath = "Software\\Microsoft\\Windows\\CurrentVersion\\WSMAN\\";
|
||||||
|
|
||||||
@@ -155,6 +153,7 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
"Windows PowerShell remoting features are not enabled or not supported on this machine.\nThis may be because you do not have the correct version of WS-Management installed or this version of Windows does not support remoting currently.\n For more information, type 'get-help about_remote_requirements'.");
|
"Windows PowerShell remoting features are not enabled or not supported on this machine.\nThis may be because you do not have the correct version of WS-Management installed or this version of Windows does not support remoting currently.\n For more information, type 'get-help about_remote_requirements'.");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -136,11 +136,7 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
{
|
{
|
||||||
Collection<PSDriveInfo> drives = new Collection<PSDriveInfo>();
|
Collection<PSDriveInfo> drives = new Collection<PSDriveInfo>();
|
||||||
|
|
||||||
if (!Platform.HasRegistrySupport())
|
#if !LINUX
|
||||||
{
|
|
||||||
return drives;
|
|
||||||
}
|
|
||||||
|
|
||||||
drives.Add(
|
drives.Add(
|
||||||
new PSDriveInfo(
|
new PSDriveInfo(
|
||||||
"HKLM",
|
"HKLM",
|
||||||
@@ -156,6 +152,7 @@ namespace Microsoft.PowerShell.Commands
|
|||||||
"HKEY_CURRENT_USER",
|
"HKEY_CURRENT_USER",
|
||||||
RegistryProviderStrings.HKCUDriveDescription,
|
RegistryProviderStrings.HKCUDriveDescription,
|
||||||
null));
|
null));
|
||||||
|
#endif
|
||||||
|
|
||||||
return drives;
|
return drives;
|
||||||
} // InitializeDefaultDrives
|
} // InitializeDefaultDrives
|
||||||
|
|||||||
@@ -58,13 +58,13 @@ namespace Microsoft.PowerShell.Commands.Internal
|
|||||||
|
|
||||||
override protected bool ReleaseHandle()
|
override protected bool ReleaseHandle()
|
||||||
{
|
{
|
||||||
if (!Platform.HasRegistrySupport())
|
#if LINUX
|
||||||
{
|
return true;
|
||||||
return true;
|
#else
|
||||||
}
|
|
||||||
// Returns a Win32 error code, 0 for success
|
// Returns a Win32 error code, 0 for success
|
||||||
int r = RegCloseKey(handle);
|
int r = RegCloseKey(handle);
|
||||||
return r == 0;
|
return r == 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,12 +15,6 @@ namespace PSTests
|
|||||||
Assert.True(Platform.IsCore);
|
Assert.True(Platform.IsCore);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public static void TestHasRegistrySupport()
|
|
||||||
{
|
|
||||||
Assert.False(Platform.HasRegistrySupport());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public static void TestGetUserName()
|
public static void TestGetUserName()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user