Skip to content

Commit

Permalink
ICU-13842 Use GetDynamicTimeZoneInformation instead of Windows regist…
Browse files Browse the repository at this point in the history
…ry access in wintz.cpp (unicode-org#55)

Use GetDynamicTimeZoneInformation instead of accessing the Windows registries so that it does not rely on COM in wintz. So that UWP apps could also use this code.
  • Loading branch information
mingyzha authored Aug 23, 2018
1 parent f9ecf70 commit a3f8fc6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 361 deletions.
4 changes: 1 addition & 3 deletions icu4c/source/common/common_uwp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,7 @@
<ClCompile Include="umutex.cpp" />
<ClCompile Include="utrace.cpp" />
<ClCompile Include="utypes.cpp" />
<ClCompile Include="wintz.cpp">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="wintz.cpp" />
<ClCompile Include="ucnv.cpp" />
<ClCompile Include="ucnv2022.cpp" />
<ClCompile Include="ucnv_bld.cpp" />
Expand Down
43 changes: 1 addition & 42 deletions icu4c/source/common/putil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@
# define NOMCX
# include <windows.h>
# include "unicode/uloc.h"
#if U_PLATFORM_HAS_WINUWP_API == 0
# include "wintz.h"
#else // U_PLATFORM_HAS_WINUWP_API
#if U_PLATFORM_HAS_WINUWP_API
typedef PVOID LPMSG; // TODO: figure out how to get rid of this typedef
#include <Windows.Globalization.h>
#include <windows.system.userprofile.h>
Expand Down Expand Up @@ -1062,53 +1061,13 @@ uprv_tzname_clear_cache()
#endif
}

// With the Universal Windows Platform we can just ask Windows for the name
#if U_PLATFORM_HAS_WINUWP_API
U_CAPI const char* U_EXPORT2
uprv_getWindowsTimeZone()
{
// Get default Windows timezone.
ComPtr<IInspectable> calendar;
HRESULT hr = RoActivateInstance(
HStringReference(RuntimeClass_Windows_Globalization_Calendar).Get(),
&calendar);
if (SUCCEEDED(hr))
{
ComPtr<ABI::Windows::Globalization::ITimeZoneOnCalendar> timezone;
hr = calendar.As(&timezone);
if (SUCCEEDED(hr))
{
HString timezoneString;
hr = timezone->GetTimeZone(timezoneString.GetAddressOf());
if (SUCCEEDED(hr))
{
int32_t length = static_cast<int32_t>(wcslen(timezoneString.GetRawBuffer(NULL)));
char* asciiId = (char*)uprv_calloc(length + 1, sizeof(char));
if (asciiId != nullptr)
{
u_UCharsToChars((UChar*)timezoneString.GetRawBuffer(NULL), asciiId, length);
return asciiId;
}
}
}
}

// Failed
return nullptr;
}
#endif

U_CAPI const char* U_EXPORT2
uprv_tzname(int n)
{
(void)n; // Avoid unreferenced parameter warning.
const char *tzid = NULL;
#if U_PLATFORM_USES_ONLY_WIN32_API
#if U_PLATFORM_HAS_WINUWP_API > 0
tzid = uprv_getWindowsTimeZone();
#else
tzid = uprv_detectWindowsTimeZone();
#endif

if (tzid != NULL) {
return tzid;
Expand Down
Loading

0 comments on commit a3f8fc6

Please sign in to comment.