Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenlocale.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/ex/locale.c 00005 * PURPOSE: Locale (Language) Support for the Executive 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 * Eric Kohl 00008 * Thomas Weidenmueller (w3seek@reactos.org 00009 */ 00010 00011 /* INCLUDES ******************************************************************/ 00012 00013 #include <ntoskrnl.h> 00014 #define NDEBUG 00015 #include <debug.h> 00016 00017 /* GLOBALS *******************************************************************/ 00018 00019 /* System IDs: EN_US */ 00020 LCID PsDefaultSystemLocaleId = 0x00000409; 00021 LANGID PsInstallUILanguageId = LANGIDFROMLCID(0x00000409); 00022 00023 /* UI/Thread IDs: Same as system */ 00024 LANGID PsDefaultUILanguageId = 0x00000409; 00025 LCID PsDefaultThreadLocaleId = LANGIDFROMLCID(0x00000409); 00026 00027 /* PRIVATE FUNCTIONS *********************************************************/ 00028 00029 NTSTATUS 00030 NTAPI 00031 ExpGetCurrentUserUILanguage(IN PWSTR MuiName, 00032 OUT LANGID* LanguageId) 00033 { 00034 UCHAR ValueBuffer[256]; 00035 PKEY_VALUE_PARTIAL_INFORMATION ValueInfo; 00036 OBJECT_ATTRIBUTES ObjectAttributes; 00037 UNICODE_STRING KeyName = 00038 RTL_CONSTANT_STRING(L"Control Panel\\International"); 00039 UNICODE_STRING ValueName; 00040 UNICODE_STRING ValueString; 00041 ULONG ValueLength; 00042 ULONG Value; 00043 HANDLE UserKey; 00044 HANDLE KeyHandle; 00045 NTSTATUS Status; 00046 PAGED_CODE(); 00047 00048 /* Setup the key name */ 00049 RtlInitUnicodeString(&ValueName, MuiName); 00050 00051 /* Open the use key */ 00052 Status = RtlOpenCurrentUser(KEY_READ, &UserKey); 00053 if (!NT_SUCCESS(Status)) return Status; 00054 00055 /* Initialize the attributes and open the key */ 00056 InitializeObjectAttributes(&ObjectAttributes, 00057 &KeyName, 00058 OBJ_CASE_INSENSITIVE, 00059 UserKey, 00060 NULL); 00061 Status = ZwOpenKey(&KeyHandle, KEY_QUERY_VALUE,&ObjectAttributes); 00062 if (NT_SUCCESS(Status)) 00063 { 00064 /* Set buffer and query the current value */ 00065 ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION)ValueBuffer; 00066 Status = ZwQueryValueKey(KeyHandle, 00067 &ValueName, 00068 KeyValuePartialInformation, 00069 ValueBuffer, 00070 sizeof(ValueBuffer), 00071 &ValueLength); 00072 if (NT_SUCCESS(Status)) 00073 { 00074 /* Success, is the value the right type? */ 00075 if (ValueInfo->Type == REG_SZ) 00076 { 00077 /* It is. Initialize the data and convert it */ 00078 RtlInitUnicodeString(&ValueString, (PWSTR)ValueInfo->Data); 00079 Status = RtlUnicodeStringToInteger(&ValueString, 16, &Value); 00080 if (NT_SUCCESS(Status)) 00081 { 00082 /* Return the language */ 00083 *LanguageId = (USHORT)Value; 00084 } 00085 } 00086 else 00087 { 00088 /* Fail */ 00089 Status = STATUS_UNSUCCESSFUL; 00090 } 00091 00092 /* Close the key */ 00093 ZwClose(KeyHandle); 00094 } 00095 } 00096 00097 /* Close the user key and return */ 00098 ZwClose(UserKey); 00099 return Status; 00100 } 00101 00102 NTSTATUS 00103 NTAPI 00104 ExpSetCurrentUserUILanguage(IN PWSTR MuiName, 00105 IN LANGID LanguageId) 00106 { 00107 OBJECT_ATTRIBUTES ObjectAttributes; 00108 UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"Control Panel\\Desktop"); 00109 UNICODE_STRING ValueName; 00110 WCHAR ValueBuffer[8]; 00111 ULONG ValueLength; 00112 HANDLE UserHandle; 00113 HANDLE KeyHandle; 00114 NTSTATUS Status; 00115 PAGED_CODE(); 00116 00117 /* Setup the key name */ 00118 RtlInitUnicodeString(&ValueName, MuiName); 00119 00120 /* Open the use key */ 00121 Status = RtlOpenCurrentUser(KEY_WRITE, &UserHandle); 00122 if (!NT_SUCCESS(Status)) return Status; 00123 00124 /* Initialize the attributes */ 00125 InitializeObjectAttributes(&ObjectAttributes, 00126 &KeyName, 00127 OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, 00128 UserHandle, 00129 NULL); 00130 00131 /* Open the key */ 00132 Status = ZwOpenKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes); 00133 if (NT_SUCCESS(Status)) 00134 { 00135 /* Setup the value name */ 00136 ValueLength = swprintf(ValueBuffer, 00137 L"%04lX", 00138 (ULONG)LanguageId); 00139 00140 /* Set the length for the call and set the value */ 00141 ValueLength = (ValueLength + 1) * sizeof(WCHAR); 00142 Status = ZwSetValueKey(KeyHandle, 00143 &ValueName, 00144 0, 00145 REG_SZ, 00146 ValueBuffer, 00147 ValueLength); 00148 00149 /* Close the handle for this key */ 00150 ZwClose(KeyHandle); 00151 } 00152 00153 /* Close the user key and return status */ 00154 ZwClose(UserHandle); 00155 return Status; 00156 } 00157 00158 /* PUBLIC FUNCTIONS **********************************************************/ 00159 00160 NTSTATUS 00161 NTAPI 00162 NtQueryDefaultLocale(IN BOOLEAN UserProfile, 00163 OUT PLCID DefaultLocaleId) 00164 { 00165 NTSTATUS Status = STATUS_SUCCESS; 00166 PAGED_CODE(); 00167 00168 /* Enter SEH for probing */ 00169 _SEH2_TRY 00170 { 00171 /* Check if we came from user mode */ 00172 if (KeGetPreviousMode() != KernelMode) 00173 { 00174 /* Probe the language ID */ 00175 ProbeForWriteLangid(DefaultLocaleId); 00176 } 00177 00178 /* Check if we have a user profile */ 00179 if (UserProfile) 00180 { 00181 /* Return thread locale */ 00182 *DefaultLocaleId = PsDefaultThreadLocaleId; 00183 } 00184 else 00185 { 00186 /* Return system locale */ 00187 *DefaultLocaleId = PsDefaultSystemLocaleId; 00188 } 00189 } 00190 _SEH2_EXCEPT(ExSystemExceptionFilter()) 00191 { 00192 /* Get exception code */ 00193 Status = _SEH2_GetExceptionCode(); 00194 } 00195 _SEH2_END; 00196 00197 /* Return status */ 00198 return Status; 00199 } 00200 00201 NTSTATUS 00202 NTAPI 00203 NtSetDefaultLocale(IN BOOLEAN UserProfile, 00204 IN LCID DefaultLocaleId) 00205 { 00206 OBJECT_ATTRIBUTES ObjectAttributes; 00207 UNICODE_STRING KeyName; 00208 UNICODE_STRING ValueName; 00209 HANDLE KeyHandle; 00210 ULONG ValueLength; 00211 WCHAR ValueBuffer[20]; 00212 HANDLE UserKey = NULL; 00213 NTSTATUS Status; 00214 PAGED_CODE(); 00215 00216 /* Check if we have a profile */ 00217 if (UserProfile) 00218 { 00219 /* Open the user's key */ 00220 Status = RtlOpenCurrentUser(KEY_WRITE, &UserKey); 00221 if (!NT_SUCCESS(Status)) return(Status); 00222 00223 /* Initialize the registry location */ 00224 RtlInitUnicodeString(&KeyName, L"Control Panel\\International"); 00225 RtlInitUnicodeString(&ValueName, L"Locale"); 00226 } 00227 else 00228 { 00229 /* Initialize the system registry location */ 00230 RtlInitUnicodeString(&KeyName, 00231 L"\\Registry\\Machine\\System\\CurrentControlSet" 00232 L"\\Control\\Nls\\Language"); 00233 RtlInitUnicodeString(&ValueName, L"Default"); 00234 } 00235 00236 /* Initailize the object attributes */ 00237 InitializeObjectAttributes(&ObjectAttributes, 00238 &KeyName, 00239 OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, 00240 UserKey, 00241 NULL); 00242 00243 /* Check if we don' thave a default locale yet */ 00244 if (!DefaultLocaleId) 00245 { 00246 DPRINT1("TODO\n"); 00247 Status = STATUS_SUCCESS; 00248 ASSERT(FALSE); 00249 } 00250 else 00251 { 00252 /* Otherwise, open the key */ 00253 Status = ZwOpenKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes); 00254 if (NT_SUCCESS(Status)) 00255 { 00256 /* Check if we had a profile */ 00257 if (UserProfile) 00258 { 00259 /* Fill in the buffer */ 00260 ValueLength = swprintf(ValueBuffer, 00261 L"%08lx", 00262 (ULONG)DefaultLocaleId); 00263 } 00264 else 00265 { 00266 /* Fill in the buffer */ 00267 ValueLength = swprintf(ValueBuffer, 00268 L"%04lx", 00269 (ULONG)DefaultLocaleId & 0xFFFF); 00270 } 00271 00272 /* Set the length for the registry call */ 00273 ValueLength = (ValueLength + 1) * sizeof(WCHAR); 00274 00275 /* Now write the actual value */ 00276 Status = ZwSetValueKey(KeyHandle, 00277 &ValueName, 00278 0, 00279 REG_SZ, 00280 ValueBuffer, 00281 ValueLength); 00282 00283 /* And close the key */ 00284 ZwClose(KeyHandle); 00285 } 00286 } 00287 00288 /* Close the user key */ 00289 ZwClose(UserKey); 00290 00291 /* Check for success */ 00292 if (NT_SUCCESS(Status)) 00293 { 00294 /* Check if it was for a user */ 00295 if (UserProfile) 00296 { 00297 /* Set thread locale */ 00298 PsDefaultThreadLocaleId = DefaultLocaleId; 00299 } 00300 else 00301 { 00302 /* Set system locale */ 00303 PsDefaultSystemLocaleId = DefaultLocaleId; 00304 } 00305 } 00306 00307 /* Return status */ 00308 return Status; 00309 } 00310 00311 /* 00312 * @implemented 00313 */ 00314 NTSTATUS 00315 NTAPI 00316 NtQueryInstallUILanguage(OUT LANGID* LanguageId) 00317 { 00318 NTSTATUS Status = STATUS_SUCCESS; 00319 PAGED_CODE(); 00320 00321 /* Enter SEH for probing */ 00322 _SEH2_TRY 00323 { 00324 /* Check if we came from user mode */ 00325 if (KeGetPreviousMode() != KernelMode) 00326 { 00327 /* Probe the Language ID */ 00328 ProbeForWriteLangid(LanguageId); 00329 } 00330 00331 /* Return it */ 00332 *LanguageId = PsInstallUILanguageId; 00333 } 00334 _SEH2_EXCEPT(ExSystemExceptionFilter()) 00335 { 00336 /* Get exception code */ 00337 Status = _SEH2_GetExceptionCode(); 00338 } 00339 _SEH2_END; 00340 00341 /* Return status */ 00342 return Status; 00343 } 00344 00345 /* 00346 * @implemented 00347 */ 00348 NTSTATUS 00349 NTAPI 00350 NtQueryDefaultUILanguage(OUT LANGID* LanguageId) 00351 { 00352 NTSTATUS Status = STATUS_SUCCESS; 00353 PAGED_CODE(); 00354 00355 /* Enter SEH for probing */ 00356 _SEH2_TRY 00357 { 00358 /* Check if we came from user mode */ 00359 if (KeGetPreviousMode() != KernelMode) 00360 { 00361 /* Probe the Language ID */ 00362 ProbeForWriteLangid(LanguageId); 00363 } 00364 00365 /* Call the executive helper routine */ 00366 Status = ExpGetCurrentUserUILanguage(L"MultiUILanguageId", LanguageId); 00367 if (NT_SUCCESS(Status)) 00368 { 00369 /* Success, return the language */ 00370 *LanguageId = PsInstallUILanguageId; 00371 } 00372 } 00373 _SEH2_EXCEPT(ExSystemExceptionFilter()) 00374 { 00375 /* Get exception code */ 00376 Status = _SEH2_GetExceptionCode(); 00377 } 00378 _SEH2_END; 00379 00380 /* Return status */ 00381 return Status; 00382 } 00383 00384 /* 00385 * @implemented 00386 */ 00387 NTSTATUS 00388 NTAPI 00389 NtSetDefaultUILanguage(IN LANGID LanguageId) 00390 { 00391 PAGED_CODE(); 00392 00393 /* Check if we don't have a default yet */ 00394 if (!LanguageId) 00395 { 00396 /* FIXME */ 00397 DPRINT1("TODO\n"); 00398 ASSERT(FALSE); 00399 } 00400 00401 /* Otherwise, call the internal routine */ 00402 return ExpSetCurrentUserUILanguage(L"MUILanguagePending", LanguageId); 00403 } 00404 00405 /* EOF */ Generated on Sun May 27 2012 04:18:13 for ReactOS by
1.7.6.1
|