| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7569,8 +7569,7 @@ private static Encoding GetEncodingFromEnum(FileSystemCmdletProviderEncoding typ | |||
| 7569 | 7569 | ||
| 7570 | 7570 | case FileSystemCmdletProviderEncoding.Oem: | |
| 7571 | 7571 | { | |
| 7572 | - uint oemCP = NativeMethods.GetOEMCP(); | ||
| 7573 | - encoding = System.Text.Encoding.GetEncoding((int)oemCP); | ||
| 7572 | + encoding = ClrFacade.GetOEMEncoding(); | ||
| 7574 | 7573 | } | |
| 7575 | 7574 | break; | |
| 7576 | 7575 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -530,17 +530,26 @@ internal static object[] GetCustomAttributes<T>(Assembly assembly) | |||
| 530 | 530 | #region Encoding | |
| 531 | 531 | ||
| 532 | 532 | /// <summary> | |
| 533 | - /// Facade for Encoding.Default | ||
| 533 | + /// Facade for getting Encoding.Default | ||
| 534 | 534 | /// </summary> | |
| 535 | 535 | internal static Encoding GetDefaultEncoding() | |
| 536 | 536 | { | |
| 537 | 537 | if (s_defaultEncoding == null) | |
| 538 | 538 | { | |
| 539 | - #if CORECLR // Encoding.Default is not in CoreCLR | ||
| 540 | - // As suggested by CoreCLR team (tarekms), use latin1 (ISO-8859-1, CodePage 28591) as the default encoding. | ||
| 541 | - // We will revisit this if it causes any failures when running tests on Core PS. | ||
| 542 | - s_defaultEncoding = Encoding.GetEncoding(28591); | ||
| 543 | - #else | ||
| 539 | + #if CORECLR | ||
| 540 | + | ||
| 541 | + #if UNUX // PowerShell Core on Unix | ||
| 542 | + s_defaultEncoding = Encoding.GetEncoding(65001); | ||
| 543 | + #else // PowerShell Core on Windows | ||
| 544 | + uint aCp = NativeMethods.GetACP(); | ||
| 545 | + if (s_oemEncoding == null) | ||
| 546 | + { | ||
| 547 | + Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); | ||
| 548 | + } | ||
| 549 | + s_defaultEncoding = Encoding.GetEncoding((int)aCp); | ||
| 550 | + #endif | ||
| 551 | + | ||
| 552 | + #else // Windows PowerShell | ||
| 544 | 553 | s_defaultEncoding = Encoding.Default; | |
| 545 | 554 | #endif | |
| 546 | 555 | } | |
@@ -555,10 +564,20 @@ internal static Encoding GetOEMEncoding() | |||
| 555 | 564 | { | |
| 556 | 565 | if (s_oemEncoding == null) | |
| 557 | 566 | { | |
| 558 | - #if CORECLR // The OEM code page '437' is not supported by CoreCLR. | ||
| 559 | - // Use the default encoding (ISO-8859-1, CodePage 28591) as the OEM encoding in OneCore powershell. | ||
| 567 | + #if CORECLR | ||
| 568 | + | ||
| 569 | + #if UNUX // PowerShell Core on Unix | ||
| 560 | 570 | s_oemEncoding = GetDefaultEncoding(); | |
| 561 | - #else | ||
| 571 | + #else // PowerShell Core on Windows | ||
| 572 | + uint oemCp = NativeMethods.GetOEMCP(); | ||
| 573 | + if (s_defaultEncoding == null) | ||
| 574 | + { | ||
| 575 | + Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); | ||
| 576 | + } | ||
| 577 | + s_oemEncoding = Encoding.GetEncoding((int)oemCp); | ||
| 578 | + #endif | ||
| 579 | + | ||
| 580 | + #else // Windows PowerShell | ||
| 562 | 581 | uint oemCp = NativeMethods.GetOEMCP(); | |
| 563 | 582 | s_oemEncoding = Encoding.GetEncoding((int)oemCp); | |
| 564 | 583 | #endif | |
@@ -1033,6 +1052,12 @@ private static class NativeMethods | |||
| 1033 | 1052 | [DllImport(PinvokeDllNames.GetOEMCPDllName, SetLastError = false, CharSet = CharSet.Unicode)] | |
| 1034 | 1053 | internal static extern uint GetOEMCP(); | |
| 1035 | 1054 | ||
| 1055 | + /// <summary> | ||
| 1056 | + /// Pinvoke for GetACP to get the Windows operating system code page. | ||
| 1057 | + /// </summary> | ||
| 1058 | + [DllImport(PinvokeDllNames.GetACPDllName, SetLastError = false, CharSet = CharSet.Unicode)] | ||
| 1059 | + internal static extern uint GetACP(); | ||
| 1060 | + | ||
| 1036 | 1061 | public const int S_OK = 0x00000000; | |
| 1037 | 1062 | ||
| 1038 | 1063 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ internal static class PinvokeDllNames | |||
| 17 | 17 | internal const string QueryDosDeviceDllName = "api-ms-win-core-file-l1-1-0.dll"; /*1*/ | |
| 18 | 18 | internal const string CreateSymbolicLinkDllName = "api-ms-win-core-file-l2-1-0.dll"; /*2*/ | |
| 19 | 19 | internal const string GetOEMCPDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*3*/ | |
| 20 | + internal const string GetACPDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*3*/ | ||
| 20 | 21 | internal const string DeviceIoControlDllName = "api-ms-win-core-io-l1-1-0.dll"; /*4*/ | |
| 21 | 22 | internal const string CreateFileDllName = "api-ms-win-core-file-l1-1-0.dll"; /*5*/ | |
| 22 | 23 | internal const string DeleteFileDllName = "api-ms-win-core-file-l1-1-0.dll"; /*6*/ | |
@@ -139,6 +140,7 @@ internal static class PinvokeDllNames | |||
| 139 | 140 | internal const string QueryDosDeviceDllName = "kernel32.dll"; /*1*/ | |
| 140 | 141 | internal const string CreateSymbolicLinkDllName = "kernel32.dll"; /*2*/ | |
| 141 | 142 | internal const string GetOEMCPDllName = "kernel32.dll"; /*3*/ | |
| 143 | + internal const string GetACPDllName = "kernel32.dll"; /*3*/ | ||
| 142 | 144 | internal const string DeviceIoControlDllName = "kernel32.dll"; /*4*/ | |
| 143 | 145 | internal const string CreateFileDllName = "kernel32.dll"; /*5*/ | |
| 144 | 146 | internal const string DeleteFileDllName = "kernel32.dll"; /*6*/ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments