mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Expose Platform API from SMA and uses that in NuGetProvider
This commit is contained in:
1 parent
a8ad5aa068
commit
54784cb77a
2 files changed
+37
-2
No files matched your search
@@ -171,6 +171,10 @@
|
||||
// or $env:programfiles\NuGet\Packages\ if you are an admin.
|
||||
try
|
||||
{
|
||||
#if LINUX
|
||||
// there is only 1 installation location by default for linux ("HOME/.local/share/powershell/PackageManagement/NuGet/Packages")
|
||||
string basePath = CurrentUserDefaultInstallLocation;
|
||||
#else
|
||||
var scope = (Scope == null) ? null : Scope.Value;
|
||||
scope = string.IsNullOrWhiteSpace(scope) ? Constants.AllUsers : scope;
|
||||
string basePath;
|
||||
@@ -192,6 +196,7 @@
|
||||
Constants.Messages.InstallRequiresCurrentUserScopeParameterForNonAdminUser, AllUserDefaultInstallLocation, CurrentUserDefaultInstallLocation);
|
||||
return string.Empty;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!Directory.Exists(basePath))
|
||||
{
|
||||
@@ -215,7 +220,11 @@
|
||||
get
|
||||
{
|
||||
#if CORECLR
|
||||
#if LINUX
|
||||
return Path.Combine(Platform.SelectProductNameForDirectory(Platform.XDG_Type.POWERSHELL), "PackageManagement", "NuGet", "Packages");
|
||||
#else
|
||||
return Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), "PackageManagement", "NuGet", "Packages");
|
||||
#endif
|
||||
#else
|
||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "PackageManagement", "NuGet", "Packages");
|
||||
#endif
|
||||
@@ -228,7 +237,11 @@
|
||||
get
|
||||
{
|
||||
#if CORECLR
|
||||
#if LINUX
|
||||
return Path.Combine(Platform.SelectProductNameForDirectory(Platform.XDG_Type.POWERSHELL), "PackageManagement", "NuGet", "Packages");
|
||||
#else
|
||||
return Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "NuGet", "Packages");
|
||||
#endif
|
||||
#else
|
||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "NuGet", "Packages");
|
||||
#endif
|
||||
@@ -1289,7 +1302,11 @@
|
||||
}
|
||||
|
||||
} else {
|
||||
#if LINUX
|
||||
var appdataFolder = Platform.SelectProductNameForDirectory(Platform.XDG_Type.PROFILE);
|
||||
#else
|
||||
var appdataFolder = Environment.GetEnvironmentVariable("appdata");
|
||||
#endif
|
||||
_configurationFileLocation = Path.Combine(appdataFolder, "NuGet", NuGetConstant.SettingsFileName);
|
||||
|
||||
//create directory if does not exist
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace System.Management.Automation
|
||||
/// All these properties are calling into platform specific static classes, to make
|
||||
/// sure the platform implementations are switched at runtime (including pinvokes).
|
||||
/// </summary>
|
||||
internal static class Platform
|
||||
public static class Platform
|
||||
{
|
||||
|
||||
// Platform variables used to defined corresponding PowerShell built-in variables
|
||||
@@ -50,6 +50,7 @@ namespace System.Management.Automation
|
||||
PROFILE,
|
||||
MODULES,
|
||||
CACHE,
|
||||
POWERSHELL,
|
||||
DEFAULT
|
||||
}
|
||||
|
||||
@@ -115,7 +116,8 @@ namespace System.Management.Automation
|
||||
string xdgdatahome = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||
string xdgcachehome = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
|
||||
string xdgConfigHomeDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config", "powershell");
|
||||
string xdgModuleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".local", "share", "powershell", "Modules");
|
||||
string xdgPowerShellDefault = Path.Combine( System.Environment.GetEnvironmentVariable("HOME"), ".local", "share", "powershell");
|
||||
string xdgModuleDefault = Path.Combine ( xdgPowerShellDefault, "Modules");
|
||||
string xdgCacheDefault = Path.Combine (System.Environment.GetEnvironmentVariable("HOME"), ".cache", "powershell");
|
||||
|
||||
switch (dirpath){
|
||||
@@ -132,6 +134,22 @@ namespace System.Management.Automation
|
||||
return Path.Combine(xdgconfighome, "powershell");
|
||||
}
|
||||
|
||||
case Platform.XDG_Type.POWERSHELL:
|
||||
//the user has set XDG_DATA_HOME corresponding to module path
|
||||
if (String.IsNullOrEmpty(xdgdatahome)){
|
||||
|
||||
// create the xdg folder if needed
|
||||
if (!Directory.Exists(xdgPowerShellDefault))
|
||||
{
|
||||
Directory.CreateDirectory(xdgPowerShellDefault);
|
||||
}
|
||||
return xdgPowerShellDefault;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Path.Combine(xdgdatahome, "powershell");
|
||||
}
|
||||
|
||||
case Platform.XDG_Type.MODULES:
|
||||
//the user has set XDG_DATA_HOME corresponding to module path
|
||||
if (String.IsNullOrEmpty(xdgdatahome)){
|
||||
|
||||
Reference in new issue
Block a user