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
Move TimeZoneInfo.Win32.cs to shared CoreLib partition (#15953)
Browse files Browse the repository at this point in the history
Reconcile deltas with CoreRT and refactor interop to follow coding conventions

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
  • Loading branch information
jkotas authored and dotnet-bot committed Jan 22, 2018
1 parent c955510 commit 946e04b
Show file tree
Hide file tree
Showing 5 changed files with 1,146 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Common/src/CoreLib/Interop/Windows/Kernel32/Interop.MUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;
using System.Text;

internal static partial class Interop
{
internal static partial class Kernel32
{
internal const uint MUI_PREFERRED_UI_LANGUAGES = 0x10;

[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
internal static extern bool GetFileMUIPath(uint flags, String filePath, [Out] StringBuilder language, ref int languageLength, [Out] StringBuilder fileMuiPath, ref int fileMuiPathLength, ref Int64 enumerator);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Kernel32
{
[StructLayout(LayoutKind.Sequential)]
internal struct REG_TZI_FORMAT
{
internal int Bias;
internal int StandardBias;
internal int DaylightBias;
internal SYSTEMTIME StandardDate;
internal SYSTEMTIME DaylightDate;

internal REG_TZI_FORMAT(in TIME_ZONE_INFORMATION tzi)
{
Bias = tzi.Bias;
StandardDate = tzi.StandardDate;
StandardBias = tzi.StandardBias;
DaylightDate = tzi.DaylightDate;
DaylightBias = tzi.DaylightBias;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class Kernel32
{
internal struct SYSTEMTIME
{
internal ushort Year;
internal ushort Month;
internal ushort DayOfWeek;
internal ushort Day;
internal ushort Hour;
internal ushort Minute;
internal ushort Second;
internal ushort Milliseconds;

internal bool Equals(in SYSTEMTIME other) =>
Year == other.Year &&
Month == other.Month &&
DayOfWeek == other.DayOfWeek &&
Day == other.Day &&
Hour == other.Hour &&
Minute == other.Minute &&
Second == other.Second &&
Milliseconds == other.Milliseconds;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal unsafe struct TIME_DYNAMIC_ZONE_INFORMATION
{
internal int Bias;
internal fixed char StandardName[32];
internal SYSTEMTIME StandardDate;
internal int StandardBias;
internal fixed char DaylightName[32];
internal SYSTEMTIME DaylightDate;
internal int DaylightBias;
internal fixed char TimeZoneKeyName[128];
internal byte DynamicDaylightTimeDisabled;

internal string GetTimeZoneKeyName()
{
fixed (char* p = TimeZoneKeyName)
return new string(p);
}
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal unsafe struct TIME_ZONE_INFORMATION
{
internal int Bias;
internal fixed char StandardName[32];
internal SYSTEMTIME StandardDate;
internal int StandardBias;
internal fixed char DaylightName[32];
internal SYSTEMTIME DaylightDate;
internal int DaylightBias;

internal TIME_ZONE_INFORMATION(in TIME_DYNAMIC_ZONE_INFORMATION dtzi)
{
// The start of TIME_DYNAMIC_ZONE_INFORMATION has identical layout as TIME_ZONE_INFORMATION
fixed (TIME_ZONE_INFORMATION* pTo = &this)
fixed (TIME_DYNAMIC_ZONE_INFORMATION* pFrom = &dtzi)
*pTo = *(TIME_ZONE_INFORMATION*)pFrom;
}

internal string GetStandardName()
{
fixed (char* p = StandardName)
return new string(p);
}

internal string GetDaylightName()
{
fixed (char* p = DaylightName)
return new string(p);
}
}

internal const uint TIME_ZONE_ID_INVALID = unchecked((uint)-1);

[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
internal extern static uint GetDynamicTimeZoneInformation(out TIME_DYNAMIC_ZONE_INFORMATION pTimeZoneInformation);

[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
internal static extern uint GetTimeZoneInformation(out TIME_ZONE_INFORMATION lpTimeZoneInformation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.WriteFile_SafeHandle_NativeOverlapped.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Normaliz\Interop.Idna.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Normaliz\Interop.Normalization.cs" Condition="'$(EnableDummyGlobalizationImplementation)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.TimeZone.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysAllocStringLen.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysFreeString.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\OleAut32\Interop.SysStringLen.cs" />
Expand All @@ -682,10 +683,13 @@
</ItemGroup>
<ItemGroup Condition="$(TargetsWindows) and '$(EnableWinRT)' != 'true'">
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Win32.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Win32.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeLibraryHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FreeLibrary.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CreateFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MUI.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.TimeZone.Registry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.Constants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.SendMessageTimeout.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.LoadString.cs" />
Expand Down
Loading

0 comments on commit 946e04b

Please sign in to comment.