mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
wrapped STA code sections in #if STAMODE for potential future use
removed -importsystemmodules switch from powershell.exe and related code removed -consolefile parameter from powershell.exe and related code
This commit is contained in:
@@ -170,11 +170,10 @@ namespace Microsoft.PowerShell
|
||||
internal class CommandLineParameterParser
|
||||
{
|
||||
internal static string[] validParameters = {
|
||||
"psconsoleFile",
|
||||
"version",
|
||||
"nologo",
|
||||
"noexit",
|
||||
#if !CORECLR
|
||||
#if STAMODE
|
||||
"sta",
|
||||
"mta",
|
||||
#endif
|
||||
@@ -251,14 +250,6 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
}
|
||||
|
||||
internal bool ImportSystemModules
|
||||
{
|
||||
get
|
||||
{
|
||||
return _importSystemModules;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool SkipProfiles
|
||||
{
|
||||
get
|
||||
@@ -416,6 +407,7 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
}
|
||||
|
||||
#if STAMODE
|
||||
internal bool StaMode
|
||||
{
|
||||
get
|
||||
@@ -426,17 +418,14 @@ namespace Microsoft.PowerShell
|
||||
}
|
||||
else
|
||||
{
|
||||
#if CORECLR
|
||||
// Nano doesn't support STA COM apartment, so on Nano powershell has to use MTA as the default.
|
||||
return false;
|
||||
#else
|
||||
// return false;
|
||||
// Win8: 182409 PowerShell 3.0 should run in STA mode by default
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@@ -554,10 +543,6 @@ namespace Microsoft.PowerShell
|
||||
_noExit = true;
|
||||
noexitSeen = true;
|
||||
}
|
||||
else if (MatchSwitch(switchKey, "importsystemmodules", "imp"))
|
||||
{
|
||||
_importSystemModules = true;
|
||||
}
|
||||
else if (MatchSwitch(switchKey, "noprofile", "nop"))
|
||||
{
|
||||
_skipUserInit = true;
|
||||
@@ -728,7 +713,8 @@ namespace Microsoft.PowerShell
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if !CORECLR // explicit setting of the ApartmentState Not supported on NanoServer
|
||||
#if STAMODE
|
||||
// explicit setting of the ApartmentState Not supported on NanoServer
|
||||
else if (MatchSwitch(switchKey, "sta", "s"))
|
||||
{
|
||||
if (_staMode.HasValue)
|
||||
@@ -1184,6 +1170,7 @@ namespace Microsoft.PowerShell
|
||||
private string _helpText;
|
||||
private bool _abortStartup;
|
||||
private bool _skipUserInit;
|
||||
#if STAMODE
|
||||
// Win8: 182409 PowerShell 3.0 should run in STA mode by default
|
||||
// -sta and -mta are mutually exclusive..so tracking them using nullable boolean
|
||||
// if true, then sta is specified on the command line.
|
||||
@@ -1191,6 +1178,7 @@ namespace Microsoft.PowerShell
|
||||
// if null, then none is specified on the command line..use default in this case
|
||||
// default is sta.
|
||||
private bool? _staMode = null;
|
||||
#endif
|
||||
private bool _noExit = true;
|
||||
private bool _explicitReadCommandsFromStdin;
|
||||
private bool _noPrompt;
|
||||
@@ -1203,7 +1191,6 @@ namespace Microsoft.PowerShell
|
||||
private Collection<CommandParameter> _collectedArgs = new Collection<CommandParameter>();
|
||||
private string _file;
|
||||
private string _executionPolicy;
|
||||
private bool _importSystemModules = false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1435,7 +1435,11 @@ namespace Microsoft.PowerShell
|
||||
|
||||
// NTRAID#Windows Out Of Band Releases-915506-2005/09/09
|
||||
// Removed HandleUnexpectedExceptions infrastructure
|
||||
exitCode = DoRunspaceLoop(cpp.InitialCommand, cpp.SkipProfiles, cpp.Args, cpp.StaMode, cpp.ImportSystemModules, cpp.ConfigurationName);
|
||||
#if STAMODE
|
||||
exitCode = DoRunspaceLoop(cpp.InitialCommand, cpp.SkipProfiles, cpp.Args, cpp.StaMode, cpp.ConfigurationName);
|
||||
#else
|
||||
exitCode = DoRunspaceLoop(cpp.InitialCommand, cpp.SkipProfiles, cpp.Args, false, cpp.ConfigurationName);
|
||||
#endif
|
||||
}
|
||||
while (false);
|
||||
|
||||
@@ -1469,14 +1473,13 @@ namespace Microsoft.PowerShell
|
||||
/// The process exit code to be returned by Main.
|
||||
///
|
||||
/// </returns>
|
||||
private uint DoRunspaceLoop(string initialCommand, bool skipProfiles, Collection<CommandParameter> initialCommandArgs, bool staMode,
|
||||
bool importSystemModules, string configurationName)
|
||||
private uint DoRunspaceLoop(string initialCommand, bool skipProfiles, Collection<CommandParameter> initialCommandArgs, bool staMode, string configurationName)
|
||||
{
|
||||
ExitCode = ExitCodeSuccess;
|
||||
|
||||
while (!ShouldEndSession)
|
||||
{
|
||||
RunspaceCreationEventArgs args = new RunspaceCreationEventArgs(initialCommand, skipProfiles, staMode, importSystemModules, configurationName, initialCommandArgs);
|
||||
RunspaceCreationEventArgs args = new RunspaceCreationEventArgs(initialCommand, skipProfiles, staMode, configurationName, initialCommandArgs);
|
||||
CreateRunspace(args);
|
||||
|
||||
if (ExitCode == ExitCodeInitFailure) { break; }
|
||||
@@ -1515,10 +1518,12 @@ namespace Microsoft.PowerShell
|
||||
|
||||
_runspaceRef.Runspace.Close();
|
||||
_runspaceRef = null;
|
||||
#if STAMODE
|
||||
if (staMode) // don't recycle the Runspace in STA mode
|
||||
{
|
||||
ShouldEndSession = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return ExitCode;
|
||||
@@ -1556,7 +1561,11 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
args = runspaceCreationArgs as RunspaceCreationEventArgs;
|
||||
Dbg.Assert(args != null, "Event Arguments to CreateRunspace should not be null");
|
||||
DoCreateRunspace(args.InitialCommand, args.SkipProfiles, args.StaMode, args.ImportSystemModules, args.ConfigurationName, args.InitialCommandArgs);
|
||||
#if STAMODE
|
||||
DoCreateRunspace(args.InitialCommand, args.SkipProfiles, args.StaMode, args.ConfigurationName, args.InitialCommandArgs);
|
||||
#else
|
||||
DoCreateRunspace(args.InitialCommand, args.SkipProfiles, false, args.ConfigurationName, args.InitialCommandArgs);
|
||||
#endif
|
||||
}
|
||||
catch (ConsoleHostStartupException startupException)
|
||||
{
|
||||
@@ -1571,7 +1580,7 @@ namespace Microsoft.PowerShell
|
||||
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
private void InitializeRunspace(string initialCommand, bool skipProfiles, Collection<CommandParameter> initialCommandArgs)
|
||||
{
|
||||
DoCreateRunspace(initialCommand, skipProfiles, staMode: false, importSystemModules: false, configurationName: null, initialCommandArgs: initialCommandArgs);
|
||||
DoCreateRunspace(initialCommand, skipProfiles, staMode: false, configurationName: null, initialCommandArgs: initialCommandArgs);
|
||||
}
|
||||
|
||||
private bool LoadPSReadline()
|
||||
@@ -1594,8 +1603,7 @@ namespace Microsoft.PowerShell
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
//private void CreateRunspace(string initialCommand, bool skipProfiles, bool staMode, Collection<CommandParameter> initialCommandArgs)
|
||||
private void DoCreateRunspace(string initialCommand, bool skipProfiles, bool staMode, bool importSystemModules, string configurationName, Collection<CommandParameter> initialCommandArgs)
|
||||
private void DoCreateRunspace(string initialCommand, bool skipProfiles, bool staMode, string configurationName, Collection<CommandParameter> initialCommandArgs)
|
||||
{
|
||||
Dbg.Assert(_runspaceRef == null, "runspace should be null");
|
||||
#if !DEBUG
|
||||
@@ -1682,11 +1690,12 @@ namespace Microsoft.PowerShell
|
||||
// Record how long it took from process start to runspace open for telemetry.
|
||||
_readyForInputTimeInMS = (DateTime.Now - Process.GetCurrentProcess().StartTime).TotalMilliseconds;
|
||||
|
||||
DoRunspaceInitialization(importSystemModules, skipProfiles, initialCommand, configurationName, initialCommandArgs);
|
||||
DoRunspaceInitialization(skipProfiles, initialCommand, configurationName, initialCommandArgs);
|
||||
}
|
||||
|
||||
private void OpenConsoleRunspace(Runspace runspace, bool staMode)
|
||||
{
|
||||
#if STAMODE
|
||||
// staMode will have following values:
|
||||
// On FullPS: 'true'/'false' = default('true'=STA) + possibility of overload through cmdline parameter '-mta'
|
||||
// On NanoPS: always 'false' = default('false'=MTA) + NO possibility of overload through cmdline parameter '-mta'
|
||||
@@ -1694,12 +1703,10 @@ namespace Microsoft.PowerShell
|
||||
if (staMode)
|
||||
{
|
||||
// we can't change ApartmentStates on CoreCLR
|
||||
#if !CORECLR
|
||||
runspace.ApartmentState = ApartmentState.STA;
|
||||
#endif
|
||||
runspace.ThreadOptions = PSThreadOptions.ReuseThread;
|
||||
}
|
||||
|
||||
#endif
|
||||
runspace.ThreadOptions = PSThreadOptions.ReuseThread;
|
||||
runspace.EngineActivityId = EtwActivity.GetActivityId();
|
||||
|
||||
s_runspaceInitTracer.WriteLine("Calling Runspace.Open");
|
||||
@@ -1707,7 +1714,7 @@ namespace Microsoft.PowerShell
|
||||
runspace.Open();
|
||||
}
|
||||
|
||||
private void DoRunspaceInitialization(bool importSystemModules, bool skipProfiles, string initialCommand, string configurationName, Collection<CommandParameter> initialCommandArgs)
|
||||
private void DoRunspaceInitialization(bool skipProfiles, string initialCommand, string configurationName, Collection<CommandParameter> initialCommandArgs)
|
||||
{
|
||||
if (_runspaceRef.Runspace.Debugger != null)
|
||||
{
|
||||
@@ -1717,12 +1724,6 @@ namespace Microsoft.PowerShell
|
||||
|
||||
Executor exec = new Executor(this, false, false);
|
||||
|
||||
// Run import system modules command
|
||||
if (importSystemModules)
|
||||
{
|
||||
Exception exception = InitializeRunspaceHelper("ImportSystemModules", exec, Executor.ExecutionOptions.None);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(configurationName))
|
||||
{
|
||||
// If an endpoint configuration is specified then create a loop-back remote runspace targeting
|
||||
@@ -3015,28 +3016,28 @@ namespace Microsoft.PowerShell
|
||||
/// <param name="initialCommand"> </param>
|
||||
/// <param name="skipProfiles"></param>
|
||||
/// <param name="staMode"></param>
|
||||
/// <param name="importSystemModules"></param>
|
||||
/// <param name="configurationName"></param>
|
||||
/// <param name="initialCommandArgs"></param>
|
||||
internal RunspaceCreationEventArgs(string initialCommand,
|
||||
bool skipProfiles,
|
||||
bool staMode,
|
||||
bool importSystemModules,
|
||||
string configurationName,
|
||||
Collection<CommandParameter> initialCommandArgs)
|
||||
{
|
||||
InitialCommand = initialCommand;
|
||||
SkipProfiles = skipProfiles;
|
||||
#if STAMODE
|
||||
StaMode = staMode;
|
||||
ImportSystemModules = importSystemModules;
|
||||
#endif
|
||||
ConfigurationName = configurationName;
|
||||
InitialCommandArgs = initialCommandArgs;
|
||||
}
|
||||
|
||||
internal string InitialCommand { get; set; }
|
||||
internal bool SkipProfiles { get; set; }
|
||||
#if STAMODE
|
||||
internal bool StaMode { get; set; }
|
||||
internal bool ImportSystemModules { get; set; }
|
||||
#endif
|
||||
internal string ConfigurationName { get; set; }
|
||||
internal Collection<CommandParameter> InitialCommandArgs { get; set; }
|
||||
}
|
||||
|
||||
@@ -25,18 +25,6 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
return Start(null, bannerText, helpText, null, args);
|
||||
}
|
||||
#else
|
||||
/// <summary>Entry point in to ConsoleShell. This method is called by main of minishell.</summary>
|
||||
/// <param name="configuration">Configuration information which is used to create Runspace.</param>
|
||||
/// <param name="bannerText">Banner text to be displayed by ConsoleHost</param>
|
||||
/// <param name="helpText">Help text for minishell. This is displayed on 'minishell -?'.</param>
|
||||
/// <param name="args">Commandline parameters specified by user.</param>
|
||||
/// <returns>An integer value which should be used as exit code for the process.</returns>
|
||||
public static int Start(RunspaceConfiguration configuration, string bannerText, string helpText, string[] args)
|
||||
{
|
||||
return Start(configuration, bannerText, helpText, null, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
||||
@@ -4162,14 +4162,6 @@ End
|
||||
}
|
||||
";
|
||||
|
||||
/// <summary>
|
||||
/// This is the default function to use for 'Import System Modules'.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Win8: 320909. Retaining the original definition to ensure backward compatability.
|
||||
/// </remarks>
|
||||
private static string s_importSystemModulesText = @"";
|
||||
|
||||
/// <summary>
|
||||
/// This is the default function to use for clear-host. On Windows it rewrites the
|
||||
/// host, and on Linux, it delegates to the native binary, 'clear'.
|
||||
@@ -4971,8 +4963,6 @@ if($paths) {
|
||||
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd..", "Set-Location ..", isProductCode: true),
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd\\", "Set-Location \\", isProductCode: true),
|
||||
// Win8: 320909. Retaining the original definition to ensure backward compatability.
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("ImportSystemModules", s_importSystemModulesText, isProductCode: true),
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Pause",
|
||||
string.Concat("$null = Read-Host '", CodeGeneration.EscapeSingleQuotedStringContent(RunspaceInit.PauseDefinitionString),"'"), isProductCode: true)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user