X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ internal class CommandLineParameterParser

internal CommandLineParameterParser(PSHostUserInterface hostUI, string bannerText, string helpText)
{
if (hostUI == null) { throw new PSArgumentNullException("hostUI"); }
if (hostUI == null)
{
throw new PSArgumentNullException(nameof(hostUI));
}

_hostUI = hostUI;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ namespace Microsoft.PowerShell
/// to transfer control to Msh console host implementation.
/// </summary>

public static
class ConsoleShell
public static class ConsoleShell
{
/// <summary>Entry point in to ConsoleShell. This method is called by main of minishell.</summary>
/// <param name="bannerText">Banner text to be displayed by ConsoleHost.</param>
Expand Down
30 changes: 16 additions & 14 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Licensed under the MIT License.

using System;
using System.ComponentModel;
using System.Globalization;
using System.Management.Automation;
using System.Management.Automation.Internal;
using System.Management.Automation.Host;
using System.Management.Automation.Runspaces;
using System.Management.Automation.Tracing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;

Expand All @@ -27,14 +27,16 @@ public sealed class UnmanagedPSEntry
/// <param name="args">
/// Command line arguments to the managed MSH
/// </param>
/// <param name="argc" />
/// <param name="argc">
/// Length of the passed in argument array.
/// </param>
public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)]string[] args, int argc)
{
// Warm up some components concurrently on background threads.
System.Management.Automation.Runspaces.EarlyStartup.Init();
EarlyStartup.Init();

// We need to read the settings file before we create the console host
Microsoft.PowerShell.CommandLineParameterParser.EarlyParse(args);
CommandLineParameterParser.EarlyParse(args);

#if !UNIX
// NOTE: On Unix, logging has to be deferred until after command-line parsing
Expand Down Expand Up @@ -67,18 +69,18 @@ public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray
int exitCode = 0;
try
{
var banner = ManagedEntranceStrings.ShellBannerNonWindowsPowerShell;
var formattedBanner = string.Format(CultureInfo.InvariantCulture, banner, PSVersionInfo.GitCommitId);
exitCode = Microsoft.PowerShell.ConsoleShell.Start(
formattedBanner,
ManagedEntranceStrings.UsageHelp,
args);
var banner = string.Format(
CultureInfo.InvariantCulture,
ManagedEntranceStrings.ShellBannerNonWindowsPowerShell,
PSVersionInfo.GitCommitId);

exitCode = ConsoleShell.Start(banner, ManagedEntranceStrings.UsageHelp, args);
}
catch (System.Management.Automation.Host.HostException e)
catch (HostException e)
{
if (e.InnerException != null && e.InnerException.GetType() == typeof(System.ComponentModel.Win32Exception))
if (e.InnerException != null && e.InnerException.GetType() == typeof(Win32Exception))
{
System.ComponentModel.Win32Exception win32e = e.InnerException as System.ComponentModel.Win32Exception;
Win32Exception win32e = e.InnerException as Win32Exception;

// These exceptions are caused by killing conhost.exe
// 1236, network connection aborted by local system
Expand Down
20 changes: 6 additions & 14 deletions src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,15 @@ public static bool IsWindowsDesktop
}
}

/// <summary>
/// Gets the location for the various caches.
/// </summary>
internal static string CacheDirectory
{
get
{
#if UNIX
return Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE);
// Gets the location for cache and config folders.
internal static readonly string CacheDirectory = Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE);
internal static readonly string ConfigDirectory = Platform.SelectProductNameForDirectory(Platform.XDG_Type.CONFIG);
#else
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\PowerShell";
#endif
}
}
// Gets the location for cache and config folders.
internal static readonly string CacheDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\PowerShell";
internal static readonly string ConfigDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\PowerShell";

#if !UNIX
private static bool? _isNanoServer = null;
private static bool? _isIoT = null;
private static bool? _isWindowsDesktop = null;
Expand Down Expand Up @@ -355,7 +348,6 @@ public static string SelectProductNameForDirectory(Platform.XDG_Type dirpath)

return xdgCacheDefault;
}

else
{
if (!Directory.Exists(Path.Combine(xdgcachehome, "powershell")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2711,14 +2711,7 @@ private Exception ProcessUserDrive(Runspace initializedRunspace)
// Or for virtual accounts
// WinDir\System32\Microsoft\PowerShell\DriveRoots\[UserName]
string directoryName = MakeUserNamePath();
#if UNIX
string userDrivePath = Path.Combine(Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE), "DriveRoots", directoryName);
#else
string userDrivePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
@"Microsoft\PowerShell\DriveRoots",
directoryName);
#endif
string userDrivePath = Path.Combine(Platform.CacheDirectory, "DriveRoots", directoryName);

// Create directory if it doesn't exist.
if (!System.IO.Directory.Exists(userDrivePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,11 +1121,7 @@ static AnalysisCacheData()
cacheFileName = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", cacheFileName, hashString);
}

#if UNIX
s_cacheStoreLocation = Path.Combine(Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE), cacheFileName);
#else
s_cacheStoreLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\PowerShell", cacheFileName);
#endif
s_cacheStoreLocation = Path.Combine(Platform.CacheDirectory, cacheFileName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private PowerShellConfig()
// Note: This directory may or may not exist depending upon the
// execution scenario. Writes will attempt to create the directory
// if it does not already exist.
perUserConfigDirectory = Utils.GetUserConfigurationDirectory();
perUserConfigDirectory = Platform.ConfigDirectory;
perUserConfigFile = Path.Combine(perUserConfigDirectory, configFileName);
}

Expand Down
14 changes: 0 additions & 14 deletions src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,20 +458,6 @@ internal static string GetApplicationBase(string shellId)

private static string[] s_productFolderDirectories;

/// <summary>
/// Specifies the per-user configuration settings directory in a platform agnostic manner.
/// </summary>
/// <returns>The current user's configuration settings directory.</returns>
internal static string GetUserConfigurationDirectory()
{
#if UNIX
return Platform.SelectProductNameForDirectory(Platform.XDG_Type.CONFIG);
#else
string basePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
return IO.Path.Combine(basePath, Utils.ProductNameForDirectory);
#endif
}

private static string[] GetProductFolderDirectories()
{
if (s_productFolderDirectories == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ internal static string GetFullProfileFileName(string shellId, bool forCurrentUse

if (forCurrentUser)
{
basePath = Utils.GetUserConfigurationDirectory();
basePath = Platform.ConfigDirectory;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/engine/Basic/Telemetry.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Describe "Telemetry for shell startup" -Tag CI {
BeforeAll {
# if the telemetry file exists, move it out of the way
# the member is internal, but we can retrieve it via reflection
$cacheDir = [System.Management.Automation.Platform].GetMember("CacheDirectory","NonPublic,Static").GetMethod.Invoke($null, $null)
$cacheDir = [System.Management.Automation.Platform].GetField("CacheDirectory","NonPublic,Static").GetValue($null)
$uuidPath = Join-Path -Path $cacheDir -ChildPath telemetry.uuid
$uuidFileExists = Test-Path -Path $uuidPath
if ( $uuidFileExists ) {
Expand Down
2 changes: 1 addition & 1 deletion test/xUnit/csharp/test_PSConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class PowerShellPolicyFixture : IDisposable
public PowerShellPolicyFixture()
{
systemWideConfigDirectory = Utils.DefaultPowerShellAppBase;
currentUserConfigDirectory = Utils.GetUserConfigurationDirectory();
currentUserConfigDirectory = Platform.ConfigDirectory;

if (!Directory.Exists(currentUserConfigDirectory))
{
Expand Down
X Tutup