39
39
#if TARGET_OS_WIN32
40
40
#include <tchar.h>
41
41
42
- #include "WindowsResources .h"
42
+ #include "CFTimeZone_WindowsMapping .h"
43
43
#define NOMINMAX
44
44
#define WIN32_LEAN_AND_MEAN
45
45
#include "Windows.h"
@@ -92,11 +92,6 @@ static CFArrayRef __CFKnownTimeZoneList = NULL;
92
92
static CFMutableDictionaryRef __CFTimeZoneCache = NULL ;
93
93
static CFLock_t __CFTimeZoneGlobalLock = CFLockInit ;
94
94
95
- #if TARGET_OS_WIN32
96
- static CFDictionaryRef __CFTimeZoneWinToOlsonDict = NULL ;
97
- static CFLock_t __CFTimeZoneWinToOlsonLock = CFLockInit ;
98
- #endif
99
-
100
95
CF_INLINE void __CFTimeZoneLockGlobal (void ) {
101
96
__CFLock (& __CFTimeZoneGlobalLock );
102
97
}
@@ -672,110 +667,7 @@ CFTypeID CFTimeZoneGetTypeID(void) {
672
667
return _kCFRuntimeIDCFTimeZone ;
673
668
}
674
669
675
- #if TARGET_OS_WIN32
676
- CF_INLINE void __CFTimeZoneLockWinToOlson (void ) {
677
- __CFLock (& __CFTimeZoneWinToOlsonLock );
678
- }
679
-
680
- CF_INLINE void __CFTimeZoneUnlockWinToOlson (void ) {
681
- __CFUnlock (& __CFTimeZoneWinToOlsonLock );
682
- }
683
-
684
- static Boolean CFTimeZoneLoadPlistResource (LPCSTR lpName , LPVOID * ppResource , LPDWORD pdwSize ) {
685
- HRSRC hResource ;
686
- HGLOBAL hMemory ;
687
- HMODULE hModule ;
688
-
689
- if (!GetModuleHandleExW (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT ,
690
- (LPCWSTR )& CFTimeZoneLoadPlistResource , & hModule )) {
691
- return FALSE;
692
- }
693
-
694
- hResource = FindResourceA (hModule , lpName , "PLIST" );
695
- if (hResource == NULL ) {
696
- return FALSE;
697
- }
698
-
699
- hMemory = LoadResource (hModule , hResource );
700
- if (hMemory == NULL ) {
701
- return FALSE;
702
- }
703
-
704
- * pdwSize = SizeofResource (hModule , hResource );
705
- * ppResource = LockResource (hMemory );
706
-
707
- return * pdwSize && * ppResource ;
708
- }
709
-
710
- CFDictionaryRef CFTimeZoneCopyWinToOlsonDictionary (void ) {
711
- CFDictionaryRef dict ;
712
-
713
- __CFTimeZoneLockWinToOlson ();
714
- if (NULL == __CFTimeZoneWinToOlsonDict ) {
715
- const uint8_t * plist ;
716
- DWORD dwSize ;
717
-
718
- if (CFTimeZoneLoadPlistResource (MAKEINTRESOURCEA (IDR_WINDOWS_OLSON_MAPPING ), (LPVOID * )& plist , & dwSize )) {
719
- CFDataRef data = CFDataCreate (kCFAllocatorSystemDefault , plist , dwSize );
720
- __CFTimeZoneWinToOlsonDict = (CFDictionaryRef )CFPropertyListCreateFromXMLData (kCFAllocatorSystemDefault , data , kCFPropertyListImmutable , NULL );
721
- CFRelease (data );
722
- }
723
- }
724
- if (NULL == __CFTimeZoneWinToOlsonDict ) {
725
- __CFTimeZoneWinToOlsonDict = CFDictionaryCreate (kCFAllocatorSystemDefault , NULL , NULL , 0 , NULL , NULL );
726
- }
727
- dict = __CFTimeZoneWinToOlsonDict ? (CFDictionaryRef )CFRetain (__CFTimeZoneWinToOlsonDict ) : NULL ;
728
- __CFTimeZoneUnlockWinToOlson ();
729
-
730
- return dict ;
731
- }
732
-
733
- static CFDictionaryRef CFTimeZoneCopyOlsonToWindowsDictionary (void ) {
734
- static CFDictionaryRef dict ;
735
- static CFLock_t lock ;
736
-
737
- __CFLock (& lock );
738
- if (dict == NULL ) {
739
- const uint8_t * plist ;
740
- DWORD dwSize ;
741
-
742
- if (CFTimeZoneLoadPlistResource (MAKEINTRESOURCEA (IDR_OLSON_WINDOWS_MAPPING ), (LPVOID * )& plist , & dwSize )) {
743
- CFDataRef data = CFDataCreateWithBytesNoCopy (kCFAllocatorSystemDefault , plist , dwSize , kCFAllocatorNull );
744
- dict = CFPropertyListCreateFromXMLData (kCFAllocatorSystemDefault , data , kCFPropertyListImmutable , NULL );
745
- CFRelease (data );
746
- }
747
- }
748
- __CFUnlock (& lock );
749
-
750
- return dict ? CFRetain (dict ) : NULL ;
751
- }
752
-
753
- void CFTimeZoneSetWinToOlsonDictionary (CFDictionaryRef dict ) {
754
- __CFGenericValidateType (dict , CFDictionaryGetTypeID ());
755
- __CFTimeZoneLockWinToOlson ();
756
- if (dict != __CFTimeZoneWinToOlsonDict ) {
757
- CFDictionaryRef oldDict = __CFTimeZoneWinToOlsonDict ;
758
- __CFTimeZoneWinToOlsonDict = dict ? CFRetain (dict ) : NULL ;
759
- CFRelease (oldDict );
760
- }
761
- __CFTimeZoneUnlockWinToOlson ();
762
- }
763
-
764
- CFTimeZoneRef CFTimeZoneCreateWithWindowsName (CFAllocatorRef allocator , CFStringRef winName ) {
765
- if (!winName ) return NULL ;
766
-
767
- CFDictionaryRef winToOlson = CFTimeZoneCopyWinToOlsonDictionary ();
768
- if (!winToOlson ) return NULL ;
769
-
770
- CFStringRef olsonName = CFDictionaryGetValue (winToOlson , winName );
771
- CFTimeZoneRef retval = NULL ;
772
- if (olsonName ) {
773
- retval = CFTimeZoneCreateWithName (allocator , olsonName , false);
774
- }
775
- CFRelease (winToOlson );
776
- return retval ;
777
- }
778
- #elif TARGET_OS_MAC
670
+ #if TARGET_OS_MAC
779
671
static void __InitTZStrings (void ) {
780
672
static dispatch_once_t initOnce = 0 ;
781
673
@@ -810,7 +702,7 @@ static void __InitTZStrings(void) {
810
702
});
811
703
}
812
704
813
- #elif TARGET_OS_ANDROID
705
+ #elif TARGET_OS_ANDROID || TARGET_OS_WINDOWS
814
706
// Nothing
815
707
#elif TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
816
708
static void __InitTZStrings (void ) {
@@ -834,12 +726,7 @@ static CFTimeZoneRef __CFTimeZoneCreateSystem(void) {
834
726
LPWSTR standardName = (LPWSTR )& tzi .StandardName ;
835
727
CFStringRef cfStandardName = CFStringCreateWithBytes (kCFAllocatorSystemDefault , (UInt8 * )standardName , wcslen (standardName )* sizeof (WCHAR ), kCFStringEncodingUTF16LE , false);
836
728
if (cfStandardName ) {
837
- CFDictionaryRef winToOlson = CFTimeZoneCopyWinToOlsonDictionary ();
838
- if (winToOlson ) {
839
- name = CFDictionaryGetValue (winToOlson , cfStandardName );
840
- if (name ) CFRetain (name );
841
- CFRelease (winToOlson );
842
- }
729
+ name = _CFTimeZoneCopyOlsonNameForWindowsName (cfStandardName );
843
730
CFRelease (cfStandardName );
844
731
}
845
732
} else {
@@ -1326,16 +1213,17 @@ Boolean _CFTimeZoneInit(CFTimeZoneRef timeZone, CFStringRef name, CFDataRef data
1326
1213
1327
1214
tzName = CFDictionaryGetValue (abbrevs , name );
1328
1215
if (tzName == NULL ) {
1329
- CFDictionaryRef olson = CFTimeZoneCopyOlsonToWindowsDictionary ( );
1330
- tzName = CFDictionaryGetValue ( olson , name );
1331
- CFRelease ( olson );
1216
+ tzName = _CFTimeZoneCopyWindowsNameForOlsonName ( name );
1217
+ } else {
1218
+ CFRetain ( tzName );
1332
1219
}
1333
1220
1334
1221
CFRelease (abbrevs );
1335
1222
1336
1223
if (tzName ) {
1337
1224
__CFTimeZoneGetOffset (tzName , & offset );
1338
1225
// TODO: handle DST
1226
+ CFRelease (tzName );
1339
1227
return __CFTimeZoneInitFixed (timeZone , offset , name , 0 );
1340
1228
}
1341
1229
@@ -1542,15 +1430,16 @@ CFTimeZoneRef CFTimeZoneCreateWithName(CFAllocatorRef allocator, CFStringRef nam
1542
1430
1543
1431
tzName = CFDictionaryGetValue (abbrevs , name );
1544
1432
if (tzName == NULL ) {
1545
- CFDictionaryRef olson = CFTimeZoneCopyOlsonToWindowsDictionary ( );
1546
- tzName = CFDictionaryGetValue ( olson , name );
1547
- CFRelease ( olson );
1433
+ tzName = _CFTimeZoneCopyWindowsNameForOlsonName ( name );
1434
+ } else {
1435
+ tzName = CFRetain ( tzName );
1548
1436
}
1549
1437
1550
1438
CFRelease (abbrevs );
1551
1439
1552
1440
if (tzName ) {
1553
1441
__CFTimeZoneGetOffset (tzName , & offset );
1442
+ CFRelease (tzName );
1554
1443
// TODO: handle DST
1555
1444
result = __CFTimeZoneCreateFixed (allocator , offset , name , 0 );
1556
1445
}
0 commit comments