Author: tkreuzer Date: Fri Nov 22 15:23:18 2013 New Revision: 61077
URL: http://svn.reactos.org/svn/reactos?rev=61077&view=rev Log: [NTOSKRNL] Fix / improve NtQueryDefaultLocale, NtSetDefaultLocale, NtQueryDefaultUILanguage and NtSetDefaultUILanguage
Modified: trunk/reactos/ntoskrnl/ex/locale.c
Modified: trunk/reactos/ntoskrnl/ex/locale.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/locale.c?rev=61... ============================================================================== --- trunk/reactos/ntoskrnl/ex/locale.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/ex/locale.c [iso-8859-1] Fri Nov 22 15:23:18 2013 @@ -178,8 +178,8 @@ /* Check if we have a user profile */ if (UserProfile) { - /* Return thread locale */ - *DefaultLocaleId = PsDefaultThreadLocaleId; + /* Return session wide thread locale */ + *DefaultLocaleId = MmGetSessionLocaleId(); } else { @@ -206,11 +206,14 @@ OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; + UNICODE_STRING LocaleString; HANDLE KeyHandle; ULONG ValueLength; WCHAR ValueBuffer[20]; HANDLE UserKey; NTSTATUS Status; + UCHAR KeyValueBuffer[256]; + PKEY_VALUE_PARTIAL_INFORMATION KeyValueInformation; PAGED_CODE();
/* Check if we have a profile */ @@ -241,12 +244,52 @@ UserKey, NULL);
- /* Check if we don' thave a default locale yet */ + /* Check if we don't have a default locale yet */ if (!DefaultLocaleId) { - DPRINT1("TODO\n"); - Status = STATUS_SUCCESS; - ASSERT(FALSE); + /* Open the key for reading */ + Status = ZwOpenKey(&KeyHandle, KEY_QUERY_VALUE, &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + KeyHandle = NULL; + goto Cleanup; + } + + /* Query the key value */ + KeyValueInformation = (PKEY_VALUE_PARTIAL_INFORMATION)KeyValueBuffer; + Status = ZwQueryValueKey(KeyHandle, + &ValueName, + KeyValuePartialInformation, + KeyValueInformation, + sizeof(KeyValueBuffer), + &ValueLength); + if (!NT_SUCCESS(Status)) + { + goto Cleanup; + } + + /* Check if this is a REG_DWORD */ + if ((KeyValueInformation->Type == REG_DWORD) && + (KeyValueInformation->DataLength == sizeof(ULONG))) + { + /* It contains the LCID as a DWORD */ + DefaultLocaleId = *((ULONG*)KeyValueInformation->Data); + } + /* Otherwise check for a REG_SZ */ + else if (KeyValueInformation->Type == REG_SZ) + { + /* Initialize a unicode string from the value data */ + LocaleString.Buffer = (PWCHAR)KeyValueInformation->Data; + LocaleString.Length = (USHORT)KeyValueInformation->DataLength; + LocaleString.MaximumLength = LocaleString.Length; + + /* Convert the hex string to a number */ + RtlUnicodeStringToInteger(&LocaleString, 16, &DefaultLocaleId); + } + else + { + Status = STATUS_UNSUCCESSFUL; + } } else { @@ -280,10 +323,15 @@ REG_SZ, ValueBuffer, ValueLength); - - /* And close the key */ - ZwClose(KeyHandle); - } + } + } + +Cleanup: + + /* Close the locale key */ + if (KeyHandle) + { + ObCloseHandle(KeyHandle, KernelMode); }
/* Close the user key */ @@ -298,8 +346,8 @@ /* Check if it was for a user */ if (UserProfile) { - /* Set thread locale */ - PsDefaultThreadLocaleId = DefaultLocaleId; + /* Set the session wide thread locale */ + MmSetSessionLocaleId(DefaultLocaleId); } else { @@ -383,13 +431,13 @@ } _SEH2_EXCEPT(ExSystemExceptionFilter()) { - /* Get exception code */ - Status = _SEH2_GetExceptionCode(); + /* Return exception code */ + return _SEH2_GetExceptionCode(); } _SEH2_END;
- /* Return status */ - return Status; + /* Return success */ + return STATUS_SUCCESS; }
/* @@ -399,18 +447,29 @@ NTAPI NtSetDefaultUILanguage(IN LANGID LanguageId) { - PAGED_CODE(); - - /* Check if we don't have a default yet */ - if (!LanguageId) - { - /* FIXME */ - DPRINT1("TODO\n"); - ASSERT(FALSE); - } - - /* Otherwise, call the internal routine */ - return ExpSetCurrentUserUILanguage(L"MUILanguagePending", LanguageId); + NTSTATUS Status; + PAGED_CODE(); + + /* Check if the caller specified a language id */ + if (LanguageId) + { + /* Set the pending MUI language id */ + Status = ExpSetCurrentUserUILanguage(L"MUILanguagePending", LanguageId); + } + else + { + /* Otherwise get the pending MUI language id */ + Status = ExpGetCurrentUserUILanguage(L"MUILanguagePending", &LanguageId); + if (!NT_SUCCESS(Status)) + { + return Status; + } + + /* And apply it as actual */ + Status = ExpSetCurrentUserUILanguage(L"MultiUILanguageId", LanguageId); + } + + return Status; }
/* EOF */