Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
6.9 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /*++
  4. Copyright (c) 1990 Microsoft Corporation
  5. Module Name:
  6. nls.c
  7. Abstract:
  8. NLS related routines in the setupdll
  9. Detect Routines:
  10. ----------------
  11. Install Routines Workers:
  12. -------------------------
  13. 1. SetCurrentLocaleWorker: To set the values associated with the
  14. current locale in the cpanel area of the registry.
  15. //
  16. // Fill up the current structure with the values that we need:
  17. //
  18. // Field Name LcType Example
  19. // ---------- ------- -------
  20. // sLanguage = LOCALE_SABBREVLANGNAME, ENU
  21. // sCountry = LOCALE_SCOUNTRY, United States
  22. // iCountry = LOCALE_ICOUNTRY, 1
  23. // sList = LOCALE_SLIST ,
  24. // iMeasure = LOCALE_IMEASURE 1
  25. // sDecimal = LOCALE_SDECIMAL .
  26. // sThousand = LOCALE_STHOUSAND ,
  27. // iDigits = LOCALE_IDIGITS 2
  28. // iLZero = LOCALE_ILZERO 1
  29. // sCurrency = LOCALE_SCURRENCY $
  30. // iCurrDigits = LOCALE_ICURRDIGITS 2
  31. // iCurrency = LOCALE_ICURRENCY 0
  32. // iNegCurr = LOCALE_INEGCURR 0
  33. // sDate = LOCALE_SDATE /
  34. // sTime = LOCALE_STIME :
  35. // sShortDate = LOCALE_SSHORTDATE M/d/yy
  36. // sLongDate = LOCALE_SLONGDATE dddd, MMMM dd, yyyy
  37. // iDate = LOCALE_IDATE 0
  38. // iTime = LOCALE_ITIME 0
  39. // iTLZero = LOCALE_ITLZERO 0
  40. // s1159 = LOCALE_S1159 AM
  41. // s2359 = LOCALE_S2359 PM
  42. Author:
  43. Sunil Pai (sunilp) Sept 1992
  44. --*/
  45. BOOL
  46. SetCurrentLocaleWorker(
  47. LPSTR Locale,
  48. LPSTR ModifyCPL
  49. )
  50. /*++
  51. Routine Description:
  52. Sets the current values for all the per locale fields associated with the
  53. control panel in the user tree. Also sets the current user locale and
  54. system locale fields for the currently logged on session.
  55. Arguments:
  56. Locale: This is the current locale we have installed.
  57. Return value:
  58. Returns TRUE if successful, FALSE otherwise with the return buffer
  59. containing the error text.
  60. --*/
  61. {
  62. #define WORKSIZE 128 // size (in chars) of work buffer
  63. WCHAR szwork[WORKSIZE];
  64. INT i;
  65. LCID lcid;
  66. LPSTR pszTemp;
  67. LONG RegStatus;
  68. NTSTATUS Status;
  69. HKEY hKey;
  70. BOOL b24Hours = FALSE;
  71. //
  72. // Table of international settings and associated lctypes.
  73. //
  74. struct {
  75. PWSTR szIniKey;
  76. LCTYPE dwLcType;
  77. } IntlDataArray[] = {
  78. { L"sLanguage" , LOCALE_SABBREVLANGNAME } ,
  79. { L"sCountry" , LOCALE_SCOUNTRY } ,
  80. { L"iCountry" , LOCALE_ICOUNTRY } ,
  81. { L"sList" , LOCALE_SLIST } ,
  82. { L"iMeasure" , LOCALE_IMEASURE } ,
  83. { L"sDecimal" , LOCALE_SDECIMAL } ,
  84. { L"sThousand" , LOCALE_STHOUSAND } ,
  85. { L"iDigits" , LOCALE_IDIGITS } ,
  86. { L"iLZero" , LOCALE_ILZERO } ,
  87. { L"sCurrency" , LOCALE_SCURRENCY } ,
  88. { L"iCurrDigits" , LOCALE_ICURRDIGITS } ,
  89. { L"iCurrency" , LOCALE_ICURRENCY } ,
  90. { L"iNegCurr" , LOCALE_INEGCURR } ,
  91. { L"sDate" , LOCALE_SDATE } ,
  92. { L"sTime" , LOCALE_STIME } ,
  93. { L"sTimeFormat" , LOCALE_STIMEFORMAT } ,
  94. { L"sShortDate" , LOCALE_SSHORTDATE } ,
  95. { L"sLongDate" , LOCALE_SLONGDATE } ,
  96. { L"iDate" , LOCALE_IDATE } ,
  97. { L"iTime" , LOCALE_ITIME } ,
  98. { L"iTLZero" , LOCALE_ITLZERO } ,
  99. { L"s1159" , LOCALE_S1159 } ,
  100. { L"s2359" , LOCALE_S2359 }
  101. };
  102. //
  103. // Check to make sure we can modify all locale components later
  104. //
  105. RegStatus = RegOpenKeyEx(
  106. HKEY_LOCAL_MACHINE,
  107. "System\\CurrentControlSet\\Control\\Nls\\Language",
  108. 0,
  109. KEY_WRITE,
  110. &hKey
  111. );
  112. if( RegStatus != ERROR_SUCCESS ) {
  113. SetReturnText( "ERROR_PRIVILEGE" );
  114. return( FALSE );
  115. }
  116. else {
  117. RegCloseKey( hKey );
  118. }
  119. RegStatus = RegOpenKeyEx(
  120. HKEY_LOCAL_MACHINE,
  121. "System\\CurrentControlSet\\Control\\Nls\\CodePage",
  122. 0,
  123. KEY_WRITE,
  124. &hKey
  125. );
  126. if( RegStatus != ERROR_SUCCESS ) {
  127. SetReturnText( "ERROR_PRIVILEGE" );
  128. return( FALSE );
  129. }
  130. else {
  131. RegCloseKey( hKey );
  132. }
  133. lcid = (LCID)strtoul( Locale, &pszTemp, 16);
  134. if( !lstrcmpi( ModifyCPL, "YES" ) ) {
  135. //
  136. // Update the control panel user area for new defaults for
  137. // current locale
  138. //
  139. for( i = 0; i < sizeof(IntlDataArray)/sizeof(IntlDataArray[0]); i++ ) {
  140. if(!GetLocaleInfoW(lcid,IntlDataArray[i].dwLcType,szwork,WORKSIZE)) {
  141. SetReturnText( "ERROR_UNSUPPORTED" );
  142. return( FALSE );
  143. }
  144. //
  145. // if the default setting is 24hours,
  146. // we set s1159 and s2359 with NULL.
  147. //
  148. if(IntlDataArray[i].dwLcType == LOCALE_ITIME) {
  149. if(szwork[0] == L'1') {
  150. b24Hours = TRUE;
  151. }
  152. } else if((IntlDataArray[i].dwLcType == LOCALE_S1159)||
  153. (IntlDataArray[i].dwLcType == LOCALE_S2359) ) {
  154. if(b24Hours) {
  155. szwork[0] = L'\0';
  156. }
  157. }
  158. if(!WriteProfileStringW(L"INTL",IntlDataArray[i].szIniKey,szwork)) {
  159. SetReturnText( "ERROR_PRIVILEGE" );
  160. return( FALSE );
  161. }
  162. }
  163. //
  164. // Flush win.ini
  165. //
  166. WriteProfileString( NULL, NULL, NULL );
  167. }
  168. //
  169. // Set the current thread current system and user locales
  170. //
  171. Status = NtSetDefaultLocale( FALSE, lcid );
  172. if(!NT_SUCCESS( Status )) {
  173. SetReturnText( "ERROR_PRIVILEGE" );
  174. return( FALSE );
  175. }
  176. Status = NtSetDefaultLocale( TRUE, lcid );
  177. if(!NT_SUCCESS( Status )) {
  178. SetReturnText( "ERROR_PRIVILEGE" );
  179. return( FALSE );
  180. }
  181. return ( TRUE );
  182. }