[KERNEL32] Era first year is GANNEN
authorKatayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
Tue, 16 Apr 2019 02:10:00 +0000 (11:10 +0900)
committerKatayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
Tue, 16 Apr 2019 02:10:00 +0000 (11:10 +0900)
dll/win32/kernel32/winnls/string/japanese.c
dll/win32/kernel32/winnls/string/japanese.h
dll/win32/kernel32/winnls/string/lcformat.c

index c3719f5..2edbdae 100644 (file)
@@ -53,6 +53,44 @@ static INT JapaneseEra_Compare(const void *e1, const void *e2)
     return 0;
 }
 
     return 0;
 }
 
+BOOL JapaneseEra_IsFirstYearGannen(void)
+{
+#ifdef DONT_USE_REGISTRY
+    return TRUE;
+#else
+    HANDLE KeyHandle;
+    DWORD dwIndex;
+    WCHAR szName[32], szValue[32];
+    static BOOL s_bIsCached = FALSE, s_bFirstIsGannen = TRUE;
+
+    if (s_bIsCached)
+        return s_bFirstIsGannen;
+
+    KeyHandle = NLS_RegOpenKey(NULL, L"\\Registry\\Machine\\System\\"
+        L"CurrentControlSet\\Control\\Nls\\Calendars\\Japanese");
+    if (!KeyHandle)
+        return TRUE;
+
+    for (dwIndex = 0; dwIndex < 16; ++dwIndex)
+    {
+        if (!NLS_RegEnumValue(KeyHandle, dwIndex, szName, sizeof(szName),
+                              szValue, sizeof(szValue)))
+        {
+            break;
+        }
+
+        if (lstrcmpiW(szName, L"InitialEraYear") == 0)
+        {
+            s_bFirstIsGannen = (szValue[0] == 0x5143);
+            s_bIsCached = TRUE;
+            break;
+        }
+    }
+
+    return s_bFirstIsGannen;
+#endif
+}
+
 /* 
  * SEE ALSO:
  * https://en.wikipedia.org/wiki/Japanese_era_name
 /* 
  * SEE ALSO:
  * https://en.wikipedia.org/wiki/Japanese_era_name
@@ -61,7 +99,7 @@ static INT JapaneseEra_Compare(const void *e1, const void *e2)
 static PCJAPANESE_ERA JapaneseEra_Load(DWORD *pdwCount)
 {
 #ifndef DONT_USE_REGISTRY
 static PCJAPANESE_ERA JapaneseEra_Load(DWORD *pdwCount)
 {
 #ifndef DONT_USE_REGISTRY
-    HANDLE KeyHandle = NULL;
+    HANDLE KeyHandle;
     DWORD dwIndex;
     WCHAR szName[128], szValue[128];
     JAPANESE_ERA *pEntry;
     DWORD dwIndex;
     WCHAR szName[128], szValue[128];
     JAPANESE_ERA *pEntry;
index 747ee13..a4829be 100644 (file)
@@ -18,4 +18,5 @@ typedef struct JAPANESE_ERA
 } JAPANESE_ERA, *PJAPANESE_ERA;
 typedef const JAPANESE_ERA *PCJAPANESE_ERA;
 
 } JAPANESE_ERA, *PJAPANESE_ERA;
 typedef const JAPANESE_ERA *PCJAPANESE_ERA;
 
+BOOL JapaneseEra_IsFirstYearGannen(void);
 PCJAPANESE_ERA JapaneseEra_Find(const SYSTEMTIME *pst OPTIONAL);
 PCJAPANESE_ERA JapaneseEra_Find(const SYSTEMTIME *pst OPTIONAL);
index 8d85351..441c41b 100644 (file)
@@ -625,7 +625,15 @@ static INT NLS_GetDateTimeFormatW(LCID lcid, DWORD dwFlags,
                 {
                     count = 2;
                 }
                 {
                     count = 2;
                 }
+
                 dwVal = lpTime->wYear - pEra->wYear + 1;
                 dwVal = lpTime->wYear - pEra->wYear + 1;
+
+                if (dwVal == 1 && JapaneseEra_IsFirstYearGannen())
+                {
+                    // Gan of 'Gannen'
+                    buff[0] = 0x5143;
+                    buff[1] = 0;
+                }
                 szAdd = buff;
                 break;
             }
                 szAdd = buff;
                 break;
             }