[ros-diffs] [tretiakov] 25831: Patch by Alexey Zavyalov (Generex). Implement SetLocaleInfoA, SetLocaleInfoW.

tretiakov at svn.reactos.org tretiakov at svn.reactos.org
Sat Feb 17 16:46:25 CET 2007


Author: tretiakov
Date: Sat Feb 17 18:46:25 2007
New Revision: 25831

URL: http://svn.reactos.org/svn/reactos?rev=25831&view=rev
Log:
Patch by Alexey Zavyalov (Generex).
Implement SetLocaleInfoA, SetLocaleInfoW.


Modified:
    trunk/reactos/dll/win32/kernel32/misc/lang.c

Modified: trunk/reactos/dll/win32/kernel32/misc/lang.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/lang.c?rev=25831&r1=25830&r2=25831&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/lang.c (original)
+++ trunk/reactos/dll/win32/kernel32/misc/lang.c Sat Feb 17 18:46:25 2007
@@ -1394,8 +1394,23 @@
 }
 
 
-/*
- * @unimplemented
+/**********************************************************************
+ * @implemented
+ * RIPPED FROM WINE's dlls\kernel\locale.c ver 0.9.29
+ *
+ *           SetLocaleInfoA    (KERNEL32.@)
+ *
+ * Set the current locale info.
+ *
+ * PARAMS
+ *  Locale   [I] LCID of the locale
+ *  LCType   [I] LCTYPE_ flags from "winnls.h"
+ *  lpLCData [I] Information to set
+ *
+ * RETURNS
+ *  Success: TRUE. The information given will be returned by GetLocaleInfoA()
+ *           whenever it is called without LOCALE_NOUSEROVERRIDE.
+ *  Failure: FALSE. Use GetLastError() to determine the cause.
  */
 BOOL
 STDCALL
@@ -1405,13 +1420,39 @@
     LPCSTR  lpLCData
     )
 {
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
-}
-
-
-/*
- * @unimplemented
+    UINT codepage = CP_ACP;
+    WCHAR *strW;
+    DWORD len;
+    BOOL ret;
+
+    if (!(LCType & LOCALE_USE_CP_ACP)) codepage = get_lcid_codepage( Locale );
+
+    if (!lpLCData)
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
+    len = MultiByteToWideChar( codepage, 0, lpLCData, -1, NULL, 0 );
+    if (!(strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
+    {
+        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
+        return FALSE;
+    }
+    MultiByteToWideChar( codepage, 0, lpLCData, -1, strW, len );
+    ret = SetLocaleInfoW( Locale, LCType, strW );
+    HeapFree( GetProcessHeap(), 0, strW );
+    return ret;
+}
+
+
+/**********************************************************************
+ * @implemented
+ * RIPPED FROM WINE's dlls\kernel\locale.c ver 0.9.29
+ *
+ *           SetLocaleInfoW    (KERNEL32.@)
+ *
+ * See SetLocaleInfoA.
+ *
  */
 BOOL
 STDCALL
@@ -1421,8 +1462,69 @@
     LPCWSTR lpLCData
     )
 {
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
+    const WCHAR *value;
+    UNICODE_STRING valueW;
+    NTSTATUS status;
+    HANDLE hkey;
+
+    LCType &= 0xffff;
+    value = RosGetLocaleValueName( LCType );
+
+    if (!lpLCData || !value)
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
+
+    if (LCType == LOCALE_IDATE || LCType == LOCALE_ILDATE)
+    {
+        SetLastError( ERROR_INVALID_FLAGS );
+        return FALSE;
+    }
+
+    if (!(hkey = RosCreateRegistryKey())) return FALSE;
+    RtlInitUnicodeString( &valueW, value );
+    status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, (PVOID)lpLCData, (lstrlenW(lpLCData)+1)*sizeof(WCHAR) );
+
+    if (LCType == LOCALE_SSHORTDATE || LCType == LOCALE_SLONGDATE)
+    {
+        /* Set I-value from S value */
+        WCHAR *lpD, *lpM, *lpY;
+        WCHAR szBuff[2];
+
+        lpD = wcschr(lpLCData, 'd');
+        lpM = wcschr(lpLCData, 'M');
+        lpY = wcschr(lpLCData, 'y');
+
+        if (lpD <= lpM)
+        {
+            szBuff[0] = '1'; /* D-M-Y */
+        }
+        else
+        {
+            if (lpY <= lpM)
+                szBuff[0] = '2'; /* Y-M-D */
+            else
+                szBuff[0] = '0'; /* M-D-Y */
+        }
+
+        szBuff[1] = '\0';
+
+        if (LCType == LOCALE_SSHORTDATE)
+            LCType = LOCALE_IDATE;
+        else
+            LCType = LOCALE_ILDATE;
+
+        value = RosGetLocaleValueName( LCType );
+
+        RtlInitUnicodeString( &valueW, value );
+        status = NtSetValueKey( hkey, &valueW, 0, REG_SZ, szBuff, sizeof(szBuff) );
+    }
+
+    NtClose( hkey );
+
+    if (status) SetLastError( RtlNtStatusToDosError(status) );
+    return !status;
 }
 
 




More information about the Ros-diffs mailing list