Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Switch to use CoreLib Path class. (#13920)
Browse files Browse the repository at this point in the history
Leaving the code for UAP for now- we may end up needing to keep it.
(Notably for the Crypto)

Use the core environment variable code.
  • Loading branch information
JeremyKuhne committed Dec 10, 2016
1 parent a9926a6 commit 227c654
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 461 deletions.
62 changes: 61 additions & 1 deletion src/System.Runtime.Extensions/System.Runtime.Extensions.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Extensions", "src\System.Runtime.Extensions.csproj", "{845D2B72-D8A4-42E5-9BE9-17639EC4FC1A}"
EndProject
Expand Down Expand Up @@ -135,6 +135,66 @@ Global
{9F312D76-9AF1-4E90-B3B0-815A1EC6C346}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU
{9F312D76-9AF1-4E90-B3B0-815A1EC6C346}.Windows_Release|Any CPU.ActiveCfg = Release|Any CPU
{9F312D76-9AF1-4E90-B3B0-815A1EC6C346}.Windows_Release|Any CPU.Build.0 = Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.net46_Debug|Any CPU.ActiveCfg = net46_Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.net46_Debug|Any CPU.Build.0 = net46_Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.net46_Release|Any CPU.ActiveCfg = net46_Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.net46_Release|Any CPU.Build.0 = net46_Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.netstandard1.7_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.netstandard1.7_Debug|Any CPU.Build.0 = Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.netstandard1.7_Release|Any CPU.ActiveCfg = Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.netstandard1.7_Release|Any CPU.Build.0 = Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Release|Any CPU.Build.0 = Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Unix_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Unix_Debug|Any CPU.Build.0 = Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Unix_Release|Any CPU.ActiveCfg = Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Unix_Release|Any CPU.Build.0 = Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Windows_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Windows_Release|Any CPU.ActiveCfg = Release|Any CPU
{24BCEC6B-B9D2-47BC-9D66-725BD6B526FA}.Windows_Release|Any CPU.Build.0 = Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.net46_Debug|Any CPU.ActiveCfg = net46_Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.net46_Debug|Any CPU.Build.0 = net46_Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.net46_Release|Any CPU.ActiveCfg = net46_Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.net46_Release|Any CPU.Build.0 = net46_Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.netstandard1.7_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.netstandard1.7_Debug|Any CPU.Build.0 = Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.netstandard1.7_Release|Any CPU.ActiveCfg = Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.netstandard1.7_Release|Any CPU.Build.0 = Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Release|Any CPU.Build.0 = Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Unix_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Unix_Debug|Any CPU.Build.0 = Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Unix_Release|Any CPU.ActiveCfg = Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Unix_Release|Any CPU.Build.0 = Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Windows_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Windows_Release|Any CPU.ActiveCfg = Release|Any CPU
{AD83807C-8BE5-4F27-85DF-9793613233E1}.Windows_Release|Any CPU.Build.0 = Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.net46_Debug|Any CPU.ActiveCfg = net46_Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.net46_Debug|Any CPU.Build.0 = net46_Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.net46_Release|Any CPU.ActiveCfg = net46_Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.net46_Release|Any CPU.Build.0 = net46_Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.netstandard1.7_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.netstandard1.7_Debug|Any CPU.Build.0 = Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.netstandard1.7_Release|Any CPU.ActiveCfg = Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.netstandard1.7_Release|Any CPU.Build.0 = Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Release|Any CPU.Build.0 = Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Unix_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Unix_Debug|Any CPU.Build.0 = Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Unix_Release|Any CPU.ActiveCfg = Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Unix_Release|Any CPU.Build.0 = Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Windows_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Windows_Debug|Any CPU.Build.0 = Debug|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Windows_Release|Any CPU.ActiveCfg = Release|Any CPU
{C44B33E3-F89F-40B9-B353-D380C1524988}.Windows_Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
44 changes: 20 additions & 24 deletions src/System.Runtime.Extensions/src/System.Runtime.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@
<Compile Include="System\Environment.cs" />
<Compile Include="System\Environment.SpecialFolder.cs" />
<Compile Include="System\Environment.SpecialFolderOption.cs" />
<Compile Include="System\EnvironmentVariableTarget.cs" />
<Compile Include="System\LoaderOptimization.cs" />
<Compile Include="System\LoaderOptimizationAttribute.cs" />
<Compile Include="System\OperatingSystem.cs" />
<Compile Include="System\PlatformID.cs" />
<Compile Include="System\CodeDom\Compiler\IndentedTextWriter.cs" />
<Compile Include="System\IO\Path.cs" />
<Compile Include="System\IO\EncodingCache.cs" />
<Compile Include="System\IO\StreamReader.cs" />
<Compile Include="System\IO\StreamWriter.cs" />
Expand Down Expand Up @@ -140,8 +138,6 @@
<Compile Include="System\Environment.Windows.cs" />
<Compile Include="System\Runtime\Versioning\VersioningHelper.Windows.cs" />
<Compile Include="System\Diagnostics\Stopwatch.Windows.cs" />
<Compile Include="System\IO\Path.Windows.cs" />
<Compile Include="System\IO\PathHelper.Windows.cs" />
<Compile Include="$(CommonPath)\System\IO\Win32Marshal.cs">
<Link>Common\System\IO\Win32Marshal.cs</Link>
</Compile>
Expand All @@ -160,15 +156,9 @@
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.GetCurrentDirectory.cs">
<Link>Common\Interop\Windows\kernel32\Interop.GetCurrentDirectory.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.GetFullPathNameW.cs">
<Link>Common\Interop\Windows\kernel32\Interop.GetFullPathNameW.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.GetLongPathName.cs">
<Link>Common\Interop\Windows\kernel32\Interop.GetLongPathName.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.GetLongPathNameW.cs">
<Link>Common\Interop\Windows\kernel32\Interop.GetLongPathNameW.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.GetSystemInfo.cs">
<Link>Common\Interop\Windows\kernel32\Interop.GetSystemInfo.cs</Link>
</Compile>
Expand Down Expand Up @@ -196,20 +186,14 @@
<Compile Include="$(CommonPath)\System\IO\PathInternal.Windows.cs">
<Link>Common\System\IO\PathInternal.Windows.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\IO\PathInternal.Windows.StringBuffer.cs">
<Link>Common\System\IO\PathInternal.Windows.StringBuffer.cs</Link>
</Compile>
</ItemGroup>
<!-- Win32 or Unix -->
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or ('$(TargetsWindows)' == 'true' and '$(TargetGroup)' != 'net462' and '$(TargetGroup)' != 'net463' and '$(TargetsWindowsUap)' != 'true')">
<Compile Include="System\Environment.Win32.Unix.cs" />
</ItemGroup>
<!-- WINDOWS: Win32 -->
<ItemGroup Condition="'$(TargetsWindows)' == 'true' And '$(TargetGroup)' != 'net462' And '$(TargetGroup)' != 'net463' and '$(TargetsWindowsUap)' != 'true'">
<ItemGroup Condition="'$(TargetsWindows)' == 'true' and '$(TargetGroup)' != 'net462' and '$(TargetGroup)' != 'net463' and '$(TargetsWindowsUap)' != 'true'">
<Compile Include="System\Environment.Win32.cs" />
<Compile Include="System\IO\Path.Win32.cs" />
<Compile Include="$(CommonPath)\Interop\Windows\BCrypt\Interop.BCryptGenRandom.cs">
<Link>Common\Interop\Windows\BCrypt\Interop.BCryptGenRandom.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\BCrypt\Interop.NTSTATUS.cs">
<Link>Common\Interop\Windows\BCrypt\Interop.NTSTATUS.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.EnvironmentVariables.cs">
<Link>Common\Interop\Windows\kernel32\Interop.EnvironmentVariables.cs</Link>
</Compile>
Expand Down Expand Up @@ -334,7 +318,6 @@
<Compile Include="System\Environment.Unix.cs" />
<Compile Include="System\Runtime\Versioning\VersioningHelper.Unix.cs" />
<Compile Include="System\Diagnostics\Stopwatch.Unix.cs" />
<Compile Include="System\IO\Path.Unix.cs" />
<Compile Include="$(CommonPath)\Interop\OSX\Interop.Libraries.cs">
<Link>Common\Interop\OSX\Interop.Libraries.cs</Link>
</Compile>
Expand Down Expand Up @@ -420,12 +403,25 @@
<!-- WINDOWS: UAP -->
<ItemGroup Condition="'$(TargetsWindowsUap)' == 'true'">
<Compile Include="System\Environment.Uap.cs" />
<Compile Include="System\EnvironmentVariableTarget.cs" />
<Compile Include="System\IO\Path.cs" />
<Compile Include="System\IO\Path.Windows.cs" />
<Compile Include="System\IO\PathHelper.Windows.cs" />
<Compile Include="System\IO\Path.Uap.cs" />
<Compile Include="$(CommonPath)\System\IO\PathInternal.Windows.StringBuffer.cs">
<Link>Common\System\IO\PathInternal.Windows.StringBuffer.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.GetFullPathNameW.cs">
<Link>Common\Interop\Windows\kernel32\Interop.GetFullPathNameW.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.GetLongPathNameW.cs">
<Link>Common\Interop\Windows\kernel32\Interop.GetLongPathNameW.cs</Link>
</Compile>
<Compile Include="System\IO\BinaryReader.cs" />
<Compile Include="System\IO\BinaryWriter.cs" />
<Compile Include="System\IO\FileStreamHelpers.Uap.cs" />
<Compile Include="System\IO\EndOfStreamException.cs" />
<Compile Include="System\IO\MemoryStream.cs" />
<Compile Include="System\IO\Path.Uap.cs" />
<Compile Include="$(CommonPath)\System\SystemException.cs" />
<Compile Include="System\Net\Configuration\UnicodeDecodingConformance.cs" />
<Compile Include="System\Net\Configuration\UnicodeEncodingConformance.cs" />
Expand Down Expand Up @@ -472,4 +468,4 @@
<None Include="project.json" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>
99 changes: 99 additions & 0 deletions src/System.Runtime.Extensions/src/System/Environment.Uap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,104 @@ private static void SetEnvironmentVariableCore(string variable, string value, En
public static string UserName { get { throw new PlatformNotSupportedException(); } }

public static string UserDomainName { get { throw new PlatformNotSupportedException(); } }


public static string GetEnvironmentVariable(string variable)
{
if (variable == null)
{
throw new ArgumentNullException(nameof(variable));
}

// separated from the EnvironmentVariableTarget overload to help with tree shaking in common case
return GetEnvironmentVariableCore(variable);
}

public static string GetEnvironmentVariable(string variable, EnvironmentVariableTarget target)
{
if (variable == null)
{
throw new ArgumentNullException(nameof(variable));
}

ValidateTarget(target);

return GetEnvironmentVariableCore(variable, target);
}

public static IDictionary GetEnvironmentVariables()
{
// separated from the EnvironmentVariableTarget overload to help with tree shaking in common case
return GetEnvironmentVariablesCore();
}

public static IDictionary GetEnvironmentVariables(EnvironmentVariableTarget target)
{
ValidateTarget(target);

return GetEnvironmentVariablesCore(target);
}

public static void SetEnvironmentVariable(string variable, string value)
{
ValidateVariableAndValue(variable, ref value);

// separated from the EnvironmentVariableTarget overload to help with tree shaking in common case
SetEnvironmentVariableCore(variable, value);
}

public static void SetEnvironmentVariable(string variable, string value, EnvironmentVariableTarget target)
{
ValidateVariableAndValue(variable, ref value);
ValidateTarget(target);

SetEnvironmentVariableCore(variable, value, target);
}

private static void ValidateVariableAndValue(string variable, ref string value)
{
const int MaxEnvVariableValueLength = 32767;

if (variable == null)
{
throw new ArgumentNullException(nameof(variable));
}
if (variable.Length == 0)
{
throw new ArgumentException(SR.Argument_StringZeroLength, nameof(variable));
}
if (variable[0] == '\0')
{
throw new ArgumentException(SR.Argument_StringFirstCharIsZero, nameof(variable));
}
if (variable.Length >= MaxEnvVariableValueLength)
{
throw new ArgumentException(SR.Argument_LongEnvVarValue, nameof(variable));
}
if (variable.IndexOf('=') != -1)
{
throw new ArgumentException(SR.Argument_IllegalEnvVarName, nameof(variable));
}

if (string.IsNullOrEmpty(value) || value[0] == '\0')
{
// Explicitly null out value if it's empty
value = null;
}
else if (value.Length >= MaxEnvVariableValueLength)
{
throw new ArgumentException(SR.Argument_LongEnvVarValue, nameof(value));
}
}

private static void ValidateTarget(EnvironmentVariableTarget target)
{
if (target != EnvironmentVariableTarget.Process &&
target != EnvironmentVariableTarget.Machine &&
target != EnvironmentVariableTarget.User)
{
throw new ArgumentOutOfRangeException(nameof(target), target, SR.Format(SR.Arg_EnumIllegalVal, target));
}
}
}
}
Loading

0 comments on commit 227c654

Please sign in to comment.