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.

6457 lines
175 KiB

  1. /*++
  2. Copyright (c) 1994-2000, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. util.c
  5. Abstract:
  6. This module implements the utility functions used by the Regional
  7. Options applet.
  8. Revision History:
  9. --*/
  10. //
  11. // Include Files.
  12. //
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <shlwapi.h>
  17. #include "intl.h"
  18. #include <tchar.h>
  19. #include <windowsx.h>
  20. #include <userenv.h>
  21. #include <regstr.h>
  22. #include "intlhlp.h"
  23. #include "maxvals.h"
  24. #include "winnlsp.h"
  25. //
  26. // Global Variables.
  27. //
  28. #ifdef UNICODE
  29. #define NUM_CURRENCY_SYMBOLS 2
  30. LPWSTR pCurrencySymbols[] =
  31. {
  32. L"$",
  33. L"\x20ac"
  34. };
  35. #endif
  36. #define NUM_DATE_SEPARATORS 3
  37. LPTSTR pDateSeparators[] =
  38. {
  39. TEXT("/"),
  40. TEXT("-"),
  41. TEXT(".")
  42. };
  43. #define NUM_NEG_NUMBER_FORMATS 5
  44. LPTSTR pNegNumberFormats[] =
  45. {
  46. TEXT("(1.1)"),
  47. TEXT("-1.1"),
  48. TEXT("- 1.1"),
  49. TEXT("1.1-"),
  50. TEXT("1.1 -")
  51. };
  52. #define NUM_POS_CURRENCY_FORMATS 4
  53. LPTSTR pPosCurrencyFormats[] =
  54. {
  55. TEXT("�1.1"),
  56. TEXT("1.1�"),
  57. TEXT("� 1.1"),
  58. TEXT("1.1 �")
  59. };
  60. #define NUM_NEG_CURRENCY_FORMATS 16
  61. LPTSTR pNegCurrencyFormats[] =
  62. {
  63. TEXT("(�1.1)"),
  64. TEXT("-�1.1"),
  65. TEXT("�-1.1"),
  66. TEXT("�1.1-"),
  67. TEXT("(1.1�)"),
  68. TEXT("-1.1�"),
  69. TEXT("1.1-�"),
  70. TEXT("1.1�-"),
  71. TEXT("-1.1 �"),
  72. TEXT("-� 1.1"),
  73. TEXT("1.1 �-"),
  74. TEXT("� 1.1-"),
  75. TEXT("� -1.1"),
  76. TEXT("1.1- �"),
  77. TEXT("(� 1.1)"),
  78. TEXT("(1.1 �)")
  79. };
  80. #define NUM_AM_SYMBOLS 1
  81. LPTSTR pAMSymbols[] =
  82. {
  83. TEXT("AM")
  84. };
  85. #define NUM_PM_SYMBOLS 1
  86. LPTSTR pPMSymbols[] =
  87. {
  88. TEXT("PM")
  89. };
  90. ////////////////////////////////////////////////////////////////////////////
  91. //
  92. // Intl_StrToLong
  93. //
  94. // Returns the long integer value stored in the string. Since these
  95. // values are coming back form the NLS API as ordinal values, do not
  96. // worry about double byte characters.
  97. //
  98. ////////////////////////////////////////////////////////////////////////////
  99. LONG Intl_StrToLong(
  100. LPTSTR szNum)
  101. {
  102. LONG Rtn_Val = 0;
  103. while (*szNum)
  104. {
  105. Rtn_Val = (Rtn_Val * 10) + (*szNum - CHAR_ZERO);
  106. szNum++;
  107. }
  108. return (Rtn_Val);
  109. }
  110. ////////////////////////////////////////////////////////////////////////////
  111. //
  112. // Intl_FileExists
  113. //
  114. // Determines if the file exists and is accessible.
  115. //
  116. ////////////////////////////////////////////////////////////////////////////
  117. BOOL Intl_FileExists(
  118. LPTSTR pFileName)
  119. {
  120. WIN32_FIND_DATA FindData;
  121. HANDLE FindHandle;
  122. BOOL bRet;
  123. UINT OldMode;
  124. OldMode = SetErrorMode(SEM_FAILCRITICALERRORS);
  125. FindHandle = FindFirstFile(pFileName, &FindData);
  126. if (FindHandle == INVALID_HANDLE_VALUE)
  127. {
  128. bRet = FALSE;
  129. }
  130. else
  131. {
  132. FindClose(FindHandle);
  133. bRet = TRUE;
  134. }
  135. SetErrorMode(OldMode);
  136. return (bRet);
  137. }
  138. ////////////////////////////////////////////////////////////////////////////
  139. //
  140. // TransNum
  141. //
  142. // Converts a number string to a dword value (in hex).
  143. //
  144. ////////////////////////////////////////////////////////////////////////////
  145. DWORD TransNum(
  146. LPTSTR lpsz)
  147. {
  148. DWORD dw = 0L;
  149. TCHAR c;
  150. while (*lpsz)
  151. {
  152. c = *lpsz++;
  153. if (c >= TEXT('A') && c <= TEXT('F'))
  154. {
  155. c -= TEXT('A') - 0xa;
  156. }
  157. else if (c >= TEXT('0') && c <= TEXT('9'))
  158. {
  159. c -= TEXT('0');
  160. }
  161. else if (c >= TEXT('a') && c <= TEXT('f'))
  162. {
  163. c -= TEXT('a') - 0xa;
  164. }
  165. else
  166. {
  167. break;
  168. }
  169. dw *= 0x10;
  170. dw += c;
  171. }
  172. return (dw);
  173. }
  174. ////////////////////////////////////////////////////////////////////////////
  175. //
  176. // Item_Has_Digits
  177. //
  178. // Return true if the combo box specified by item in the property sheet
  179. // specified by the dialog handle contains any digits.
  180. //
  181. ////////////////////////////////////////////////////////////////////////////
  182. BOOL Item_Has_Digits(
  183. HWND hDlg,
  184. int nItemId,
  185. BOOL Allow_Empty)
  186. {
  187. TCHAR szBuf[SIZE_128];
  188. LPTSTR lpszBuf = szBuf;
  189. HWND hCtrl = GetDlgItem(hDlg, nItemId);
  190. int dwIndex = ComboBox_GetCurSel(hCtrl);
  191. //
  192. // If there is no selection, get whatever is in the edit box.
  193. //
  194. if (dwIndex == CB_ERR)
  195. {
  196. dwIndex = GetDlgItemText(hDlg, nItemId, szBuf, SIZE_128);
  197. if (dwIndex)
  198. {
  199. //
  200. // Get text succeeded.
  201. //
  202. szBuf[dwIndex] = 0;
  203. }
  204. else
  205. {
  206. //
  207. // Get text failed.
  208. //
  209. dwIndex = CB_ERR;
  210. }
  211. }
  212. else
  213. {
  214. ComboBox_GetLBText(hCtrl, dwIndex, szBuf);
  215. }
  216. if (dwIndex != CB_ERR)
  217. {
  218. while (*lpszBuf)
  219. {
  220. #ifndef UNICODE
  221. if (IsDBCSLeadByte(*lpszBuf))
  222. {
  223. //
  224. // Skip 2 bytes in the array.
  225. //
  226. lpszBuf += 2;
  227. }
  228. else
  229. #endif
  230. {
  231. if ((*lpszBuf >= CHAR_ZERO) && (*lpszBuf <= CHAR_NINE))
  232. {
  233. return (TRUE);
  234. }
  235. lpszBuf++;
  236. }
  237. }
  238. return (FALSE);
  239. }
  240. //
  241. // The data retrieval failed.
  242. // If !Allow_Empty, just return TRUE.
  243. //
  244. return (!Allow_Empty);
  245. }
  246. ////////////////////////////////////////////////////////////////////////////
  247. //
  248. // Item_Has_Digits_Or_Invalid_Chars
  249. //
  250. // Return true if the combo box specified by item in the property sheet
  251. // specified by the dialog handle contains any digits or any of the
  252. // given invalid characters.
  253. //
  254. ////////////////////////////////////////////////////////////////////////////
  255. BOOL Item_Has_Digits_Or_Invalid_Chars(
  256. HWND hDlg,
  257. int nItemId,
  258. BOOL Allow_Empty,
  259. LPTSTR pInvalid)
  260. {
  261. TCHAR szBuf[SIZE_128];
  262. LPTSTR lpszBuf = szBuf;
  263. HWND hCtrl = GetDlgItem(hDlg, nItemId);
  264. int dwIndex = ComboBox_GetCurSel(hCtrl);
  265. //
  266. // If there is no selection, get whatever is in the edit box.
  267. //
  268. if (dwIndex == CB_ERR)
  269. {
  270. dwIndex = GetDlgItemText(hDlg, nItemId, szBuf, SIZE_128);
  271. if (dwIndex)
  272. {
  273. //
  274. // Get text succeeded.
  275. //
  276. szBuf[dwIndex] = 0;
  277. }
  278. else
  279. {
  280. //
  281. // Get text failed.
  282. //
  283. dwIndex = CB_ERR;
  284. }
  285. }
  286. else
  287. {
  288. dwIndex = ComboBox_GetLBText(hCtrl, dwIndex, szBuf);
  289. }
  290. if (dwIndex != CB_ERR)
  291. {
  292. while (*lpszBuf)
  293. {
  294. #ifndef UNICODE
  295. if (IsDBCSLeadByte(*lpszBuf))
  296. {
  297. //
  298. // Skip 2 bytes in the array.
  299. //
  300. lpszBuf += 2;
  301. }
  302. else
  303. #endif
  304. {
  305. if ( ((*lpszBuf >= CHAR_ZERO) && (*lpszBuf <= CHAR_NINE)) ||
  306. (_tcschr(pInvalid, *lpszBuf)) )
  307. {
  308. return (TRUE);
  309. }
  310. lpszBuf++;
  311. }
  312. }
  313. return (FALSE);
  314. }
  315. //
  316. // The data retrieval failed.
  317. // If !Allow_Empty, just return TRUE.
  318. //
  319. return (!Allow_Empty);
  320. }
  321. ////////////////////////////////////////////////////////////////////////////
  322. //
  323. // Item_Check_Invalid_Chars
  324. //
  325. // Return true if the input string contains any characters that are not in
  326. // lpCkChars or in the string contained in the check id control combo box.
  327. // If there is an invalid character and the character is contained in
  328. // lpChgCase, change the invalid character's case so that it will be a
  329. // vaild character.
  330. //
  331. ////////////////////////////////////////////////////////////////////////////
  332. BOOL Item_Check_Invalid_Chars(
  333. HWND hDlg,
  334. LPTSTR lpszBuf,
  335. LPTSTR lpCkChars,
  336. int nCkIdStr,
  337. BOOL Allow_Empty,
  338. LPTSTR lpChgCase,
  339. int nItemId)
  340. {
  341. TCHAR szCkBuf[SIZE_128];
  342. LPTSTR lpCCaseChar;
  343. LPTSTR lpszSaveBuf = lpszBuf;
  344. int nCkBufLen;
  345. BOOL bInQuote = FALSE;
  346. BOOL UpdateEditTest = FALSE;
  347. HWND hCtrl = GetDlgItem(hDlg, nCkIdStr);
  348. DWORD dwIndex = ComboBox_GetCurSel(hCtrl);
  349. BOOL TextFromEditBox = (ComboBox_GetCurSel(GetDlgItem(hDlg, nItemId)) == CB_ERR);
  350. if (!lpszBuf)
  351. {
  352. return (!Allow_Empty);
  353. }
  354. if (dwIndex != CB_ERR)
  355. {
  356. nCkBufLen = ComboBox_GetLBText(hCtrl, dwIndex, szCkBuf);
  357. if (nCkBufLen == CB_ERR)
  358. {
  359. nCkBufLen = 0;
  360. }
  361. }
  362. else
  363. {
  364. //
  365. // No selection, so pull the string from the edit portion.
  366. //
  367. nCkBufLen = GetDlgItemText(hDlg, nCkIdStr, szCkBuf, SIZE_128);
  368. szCkBuf[nCkBufLen] = 0;
  369. }
  370. while (*lpszBuf)
  371. {
  372. #ifndef UNICODE
  373. if (IsDBCSLeadByte(*lpszBuf))
  374. {
  375. //
  376. // If the the text is in the midst of a quote, skip it.
  377. // Otherwise, if there is a string from the check ID to
  378. // compare, determine if the current string is equal to the
  379. // string in the combo box. If it is not equal, return true
  380. // (there are invalid characters). Otherwise, skip the entire
  381. // length of the "check" combo box's string in lpszBuf.
  382. //
  383. if (bInQuote)
  384. {
  385. lpszBuf += 2;
  386. }
  387. else if (nCkBufLen &&
  388. lstrlen(lpszBuf) >= nCkBufLen)
  389. {
  390. if (CompareString( UserLocaleID,
  391. 0,
  392. szCkBuf,
  393. nCkBufLen,
  394. lpszBuf,
  395. nCkBufLen ) != CSTR_EQUAL)
  396. {
  397. //
  398. // Invalid DB character.
  399. //
  400. return (TRUE);
  401. }
  402. lpszBuf += nCkBufLen;
  403. }
  404. }
  405. else
  406. #endif
  407. {
  408. if (bInQuote)
  409. {
  410. bInQuote = (*lpszBuf != CHAR_QUOTE);
  411. lpszBuf++;
  412. }
  413. else if (_tcschr(lpCkChars, *lpszBuf))
  414. {
  415. lpszBuf++;
  416. }
  417. else if (TextFromEditBox &&
  418. (lpCCaseChar = _tcschr(lpChgCase, *lpszBuf), lpCCaseChar))
  419. {
  420. *lpszBuf = lpCkChars[lpCCaseChar - lpChgCase];
  421. UpdateEditTest = TRUE;
  422. lpszBuf++;
  423. }
  424. else if (*lpszBuf == CHAR_QUOTE)
  425. {
  426. lpszBuf++;
  427. bInQuote = TRUE;
  428. }
  429. else if ( (nCkBufLen) &&
  430. (lstrlen(lpszBuf) >= nCkBufLen) &&
  431. (CompareString( UserLocaleID,
  432. 0,
  433. szCkBuf,
  434. nCkBufLen,
  435. lpszBuf,
  436. nCkBufLen ) == CSTR_EQUAL) )
  437. {
  438. lpszBuf += nCkBufLen;
  439. }
  440. else
  441. {
  442. //
  443. // Invalid character.
  444. //
  445. return (TRUE);
  446. }
  447. }
  448. }
  449. //
  450. // Parsing passed.
  451. // If the edit text changed, update edit box only if returning true.
  452. //
  453. if (!bInQuote && UpdateEditTest)
  454. {
  455. return (!SetDlgItemText(hDlg, nItemId, lpszSaveBuf));
  456. }
  457. //
  458. // If there are unmatched quotes return TRUE. Otherwise, return FALSE.
  459. //
  460. if (bInQuote)
  461. {
  462. return (TRUE);
  463. }
  464. return (FALSE);
  465. }
  466. ////////////////////////////////////////////////////////////////////////////
  467. //
  468. // No_Numerals_Error
  469. //
  470. // Display the no numerals allowed in "some control" error.
  471. //
  472. ////////////////////////////////////////////////////////////////////////////
  473. void No_Numerals_Error(
  474. HWND hDlg,
  475. int nItemId,
  476. int iStrId)
  477. {
  478. TCHAR szBuf[SIZE_300];
  479. TCHAR szBuf2[SIZE_128];
  480. TCHAR szErrorMessage[SIZE_300+SIZE_128];
  481. LoadString(hInstance, IDS_LOCALE_NO_NUMS_IN, szBuf, SIZE_300);
  482. LoadString(hInstance, iStrId, szBuf2, SIZE_128);
  483. wsprintf(szErrorMessage, szBuf, szBuf2);
  484. MessageBox(hDlg, szErrorMessage, NULL, MB_OK | MB_ICONINFORMATION);
  485. SetFocus(GetDlgItem(hDlg, nItemId));
  486. }
  487. ////////////////////////////////////////////////////////////////////////////
  488. //
  489. // Invalid_Chars_Error
  490. //
  491. // Display the invalid chars in "some style" error.
  492. //
  493. ////////////////////////////////////////////////////////////////////////////
  494. void Invalid_Chars_Error(
  495. HWND hDlg,
  496. int nItemId,
  497. int iStrId)
  498. {
  499. TCHAR szBuf[SIZE_300];
  500. TCHAR szBuf2[SIZE_128];
  501. TCHAR szErrorMessage[SIZE_300+SIZE_128];
  502. LoadString(hInstance, IDS_LOCALE_STYLE_ERR, szBuf, SIZE_300);
  503. LoadString(hInstance, iStrId, szBuf2, SIZE_128);
  504. wsprintf(szErrorMessage, szBuf, szBuf2);
  505. MessageBox(hDlg, szErrorMessage, NULL, MB_OK | MB_ICONINFORMATION);
  506. SetFocus(GetDlgItem(hDlg, nItemId));
  507. }
  508. ////////////////////////////////////////////////////////////////////////////
  509. //
  510. // Localize_Combobox_Styles
  511. //
  512. // Transform either all date or time style, as indicated by LCType, in
  513. // the indicated combobox from a value that the NLS will provide to a
  514. // localized value.
  515. //
  516. ////////////////////////////////////////////////////////////////////////////
  517. void Localize_Combobox_Styles(
  518. HWND hDlg,
  519. int nItemId,
  520. LCTYPE LCType)
  521. {
  522. BOOL bInQuote = FALSE;
  523. BOOL Map_Char = TRUE;
  524. TCHAR szBuf1[SIZE_128];
  525. TCHAR szBuf2[SIZE_128];
  526. LPTSTR lpszInBuf = szBuf1;
  527. LPTSTR lpszOutBuf = szBuf2;
  528. HWND hCtrl = GetDlgItem(hDlg, nItemId);
  529. DWORD ItemCnt = ComboBox_GetCount(hCtrl);
  530. DWORD Position = 0;
  531. DWORD dwIndex;
  532. if (!Styles_Localized)
  533. {
  534. return;
  535. }
  536. while (Position < ItemCnt)
  537. {
  538. //
  539. // Could check character count with CB_GETLBTEXTLEN to make sure
  540. // that the item text will fit in 128, but max values for these
  541. // items is 79 chars.
  542. //
  543. dwIndex = ComboBox_GetLBText(hCtrl, Position, szBuf1);
  544. if (dwIndex != CB_ERR)
  545. {
  546. lpszInBuf = szBuf1;
  547. lpszOutBuf = szBuf2;
  548. while (*lpszInBuf)
  549. {
  550. Map_Char = TRUE;
  551. #ifndef UNICODE
  552. if (IsDBCSLeadByte(*lpszInBuf))
  553. {
  554. //
  555. // Copy any double byte character straight through.
  556. //
  557. *lpszOutBuf++ = *lpszInBuf++;
  558. *lpszOutBuf++ = *lpszInBuf++;
  559. }
  560. else
  561. #endif
  562. {
  563. if (*lpszInBuf == CHAR_QUOTE)
  564. {
  565. bInQuote = !bInQuote;
  566. *lpszOutBuf++ = *lpszInBuf++;
  567. }
  568. else
  569. {
  570. if (!bInQuote)
  571. {
  572. if (LCType == LOCALE_STIMEFORMAT ||
  573. LCType == LOCALE_SLONGDATE)
  574. {
  575. Map_Char = FALSE;
  576. if (CompareString( UserLocaleID,
  577. 0,
  578. lpszInBuf,
  579. 1,
  580. TEXT("H"),
  581. 1 ) == CSTR_EQUAL)
  582. {
  583. *lpszOutBuf++ = szStyleH[0];
  584. #ifndef UNICODE
  585. if (IsDBCSLeadByte(*szStyleH))
  586. {
  587. *lpszOutBuf++ = szStyleH[1];
  588. }
  589. #endif
  590. }
  591. else if (CompareString( UserLocaleID,
  592. 0,
  593. lpszInBuf,
  594. 1,
  595. TEXT("h"),
  596. 1 ) == CSTR_EQUAL)
  597. {
  598. *lpszOutBuf++ = szStyleh[0];
  599. #ifndef UNICODE
  600. if (IsDBCSLeadByte(*szStyleh))
  601. {
  602. *lpszOutBuf++ = szStyleh[1];
  603. }
  604. #endif
  605. }
  606. else if (CompareString( UserLocaleID,
  607. 0,
  608. lpszInBuf,
  609. 1,
  610. TEXT("m"),
  611. 1 ) == CSTR_EQUAL)
  612. {
  613. *lpszOutBuf++ = szStylem[0];
  614. #ifndef UNICODE
  615. if (IsDBCSLeadByte(*szStylem))
  616. {
  617. *lpszOutBuf++ = szStylem[1];
  618. }
  619. #endif
  620. }
  621. else if (CompareString( UserLocaleID,
  622. 0,
  623. lpszInBuf,
  624. 1,
  625. TEXT("s"),
  626. 1 ) == CSTR_EQUAL)
  627. {
  628. *lpszOutBuf++ = szStyles[0];
  629. #ifndef UNICODE
  630. if (IsDBCSLeadByte(*szStyles))
  631. {
  632. *lpszOutBuf++ = szStyles[1];
  633. }
  634. #endif
  635. }
  636. else if (CompareString( UserLocaleID,
  637. 0,
  638. lpszInBuf,
  639. 1,
  640. TEXT("t"),
  641. 1 ) == CSTR_EQUAL)
  642. {
  643. *lpszOutBuf++ = szStylet[0];
  644. #ifndef UNICODE
  645. if (IsDBCSLeadByte(*szStylet))
  646. {
  647. *lpszOutBuf++ = szStylet[1];
  648. }
  649. #endif
  650. }
  651. else
  652. {
  653. Map_Char = TRUE;
  654. }
  655. }
  656. if (LCType == LOCALE_SSHORTDATE ||
  657. (LCType == LOCALE_SLONGDATE && Map_Char))
  658. {
  659. Map_Char = FALSE;
  660. if (CompareString( UserLocaleID,
  661. 0,
  662. lpszInBuf,
  663. 1,
  664. TEXT("d"),
  665. 1 ) == CSTR_EQUAL)
  666. {
  667. *lpszOutBuf++ = szStyled[0];
  668. #ifndef UNICODE
  669. if (IsDBCSLeadByte(*szStyled))
  670. {
  671. *lpszOutBuf++ = szStyled[1];
  672. }
  673. #endif
  674. }
  675. else if (CompareString( UserLocaleID,
  676. 0,
  677. lpszInBuf,
  678. 1,
  679. TEXT("M"),
  680. 1 ) == CSTR_EQUAL)
  681. {
  682. *lpszOutBuf++ = szStyleM[0];
  683. #ifndef UNICODE
  684. if (IsDBCSLeadByte(*szStyleM))
  685. {
  686. *lpszOutBuf++ = szStyleM[1];
  687. }
  688. #endif
  689. }
  690. else if (CompareString( UserLocaleID,
  691. 0,
  692. lpszInBuf,
  693. 1,
  694. TEXT("y"),
  695. 1 ) == CSTR_EQUAL)
  696. {
  697. *lpszOutBuf++ = szStyley[0];
  698. #ifndef UNICODE
  699. if (IsDBCSLeadByte(*szStyley))
  700. {
  701. *lpszOutBuf++ = szStyley[1];
  702. }
  703. #endif
  704. }
  705. else
  706. {
  707. Map_Char = TRUE;
  708. }
  709. }
  710. }
  711. if (Map_Char)
  712. {
  713. *lpszOutBuf++ = *lpszInBuf++;
  714. }
  715. else
  716. {
  717. lpszInBuf++;
  718. }
  719. }
  720. }
  721. }
  722. //
  723. // Append null to localized string.
  724. //
  725. *lpszOutBuf = 0;
  726. ComboBox_DeleteString(hCtrl, Position);
  727. ComboBox_InsertString(hCtrl, Position, szBuf2);
  728. }
  729. Position++;
  730. }
  731. }
  732. ////////////////////////////////////////////////////////////////////////////
  733. //
  734. // NLSize_Style
  735. //
  736. // Transform either date or time style, as indicated by LCType, from a
  737. // localized value to one that the NLS API will recognize.
  738. //
  739. ////////////////////////////////////////////////////////////////////////////
  740. BOOL NLSize_Style(
  741. HWND hDlg,
  742. int nItemId,
  743. LPTSTR lpszOutBuf,
  744. LCTYPE LCType)
  745. {
  746. BOOL bInQuote = FALSE;
  747. BOOL Map_Char = TRUE;
  748. TCHAR szBuf[SIZE_128];
  749. LPTSTR lpszInBuf = szBuf;
  750. LPTSTR lpNLSChars1;
  751. LPTSTR lpNLSChars2;
  752. HWND hCtrl = GetDlgItem(hDlg, nItemId);
  753. DWORD dwIndex = ComboBox_GetCurSel(hCtrl);
  754. BOOL TextFromEditBox = dwIndex == CB_ERR;
  755. int Cmp_Size;
  756. #ifndef UNICODE
  757. BOOL Is_Dbl = FALSE;
  758. #endif
  759. //
  760. // If there is no selection, get whatever is in the edit box.
  761. //
  762. if (TextFromEditBox)
  763. {
  764. dwIndex = GetDlgItemText(hDlg, nItemId, szBuf, SIZE_128);
  765. if (dwIndex)
  766. {
  767. //
  768. // Get text succeeded.
  769. //
  770. szBuf[dwIndex] = 0;
  771. }
  772. else
  773. {
  774. //
  775. // Get text failed.
  776. //
  777. dwIndex = (DWORD)CB_ERR;
  778. }
  779. }
  780. else
  781. {
  782. dwIndex = ComboBox_GetLBText(hCtrl, dwIndex, szBuf);
  783. }
  784. if (!Styles_Localized)
  785. {
  786. lstrcpy(lpszOutBuf, lpszInBuf);
  787. return (FALSE);
  788. }
  789. switch (LCType)
  790. {
  791. case ( LOCALE_STIMEFORMAT ) :
  792. {
  793. lpNLSChars1 = szTLetters;
  794. lpNLSChars2 = szTCaseSwap;
  795. break;
  796. }
  797. case ( LOCALE_SLONGDATE ) :
  798. {
  799. lpNLSChars1 = szLDLetters;
  800. lpNLSChars2 = szLDCaseSwap;
  801. break;
  802. }
  803. case ( LOCALE_SSHORTDATE ) :
  804. {
  805. lpNLSChars1 = szSDLetters;
  806. lpNLSChars2 = szSDCaseSwap;
  807. break;
  808. }
  809. }
  810. while (*lpszInBuf)
  811. {
  812. Map_Char = TRUE;
  813. #ifdef UNICODE
  814. Cmp_Size = 1;
  815. #else
  816. Is_Dbl = IsDBCSLeadByte(*lpszInBuf);
  817. Cmp_Size = Is_Dbl ? 2 : 1;
  818. #endif
  819. if (*lpszInBuf == CHAR_QUOTE)
  820. {
  821. bInQuote = !bInQuote;
  822. *lpszOutBuf++ = *lpszInBuf++;
  823. }
  824. else
  825. {
  826. if (!bInQuote)
  827. {
  828. if (LCType == LOCALE_STIMEFORMAT || LCType == LOCALE_SLONGDATE)
  829. {
  830. Map_Char = FALSE;
  831. if (CompareString( UserLocaleID,
  832. 0,
  833. lpszInBuf,
  834. Cmp_Size,
  835. szStyleH,
  836. -1 ) == CSTR_EQUAL)
  837. {
  838. *lpszOutBuf++ = CHAR_CAP_H;
  839. }
  840. else if (CompareString( UserLocaleID,
  841. 0,
  842. lpszInBuf,
  843. Cmp_Size,
  844. szStyleh,
  845. -1 ) == CSTR_EQUAL)
  846. {
  847. *lpszOutBuf++ = CHAR_SML_H;
  848. }
  849. else if (CompareString( UserLocaleID,
  850. 0,
  851. lpszInBuf,
  852. Cmp_Size,
  853. szStylem,
  854. -1 ) == CSTR_EQUAL)
  855. {
  856. *lpszOutBuf++ = CHAR_SML_M;
  857. }
  858. else if (CompareString( UserLocaleID,
  859. 0,
  860. lpszInBuf,
  861. Cmp_Size,
  862. szStyles,
  863. -1 ) == CSTR_EQUAL)
  864. {
  865. *lpszOutBuf++ = CHAR_SML_S;
  866. }
  867. else if (CompareString( UserLocaleID,
  868. 0,
  869. lpszInBuf,
  870. Cmp_Size,
  871. szStylet,
  872. -1 ) == CSTR_EQUAL)
  873. {
  874. *lpszOutBuf++ = CHAR_SML_T;
  875. }
  876. else
  877. {
  878. Map_Char = TRUE;
  879. }
  880. }
  881. if (LCType == LOCALE_SSHORTDATE ||
  882. (LCType == LOCALE_SLONGDATE && Map_Char))
  883. {
  884. Map_Char = FALSE;
  885. if (CompareString( UserLocaleID,
  886. 0,
  887. lpszInBuf,
  888. Cmp_Size,
  889. szStyled,
  890. -1 ) == CSTR_EQUAL)
  891. {
  892. *lpszOutBuf++ = CHAR_SML_D;
  893. }
  894. else if (CompareString( UserLocaleID,
  895. 0,
  896. lpszInBuf,
  897. Cmp_Size,
  898. szStyleM,
  899. -1) == CSTR_EQUAL)
  900. {
  901. *lpszOutBuf++ = CHAR_CAP_M;
  902. }
  903. else if (CompareString( UserLocaleID,
  904. 0,
  905. lpszInBuf,
  906. Cmp_Size,
  907. szStyley,
  908. -1 ) == CSTR_EQUAL)
  909. {
  910. *lpszOutBuf++ = CHAR_SML_Y;
  911. }
  912. else if (CompareString( UserLocaleID,
  913. 0,
  914. lpszInBuf,
  915. Cmp_Size,
  916. TEXT("g"),
  917. -1) == CSTR_EQUAL)
  918. {
  919. //
  920. // g is not localized, but it's legal.
  921. //
  922. *lpszOutBuf++ = CHAR_SML_G;
  923. }
  924. else
  925. {
  926. Map_Char = TRUE;
  927. }
  928. }
  929. }
  930. if (Map_Char)
  931. {
  932. //
  933. // Just copy chars in quotes or chars that are not
  934. // recognized. Leave the char checking to the other
  935. // function. However, do check for NLS standard chars
  936. // that were not supposed to be here due to localization.
  937. //
  938. if ( !bInQuote &&
  939. #ifndef UNICODE
  940. !Is_Dbl &&
  941. #endif
  942. (CompareString( UserLocaleID,
  943. 0,
  944. lpszInBuf,
  945. Cmp_Size,
  946. TEXT(" "),
  947. -1 ) != CSTR_EQUAL) &&
  948. ( _tcschr(lpNLSChars1, *lpszInBuf) ||
  949. _tcschr(lpNLSChars2, *lpszInBuf) ) )
  950. {
  951. return (TRUE);
  952. }
  953. *lpszOutBuf++ = *lpszInBuf++;
  954. #ifndef UNICODE
  955. if (Is_Dbl)
  956. {
  957. //
  958. // Copy 2nd byte.
  959. //
  960. *lpszOutBuf++ = *lpszInBuf++;
  961. }
  962. #endif
  963. }
  964. #ifndef UNICODE
  965. else if (Is_Dbl)
  966. {
  967. lpszInBuf += 2;
  968. }
  969. #endif
  970. else
  971. {
  972. lpszInBuf++;
  973. }
  974. }
  975. }
  976. //
  977. // Append null to localized string.
  978. //
  979. *lpszOutBuf = 0;
  980. return (FALSE);
  981. }
  982. #ifndef WINNT
  983. ////////////////////////////////////////////////////////////////////////////
  984. //
  985. // SDate3_1_Compatibility
  986. //
  987. // There is a requirement to keep windows 3.1 compatibility in the
  988. // registry (win.ini). Only allow 1 or 2 'M's, 1 or 2 'd's, and
  989. // 2 or 4 'y's. The remainder of the date style is compatible.
  990. //
  991. ////////////////////////////////////////////////////////////////////////////
  992. void SDate3_1_Compatibility(
  993. LPTSTR lpszBuf,
  994. int Buf_Size)
  995. {
  996. BOOL bInQuote = FALSE;
  997. int Index, Del_Cnt;
  998. int Len = lstrlen(lpszBuf);
  999. int MCnt = 0; // running total of Ms
  1000. int dCnt = 0; // running total of ds
  1001. int yCnt = 0; // running total of ys
  1002. while (*lpszBuf)
  1003. {
  1004. #ifndef UNICODE
  1005. if (IsDBCSLeadByte(*lpszBuf))
  1006. {
  1007. lpszBuf += 2;
  1008. }
  1009. else
  1010. #endif
  1011. {
  1012. if (bInQuote)
  1013. {
  1014. bInQuote = (*lpszBuf != CHAR_QUOTE);
  1015. lpszBuf++;
  1016. }
  1017. else if (*lpszBuf == CHAR_CAP_M)
  1018. {
  1019. if (MCnt++ < 2)
  1020. {
  1021. lpszBuf++;
  1022. }
  1023. else
  1024. {
  1025. //
  1026. // At least 1 extra M. Move all of the chars, including
  1027. // null, up by Del_Cnt.
  1028. //
  1029. Del_Cnt = 1;
  1030. Index = 1;
  1031. while (lpszBuf[Index++] == CHAR_CAP_M)
  1032. {
  1033. Del_Cnt++;
  1034. }
  1035. for (Index = 0; Index <= Len - Del_Cnt + 1; Index++)
  1036. {
  1037. lpszBuf[Index] = lpszBuf[Index + Del_Cnt];
  1038. }
  1039. Len -= Del_Cnt;
  1040. }
  1041. }
  1042. else if (*lpszBuf == CHAR_SML_D)
  1043. {
  1044. if (dCnt++ < 2)
  1045. {
  1046. lpszBuf++;
  1047. }
  1048. else
  1049. {
  1050. //
  1051. // At least 1 extra d. Move all of the chars, including
  1052. // null, up by Del_Cnt.
  1053. //
  1054. Del_Cnt = 1;
  1055. Index = 1;
  1056. while (lpszBuf[Index++] == CHAR_SML_D)
  1057. {
  1058. Del_Cnt++;
  1059. }
  1060. for (Index = 0; Index <= Len - Del_Cnt + 1; Index++)
  1061. {
  1062. lpszBuf[Index] = lpszBuf[Index + Del_Cnt];
  1063. }
  1064. Len -= Del_Cnt;
  1065. }
  1066. }
  1067. else if (*lpszBuf == CHAR_SML_Y)
  1068. {
  1069. if (yCnt == 0 || yCnt == 2)
  1070. {
  1071. if (lpszBuf[1] == CHAR_SML_Y)
  1072. {
  1073. lpszBuf += 2;
  1074. yCnt += 2;
  1075. }
  1076. else if (Len < Buf_Size - 1)
  1077. {
  1078. //
  1079. // Odd # of ys & room for one more.
  1080. // Move the remaining text down by 1 (the y will
  1081. // be copied).
  1082. //
  1083. // Use Del_Cnt for unparsed string length.
  1084. //
  1085. Del_Cnt = lstrlen(lpszBuf);
  1086. for (Index = Del_Cnt + 1; Index > 0; Index--)
  1087. {
  1088. lpszBuf[Index] = lpszBuf[Index - 1];
  1089. }
  1090. }
  1091. else
  1092. {
  1093. //
  1094. // No room, move all of the chars, including null,
  1095. // up by 1.
  1096. //
  1097. for (Index = 0; Index <= Len; Index++)
  1098. {
  1099. lpszBuf[Index] = lpszBuf[Index + 1];
  1100. }
  1101. Len--;
  1102. }
  1103. }
  1104. else
  1105. {
  1106. //
  1107. // At least 1 extra y. Move all of the chars, including
  1108. // null, up by Del_Cnt.
  1109. //
  1110. Del_Cnt = 1;
  1111. Index = 1;
  1112. while (lpszBuf[Index++] == CHAR_SML_Y)
  1113. {
  1114. Del_Cnt++;
  1115. }
  1116. for (Index = 0; Index <= Len - Del_Cnt + 1; Index++)
  1117. {
  1118. lpszBuf[Index] = lpszBuf[Index + Del_Cnt];
  1119. }
  1120. Len -= Del_Cnt;
  1121. }
  1122. }
  1123. else if (*lpszBuf == CHAR_QUOTE)
  1124. {
  1125. lpszBuf++;
  1126. bInQuote = TRUE;
  1127. }
  1128. else
  1129. {
  1130. lpszBuf++;
  1131. }
  1132. }
  1133. }
  1134. }
  1135. #endif
  1136. ////////////////////////////////////////////////////////////////////////////
  1137. //
  1138. // Set_Locale_Values
  1139. //
  1140. // Set_Locale_Values is called for each LCType that has either been
  1141. // directly modified via a user change, or indirectly modified by the user
  1142. // changing the regional locale setting. When a dialog handle is available,
  1143. // Set_Locale_Values will pull the new value of the LCType from the
  1144. // appropriate list box (this is a direct change), register it in the
  1145. // locale database, and then update the registry string. If no dialog
  1146. // handle is available, it will simply update the registry string based on
  1147. // the locale registry. If the registration succeeds, return true.
  1148. // Otherwise, return false.
  1149. //
  1150. ////////////////////////////////////////////////////////////////////////////
  1151. BOOL Set_Locale_Values(
  1152. HWND hDlg,
  1153. LCTYPE LCType,
  1154. int nItemId,
  1155. LPTSTR lpIniStr,
  1156. BOOL bValue,
  1157. int Ordinal_Offset,
  1158. LPTSTR Append_Str,
  1159. LPTSTR NLS_Str)
  1160. {
  1161. DWORD dwIndex;
  1162. BOOL bSuccess = TRUE;
  1163. TCHAR szBuf[SIZE_128 + 1];
  1164. LPTSTR pBuf = szBuf;
  1165. HWND hCtrl;
  1166. if (NLS_Str)
  1167. {
  1168. //
  1169. // Use a non-localized string.
  1170. //
  1171. lstrcpy(pBuf, NLS_Str);
  1172. bSuccess = SetLocaleInfo(UserLocaleID, LCType, pBuf);
  1173. }
  1174. else if (hDlg)
  1175. {
  1176. //
  1177. // Get the new value from the list box.
  1178. //
  1179. hCtrl = GetDlgItem(hDlg, nItemId);
  1180. dwIndex = ComboBox_GetCurSel(hCtrl);
  1181. //
  1182. // If there is no selection, get whatever is in the edit box.
  1183. //
  1184. if (dwIndex == CB_ERR)
  1185. {
  1186. dwIndex = GetDlgItemText(hDlg, nItemId, pBuf, SIZE_128);
  1187. if (dwIndex)
  1188. {
  1189. //
  1190. // Get text succeeded.
  1191. //
  1192. pBuf[dwIndex] = 0;
  1193. }
  1194. else
  1195. {
  1196. //
  1197. // Get text failed.
  1198. // Allow the AM/PM symbols to be set as empty strings.
  1199. // Otherwise, fail.
  1200. //
  1201. if ((LCType == LOCALE_S1159) || (LCType == LOCALE_S2359))
  1202. {
  1203. pBuf[0] = 0;
  1204. }
  1205. else
  1206. {
  1207. bSuccess = FALSE;
  1208. }
  1209. }
  1210. }
  1211. else if (bValue)
  1212. {
  1213. //
  1214. // Need string representation of ordinal locale value.
  1215. //
  1216. if (nItemId == IDC_CALENDAR_TYPE)
  1217. {
  1218. dwIndex = (DWORD)ComboBox_GetItemData(hCtrl, dwIndex);
  1219. }
  1220. else
  1221. {
  1222. //
  1223. // Ordinal_Offset is required since calendar is 1 based,
  1224. // not 0 based.
  1225. //
  1226. dwIndex += Ordinal_Offset;
  1227. }
  1228. //
  1229. // Special case the grouping string.
  1230. //
  1231. if (nItemId == IDC_NUM_DIGITS_GROUP)
  1232. {
  1233. switch (dwIndex)
  1234. {
  1235. case ( 0 ) :
  1236. {
  1237. lstrcpy(pBuf, TEXT("0"));
  1238. break;
  1239. }
  1240. case ( 1 ) :
  1241. {
  1242. lstrcpy(pBuf, TEXT("3"));
  1243. break;
  1244. }
  1245. case ( 2 ) :
  1246. {
  1247. lstrcpy(pBuf, TEXT("3;2"));
  1248. break;
  1249. }
  1250. case ( 3 ) :
  1251. {
  1252. wsprintf( pBuf,
  1253. TEXT("%d"),
  1254. ComboBox_GetItemData(hCtrl, dwIndex) );
  1255. break;
  1256. }
  1257. }
  1258. }
  1259. else if (dwIndex < cInt_Str)
  1260. {
  1261. lstrcpy(pBuf, aInt_Str[dwIndex]);
  1262. }
  1263. else
  1264. {
  1265. wsprintf(pBuf, TEXT("%d"), dwIndex);
  1266. }
  1267. }
  1268. else
  1269. {
  1270. //
  1271. // Get actual value of locale data.
  1272. //
  1273. bSuccess = (ComboBox_GetLBText(hCtrl, dwIndex, pBuf) != CB_ERR);
  1274. }
  1275. if (bSuccess)
  1276. {
  1277. //
  1278. // If edit text, index value or selection text succeeds...
  1279. //
  1280. if (Append_Str)
  1281. {
  1282. lstrcat(pBuf, Append_Str);
  1283. }
  1284. //
  1285. // If this is sNativeDigits, the LPK is installed, and the
  1286. // first char is 0x206f (nominal digit shapes), then do not
  1287. // store the first char in the registry.
  1288. //
  1289. if ((LCType == LOCALE_SNATIVEDIGITS) &&
  1290. (bLPKInstalled) &&
  1291. (pBuf[0] == TEXT('\x206f')))
  1292. {
  1293. pBuf++;
  1294. }
  1295. bSuccess = SetLocaleInfo( UserLocaleID, LCType, pBuf );
  1296. }
  1297. }
  1298. if (lpIniStr && bSuccess)
  1299. {
  1300. //
  1301. // Set the registry string to the string that is stored in the list
  1302. // box. If there is no dialog handle, get the required string
  1303. // locale value from the NLS function. Write the associated string
  1304. // into the registry.
  1305. //
  1306. if (!hDlg && !NLS_Str)
  1307. {
  1308. GetLocaleInfo( UserLocaleID,
  1309. LCType | LOCALE_NOUSEROVERRIDE,
  1310. pBuf,
  1311. SIZE_128 );
  1312. }
  1313. #ifndef WINNT
  1314. //
  1315. // There is a requirement to keep windows 3.1 compatibility in the
  1316. // win.ini. There are some win32 short date formats that are
  1317. // incompatible with exisiting win 3.1 apps... modify these styles.
  1318. //
  1319. if (LCType == LOCALE_SSHORTDATE)
  1320. {
  1321. SDate3_1_Compatibility(pBuf, SIZE_128);
  1322. }
  1323. #endif
  1324. //
  1325. // Check the value whether it is empty or not.
  1326. //
  1327. switch (LCType)
  1328. {
  1329. case ( LOCALE_STHOUSAND ) :
  1330. case ( LOCALE_SDECIMAL ) :
  1331. case ( LOCALE_SDATE ) :
  1332. case ( LOCALE_STIME ) :
  1333. case ( LOCALE_SLIST ) :
  1334. {
  1335. CheckEmptyString(pBuf);
  1336. break;
  1337. }
  1338. }
  1339. //
  1340. // Set the locale information in the registry.
  1341. //
  1342. // NOTE: We want to use SetLocaleInfo if possible so that the
  1343. // NLS cache is updated right away. Otherwise, we'll
  1344. // simply use WriteProfileString.
  1345. //
  1346. if (!SetLocaleInfo(UserLocaleID, LCType, pBuf))
  1347. {
  1348. WriteProfileString(szIntl, lpIniStr, pBuf);
  1349. }
  1350. }
  1351. else if (!bSuccess)
  1352. {
  1353. LoadString(hInstance, IDS_LOCALE_SET_ERROR, szBuf, SIZE_128);
  1354. MessageBox(hDlg, szBuf, NULL, MB_OK | MB_ICONINFORMATION);
  1355. SetFocus(GetDlgItem(hDlg, nItemId));
  1356. return (FALSE);
  1357. }
  1358. return (TRUE);
  1359. }
  1360. ////////////////////////////////////////////////////////////////////////////
  1361. //
  1362. // Set_List_Values
  1363. //
  1364. // Set_List_Values is called several times for each drop down list which is
  1365. // populated via an enum function. The first call to this function should
  1366. // be with a valid dialog handle, valid dialog item ID, and null string
  1367. // value. If the function is not already in use, it will clear the list box
  1368. // and store the handle and id information for the subsequent calls to this
  1369. // function that will be made by the enumeration function. The calls from
  1370. // the enumeration function will add the specified string values to the
  1371. // list box. When the enumeration function is complete, this function
  1372. // should be called with a null dialog handle, the valid dialog item id,
  1373. // and a null string value. This will clear all of the state information,
  1374. // including the lock flag.
  1375. //
  1376. ////////////////////////////////////////////////////////////////////////////
  1377. BOOL Set_List_Values(
  1378. HWND hDlg,
  1379. int nItemId,
  1380. LPTSTR lpValueString)
  1381. {
  1382. static BOOL bLock, bString;
  1383. static HWND hDialog;
  1384. static int nDItemId, nID;
  1385. if (!lpValueString)
  1386. {
  1387. //
  1388. // Clear the lock if there is no dialog handle and the item IDs
  1389. // match.
  1390. //
  1391. if (bLock && !hDlg && (nItemId == nDItemId))
  1392. {
  1393. if (nItemId != IDC_CALENDAR_TYPE)
  1394. {
  1395. hDialog = 0;
  1396. nDItemId = 0;
  1397. bLock = FALSE;
  1398. }
  1399. else
  1400. {
  1401. if (bString)
  1402. {
  1403. hDialog = 0;
  1404. nDItemId = 0;
  1405. bLock = FALSE;
  1406. bString = FALSE;
  1407. }
  1408. else
  1409. {
  1410. nID = 0;
  1411. bString = TRUE;
  1412. }
  1413. }
  1414. return (TRUE);
  1415. }
  1416. //
  1417. // Return false, for failure, if the function is locked or if the
  1418. // handle or ID parameters are null.
  1419. //
  1420. if (bLock || !hDlg || !nItemId)
  1421. {
  1422. return (FALSE);
  1423. }
  1424. //
  1425. // Prepare for subsequent calls to populate the list box.
  1426. //
  1427. bLock = TRUE;
  1428. hDialog = hDlg;
  1429. nDItemId = nItemId;
  1430. }
  1431. else if (bLock && hDialog && nDItemId)
  1432. {
  1433. //
  1434. // Add the string to the list box.
  1435. //
  1436. if (!bString)
  1437. {
  1438. ComboBox_InsertString( GetDlgItem(hDialog, nDItemId),
  1439. -1,
  1440. lpValueString );
  1441. }
  1442. else
  1443. {
  1444. ComboBox_SetItemData( GetDlgItem(hDialog, nDItemId),
  1445. nID++,
  1446. Intl_StrToLong(lpValueString) );
  1447. }
  1448. }
  1449. else
  1450. {
  1451. return (FALSE);
  1452. }
  1453. return (TRUE);
  1454. }
  1455. ////////////////////////////////////////////////////////////////////////////
  1456. //
  1457. // DropDown_Use_Locale_Values
  1458. //
  1459. // Get the user locale value for the locale type specifier. Add it to
  1460. // the list box and make this value the current selection. If the user
  1461. // locale value for the locale type is different than the system value,
  1462. // add the system value to the list box. If the user default is different
  1463. // than the user override, add the user default.
  1464. //
  1465. ////////////////////////////////////////////////////////////////////////////
  1466. void DropDown_Use_Locale_Values(
  1467. HWND hDlg,
  1468. LCTYPE LCType,
  1469. int nItemId)
  1470. {
  1471. TCHAR szBuf[SIZE_128];
  1472. TCHAR szCmpBuf1[SIZE_128];
  1473. TCHAR szCmpBuf2[SIZE_128];
  1474. HWND hCtrl = GetDlgItem(hDlg, nItemId);
  1475. int ctr;
  1476. if (GetLocaleInfo(UserLocaleID, LCType, szBuf, SIZE_128))
  1477. {
  1478. ComboBox_SetCurSel(hCtrl, ComboBox_InsertString(hCtrl, -1, szBuf));
  1479. //
  1480. // If the system setting is different, add it to the list box.
  1481. //
  1482. if (GetLocaleInfo( SysLocaleID,
  1483. LCType | LOCALE_NOUSEROVERRIDE,
  1484. szCmpBuf1,
  1485. SIZE_128 ))
  1486. {
  1487. if (CompareString( UserLocaleID,
  1488. 0,
  1489. szCmpBuf1,
  1490. -1,
  1491. szBuf,
  1492. -1 ) != CSTR_EQUAL)
  1493. {
  1494. ComboBox_InsertString(hCtrl, -1, szCmpBuf1);
  1495. }
  1496. }
  1497. //
  1498. // If the default user locale setting is different than the user
  1499. // overridden setting and different than the system setting, add
  1500. // it to the list box.
  1501. //
  1502. if (GetLocaleInfo( UserLocaleID,
  1503. LCType | LOCALE_NOUSEROVERRIDE,
  1504. szCmpBuf2,
  1505. SIZE_128 ))
  1506. {
  1507. if (CompareString(UserLocaleID, 0, szCmpBuf2, -1, szBuf, -1) != CSTR_EQUAL &&
  1508. CompareString(UserLocaleID, 0, szCmpBuf2, -1, szCmpBuf1, -1) != CSTR_EQUAL)
  1509. {
  1510. ComboBox_InsertString(hCtrl, -1, szCmpBuf2);
  1511. }
  1512. }
  1513. }
  1514. else
  1515. {
  1516. //
  1517. // Failed to get user value, try for system value. If system value
  1518. // fails, display a message box indicating that there was a locale
  1519. // problem.
  1520. //
  1521. if (GetLocaleInfo( SysLocaleID,
  1522. LCType | LOCALE_NOUSEROVERRIDE,
  1523. szBuf,
  1524. SIZE_128 ))
  1525. {
  1526. ComboBox_SetCurSel(hCtrl, ComboBox_InsertString(hCtrl, -1, szBuf));
  1527. }
  1528. else
  1529. {
  1530. MessageBox(hDlg, szLocaleGetError, NULL, MB_OK | MB_ICONINFORMATION);
  1531. }
  1532. }
  1533. //
  1534. // If it's the date separator, then we want slash, dot, and dash in
  1535. // the list in addition to the user and system settings (if different).
  1536. //
  1537. if (LCType == LOCALE_SDATE)
  1538. {
  1539. for (ctr = 0; ctr < NUM_DATE_SEPARATORS; ctr++)
  1540. {
  1541. if (ComboBox_FindStringExact( hCtrl,
  1542. -1,
  1543. pDateSeparators[ctr] ) == CB_ERR)
  1544. {
  1545. ComboBox_InsertString(hCtrl, -1, pDateSeparators[ctr]);
  1546. }
  1547. }
  1548. }
  1549. //
  1550. // If it's the AM symbol, then we want AM in the list in addition
  1551. // to the user and system settings (if different).
  1552. //
  1553. if (LCType == LOCALE_S1159)
  1554. {
  1555. for (ctr = 0; ctr < NUM_AM_SYMBOLS; ctr++)
  1556. {
  1557. if (ComboBox_FindStringExact( hCtrl,
  1558. -1,
  1559. pAMSymbols[ctr] ) == CB_ERR)
  1560. {
  1561. ComboBox_InsertString(hCtrl, -1, pAMSymbols[ctr]);
  1562. }
  1563. }
  1564. }
  1565. //
  1566. // If it's the PM symbol, then we want PM in the list in addition
  1567. // to the user and system settings (if different).
  1568. //
  1569. if (LCType == LOCALE_S2359)
  1570. {
  1571. for (ctr = 0; ctr < NUM_PM_SYMBOLS; ctr++)
  1572. {
  1573. if (ComboBox_FindStringExact( hCtrl,
  1574. -1,
  1575. pPMSymbols[ctr] ) == CB_ERR)
  1576. {
  1577. ComboBox_InsertString(hCtrl, -1, pPMSymbols[ctr]);
  1578. }
  1579. }
  1580. }
  1581. #ifdef UNICODE
  1582. //
  1583. // If it's the currency symbol, then we want the Euro symbol and dollar
  1584. // sign in the list in addition to the user and system settings (if
  1585. // different).
  1586. //
  1587. if (LCType == LOCALE_SCURRENCY)
  1588. {
  1589. for (ctr = 0; ctr < NUM_CURRENCY_SYMBOLS; ctr++)
  1590. {
  1591. if (ComboBox_FindStringExact( hCtrl,
  1592. -1,
  1593. pCurrencySymbols[ctr] ) == CB_ERR)
  1594. {
  1595. ComboBox_InsertString(hCtrl, -1, pCurrencySymbols[ctr]);
  1596. }
  1597. }
  1598. }
  1599. #endif
  1600. }
  1601. ////////////////////////////////////////////////////////////////////////////
  1602. //
  1603. // EnumProc
  1604. //
  1605. // This call back function calls Set_List_Values assuming that whatever
  1606. // code called the NLS enumeration function (or dummied enumeration
  1607. // function) has properly set up Set_List_Values for the list box
  1608. // population.
  1609. //
  1610. ////////////////////////////////////////////////////////////////////////////
  1611. BOOL CALLBACK EnumProc(
  1612. LPTSTR lpValueString)
  1613. {
  1614. return (Set_List_Values(0, 0, lpValueString));
  1615. }
  1616. ////////////////////////////////////////////////////////////////////////////
  1617. //
  1618. // EnumProcEx
  1619. //
  1620. // This call back function calls Set_List_Values assuming that whatever
  1621. // code called the enumeration function has properly set up
  1622. // Set_List_Values for the list box population.
  1623. // Also, this function fixes the string passed in to contain the correct
  1624. // decimal separator and negative sign, if appropriate.
  1625. //
  1626. ////////////////////////////////////////////////////////////////////////////
  1627. BOOL CALLBACK EnumProcEx(
  1628. LPTSTR lpValueString,
  1629. LPTSTR lpDecimalString,
  1630. LPTSTR lpNegativeString,
  1631. LPTSTR lpSymbolString)
  1632. {
  1633. TCHAR szString[SIZE_128];
  1634. LPTSTR pStr, pValStr, pTemp;
  1635. //
  1636. // Simplify things if we have a NULL string.
  1637. //
  1638. if (lpDecimalString && (*lpDecimalString == CHAR_NULL))
  1639. {
  1640. lpDecimalString = NULL;
  1641. }
  1642. if (lpNegativeString && (*lpNegativeString == CHAR_NULL))
  1643. {
  1644. lpNegativeString = NULL;
  1645. }
  1646. if (lpSymbolString && (*lpSymbolString == CHAR_NULL))
  1647. {
  1648. lpSymbolString = NULL;
  1649. }
  1650. //
  1651. // See if we need to do any substitutions.
  1652. //
  1653. if (lpDecimalString || lpNegativeString || lpSymbolString)
  1654. {
  1655. pValStr = lpValueString;
  1656. pStr = szString;
  1657. while (*pValStr)
  1658. {
  1659. if (lpDecimalString && (*pValStr == CHAR_DECIMAL))
  1660. {
  1661. //
  1662. // Substitute the current user decimal separator.
  1663. //
  1664. pTemp = lpDecimalString;
  1665. while (*pTemp)
  1666. {
  1667. *pStr = *pTemp;
  1668. pStr++;
  1669. pTemp++;
  1670. }
  1671. }
  1672. else if (lpNegativeString && (*pValStr == CHAR_HYPHEN))
  1673. {
  1674. //
  1675. // Substitute the current user negative sign.
  1676. //
  1677. pTemp = lpNegativeString;
  1678. while (*pTemp)
  1679. {
  1680. *pStr = *pTemp;
  1681. pStr++;
  1682. pTemp++;
  1683. }
  1684. }
  1685. else if (lpSymbolString && (*pValStr == CHAR_INTL_CURRENCY))
  1686. {
  1687. //
  1688. // Substitute the current user currency symbol.
  1689. //
  1690. pTemp = lpSymbolString;
  1691. while (*pTemp)
  1692. {
  1693. *pStr = *pTemp;
  1694. pStr++;
  1695. pTemp++;
  1696. }
  1697. }
  1698. else
  1699. {
  1700. //
  1701. // Simply copy the character.
  1702. //
  1703. *pStr = *pValStr;
  1704. pStr++;
  1705. }
  1706. pValStr++;
  1707. }
  1708. *pStr = CHAR_NULL;
  1709. return (Set_List_Values(0, 0, szString));
  1710. }
  1711. else
  1712. {
  1713. return (Set_List_Values(0, 0, lpValueString));
  1714. }
  1715. }
  1716. ////////////////////////////////////////////////////////////////////////////
  1717. //
  1718. // EnumLeadingZeros
  1719. //
  1720. ////////////////////////////////////////////////////////////////////////////
  1721. BOOL EnumLeadingZeros(
  1722. LEADINGZEROS_ENUMPROC lpLeadingZerosEnumProc,
  1723. LCID LCId,
  1724. DWORD dwFlags)
  1725. {
  1726. TCHAR szBuf[SIZE_128];
  1727. TCHAR szDecimal[SIZE_128];
  1728. //
  1729. // If there is no enum proc, return false to indicate a failure.
  1730. //
  1731. if (!lpLeadingZerosEnumProc)
  1732. {
  1733. return (FALSE);
  1734. }
  1735. //
  1736. // Get the Decimal Separator for the current user locale so that
  1737. // it may be displayed correctly.
  1738. //
  1739. if (!GetLocaleInfo(UserLocaleID, LOCALE_SDECIMAL, szDecimal, SIZE_128) ||
  1740. ((szDecimal[0] == CHAR_DECIMAL) && (szDecimal[1] == CHAR_NULL)))
  1741. {
  1742. szDecimal[0] = CHAR_NULL;
  1743. }
  1744. //
  1745. // Call enum proc with the NO string. Check to make sure the
  1746. // enum proc requests continuation.
  1747. //
  1748. LoadString(hInstance, IDS_NO_LZERO, szBuf, SIZE_128);
  1749. if (!lpLeadingZerosEnumProc(szBuf, szDecimal, NULL, NULL))
  1750. {
  1751. return (TRUE);
  1752. }
  1753. //
  1754. // Call enum proc with the YES string.
  1755. //
  1756. LoadString(hInstance, IDS_LZERO, szBuf, SIZE_128);
  1757. lpLeadingZerosEnumProc(szBuf, szDecimal, NULL, NULL);
  1758. return (TRUE);
  1759. }
  1760. ////////////////////////////////////////////////////////////////////////////
  1761. //
  1762. // EnumNegNumFmt
  1763. //
  1764. ////////////////////////////////////////////////////////////////////////////
  1765. BOOL EnumNegNumFmt(
  1766. NEGNUMFMT_ENUMPROC lpNegNumFmtEnumProc,
  1767. LCID LCId,
  1768. DWORD dwFlags)
  1769. {
  1770. TCHAR szDecimal[SIZE_128];
  1771. TCHAR szNeg[SIZE_128];
  1772. int ctr;
  1773. //
  1774. // If there is no enum proc, return false to indicate a failure.
  1775. //
  1776. if (!lpNegNumFmtEnumProc)
  1777. {
  1778. return (FALSE);
  1779. }
  1780. //
  1781. // Get the Decimal Separator for the current user locale so that
  1782. // it may be displayed correctly.
  1783. //
  1784. if (!GetLocaleInfo(UserLocaleID, LOCALE_SDECIMAL, szDecimal, SIZE_128) ||
  1785. ((szDecimal[0] == CHAR_DECIMAL) && (szDecimal[1] == CHAR_NULL)))
  1786. {
  1787. szDecimal[0] = CHAR_NULL;
  1788. }
  1789. //
  1790. // Get the Negative Sign for the current user locale so that
  1791. // it may be displayed correctly.
  1792. //
  1793. if (!GetLocaleInfo(UserLocaleID, LOCALE_SNEGATIVESIGN, szNeg, SIZE_128) ||
  1794. ((szNeg[0] == CHAR_HYPHEN) && (szNeg[1] == CHAR_NULL)))
  1795. {
  1796. szNeg[0] = CHAR_NULL;
  1797. }
  1798. //
  1799. // Call enum proc with each format string. Check to make sure
  1800. // the enum proc requests continuation.
  1801. //
  1802. for (ctr = 0; ctr < NUM_NEG_NUMBER_FORMATS; ctr++)
  1803. {
  1804. if (!lpNegNumFmtEnumProc( pNegNumberFormats[ctr],
  1805. szDecimal,
  1806. szNeg,
  1807. NULL ))
  1808. {
  1809. return (TRUE);
  1810. }
  1811. }
  1812. return (TRUE);
  1813. }
  1814. ////////////////////////////////////////////////////////////////////////////
  1815. //
  1816. // EnumMeasureSystem
  1817. //
  1818. ////////////////////////////////////////////////////////////////////////////
  1819. BOOL EnumMeasureSystem(
  1820. MEASURESYSTEM_ENUMPROC lpMeasureSystemEnumProc,
  1821. LCID LCId,
  1822. DWORD dwFlags)
  1823. {
  1824. TCHAR szBuf[SIZE_128];
  1825. //
  1826. // If there is no enum proc, return false to indicate a failure.
  1827. //
  1828. if (!lpMeasureSystemEnumProc)
  1829. {
  1830. return (FALSE);
  1831. }
  1832. //
  1833. // Call enum proc with the metric string. Check to make sure the
  1834. // enum proc requests continuation.
  1835. //
  1836. LoadString(hInstance, IDS_METRIC, szBuf, SIZE_128);
  1837. if (!lpMeasureSystemEnumProc(szBuf))
  1838. {
  1839. return (TRUE);
  1840. }
  1841. //
  1842. // Call enum proc with the U.S. string.
  1843. //
  1844. LoadString(hInstance, IDS_US, szBuf, SIZE_128);
  1845. lpMeasureSystemEnumProc(szBuf);
  1846. return (TRUE);
  1847. }
  1848. ////////////////////////////////////////////////////////////////////////////
  1849. //
  1850. // EnumPosCurrency
  1851. //
  1852. ////////////////////////////////////////////////////////////////////////////
  1853. BOOL EnumPosCurrency(
  1854. POSCURRENCY_ENUMPROC lpPosCurrencyEnumProc,
  1855. LCID LCId,
  1856. DWORD dwFlags)
  1857. {
  1858. TCHAR szDecimal[SIZE_128];
  1859. TCHAR szSymbol[SIZE_128];
  1860. int ctr;
  1861. //
  1862. // If there is no enum proc, return false to indicate a failure.
  1863. //
  1864. if (!lpPosCurrencyEnumProc)
  1865. {
  1866. return (FALSE);
  1867. }
  1868. //
  1869. // Get the Decimal Separator for the current user locale so that
  1870. // it may be displayed correctly.
  1871. //
  1872. if (!GetLocaleInfo(UserLocaleID, LOCALE_SMONDECIMALSEP, szDecimal, SIZE_128) ||
  1873. ((szDecimal[0] == CHAR_DECIMAL) && (szDecimal[1] == CHAR_NULL)))
  1874. {
  1875. szDecimal[0] = CHAR_NULL;
  1876. }
  1877. //
  1878. // Get the Currency Symbol for the current user locale so that
  1879. // it may be displayed correctly.
  1880. //
  1881. if (!GetLocaleInfo(UserLocaleID, LOCALE_SCURRENCY, szSymbol, SIZE_128) ||
  1882. ((szSymbol[0] == CHAR_INTL_CURRENCY) && (szSymbol[1] == CHAR_NULL)))
  1883. {
  1884. szSymbol[0] = CHAR_NULL;
  1885. }
  1886. //
  1887. // Call enum proc with each format string. Check to make sure the
  1888. // enum proc requests continuation.
  1889. //
  1890. for (ctr = 0; ctr < NUM_POS_CURRENCY_FORMATS; ctr++)
  1891. {
  1892. if (!lpPosCurrencyEnumProc( pPosCurrencyFormats[ctr],
  1893. szDecimal,
  1894. NULL,
  1895. szSymbol ))
  1896. {
  1897. return (TRUE);
  1898. }
  1899. }
  1900. return (TRUE);
  1901. }
  1902. ////////////////////////////////////////////////////////////////////////////
  1903. //
  1904. // EnumNegCurrency
  1905. //
  1906. ////////////////////////////////////////////////////////////////////////////
  1907. BOOL EnumNegCurrency(
  1908. NEGCURRENCY_ENUMPROC lpNegCurrencyEnumProc,
  1909. LCID LCId,
  1910. DWORD dwFlags)
  1911. {
  1912. TCHAR szDecimal[SIZE_128];
  1913. TCHAR szNeg[SIZE_128];
  1914. TCHAR szSymbol[SIZE_128];
  1915. int ctr;
  1916. //
  1917. // If there is no enum proc, return false to indicate a failure.
  1918. //
  1919. if (!lpNegCurrencyEnumProc)
  1920. {
  1921. return (FALSE);
  1922. }
  1923. //
  1924. // Get the Decimal Separator for the current user locale so that
  1925. // it may be displayed correctly.
  1926. //
  1927. if (!GetLocaleInfo(UserLocaleID, LOCALE_SMONDECIMALSEP, szDecimal, SIZE_128) ||
  1928. ((szDecimal[0] == CHAR_DECIMAL) && (szDecimal[1] == CHAR_NULL)))
  1929. {
  1930. szDecimal[0] = CHAR_NULL;
  1931. }
  1932. //
  1933. // Get the Negative Sign for the current user locale so that
  1934. // it may be displayed correctly.
  1935. //
  1936. if (!GetLocaleInfo(UserLocaleID, LOCALE_SNEGATIVESIGN, szNeg, SIZE_128) ||
  1937. ((szNeg[0] == CHAR_HYPHEN) && (szNeg[1] == CHAR_NULL)))
  1938. {
  1939. szNeg[0] = CHAR_NULL;
  1940. }
  1941. //
  1942. // Get the Currency Symbol for the current user locale so that
  1943. // it may be displayed correctly.
  1944. //
  1945. if (!GetLocaleInfo(UserLocaleID, LOCALE_SCURRENCY, szSymbol, SIZE_128) ||
  1946. ((szSymbol[0] == CHAR_INTL_CURRENCY) && (szSymbol[1] == CHAR_NULL)))
  1947. {
  1948. szSymbol[0] = CHAR_NULL;
  1949. }
  1950. //
  1951. // Call enum proc with each format string. Check to make sure the
  1952. // enum proc requests continuation.
  1953. //
  1954. for (ctr = 0; ctr < NUM_NEG_CURRENCY_FORMATS; ctr++)
  1955. {
  1956. if (!lpNegCurrencyEnumProc( pNegCurrencyFormats[ctr],
  1957. szDecimal,
  1958. szNeg,
  1959. szSymbol ))
  1960. {
  1961. return (TRUE);
  1962. }
  1963. }
  1964. return (TRUE);
  1965. }
  1966. ////////////////////////////////////////////////////////////////////////////
  1967. //
  1968. // CheckEmptyString
  1969. //
  1970. // If lpStr is empty, then it fills it with a null ("") string.
  1971. // If lpStr is filled only by space, fills with a blank (" ") string.
  1972. //
  1973. ////////////////////////////////////////////////////////////////////////////
  1974. void CheckEmptyString(
  1975. LPTSTR lpStr)
  1976. {
  1977. LPTSTR lpString;
  1978. WORD wStrCType[64];
  1979. if (!(*lpStr))
  1980. {
  1981. //
  1982. // Put "" string in buffer.
  1983. //
  1984. lstrcpy(lpStr, TEXT("\"\""));
  1985. }
  1986. else
  1987. {
  1988. for (lpString = lpStr; *lpString; lpString = CharNext(lpString))
  1989. {
  1990. GetStringTypeEx( LOCALE_USER_DEFAULT,
  1991. CT_CTYPE1,
  1992. lpString,
  1993. 1,
  1994. wStrCType);
  1995. if (wStrCType[0] != CHAR_SPACE)
  1996. {
  1997. return;
  1998. }
  1999. }
  2000. //
  2001. // Put " " string in buffer.
  2002. //
  2003. lstrcpy(lpStr, TEXT("\" \""));
  2004. }
  2005. }
  2006. ////////////////////////////////////////////////////////////////////////////
  2007. //
  2008. // SetDlgItemRTL
  2009. //
  2010. ////////////////////////////////////////////////////////////////////////////
  2011. void SetDlgItemRTL(
  2012. HWND hDlg,
  2013. UINT uItem)
  2014. {
  2015. HWND hItem = GetDlgItem(hDlg, uItem);
  2016. DWORD dwExStyle = GetWindowLong(hItem, GWL_EXSTYLE);
  2017. SetWindowLong(hItem, GWL_EXSTYLE, dwExStyle | WS_EX_RTLREADING);
  2018. }
  2019. ////////////////////////////////////////////////////////////////////////////
  2020. //
  2021. // ShowMsg
  2022. //
  2023. ////////////////////////////////////////////////////////////////////////////
  2024. int ShowMsg(
  2025. HWND hDlg,
  2026. UINT iMsg,
  2027. UINT iTitle,
  2028. UINT iType,
  2029. LPTSTR pString)
  2030. {
  2031. TCHAR szTitle[MAX_PATH];
  2032. TCHAR szMsg[MAX_PATH*2];
  2033. TCHAR szErrMsg[MAX_PATH*2];
  2034. LPTSTR pTitle = NULL;
  2035. if (iTitle)
  2036. {
  2037. if (LoadString(hInstance, iTitle, szTitle, ARRAYSIZE(szTitle)))
  2038. {
  2039. pTitle = szTitle;
  2040. }
  2041. }
  2042. if (pString)
  2043. {
  2044. if (LoadString(hInstance, iMsg, szMsg, ARRAYSIZE(szMsg)))
  2045. {
  2046. wsprintf(szErrMsg, szMsg, pString);
  2047. return (MessageBox(hDlg, szErrMsg, pTitle, iType));
  2048. }
  2049. }
  2050. else
  2051. {
  2052. if (LoadString(hInstance, iMsg, szErrMsg, ARRAYSIZE(szErrMsg)))
  2053. {
  2054. return (MessageBox(hDlg, szErrMsg, pTitle, iType));
  2055. }
  2056. }
  2057. return (FALSE);
  2058. }
  2059. ////////////////////////////////////////////////////////////////////////////
  2060. //
  2061. // Intl_EnumLocales
  2062. //
  2063. ////////////////////////////////////////////////////////////////////////////
  2064. void Intl_EnumLocales(
  2065. HWND hDlg,
  2066. HWND hLocale,
  2067. BOOL EnumSystemLocales)
  2068. {
  2069. LPLANGUAGEGROUP pLG;
  2070. DWORD Locale, dwIndex;
  2071. BOOL fSpanish = FALSE;
  2072. UINT ctr;
  2073. TCHAR szBuf[SIZE_300];
  2074. DWORD dwLocaleACP;
  2075. INT iRet = TRUE;
  2076. //
  2077. // Go through the language groups to see which ones are installed.
  2078. // Display only the locales for the groups that are either already
  2079. // installed or the groups the user wants to be installed.
  2080. //
  2081. pLG = pLanguageGroups;
  2082. while (pLG)
  2083. {
  2084. //
  2085. // If the language group is originally installed and not marked for
  2086. // removal OR is marked to be installed, then add the locales for
  2087. // this language group to the System and User combo boxes.
  2088. //
  2089. if (pLG->wStatus & ML_INSTALL)
  2090. {
  2091. for (ctr = 0; ctr < pLG->NumLocales; ctr++)
  2092. {
  2093. //
  2094. // Save the locale id.
  2095. //
  2096. Locale = (pLG->pLocaleList)[ctr];
  2097. //
  2098. // See if we need to special case Spanish.
  2099. //
  2100. if ((LANGIDFROMLCID(Locale) == LANG_SPANISH_TRADITIONAL) ||
  2101. (LANGIDFROMLCID(Locale) == LANG_SPANISH_INTL))
  2102. {
  2103. //
  2104. // If we've already displayed Spanish (Spain), then
  2105. // don't display it again.
  2106. //
  2107. if (!fSpanish)
  2108. {
  2109. //
  2110. // Add the Spanish locale to the list box.
  2111. //
  2112. if (LoadString(hInstance, IDS_SPANISH_NAME, szBuf, SIZE_300))
  2113. {
  2114. dwIndex = ComboBox_AddString(hLocale, szBuf);
  2115. ComboBox_SetItemData( hLocale,
  2116. dwIndex,
  2117. LCID_SPANISH_INTL );
  2118. fSpanish = TRUE;
  2119. }
  2120. }
  2121. }
  2122. else
  2123. {
  2124. //
  2125. // Don't enum system locales that don't have an ACP.
  2126. //
  2127. if (EnumSystemLocales)
  2128. {
  2129. iRet = GetLocaleInfo( Locale,
  2130. LOCALE_IDEFAULTANSICODEPAGE |
  2131. LOCALE_NOUSEROVERRIDE |
  2132. LOCALE_RETURN_NUMBER,
  2133. (PTSTR) &dwLocaleACP,
  2134. sizeof(dwLocaleACP) / sizeof(TCHAR) );
  2135. if (iRet)
  2136. {
  2137. iRet = dwLocaleACP;
  2138. }
  2139. }
  2140. if (iRet)
  2141. {
  2142. //
  2143. // Get the name of the locale.
  2144. //
  2145. GetLocaleInfo(Locale, LOCALE_SLANGUAGE, szBuf, SIZE_300);
  2146. //
  2147. // Add the new locale to the list box.
  2148. //
  2149. dwIndex = ComboBox_AddString(hLocale, szBuf);
  2150. ComboBox_SetItemData(hLocale, dwIndex, Locale);
  2151. }
  2152. }
  2153. }
  2154. }
  2155. pLG = pLG->pNext;
  2156. }
  2157. }
  2158. ////////////////////////////////////////////////////////////////////////////
  2159. //
  2160. // Intl_EnumInstalledCPProc
  2161. //
  2162. ////////////////////////////////////////////////////////////////////////////
  2163. BOOL CALLBACK Intl_EnumInstalledCPProc(
  2164. LPTSTR pString)
  2165. {
  2166. UINT CodePage;
  2167. LPCODEPAGE pCP;
  2168. //
  2169. // Convert the code page string to an integer.
  2170. //
  2171. CodePage = Intl_StrToLong(pString);
  2172. //
  2173. // Find the code page in the linked list and mark it as
  2174. // originally installed.
  2175. //
  2176. pCP = pCodePages;
  2177. while (pCP)
  2178. {
  2179. if (pCP->CodePage == CodePage)
  2180. {
  2181. pCP->wStatus |= ML_ORIG_INSTALLED;
  2182. break;
  2183. }
  2184. pCP = pCP->pNext;
  2185. }
  2186. //
  2187. // Return success.
  2188. //
  2189. return (TRUE);
  2190. }
  2191. ////////////////////////////////////////////////////////////////////////////
  2192. //
  2193. // Intl_InstallKeyboardLayout
  2194. //
  2195. // Install the Keyboard Layout requested. If the Layout parameter is 0,
  2196. // the function will proceed with the installation of the default layout
  2197. // for the Locale specified. No need to validate the Layout because it's
  2198. // done by the Text Services call.
  2199. //
  2200. ////////////////////////////////////////////////////////////////////////////
  2201. BOOL Intl_InstallKeyboardLayout(
  2202. HWND hDlg,
  2203. LCID Locale,
  2204. DWORD Layout,
  2205. BOOL bDefaultLayout,
  2206. BOOL bDefaultUser,
  2207. BOOL bSystemLocale)
  2208. {
  2209. TCHAR szData[MAX_PATH];
  2210. DWORD dwLayout = Layout;
  2211. DWORD dwLocale = (DWORD)Locale;
  2212. TCHAR szLayout[50];
  2213. HKL hklValue = (HKL)NULL;
  2214. BOOL bOverrideDefaultLayout = FALSE;
  2215. //
  2216. // Check if input.dll is loaded.
  2217. //
  2218. if (hInputDLL && pfnInstallInputLayout)
  2219. {
  2220. //
  2221. // See if we need to look for the default layout.
  2222. //
  2223. if (!Layout)
  2224. {
  2225. //
  2226. // Look in the INF file for the default layout.
  2227. //
  2228. if (!Intl_GetDefaultLayoutFromInf(&dwLocale, &dwLayout))
  2229. {
  2230. //
  2231. // Try just the language id.
  2232. //
  2233. if (HIWORD(Locale) != 0)
  2234. {
  2235. dwLocale = LANGIDFROMLCID(Locale);
  2236. if (!Intl_GetDefaultLayoutFromInf(&dwLocale, &dwLayout))
  2237. {
  2238. if (g_bLog)
  2239. {
  2240. wsprintf(szLayout, TEXT("%08x:%08x"), dwLocale, dwLayout);
  2241. Intl_LogSimpleMessage(IDS_LOG_LOCALE_KBD_FAIL, szLayout);
  2242. }
  2243. return (FALSE);
  2244. }
  2245. }
  2246. else
  2247. {
  2248. if (g_bLog)
  2249. {
  2250. wsprintf(szLayout,TEXT("%08x:%08x"), dwLocale, dwLayout);
  2251. Intl_LogSimpleMessage(IDS_LOG_LOCALE_KBD_FAIL, szLayout);
  2252. }
  2253. return (FALSE);
  2254. }
  2255. }
  2256. }
  2257. //
  2258. // See if we need to provide the HKL. This case only occurs when
  2259. // we need to set the Layout as the default. Otherwise, the value
  2260. // can be NULL.
  2261. //
  2262. if (bDefaultLayout)
  2263. {
  2264. hklValue = Intl_GetHKL(dwLocale, dwLayout);
  2265. }
  2266. //
  2267. // Check if need to override the default layout.
  2268. //
  2269. if (g_bSetupCase && ((HIWORD(dwLayout) & 0xf000) == 0xe000))
  2270. {
  2271. bOverrideDefaultLayout = TRUE;
  2272. }
  2273. //
  2274. // Install the input Layout.
  2275. //
  2276. if (!(*pfnInstallInputLayout)( dwLocale,
  2277. dwLayout,
  2278. bOverrideDefaultLayout ? FALSE : bDefaultLayout,
  2279. hklValue,
  2280. bDefaultUser,
  2281. g_bSetupCase ? TRUE : bSystemLocale ))
  2282. {
  2283. if (hDlg != NULL)
  2284. {
  2285. GetLocaleInfo(Locale, LOCALE_SLANGUAGE, szData, MAX_PATH);
  2286. ShowMsg( hDlg,
  2287. IDS_KBD_LOAD_KBD_FAILED,
  2288. 0,
  2289. MB_OK_OOPS,
  2290. szData );
  2291. }
  2292. else
  2293. {
  2294. if (g_bLog)
  2295. {
  2296. wsprintf(szLayout, TEXT("%08x:%08x"), dwLocale, dwLayout);
  2297. Intl_LogSimpleMessage(IDS_LOG_LOCALE_KBD_FAIL, szLayout);
  2298. }
  2299. }
  2300. return (FALSE);
  2301. }
  2302. //
  2303. // If the language has a default layout that has a different locale
  2304. // than the language (e.g. Thai), we want the default locale to be
  2305. // English (so that logon can occur with a US keyboard), but the
  2306. // first Thai keyboard layout should be installed when the Thai
  2307. // locale is chosen. This is why we have two locales and layouts
  2308. // passed back to the caller.
  2309. //
  2310. if (PRIMARYLANGID(LANGIDFROMLCID(dwLocale)) !=
  2311. PRIMARYLANGID(LANGIDFROMLCID(Locale)))
  2312. {
  2313. dwLocale = Locale;
  2314. dwLayout = 0;
  2315. if (!Intl_GetSecondValidLayoutFromInf(&dwLocale, &dwLayout))
  2316. {
  2317. //
  2318. // Try just the language id.
  2319. //
  2320. if (HIWORD(Locale) != 0)
  2321. {
  2322. dwLocale = LANGIDFROMLCID(Locale);
  2323. if (!Intl_GetSecondValidLayoutFromInf(&dwLocale, &dwLayout))
  2324. {
  2325. if (g_bLog)
  2326. {
  2327. wsprintf(szLayout, TEXT("%08x:%08x"), dwLocale, dwLayout);
  2328. Intl_LogSimpleMessage(IDS_LOG_LOCALE_KBD_FAIL, szLayout);
  2329. }
  2330. return (FALSE);
  2331. }
  2332. }
  2333. else
  2334. {
  2335. if (g_bLog)
  2336. {
  2337. wsprintf(szLayout,TEXT("%08x:%08x"), dwLocale, dwLayout);
  2338. Intl_LogSimpleMessage(IDS_LOG_LOCALE_KBD_FAIL, szLayout);
  2339. }
  2340. return (FALSE);
  2341. }
  2342. }
  2343. }
  2344. //
  2345. // See if we need to provide the HKL. This case only occurs when
  2346. // we need to set the Layout as the default. Otherwise, the value
  2347. // can be NULL.
  2348. //
  2349. if (bDefaultLayout)
  2350. {
  2351. hklValue = Intl_GetHKL(dwLocale, dwLayout);
  2352. }
  2353. //
  2354. // Install the input Layout.
  2355. //
  2356. if (!(*pfnInstallInputLayout)( dwLocale,
  2357. dwLayout,
  2358. FALSE,
  2359. hklValue,
  2360. bDefaultUser,
  2361. g_bSetupCase ? TRUE : bSystemLocale))
  2362. {
  2363. if (hDlg != NULL)
  2364. {
  2365. GetLocaleInfo(Locale, LOCALE_SLANGUAGE, szData, MAX_PATH);
  2366. ShowMsg( hDlg,
  2367. IDS_KBD_LOAD_KBD_FAILED,
  2368. 0,
  2369. MB_OK_OOPS,
  2370. szData );
  2371. }
  2372. else
  2373. {
  2374. if (g_bLog)
  2375. {
  2376. wsprintf(szLayout, TEXT("%08x:%08x"), dwLocale, dwLayout);
  2377. Intl_LogSimpleMessage(IDS_LOG_LOCALE_KBD_FAIL, szLayout);
  2378. }
  2379. }
  2380. return (FALSE);
  2381. }
  2382. }
  2383. else
  2384. {
  2385. if (g_bLog)
  2386. {
  2387. wsprintf(szLayout, TEXT("%08x:%08x"), dwLocale, dwLayout);
  2388. Intl_LogSimpleMessage(IDS_LOG_LAYOUT_INSTALLED, szLayout);
  2389. }
  2390. }
  2391. //
  2392. // Return success.
  2393. //
  2394. return (TRUE);
  2395. }
  2396. ////////////////////////////////////////////////////////////////////////////
  2397. //
  2398. // Intl_InstallKeyboardLayoutList
  2399. //
  2400. // Install all keyboard requested. Pass through the layout list and ask the
  2401. // Text Services to process with the installation.
  2402. //
  2403. ////////////////////////////////////////////////////////////////////////////
  2404. BOOL Intl_InstallKeyboardLayoutList(
  2405. PINFCONTEXT pContext,
  2406. DWORD dwStartField,
  2407. BOOL bDefaultUserCase)
  2408. {
  2409. DWORD dwNumFields, dwNumList, dwCtr;
  2410. DWORD Locale;
  2411. DWORD Layout;
  2412. BOOL bDefaultLayout = FALSE;
  2413. TCHAR szBuffer[MAX_PATH];
  2414. LPTSTR pPos;
  2415. //
  2416. // Get the number of items in the list.
  2417. //
  2418. dwNumFields = SetupGetFieldCount(pContext);
  2419. if (dwNumFields < dwStartField)
  2420. {
  2421. return (FALSE);
  2422. }
  2423. dwNumList = dwNumFields - dwStartField + 1;
  2424. //
  2425. // Install all Keyboard layouts from the list.
  2426. //
  2427. for (dwCtr = dwStartField; dwCtr <= dwNumFields; dwCtr++)
  2428. {
  2429. if (SetupGetStringField( pContext,
  2430. dwCtr,
  2431. szBuffer,
  2432. MAX_PATH,
  2433. NULL ))
  2434. {
  2435. //
  2436. // Find the colon in order to save the input locale
  2437. // and layout values separately.
  2438. //
  2439. pPos = szBuffer;
  2440. while (*pPos)
  2441. {
  2442. if ((*pPos == CHAR_COLON) && (pPos != szBuffer))
  2443. {
  2444. *pPos = 0;
  2445. pPos++;
  2446. //
  2447. // Check if related to the invariant locale.
  2448. //
  2449. Locale = TransNum(szBuffer);
  2450. Layout = TransNum(pPos);
  2451. if (Locale != LOCALE_INVARIANT)
  2452. {
  2453. //
  2454. // Only the first one in list would be installed as
  2455. // the default in the Preload section.
  2456. //
  2457. if (dwCtr == dwStartField)
  2458. {
  2459. bDefaultLayout = TRUE;
  2460. }
  2461. else
  2462. {
  2463. bDefaultLayout = FALSE;
  2464. }
  2465. //
  2466. // Install the keyboard layout requested
  2467. //
  2468. if (Intl_InstallKeyboardLayout( NULL,
  2469. Locale,
  2470. Layout,
  2471. bDefaultLayout,
  2472. bDefaultUserCase,
  2473. FALSE ))
  2474. {
  2475. //
  2476. // Log Layout installation info.
  2477. //
  2478. if (g_bLog)
  2479. {
  2480. Intl_LogSimpleMessage(IDS_LOG_LAYOUT, szBuffer);
  2481. }
  2482. }
  2483. }
  2484. else
  2485. {
  2486. //
  2487. // Log invariant locale blocked.
  2488. //
  2489. if (g_bLog)
  2490. {
  2491. Intl_LogSimpleMessage(IDS_LOG_INV_BLOCK, NULL);
  2492. }
  2493. }
  2494. break;
  2495. }
  2496. pPos++;
  2497. }
  2498. }
  2499. }
  2500. //
  2501. // Return success.
  2502. //
  2503. return (TRUE);
  2504. }
  2505. ////////////////////////////////////////////////////////////////////////////
  2506. //
  2507. // Intl_InstallAllKeyboardLayout
  2508. //
  2509. // Install all keyboard layouts associated with a Language groups.
  2510. //
  2511. ////////////////////////////////////////////////////////////////////////////
  2512. BOOL Intl_InstallAllKeyboardLayout(
  2513. LANGID Language)
  2514. {
  2515. BOOL bRet = TRUE;
  2516. HINF hIntlInf;
  2517. LCID Locale = MAKELCID(Language, SORT_DEFAULT);
  2518. TCHAR szLCID[25];
  2519. INFCONTEXT Context;
  2520. //
  2521. // Open the INF file
  2522. //
  2523. if (Intl_OpenIntlInfFile(&hIntlInf))
  2524. {
  2525. //
  2526. // Get the locale.
  2527. //
  2528. wsprintf(szLCID, TEXT("%08x"), Locale);
  2529. //
  2530. // Look for the keyboard section.
  2531. //
  2532. if (SetupFindFirstLine( hIntlInf,
  2533. TEXT("Locales"),
  2534. szLCID,
  2535. &Context ))
  2536. {
  2537. bRet = Intl_InstallKeyboardLayoutList(&Context, 5, FALSE);
  2538. }
  2539. Intl_CloseInfFile(&hIntlInf);
  2540. }
  2541. return (bRet);
  2542. }
  2543. ////////////////////////////////////////////////////////////////////////////
  2544. //
  2545. // Intl_UninstallAllKeyboardLayout
  2546. //
  2547. // Remove all keyboard layouts associated with a Language groups.
  2548. //
  2549. ////////////////////////////////////////////////////////////////////////////
  2550. BOOL Intl_UninstallAllKeyboardLayout(
  2551. UINT uiLangGroup,
  2552. BOOL DefaultUserCase)
  2553. {
  2554. LPLANGUAGEGROUP pLG = pLanguageGroups;
  2555. LANGID lidCurrent, lidPrev = 0;
  2556. LCID *pLocale;
  2557. BOOL bRet = TRUE;
  2558. //
  2559. // Bail out if we can't get this API from input.dll.
  2560. //
  2561. if (pfnUninstallInputLayout)
  2562. {
  2563. //
  2564. // Walk through all language groups.
  2565. //
  2566. while (pLG)
  2567. {
  2568. if (pLG->LanguageGroup == uiLangGroup)
  2569. {
  2570. TCHAR szLang[MAX_PATH];
  2571. pLocale = pLG->pLocaleList;
  2572. //
  2573. // Walk through the locale list, remove relevant keyboard
  2574. // layouts by the locale's primary language.
  2575. //
  2576. while (*pLocale)
  2577. {
  2578. lidCurrent = PRIMARYLANGID(*pLocale);
  2579. //
  2580. // Don't uninstall any US keyboard layouts.
  2581. //
  2582. if (lidCurrent == 0x09)
  2583. {
  2584. pLocale++;
  2585. continue;
  2586. }
  2587. //
  2588. // The locale list is sorted, so we can avoid redundant
  2589. // UninstallInputLayout calls.
  2590. //
  2591. if (lidCurrent != lidPrev)
  2592. {
  2593. //
  2594. // Uninstall the input layouts associated with
  2595. // this current locale in the list.
  2596. //
  2597. BOOL bSuccess =
  2598. (*pfnUninstallInputLayout)( (LCID) lidCurrent,
  2599. 0L,
  2600. DefaultUserCase );
  2601. if (g_bLog)
  2602. {
  2603. wsprintf(szLang, TEXT("%04x"), lidCurrent);
  2604. Intl_LogSimpleMessage( bSuccess
  2605. ? IDS_LOG_LOCALE_LG_REM
  2606. : IDS_LOG_LOCALE_LG_FAIL,
  2607. szLang );
  2608. }
  2609. if (!bSuccess && bRet)
  2610. {
  2611. bRet = bSuccess;
  2612. }
  2613. lidPrev = lidCurrent;
  2614. }
  2615. pLocale++;
  2616. }
  2617. break;
  2618. }
  2619. pLG = pLG->pNext;
  2620. }
  2621. }
  2622. return bRet;
  2623. }
  2624. ////////////////////////////////////////////////////////////////////////////
  2625. //
  2626. // Intl_GetHKL
  2627. //
  2628. ////////////////////////////////////////////////////////////////////////////
  2629. HKL Intl_GetHKL(
  2630. DWORD dwLocale,
  2631. DWORD dwLayout)
  2632. {
  2633. TCHAR szData[MAX_PATH];
  2634. INFCONTEXT Context;
  2635. HINF hIntlInf;
  2636. TCHAR szLayout[25];
  2637. //
  2638. // Get the HKL based on the input locale value and the layout value.
  2639. //
  2640. if (dwLayout == 0)
  2641. {
  2642. //
  2643. // See if it's the default layout for the input locale or an IME.
  2644. //
  2645. if (HIWORD(dwLocale) == 0)
  2646. {
  2647. return ((HKL)MAKELPARAM(dwLocale, dwLocale));
  2648. }
  2649. else if ((HIWORD(dwLocale) & 0xf000) == 0xe000)
  2650. {
  2651. return ((HKL)IntToPtr(dwLocale));
  2652. }
  2653. }
  2654. else
  2655. {
  2656. //
  2657. // Open the INF file.
  2658. //
  2659. if (Intl_OpenIntlInfFile(&hIntlInf))
  2660. {
  2661. //
  2662. // Create the Layout string.
  2663. //
  2664. wsprintf(szLayout, TEXT("%08x"), dwLayout);
  2665. //
  2666. // Use the layout to make the hkl.
  2667. //
  2668. if (HIWORD(dwLayout) != 0)
  2669. {
  2670. //
  2671. // We have a special id. Need to find out what the layout id
  2672. // should be.
  2673. //
  2674. if ((SetupFindFirstLine(hIntlInf, szKbdLayoutIds, szLayout, &Context)) &&
  2675. (SetupGetStringField(&Context, 1, szData, MAX_PATH, NULL)))
  2676. {
  2677. dwLayout = (DWORD)(LOWORD(TransNum(szData)) | 0xf000);
  2678. }
  2679. }
  2680. //
  2681. // Close the handle
  2682. //
  2683. Intl_CloseInfFile(&hIntlInf);
  2684. //
  2685. // Return the hkl:
  2686. // loword = input locale id
  2687. // hiword = layout id
  2688. //
  2689. return ((HKL)MAKELPARAM(dwLocale, dwLayout));
  2690. }
  2691. }
  2692. //
  2693. // Return failure.
  2694. //
  2695. return (0);
  2696. }
  2697. ////////////////////////////////////////////////////////////////////////////
  2698. //
  2699. // Intl_GetDefaultLayoutFromInf
  2700. //
  2701. ////////////////////////////////////////////////////////////////////////////
  2702. BOOL Intl_GetDefaultLayoutFromInf(
  2703. LPDWORD pdwLocale,
  2704. LPDWORD pdwLayout)
  2705. {
  2706. BOOL bRet = TRUE;
  2707. HINF hIntlInf;
  2708. if (Intl_OpenIntlInfFile(&hIntlInf))
  2709. {
  2710. bRet = Intl_ReadDefaultLayoutFromInf(pdwLocale, pdwLayout, hIntlInf);
  2711. Intl_CloseInfFile(&hIntlInf);
  2712. }
  2713. return (bRet);
  2714. }
  2715. ////////////////////////////////////////////////////////////////////////////
  2716. //
  2717. // Intl_GetSecondValidLayoutFromInf
  2718. //
  2719. ////////////////////////////////////////////////////////////////////////////
  2720. BOOL Intl_GetSecondValidLayoutFromInf(
  2721. LPDWORD pdwLocale,
  2722. LPDWORD pdwLayout)
  2723. {
  2724. BOOL bRet = TRUE;
  2725. HINF hIntlInf;
  2726. if (Intl_OpenIntlInfFile(&hIntlInf))
  2727. {
  2728. bRet = Intl_ReadSecondValidLayoutFromInf(pdwLocale, pdwLayout, hIntlInf);
  2729. Intl_CloseInfFile(&hIntlInf);
  2730. }
  2731. return (bRet);
  2732. }
  2733. ////////////////////////////////////////////////////////////////////////////
  2734. //
  2735. // Intl_InitInf
  2736. //
  2737. ////////////////////////////////////////////////////////////////////////////
  2738. BOOL Intl_InitInf(
  2739. HWND hDlg,
  2740. HINF *phIntlInf,
  2741. LPTSTR pszInf,
  2742. HSPFILEQ *pFileQueue,
  2743. PVOID *pQueueContext)
  2744. {
  2745. BOOL bSpecialCase = TRUE;
  2746. //
  2747. // Open the Inf file.
  2748. //
  2749. *phIntlInf = SetupOpenInfFile(pszInf, NULL, INF_STYLE_WIN4, NULL);
  2750. if (*phIntlInf == INVALID_HANDLE_VALUE)
  2751. {
  2752. if (g_bLog)
  2753. {
  2754. Intl_LogFormatMessage(IDS_LOG_INTL_ERROR);
  2755. }
  2756. return (FALSE);
  2757. }
  2758. if (!SetupOpenAppendInfFile(NULL, *phIntlInf, NULL))
  2759. {
  2760. if (g_bLog)
  2761. {
  2762. Intl_LogFormatMessage(IDS_LOG_SETUP_ERROR);
  2763. }
  2764. SetupCloseInfFile(*phIntlInf);
  2765. return (FALSE);
  2766. }
  2767. //
  2768. // Create a setup file queue and initialize default setup
  2769. // copy queue callback context.
  2770. //
  2771. *pFileQueue = SetupOpenFileQueue();
  2772. if ((!*pFileQueue) || (*pFileQueue == INVALID_HANDLE_VALUE))
  2773. {
  2774. if (g_bLog)
  2775. {
  2776. Intl_LogFormatMessage(IDS_LOG_SETUP_ERROR);
  2777. }
  2778. SetupCloseInfFile(*phIntlInf);
  2779. return (FALSE);
  2780. }
  2781. //
  2782. // Determine if we are dealing with a special case.
  2783. //
  2784. if ((g_bUnttendMode || g_bSetupCase) && !g_bProgressBarDisplay)
  2785. {
  2786. bSpecialCase = FALSE;
  2787. }
  2788. //
  2789. // Don't display FileCopy progress operation during GUI mode setup or Unattend mode.
  2790. //
  2791. *pQueueContext = SetupInitDefaultQueueCallbackEx( GetParent(hDlg),
  2792. (bSpecialCase ? NULL : INVALID_HANDLE_VALUE),
  2793. 0L,
  2794. 0L,
  2795. NULL );
  2796. if (!*pQueueContext)
  2797. {
  2798. if (g_bLog)
  2799. {
  2800. Intl_LogFormatMessage(IDS_LOG_SETUP_ERROR);
  2801. }
  2802. SetupCloseFileQueue(*pFileQueue);
  2803. SetupCloseInfFile(*phIntlInf);
  2804. return (FALSE);
  2805. }
  2806. //
  2807. // Return success.
  2808. //
  2809. return (TRUE);
  2810. }
  2811. ////////////////////////////////////////////////////////////////////////////
  2812. //
  2813. // Intl_OpenIntlInfFile
  2814. //
  2815. ////////////////////////////////////////////////////////////////////////////
  2816. BOOL Intl_OpenIntlInfFile(
  2817. HINF *phInf)
  2818. {
  2819. HINF hIntlInf;
  2820. //
  2821. // Open the intl.inf file.
  2822. //
  2823. hIntlInf = SetupOpenInfFile(szIntlInf, NULL, INF_STYLE_WIN4, NULL);
  2824. if (hIntlInf == INVALID_HANDLE_VALUE)
  2825. {
  2826. return (FALSE);
  2827. }
  2828. if (!SetupOpenAppendInfFile(NULL, hIntlInf, NULL))
  2829. {
  2830. SetupCloseInfFile(hIntlInf);
  2831. return (FALSE);
  2832. }
  2833. *phInf = hIntlInf;
  2834. return (TRUE);
  2835. }
  2836. ////////////////////////////////////////////////////////////////////////////
  2837. //
  2838. // Intl_CloseInf
  2839. //
  2840. ////////////////////////////////////////////////////////////////////////////
  2841. void Intl_CloseInf(
  2842. HINF hIntlInf,
  2843. HSPFILEQ FileQueue,
  2844. PVOID QueueContext)
  2845. {
  2846. //
  2847. // Terminate the Queue.
  2848. //
  2849. SetupTermDefaultQueueCallback(QueueContext);
  2850. //
  2851. // Close the file queue.
  2852. //
  2853. SetupCloseFileQueue(FileQueue);
  2854. //
  2855. // Close the Inf file.
  2856. //
  2857. SetupCloseInfFile(hIntlInf);
  2858. }
  2859. ////////////////////////////////////////////////////////////////////////////
  2860. //
  2861. // Intl_ReadDefaultLayoutFromInf
  2862. //
  2863. ////////////////////////////////////////////////////////////////////////////
  2864. BOOL Intl_ReadDefaultLayoutFromInf(
  2865. LPDWORD pdwLocale,
  2866. LPDWORD pdwLayout,
  2867. HINF hIntlInf)
  2868. {
  2869. INFCONTEXT Context;
  2870. TCHAR szPair[MAX_PATH * 2];
  2871. LPTSTR pPos;
  2872. TCHAR szLCID[25];
  2873. //
  2874. // Get the locale.
  2875. //
  2876. wsprintf(szLCID, TEXT("%08x"), *pdwLocale);
  2877. //
  2878. // Get the first (default) LANGID:HKL pair for the given locale.
  2879. // Example String: "0409:00000409"
  2880. //
  2881. szPair[0] = 0;
  2882. if (SetupFindFirstLine( hIntlInf,
  2883. TEXT("Locales"),
  2884. szLCID,
  2885. &Context ))
  2886. {
  2887. SetupGetStringField(&Context, 5, szPair, MAX_PATH, NULL);
  2888. }
  2889. //
  2890. // Make sure we have a string.
  2891. //
  2892. if (szPair[0] == 0)
  2893. {
  2894. return (FALSE);
  2895. }
  2896. //
  2897. // Find the colon in the string and then set the position
  2898. // pointer to the next character.
  2899. //
  2900. pPos = szPair;
  2901. while (*pPos)
  2902. {
  2903. if ((*pPos == CHAR_COLON) && (pPos != szPair))
  2904. {
  2905. *pPos = 0;
  2906. pPos++;
  2907. break;
  2908. }
  2909. pPos++;
  2910. }
  2911. //
  2912. // If there is a layout, then return the input locale and the layout.
  2913. //
  2914. if ((*pPos) &&
  2915. (*pdwLocale = TransNum(szPair)) &&
  2916. (*pdwLayout = TransNum(pPos)))
  2917. {
  2918. return (TRUE);
  2919. }
  2920. //
  2921. // Return failure.
  2922. //
  2923. return (FALSE);
  2924. }
  2925. ////////////////////////////////////////////////////////////////////////////
  2926. //
  2927. // Intl_ReadSecondValidLayoutFromInf
  2928. //
  2929. ////////////////////////////////////////////////////////////////////////////
  2930. BOOL Intl_ReadSecondValidLayoutFromInf(
  2931. LPDWORD pdwLocale,
  2932. LPDWORD pdwLayout,
  2933. HINF hIntlInf)
  2934. {
  2935. INFCONTEXT Context;
  2936. int iField = 6;
  2937. TCHAR szPair[MAX_PATH * 2];
  2938. LPTSTR pPos;
  2939. DWORD dwLoc, dwlay, savedLocale = *pdwLocale;
  2940. TCHAR szLCID[25];
  2941. //
  2942. // Get the locale.
  2943. //
  2944. wsprintf(szLCID, TEXT("%08x"), *pdwLocale);
  2945. //
  2946. // Get the first (default) LANGID:HKL pair for the given locale.
  2947. // Example String: "0409:00000409"
  2948. //
  2949. szPair[0] = 0;
  2950. if (SetupFindFirstLine(hIntlInf, TEXT("Locales"), szLCID, &Context))
  2951. {
  2952. while (SetupGetStringField(&Context, iField, szPair, MAX_PATH, NULL))
  2953. {
  2954. //
  2955. // Make sure we have a string.
  2956. //
  2957. if (szPair[0] == 0)
  2958. {
  2959. iField++;
  2960. continue;
  2961. }
  2962. //
  2963. // Find the colon in the string and then set the position
  2964. // pointer to the next character.
  2965. //
  2966. pPos = szPair;
  2967. while (*pPos)
  2968. {
  2969. if ((*pPos == CHAR_COLON) && (pPos != szPair))
  2970. {
  2971. *pPos = 0;
  2972. pPos++;
  2973. break;
  2974. }
  2975. pPos++;
  2976. }
  2977. if (*pPos == 0)
  2978. {
  2979. iField++;
  2980. continue;
  2981. }
  2982. //
  2983. // If there is a layout, then return the input locale and the
  2984. // layout.
  2985. //
  2986. if (((dwLoc = TransNum(szPair)) == 0) ||
  2987. ((dwlay = TransNum(pPos)) == 0))
  2988. {
  2989. iField++;
  2990. continue;
  2991. }
  2992. if (PRIMARYLANGID(LANGIDFROMLCID(dwLoc)) ==
  2993. PRIMARYLANGID(LANGIDFROMLCID(savedLocale)))
  2994. {
  2995. *pdwLayout = dwlay;
  2996. *pdwLocale = dwLoc;
  2997. return (TRUE);
  2998. }
  2999. iField++;
  3000. }
  3001. }
  3002. //
  3003. // Return failure.
  3004. //
  3005. return (FALSE);
  3006. }
  3007. ////////////////////////////////////////////////////////////////////////////
  3008. //
  3009. // Intl_CloseInfFile
  3010. //
  3011. ////////////////////////////////////////////////////////////////////////////
  3012. BOOL Intl_CloseInfFile(
  3013. HINF *phInf)
  3014. {
  3015. SetupCloseInfFile(*phInf);
  3016. *phInf = INVALID_HANDLE_VALUE;
  3017. return (TRUE);
  3018. }
  3019. ////////////////////////////////////////////////////////////////////////////
  3020. //
  3021. // Intl_IsValidLayout
  3022. //
  3023. ////////////////////////////////////////////////////////////////////////////
  3024. BOOL Intl_IsValidLayout(
  3025. DWORD dwLayout)
  3026. {
  3027. HKEY hKey1, hKey2;
  3028. TCHAR szLayout[MAX_PATH];
  3029. //
  3030. // Get the layout id as a string.
  3031. //
  3032. wsprintf(szLayout, TEXT("%08x"), dwLayout);
  3033. //
  3034. // Open the Keyboard Layouts key.
  3035. //
  3036. if (RegOpenKey(HKEY_LOCAL_MACHINE, szLayoutPath, &hKey1) != ERROR_SUCCESS)
  3037. {
  3038. return (FALSE);
  3039. }
  3040. //
  3041. // Try to open the layout id key under the Keyboard Layouts key.
  3042. //
  3043. if (RegOpenKey(hKey1, szLayout, &hKey2) != ERROR_SUCCESS)
  3044. {
  3045. RegCloseKey(hKey1);
  3046. return (FALSE);
  3047. }
  3048. //
  3049. // Close the keys.
  3050. //
  3051. RegCloseKey(hKey1);
  3052. RegCloseKey(hKey2);
  3053. //
  3054. // Return success.
  3055. //
  3056. return (TRUE);
  3057. }
  3058. ////////////////////////////////////////////////////////////////////////////
  3059. //
  3060. // Intl_RunRegApps
  3061. //
  3062. ////////////////////////////////////////////////////////////////////////////
  3063. void Intl_RunRegApps(
  3064. LPCTSTR pszRegKey)
  3065. {
  3066. HKEY hkey;
  3067. DWORD cbData, cbValue, dwType, ctr;
  3068. TCHAR szValueName[32], szCmdLine[MAX_PATH];
  3069. STARTUPINFO startup;
  3070. PROCESS_INFORMATION pi;
  3071. if (RegOpenKey( HKEY_LOCAL_MACHINE,
  3072. pszRegKey,
  3073. &hkey ) == ERROR_SUCCESS)
  3074. {
  3075. startup.cb = sizeof(STARTUPINFO);
  3076. startup.lpReserved = NULL;
  3077. startup.lpDesktop = NULL;
  3078. startup.lpTitle = NULL;
  3079. startup.dwFlags = 0L;
  3080. startup.cbReserved2 = 0;
  3081. startup.lpReserved2 = NULL;
  3082. // startup.wShowWindow = wShowWindow;
  3083. for (ctr = 0; ; ctr++)
  3084. {
  3085. LONG lEnum;
  3086. cbValue = sizeof(szValueName) / sizeof(TCHAR);
  3087. cbData = sizeof(szCmdLine);
  3088. if ((lEnum = RegEnumValue( hkey,
  3089. ctr,
  3090. szValueName,
  3091. &cbValue,
  3092. NULL,
  3093. &dwType,
  3094. (LPBYTE)szCmdLine,
  3095. &cbData )) == ERROR_MORE_DATA)
  3096. {
  3097. //
  3098. // ERROR_MORE_DATA means the value name or data was too
  3099. // large, so skip to the next item.
  3100. //
  3101. continue;
  3102. }
  3103. else if (lEnum != ERROR_SUCCESS)
  3104. {
  3105. //
  3106. // This could be ERROR_NO_MORE_ENTRIES, or some kind of
  3107. // failure. We can't recover from any other registry
  3108. // problem anyway.
  3109. //
  3110. break;
  3111. }
  3112. //
  3113. // Found a value.
  3114. //
  3115. if (dwType == REG_SZ)
  3116. {
  3117. //
  3118. // Adjust for shift in value index.
  3119. //
  3120. ctr--;
  3121. //
  3122. // Delete the value.
  3123. //
  3124. RegDeleteValue(hkey, szValueName);
  3125. //
  3126. // Only run things marked with a "*" in clean boot.
  3127. //
  3128. if (CreateProcess( NULL,
  3129. szCmdLine,
  3130. NULL,
  3131. NULL,
  3132. FALSE,
  3133. CREATE_NEW_PROCESS_GROUP,
  3134. NULL,
  3135. NULL,
  3136. &startup,
  3137. &pi ))
  3138. {
  3139. WaitForSingleObjectEx(pi.hProcess, INFINITE, TRUE);
  3140. CloseHandle(pi.hProcess);
  3141. CloseHandle(pi.hThread);
  3142. }
  3143. }
  3144. }
  3145. RegCloseKey(hkey);
  3146. }
  3147. }
  3148. ////////////////////////////////////////////////////////////////////////////
  3149. //
  3150. // Intl_RebootTheSystem
  3151. //
  3152. // This routine enables all privileges in the token, calls ExitWindowsEx
  3153. // to reboot the system, and then resets all of the privileges to their
  3154. // old state.
  3155. //
  3156. ////////////////////////////////////////////////////////////////////////////
  3157. VOID Intl_RebootTheSystem()
  3158. {
  3159. HANDLE Token = NULL;
  3160. ULONG ReturnLength, Index;
  3161. PTOKEN_PRIVILEGES NewState = NULL;
  3162. PTOKEN_PRIVILEGES OldState = NULL;
  3163. BOOL Result;
  3164. Result = OpenProcessToken( GetCurrentProcess(),
  3165. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
  3166. &Token );
  3167. if (Result)
  3168. {
  3169. ReturnLength = 4096;
  3170. NewState = (PTOKEN_PRIVILEGES)LocalAlloc(LPTR, ReturnLength);
  3171. OldState = (PTOKEN_PRIVILEGES)LocalAlloc(LPTR, ReturnLength);
  3172. Result = (BOOL)((NewState != NULL) && (OldState != NULL));
  3173. if (Result)
  3174. {
  3175. Result = GetTokenInformation( Token, // TokenHandle
  3176. TokenPrivileges, // TokenInformationClass
  3177. NewState, // TokenInformation
  3178. ReturnLength, // TokenInformationLength
  3179. &ReturnLength ); // ReturnLength
  3180. if (Result)
  3181. {
  3182. //
  3183. // Set the state settings so that all privileges are
  3184. // enabled...
  3185. //
  3186. if (NewState->PrivilegeCount > 0)
  3187. {
  3188. for (Index = 0; Index < NewState->PrivilegeCount; Index++)
  3189. {
  3190. NewState->Privileges[Index].Attributes = SE_PRIVILEGE_ENABLED;
  3191. }
  3192. }
  3193. Result = AdjustTokenPrivileges( Token, // TokenHandle
  3194. FALSE, // DisableAllPrivileges
  3195. NewState, // NewState
  3196. ReturnLength, // BufferLength
  3197. OldState, // PreviousState
  3198. &ReturnLength ); // ReturnLength
  3199. if (Result)
  3200. {
  3201. ExitWindowsEx(EWX_REBOOT, 0);
  3202. AdjustTokenPrivileges( Token,
  3203. FALSE,
  3204. OldState,
  3205. 0,
  3206. NULL,
  3207. NULL );
  3208. }
  3209. }
  3210. }
  3211. }
  3212. if (NewState != NULL)
  3213. {
  3214. LocalFree(NewState);
  3215. }
  3216. if (OldState != NULL)
  3217. {
  3218. LocalFree(OldState);
  3219. }
  3220. if (Token != NULL)
  3221. {
  3222. CloseHandle(Token);
  3223. }
  3224. }
  3225. ////////////////////////////////////////////////////////////////////////////
  3226. //
  3227. // Intl_InstallUserLocale
  3228. //
  3229. // When the DefaultUserCase flag is FALSE, this function write information
  3230. // related to the locale for the current user. Otherwise, this function
  3231. // write information for the .DEFAULT user. In the Default user case, the
  3232. // the information are stored in the registry and the NTSUSER.DAT.
  3233. //
  3234. ////////////////////////////////////////////////////////////////////////////
  3235. BOOL Intl_InstallUserLocale(
  3236. LCID Locale,
  3237. BOOL DefaultUserCase,
  3238. BOOL bChangeLocaleInfo )
  3239. {
  3240. HKEY hKey = NULL;
  3241. HKEY hHive = NULL;
  3242. BOOLEAN wasEnabled;
  3243. TCHAR szLCID[25];
  3244. DWORD dwRet;
  3245. //
  3246. // Save the locale id as a string.
  3247. //
  3248. wsprintf(szLCID, TEXT("%08x"), Locale);
  3249. //
  3250. // Make sure the locale is valid.
  3251. //
  3252. if (!IsValidLocale(Locale, LCID_INSTALLED))
  3253. {
  3254. if (g_bLog)
  3255. {
  3256. Intl_LogSimpleMessage(IDS_LOG_INVALID_LOCALE, szLCID);
  3257. }
  3258. return (FALSE);
  3259. }
  3260. //
  3261. // Log user locale info change.
  3262. //
  3263. if (g_bLog)
  3264. {
  3265. Intl_LogSimpleMessage(IDS_LOG_USER_LOCALE_CHG, szLCID);
  3266. }
  3267. //
  3268. // Open the right registry section.
  3269. //
  3270. if (!DefaultUserCase)
  3271. {
  3272. dwRet = RegOpenKeyEx( HKEY_CURRENT_USER,
  3273. c_szCPanelIntl,
  3274. 0L,
  3275. KEY_READ | KEY_WRITE,
  3276. &hKey );
  3277. }
  3278. else
  3279. {
  3280. dwRet = RegOpenKeyEx( HKEY_USERS,
  3281. c_szCPanelIntl_DefUser,
  3282. 0L,
  3283. KEY_READ | KEY_WRITE,
  3284. &hKey );
  3285. if (dwRet == ERROR_SUCCESS)
  3286. {
  3287. //
  3288. // Load the default hive.
  3289. //
  3290. if ((hHive = Intl_LoadNtUserHive( TEXT("tempKey"),
  3291. c_szCPanelIntl,
  3292. &wasEnabled )) == NULL )
  3293. {
  3294. RegCloseKey(hKey);
  3295. return (FALSE);
  3296. }
  3297. //
  3298. // Save the Locale value in NTUSER.DAT.
  3299. //
  3300. RegSetValueEx( hHive,
  3301. TEXT("Locale"),
  3302. 0L,
  3303. REG_SZ,
  3304. (LPBYTE)szLCID,
  3305. (lstrlen(szLCID) + 1) * sizeof(TCHAR));
  3306. //
  3307. // Clean up.
  3308. //
  3309. RegCloseKey(hHive);
  3310. Intl_UnloadNtUserHive(TEXT("tempKey"), &wasEnabled);
  3311. }
  3312. }
  3313. //
  3314. // Set the locale value in the user's control panel international
  3315. // section of the registry.
  3316. //
  3317. if ((dwRet != ERROR_SUCCESS) ||
  3318. (RegSetValueEx( hKey,
  3319. TEXT("Locale"),
  3320. 0L,
  3321. REG_SZ,
  3322. (LPBYTE)szLCID,
  3323. (lstrlen(szLCID) + 1) * sizeof(TCHAR) ) != ERROR_SUCCESS))
  3324. {
  3325. if (hKey != NULL)
  3326. {
  3327. RegCloseKey(hKey);
  3328. }
  3329. return (FALSE);
  3330. }
  3331. //
  3332. // When the locale changes, update ALL registry information when asked.
  3333. //
  3334. if (bChangeLocaleInfo)
  3335. {
  3336. Intl_SetLocaleInfo(Locale, LOCALE_SABBREVLANGNAME, TEXT("sLanguage"), DefaultUserCase);
  3337. Intl_SetLocaleInfo(Locale, LOCALE_SCOUNTRY, TEXT("sCountry"), DefaultUserCase);
  3338. Intl_SetLocaleInfo(Locale, LOCALE_ICOUNTRY, TEXT("iCountry"), DefaultUserCase);
  3339. Intl_SetLocaleInfo(Locale, LOCALE_S1159, TEXT("s1159"), DefaultUserCase);
  3340. Intl_SetLocaleInfo(Locale, LOCALE_S2359, TEXT("s2359"), DefaultUserCase);
  3341. Intl_SetLocaleInfo(Locale, LOCALE_STIMEFORMAT, TEXT("sTimeFormat"), DefaultUserCase);
  3342. Intl_SetLocaleInfo(Locale, LOCALE_STIME, TEXT("sTime"), DefaultUserCase);
  3343. Intl_SetLocaleInfo(Locale, LOCALE_ITIME, TEXT("iTime"), DefaultUserCase);
  3344. Intl_SetLocaleInfo(Locale, LOCALE_ITLZERO, TEXT("iTLZero"), DefaultUserCase);
  3345. Intl_SetLocaleInfo(Locale, LOCALE_ITIMEMARKPOSN, TEXT("iTimePrefix"), DefaultUserCase);
  3346. Intl_SetLocaleInfo(Locale, LOCALE_SSHORTDATE, TEXT("sShortDate"), DefaultUserCase);
  3347. Intl_SetLocaleInfo(Locale, LOCALE_IDATE, TEXT("iDate"), DefaultUserCase);
  3348. Intl_SetLocaleInfo(Locale, LOCALE_SDATE, TEXT("sDate"), DefaultUserCase);
  3349. Intl_SetLocaleInfo(Locale, LOCALE_SLONGDATE, TEXT("sLongDate"), DefaultUserCase);
  3350. Intl_SetLocaleInfo(Locale, LOCALE_SCURRENCY, TEXT("sCurrency"), DefaultUserCase);
  3351. Intl_SetLocaleInfo(Locale, LOCALE_ICURRENCY, TEXT("iCurrency"), DefaultUserCase);
  3352. Intl_SetLocaleInfo(Locale, LOCALE_INEGCURR, TEXT("iNegCurr"), DefaultUserCase);
  3353. Intl_SetLocaleInfo(Locale, LOCALE_ICURRDIGITS, TEXT("iCurrDigits"), DefaultUserCase);
  3354. Intl_SetLocaleInfo(Locale, LOCALE_SDECIMAL, TEXT("sDecimal"), DefaultUserCase);
  3355. Intl_SetLocaleInfo(Locale, LOCALE_SMONDECIMALSEP, TEXT("sMonDecimalSep"), DefaultUserCase);
  3356. Intl_SetLocaleInfo(Locale, LOCALE_STHOUSAND, TEXT("sThousand"), DefaultUserCase);
  3357. Intl_SetLocaleInfo(Locale, LOCALE_SMONTHOUSANDSEP, TEXT("sMonThousandSep"), DefaultUserCase);
  3358. Intl_SetLocaleInfo(Locale, LOCALE_SLIST, TEXT("sList"), DefaultUserCase);
  3359. Intl_SetLocaleInfo(Locale, LOCALE_IDIGITS, TEXT("iDigits"), DefaultUserCase);
  3360. Intl_SetLocaleInfo(Locale, LOCALE_ILZERO, TEXT("iLzero"), DefaultUserCase);
  3361. Intl_SetLocaleInfo(Locale, LOCALE_INEGNUMBER, TEXT("iNegNumber"), DefaultUserCase);
  3362. Intl_SetLocaleInfo(Locale, LOCALE_SNATIVEDIGITS, TEXT("sNativeDigits"), DefaultUserCase);
  3363. Intl_SetLocaleInfo(Locale, LOCALE_IDIGITSUBSTITUTION, TEXT("NumShape"), DefaultUserCase);
  3364. Intl_SetLocaleInfo(Locale, LOCALE_IMEASURE, TEXT("iMeasure"), DefaultUserCase);
  3365. Intl_SetLocaleInfo(Locale, LOCALE_ICALENDARTYPE, TEXT("iCalendarType"), DefaultUserCase);
  3366. Intl_SetLocaleInfo(Locale, LOCALE_IFIRSTDAYOFWEEK, TEXT("iFirstDayOfWeek"), DefaultUserCase);
  3367. Intl_SetLocaleInfo(Locale, LOCALE_IFIRSTWEEKOFYEAR, TEXT("iFirstWeekOfYear"), DefaultUserCase);
  3368. Intl_SetLocaleInfo(Locale, LOCALE_SGROUPING, TEXT("sGrouping"), DefaultUserCase);
  3369. Intl_SetLocaleInfo(Locale, LOCALE_SMONGROUPING, TEXT("sMonGrouping"), DefaultUserCase);
  3370. Intl_SetLocaleInfo(Locale, LOCALE_SPOSITIVESIGN, TEXT("sPositiveSign"), DefaultUserCase);
  3371. Intl_SetLocaleInfo(Locale, LOCALE_SNEGATIVESIGN, TEXT("sNegativeSign"), DefaultUserCase);
  3372. }
  3373. //
  3374. // Set the user's default locale in the system so that any new
  3375. // process will use the new locale.
  3376. //
  3377. if (!DefaultUserCase)
  3378. {
  3379. NtSetDefaultLocale(TRUE, Locale);
  3380. }
  3381. //
  3382. // Flush the International key.
  3383. //
  3384. if (hKey != NULL)
  3385. {
  3386. RegFlushKey(hKey);
  3387. RegCloseKey(hKey);
  3388. }
  3389. //
  3390. // Return success.
  3391. //
  3392. return (TRUE);
  3393. }
  3394. ////////////////////////////////////////////////////////////////////////////
  3395. //
  3396. // Intl_SetLocaleInfo
  3397. //
  3398. ////////////////////////////////////////////////////////////////////////////
  3399. void Intl_SetLocaleInfo(
  3400. LCID Locale,
  3401. LCTYPE LCType,
  3402. LPTSTR lpIniStr,
  3403. BOOL bDefaultUserCase)
  3404. {
  3405. TCHAR pBuf[SIZE_128];
  3406. //
  3407. // Get the default information for the given locale.
  3408. //
  3409. if (GetLocaleInfo( Locale,
  3410. LCType | LOCALE_NOUSEROVERRIDE,
  3411. pBuf,
  3412. SIZE_128 ))
  3413. {
  3414. if (!bDefaultUserCase)
  3415. {
  3416. //
  3417. // Set the default information in the registry.
  3418. //
  3419. // NOTE: We want to use SetLocaleInfo if possible so that the
  3420. // NLS cache is updated right away. Otherwise, we'll
  3421. // simply use WriteProfileString.
  3422. //
  3423. if (!SetLocaleInfo(Locale, LCType, pBuf))
  3424. {
  3425. //
  3426. // If SetLocaleInfo failed, try WriteProfileString since
  3427. // some of the LCTypes are not supported in SetLocaleInfo.
  3428. //
  3429. WriteProfileString(szIntl, lpIniStr, pBuf);
  3430. }
  3431. }
  3432. else
  3433. {
  3434. //
  3435. // Set the default information in the registry and NTUSER.DAT.
  3436. //
  3437. Intl_SetDefaultUserLocaleInfo(lpIniStr, pBuf);
  3438. }
  3439. }
  3440. }
  3441. ////////////////////////////////////////////////////////////////////////////
  3442. //
  3443. // Intl_AddPage
  3444. //
  3445. ////////////////////////////////////////////////////////////////////////////
  3446. void Intl_AddPage(
  3447. LPPROPSHEETHEADER ppsh,
  3448. UINT id,
  3449. DLGPROC pfn,
  3450. LPARAM lParam,
  3451. UINT iMaxPages)
  3452. {
  3453. if (ppsh->nPages < iMaxPages)
  3454. {
  3455. PROPSHEETPAGE psp;
  3456. psp.dwSize = sizeof(psp);
  3457. psp.dwFlags = PSP_DEFAULT;
  3458. psp.hInstance = hInstance;
  3459. psp.pszTemplate = MAKEINTRESOURCE(id);
  3460. psp.pfnDlgProc = pfn;
  3461. psp.lParam = lParam;
  3462. ppsh->phpage[ppsh->nPages] = CreatePropertySheetPage(&psp);
  3463. if (ppsh->phpage[ppsh->nPages])
  3464. {
  3465. ppsh->nPages++;
  3466. }
  3467. }
  3468. }
  3469. ////////////////////////////////////////////////////////////////////////////
  3470. //
  3471. // Intl_AddExternalPage
  3472. //
  3473. // Adds a property sheet page from the given dll.
  3474. //
  3475. ////////////////////////////////////////////////////////////////////////////
  3476. void Intl_AddExternalPage(
  3477. LPPROPSHEETHEADER ppsh,
  3478. UINT id,
  3479. HINSTANCE hInst,
  3480. LPSTR ProcName,
  3481. UINT iMaxPages)
  3482. {
  3483. DLGPROC pfn;
  3484. if (ppsh->nPages < iMaxPages)
  3485. {
  3486. PROPSHEETPAGE psp;
  3487. if (hInst)
  3488. {
  3489. pfn = (DLGPROC)GetProcAddress(hInst, ProcName);
  3490. if (!pfn)
  3491. {
  3492. return;
  3493. }
  3494. psp.dwSize = sizeof(psp);
  3495. psp.dwFlags = PSP_DEFAULT;
  3496. psp.hInstance = hInst;
  3497. psp.pszTemplate = MAKEINTRESOURCE(id);
  3498. psp.pfnDlgProc = pfn;
  3499. psp.lParam = 0;
  3500. ppsh->phpage[ppsh->nPages] = CreatePropertySheetPage(&psp);
  3501. if (ppsh->phpage[ppsh->nPages])
  3502. {
  3503. ppsh->nPages++;
  3504. }
  3505. }
  3506. }
  3507. }
  3508. ////////////////////////////////////////////////////////////////////////////
  3509. //
  3510. // Intl_SetDefaultUserLocaleInfo
  3511. //
  3512. ////////////////////////////////////////////////////////////////////////////
  3513. BOOL Intl_SetDefaultUserLocaleInfo(
  3514. LPCTSTR lpKeyName,
  3515. LPCTSTR lpString)
  3516. {
  3517. HKEY hKey = NULL;
  3518. LONG rc = 0L;
  3519. TCHAR szProfile[REGSTR_MAX_VALUE_LENGTH];
  3520. BOOLEAN wasEnabled;
  3521. //
  3522. // Open the .DEFAULT control panel international section.
  3523. //
  3524. if ((rc = RegOpenKeyEx( HKEY_USERS,
  3525. c_szCPanelIntl_DefUser,
  3526. 0L,
  3527. KEY_READ | KEY_WRITE,
  3528. &hKey )) == ERROR_SUCCESS)
  3529. {
  3530. //
  3531. // Set the value
  3532. //
  3533. rc = RegSetValueEx( hKey,
  3534. lpKeyName,
  3535. 0L,
  3536. REG_SZ,
  3537. (LPBYTE)lpString,
  3538. (lstrlen(lpString) + 1) * sizeof(TCHAR) );
  3539. //
  3540. // Flush the International key.
  3541. //
  3542. RegFlushKey(hKey);
  3543. RegCloseKey(hKey);
  3544. }
  3545. if (rc == ERROR_SUCCESS)
  3546. {
  3547. //
  3548. // Load the hive.
  3549. //
  3550. if ((hKey = Intl_LoadNtUserHive( TEXT("RegionalSettingsTempKey"),
  3551. c_szCPanelIntl,
  3552. &wasEnabled)) == NULL)
  3553. {
  3554. return (FALSE);
  3555. }
  3556. //
  3557. // Set the value.
  3558. //
  3559. rc = RegSetValueEx( hKey,
  3560. lpKeyName,
  3561. 0L,
  3562. REG_SZ,
  3563. (LPBYTE)lpString,
  3564. (lstrlen(lpString) + 1) * sizeof(TCHAR) );
  3565. //
  3566. // Clean up.
  3567. //
  3568. RegCloseKey(hKey);
  3569. Intl_UnloadNtUserHive(TEXT("RegionalSettingsTempKey"), &wasEnabled);
  3570. }
  3571. else
  3572. {
  3573. return (FALSE);
  3574. }
  3575. return (TRUE);
  3576. }
  3577. ////////////////////////////////////////////////////////////////////////////
  3578. //
  3579. // Intl_DeleteRegKeyValues
  3580. //
  3581. // This deletes all values under a specific key.
  3582. //
  3583. ////////////////////////////////////////////////////////////////////////////
  3584. void Intl_DeleteRegKeyValues(
  3585. HKEY hKey)
  3586. {
  3587. TCHAR szValueName[REGSTR_MAX_VALUE_LENGTH];
  3588. DWORD cbValue = REGSTR_MAX_VALUE_LENGTH;
  3589. //
  3590. // Sanity check.
  3591. //
  3592. if (hKey == NULL)
  3593. {
  3594. return;
  3595. }
  3596. //
  3597. // Enumerate values.
  3598. //
  3599. while (RegEnumValue( hKey,
  3600. 0,
  3601. szValueName,
  3602. &cbValue,
  3603. NULL,
  3604. NULL,
  3605. NULL,
  3606. NULL ) == ERROR_SUCCESS)
  3607. {
  3608. //
  3609. // Delete the value.
  3610. //
  3611. RegDeleteValue(hKey, szValueName);
  3612. cbValue = REGSTR_MAX_VALUE_LENGTH;
  3613. }
  3614. }
  3615. ////////////////////////////////////////////////////////////////////////////
  3616. //
  3617. // Intl_DeleteRegTree
  3618. //
  3619. // This deletes all subkeys under a specific key.
  3620. //
  3621. // Note: The code makes no attempt to check or recover from partial
  3622. // deletions.
  3623. //
  3624. // A registry key that is opened by an application can be deleted
  3625. // without error by another application. This is by design.
  3626. //
  3627. ////////////////////////////////////////////////////////////////////////////
  3628. DWORD Intl_DeleteRegTree(
  3629. HKEY hStartKey,
  3630. LPTSTR pKeyName)
  3631. {
  3632. DWORD dwRtn, dwSubKeyLength;
  3633. LPTSTR pSubKey = NULL;
  3634. TCHAR szSubKey[REGSTR_MAX_VALUE_LENGTH]; // (256) this should be dynamic.
  3635. HKEY hKey;
  3636. //
  3637. // Do not allow NULL or empty key name.
  3638. //
  3639. if (pKeyName && lstrlen(pKeyName))
  3640. {
  3641. if ((dwRtn = RegOpenKeyEx( hStartKey,
  3642. pKeyName,
  3643. 0,
  3644. KEY_ENUMERATE_SUB_KEYS | DELETE,
  3645. &hKey )) == ERROR_SUCCESS)
  3646. {
  3647. while (dwRtn == ERROR_SUCCESS)
  3648. {
  3649. dwSubKeyLength = REGSTR_MAX_VALUE_LENGTH;
  3650. dwRtn = RegEnumKeyEx( hKey,
  3651. 0, // always index zero
  3652. szSubKey,
  3653. &dwSubKeyLength,
  3654. NULL,
  3655. NULL,
  3656. NULL,
  3657. NULL );
  3658. if (dwRtn == ERROR_NO_MORE_ITEMS)
  3659. {
  3660. dwRtn = RegDeleteKey(hStartKey, pKeyName);
  3661. break;
  3662. }
  3663. else if (dwRtn == ERROR_SUCCESS)
  3664. {
  3665. dwRtn = Intl_DeleteRegTree(hKey, szSubKey);
  3666. }
  3667. }
  3668. RegCloseKey(hKey);
  3669. //
  3670. // Do not save return code because error has already occurred.
  3671. //
  3672. }
  3673. }
  3674. else
  3675. {
  3676. dwRtn = ERROR_BADKEY;
  3677. }
  3678. return (dwRtn);
  3679. }
  3680. ////////////////////////////////////////////////////////////////////////////
  3681. //
  3682. // Intl_DeleteRegSubKeys
  3683. //
  3684. // This deletes all subkeys under a specific key.
  3685. //
  3686. ////////////////////////////////////////////////////////////////////////////
  3687. void Intl_DeleteRegSubKeys(
  3688. HKEY hKey)
  3689. {
  3690. TCHAR szKeyName[REGSTR_MAX_VALUE_LENGTH];
  3691. DWORD cbKey = REGSTR_MAX_VALUE_LENGTH;
  3692. //
  3693. // Sanity check.
  3694. //
  3695. if (hKey == NULL)
  3696. {
  3697. return;
  3698. }
  3699. //
  3700. // Enumerate values.
  3701. //
  3702. while (RegEnumKeyEx( hKey,
  3703. 0,
  3704. szKeyName,
  3705. &cbKey,
  3706. NULL,
  3707. NULL,
  3708. NULL,
  3709. NULL ) == ERROR_SUCCESS)
  3710. {
  3711. //
  3712. // Delete the value.
  3713. //
  3714. Intl_DeleteRegTree(hKey, szKeyName);
  3715. cbKey = REGSTR_MAX_VALUE_LENGTH;
  3716. }
  3717. }
  3718. ////////////////////////////////////////////////////////////////////////////
  3719. //
  3720. // Intl_CopyRegKeyValues
  3721. //
  3722. // This copies all values under the source key to the destination key.
  3723. //
  3724. ////////////////////////////////////////////////////////////////////////////
  3725. DWORD Intl_CopyRegKeyValues(
  3726. HKEY hSrc,
  3727. HKEY hDest)
  3728. {
  3729. DWORD cbValue, dwSubKeyIndex=0, dwType, cdwBuf;
  3730. DWORD dwValues, cbMaxValueData, i;
  3731. TCHAR szValue[REGSTR_MAX_VALUE_LENGTH]; // this should be dynamic.
  3732. DWORD lRet = ERROR_SUCCESS;
  3733. LPBYTE pBuf;
  3734. if ((lRet = RegQueryInfoKey( hSrc,
  3735. NULL,
  3736. NULL,
  3737. NULL,
  3738. NULL,
  3739. NULL,
  3740. NULL,
  3741. &dwValues,
  3742. NULL,
  3743. &cbMaxValueData,
  3744. NULL,
  3745. NULL )) == ERROR_SUCCESS)
  3746. {
  3747. if (dwValues)
  3748. {
  3749. if ((pBuf = HeapAlloc( GetProcessHeap(),
  3750. HEAP_ZERO_MEMORY,
  3751. cbMaxValueData )))
  3752. {
  3753. for (i = 0; i < dwValues; i++)
  3754. {
  3755. //
  3756. // Get values to create.
  3757. //
  3758. cbValue = REGSTR_MAX_VALUE_LENGTH;
  3759. cdwBuf = cbMaxValueData;
  3760. lRet = RegEnumValue( hSrc, // handle of key to query
  3761. i, // index of value to query
  3762. szValue, // buffer for value string
  3763. &cbValue, // address for size of buffer
  3764. NULL, // reserved
  3765. &dwType, // buffer address for type code
  3766. pBuf, // address of buffer for value data
  3767. &cdwBuf ); // address for size of buffer
  3768. if (lRet == ERROR_SUCCESS)
  3769. {
  3770. if ((lRet = RegSetValueEx( hDest,
  3771. szValue,
  3772. 0,
  3773. dwType,
  3774. (CONST BYTE *)pBuf,
  3775. cdwBuf )) != ERROR_SUCCESS)
  3776. {
  3777. break;
  3778. }
  3779. }
  3780. else
  3781. {
  3782. break;
  3783. }
  3784. }
  3785. HeapFree(GetProcessHeap(), 0, pBuf);
  3786. }
  3787. }
  3788. }
  3789. return (lRet);
  3790. }
  3791. ////////////////////////////////////////////////////////////////////////////
  3792. //
  3793. // Intl_CreateRegTree
  3794. //
  3795. // This copies all values and subkeys under the source key to the
  3796. // destination key.
  3797. //
  3798. ////////////////////////////////////////////////////////////////////////////
  3799. DWORD Intl_CreateRegTree(
  3800. HKEY hSrc,
  3801. HKEY hDest)
  3802. {
  3803. DWORD cdwClass, dwSubKeyLength, dwDisposition, dwKeyIndex = 0;
  3804. LPTSTR pSubKey = NULL;
  3805. TCHAR szSubKey[REGSTR_MAX_VALUE_LENGTH]; // this should be dynamic.
  3806. TCHAR szClass[REGSTR_MAX_VALUE_LENGTH]; // this should be dynamic.
  3807. HKEY hNewKey, hKey;
  3808. DWORD lRet;
  3809. //
  3810. // Copy values
  3811. //
  3812. if ((lRet = Intl_CopyRegKeyValues( hSrc,
  3813. hDest )) != ERROR_SUCCESS)
  3814. {
  3815. return (lRet);
  3816. }
  3817. //
  3818. // Copy the subkeys and the subkey values.
  3819. //
  3820. for (;;)
  3821. {
  3822. dwSubKeyLength = REGSTR_MAX_VALUE_LENGTH;
  3823. cdwClass = REGSTR_MAX_VALUE_LENGTH;
  3824. lRet = RegEnumKeyEx( hSrc,
  3825. dwKeyIndex,
  3826. szSubKey,
  3827. &dwSubKeyLength,
  3828. NULL,
  3829. szClass,
  3830. &cdwClass,
  3831. NULL );
  3832. if (lRet == ERROR_NO_MORE_ITEMS)
  3833. {
  3834. lRet = ERROR_SUCCESS;
  3835. break;
  3836. }
  3837. else if (lRet == ERROR_SUCCESS)
  3838. {
  3839. if ((lRet = RegCreateKeyEx( hDest,
  3840. szSubKey,
  3841. 0,
  3842. szClass,
  3843. REG_OPTION_NON_VOLATILE,
  3844. KEY_ALL_ACCESS,
  3845. NULL,
  3846. &hNewKey,
  3847. &dwDisposition )) == ERROR_SUCCESS)
  3848. {
  3849. //
  3850. // Copy all subkeys.
  3851. //
  3852. if ((lRet = RegOpenKeyEx( hSrc,
  3853. szSubKey,
  3854. 0,
  3855. KEY_ALL_ACCESS,
  3856. &hKey )) == ERROR_SUCCESS)
  3857. {
  3858. //
  3859. // Recursively copy the remainder of the tree.
  3860. //
  3861. lRet = Intl_CreateRegTree(hKey, hNewKey);
  3862. CloseHandle(hKey);
  3863. CloseHandle(hNewKey);
  3864. if (lRet != ERROR_SUCCESS)
  3865. {
  3866. break;
  3867. }
  3868. }
  3869. else
  3870. {
  3871. CloseHandle(hNewKey);
  3872. break;
  3873. }
  3874. }
  3875. }
  3876. else
  3877. {
  3878. break;
  3879. }
  3880. ++dwKeyIndex;
  3881. }
  3882. return (lRet);
  3883. }
  3884. ////////////////////////////////////////////////////////////////////////////
  3885. //
  3886. // Intl_LoadNtUserHive
  3887. //
  3888. // The caller of this function needs to call Intl_UnloadNtUserHive() when
  3889. // the function succeeds in order to properly release the handle on the
  3890. // NTUSER.DAT file.
  3891. //
  3892. ////////////////////////////////////////////////////////////////////////////
  3893. HKEY Intl_LoadNtUserHive(
  3894. LPCTSTR lpRoot,
  3895. LPCTSTR lpKeyName,
  3896. BOOLEAN *lpWasEnabled)
  3897. {
  3898. HKEY hKey = NULL;
  3899. LONG rc = 0L;
  3900. BOOL bRet = TRUE;
  3901. TCHAR szProfile[REGSTR_MAX_VALUE_LENGTH] = {0};
  3902. TCHAR szKeyName[REGSTR_MAX_VALUE_LENGTH] = {0};
  3903. DWORD cchSize;
  3904. //
  3905. // Get the file name for the Default User profile.
  3906. //
  3907. cchSize = MAX_PATH;
  3908. if (!GetDefaultUserProfileDirectory(szProfile, &cchSize))
  3909. {
  3910. return (NULL);
  3911. }
  3912. lstrcat(szProfile, TEXT("\\NTUSER.DAT"));
  3913. //
  3914. // Set the value in the Default User hive.
  3915. //
  3916. rc = RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, TRUE, FALSE, lpWasEnabled);
  3917. if (NT_SUCCESS(rc))
  3918. {
  3919. //
  3920. // Load the hive and restore the privilege to its previous state.
  3921. //
  3922. rc = RegLoadKey(HKEY_USERS, lpRoot, szProfile);
  3923. RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, *lpWasEnabled, FALSE, lpWasEnabled);
  3924. //
  3925. // If the hive loaded properly, set the value.
  3926. //
  3927. if (rc == ERROR_SUCCESS)
  3928. {
  3929. //
  3930. // Get the temporary key name.
  3931. //
  3932. swprintf(szKeyName, TEXT("%s\\%s"), lpRoot, lpKeyName);
  3933. if ((rc = RegOpenKeyEx( HKEY_USERS,
  3934. szKeyName,
  3935. 0L,
  3936. KEY_READ | KEY_WRITE,
  3937. &hKey )) == ERROR_SUCCESS)
  3938. {
  3939. return (hKey);
  3940. }
  3941. else
  3942. {
  3943. Intl_UnloadNtUserHive(lpRoot, lpWasEnabled);
  3944. return (NULL);
  3945. }
  3946. }
  3947. }
  3948. return (NULL);
  3949. }
  3950. ////////////////////////////////////////////////////////////////////////////
  3951. //
  3952. // Intl_UnloadNtUserHive
  3953. //
  3954. ////////////////////////////////////////////////////////////////////////////
  3955. void Intl_UnloadNtUserHive(
  3956. LPCTSTR lpRoot,
  3957. BOOLEAN *lpWasEnabled)
  3958. {
  3959. if (NT_SUCCESS(RtlAdjustPrivilege( SE_RESTORE_PRIVILEGE,
  3960. TRUE,
  3961. FALSE,
  3962. lpWasEnabled )))
  3963. {
  3964. RegUnLoadKey(HKEY_USERS, lpRoot);
  3965. RtlAdjustPrivilege( SE_RESTORE_PRIVILEGE,
  3966. *lpWasEnabled,
  3967. FALSE,
  3968. lpWasEnabled );
  3969. }
  3970. }
  3971. ////////////////////////////////////////////////////////////////////////////
  3972. //
  3973. // Intl_ChangeUILangForAllUsers
  3974. //
  3975. ////////////////////////////////////////////////////////////////////////////
  3976. BOOL Intl_ChangeUILangForAllUsers(
  3977. LANGID UILanguageId)
  3978. {
  3979. HKEY hKey;
  3980. HKEY hHive;
  3981. TCHAR szData[MAX_PATH];
  3982. LONG rc = 0L;
  3983. BOOLEAN wasEnabled;
  3984. int i;
  3985. //
  3986. // Array of user accounts that we care
  3987. // S-1-5-19, local services, S-1-5-20, network services
  3988. //
  3989. LPTSTR ppDefaultUser[] = { TEXT(".DEFAULT"), TEXT("S-1-5-19"), TEXT("S-1-5-20")};
  3990. TCHAR szRegPath[MAX_PATH];
  3991. //
  3992. // Save the UILanguageId as a string.
  3993. //
  3994. wsprintf(szData, TEXT("%08x"), UILanguageId);
  3995. for (i=0; i< ARRAYSIZE(ppDefaultUser); i++)
  3996. {
  3997. if (!PathCombine(szRegPath, ppDefaultUser[i], TEXT("Control Panel\\Desktop")))
  3998. {
  3999. return (FALSE);
  4000. }
  4001. //
  4002. // Set the value in .DEFAULT registry.
  4003. //
  4004. if ((rc = RegOpenKeyEx( HKEY_USERS,
  4005. szRegPath,
  4006. 0L,
  4007. KEY_READ | KEY_WRITE,
  4008. &hKey )) == ERROR_SUCCESS)
  4009. {
  4010. rc = RegSetValueEx( hKey,
  4011. c_szMUIValue,
  4012. 0L,
  4013. REG_SZ,
  4014. (LPBYTE)szData,
  4015. (lstrlen(szData) + 1) * sizeof(TCHAR) );
  4016. //
  4017. // Sync up UI language pending key
  4018. //
  4019. if (rc == ERROR_SUCCESS)
  4020. {
  4021. rc = RegSetValueEx( hKey,
  4022. szMUILangPending,
  4023. 0L,
  4024. REG_SZ,
  4025. (LPBYTE)szData,
  4026. (lstrlen(szData) + 1) * sizeof(TCHAR) );
  4027. }
  4028. RegCloseKey(hKey);
  4029. }
  4030. }
  4031. //
  4032. // Save the value into the .DEFAULT user hive
  4033. //
  4034. if (rc == ERROR_SUCCESS)
  4035. {
  4036. //
  4037. // Load the default hive
  4038. //
  4039. if ((hHive = Intl_LoadNtUserHive( TEXT("tempKey"),
  4040. c_szCPanelDesktop,
  4041. &wasEnabled )) == NULL )
  4042. {
  4043. return (FALSE);
  4044. }
  4045. //
  4046. // Save the MUI language value in the NTUSER.dat
  4047. //
  4048. RegSetValueEx( hHive,
  4049. c_szMUIValue,
  4050. 0L,
  4051. REG_SZ,
  4052. (LPBYTE)szData,
  4053. (lstrlen(szData) + 1) * sizeof(TCHAR));
  4054. //
  4055. // Sync up UI language pending key
  4056. //
  4057. if (rc == ERROR_SUCCESS)
  4058. {
  4059. rc = RegSetValueEx( hHive,
  4060. szMUILangPending,
  4061. 0L,
  4062. REG_SZ,
  4063. (LPBYTE)szData,
  4064. (lstrlen(szData) + 1) * sizeof(TCHAR) );
  4065. }
  4066. //
  4067. // Clean up
  4068. //
  4069. RegCloseKey(hHive);
  4070. Intl_UnloadNtUserHive(TEXT("tempKey"), &wasEnabled);
  4071. }
  4072. else
  4073. {
  4074. return (FALSE);
  4075. }
  4076. //
  4077. // Install Language Input locales.
  4078. //
  4079. return Intl_InstallKeyboardLayout(NULL,
  4080. MAKELCID(UILanguageId, SORT_DEFAULT),
  4081. 0,
  4082. FALSE,
  4083. TRUE,
  4084. FALSE);
  4085. }
  4086. ////////////////////////////////////////////////////////////////////////////
  4087. //
  4088. // Intl_LoadLanguageGroups
  4089. //
  4090. ////////////////////////////////////////////////////////////////////////////
  4091. BOOL Intl_LoadLanguageGroups(
  4092. HWND hDlg)
  4093. {
  4094. LPLANGUAGEGROUP pLG;
  4095. DWORD dwExStyle;
  4096. RECT Rect;
  4097. LV_COLUMN Column;
  4098. LV_ITEM Item;
  4099. int iIndex;
  4100. //
  4101. // Open the Inf file.
  4102. //
  4103. g_hIntlInf = SetupOpenInfFile(szIntlInf, NULL, INF_STYLE_WIN4, NULL);
  4104. if (g_hIntlInf == INVALID_HANDLE_VALUE)
  4105. {
  4106. return (FALSE);
  4107. }
  4108. if (!SetupOpenAppendInfFile(NULL, g_hIntlInf, NULL))
  4109. {
  4110. SetupCloseInfFile(g_hIntlInf);
  4111. g_hIntlInf = NULL;
  4112. return (FALSE);
  4113. }
  4114. //
  4115. // Get all supported language groups from the inf file.
  4116. //
  4117. if (Intl_GetSupportedLanguageGroups() == FALSE)
  4118. {
  4119. return (FALSE);
  4120. }
  4121. //
  4122. // Close the inf file.
  4123. //
  4124. SetupCloseInfFile(g_hIntlInf);
  4125. g_hIntlInf = NULL;
  4126. //
  4127. // Enumerate all installed language groups.
  4128. //
  4129. if (Intl_EnumInstalledLanguageGroups() == FALSE)
  4130. {
  4131. return (FALSE);
  4132. }
  4133. //
  4134. // Return success.
  4135. //
  4136. return (TRUE);
  4137. }
  4138. ////////////////////////////////////////////////////////////////////////////
  4139. //
  4140. // Intl_GetSupportedLanguageGroups
  4141. //
  4142. ////////////////////////////////////////////////////////////////////////////
  4143. BOOL Intl_GetSupportedLanguageGroups()
  4144. {
  4145. UINT LanguageGroup;
  4146. HANDLE hLanguageGroup;
  4147. LPLANGUAGEGROUP pLG;
  4148. INFCONTEXT Context;
  4149. TCHAR szSection[MAX_PATH];
  4150. TCHAR szTemp[MAX_PATH];
  4151. int LineCount, LineNum;
  4152. DWORD ItemCount;
  4153. WORD wItemStatus;
  4154. //
  4155. // Get the number of supported language groups from the inf file.
  4156. //
  4157. LineCount = (UINT)SetupGetLineCount(g_hIntlInf, TEXT("LanguageGroups"));
  4158. if (LineCount <= 0)
  4159. {
  4160. return (FALSE);
  4161. }
  4162. //
  4163. // Go through all supported language groups in the inf file.
  4164. //
  4165. for (LineNum = 0; LineNum < LineCount; LineNum++)
  4166. {
  4167. if (SetupGetLineByIndex(g_hIntlInf, TEXT("LanguageGroups"), LineNum, &Context) &&
  4168. SetupGetIntField(&Context, 0, &LanguageGroup))
  4169. {
  4170. //
  4171. // Create the new node.
  4172. //
  4173. if (!(hLanguageGroup = GlobalAlloc(GHND, sizeof(LANGUAGEGROUP))))
  4174. {
  4175. return (FALSE);
  4176. }
  4177. pLG = GlobalLock(hLanguageGroup);
  4178. //
  4179. // Fill in the new node with the appropriate info.
  4180. //
  4181. pLG->wStatus = 0;
  4182. pLG->LanguageGroup = LanguageGroup;
  4183. pLG->hLanguageGroup = hLanguageGroup;
  4184. (pLG->pszName)[0] = 0;
  4185. pLG->NumLocales = 0;
  4186. pLG->NumAltSorts = 0;
  4187. //
  4188. // Set the collection
  4189. //
  4190. if ((pLG->LanguageGroup == LGRPID_JAPANESE) ||
  4191. (pLG->LanguageGroup == LGRPID_KOREAN) ||
  4192. (pLG->LanguageGroup == LGRPID_TRADITIONAL_CHINESE) ||
  4193. (pLG->LanguageGroup == LGRPID_SIMPLIFIED_CHINESE) )
  4194. {
  4195. pLG->LanguageCollection = CJK_COLLECTION;
  4196. }
  4197. else if ((pLG->LanguageGroup == LGRPID_ARABIC) ||
  4198. (pLG->LanguageGroup == LGRPID_ARMENIAN) ||
  4199. (pLG->LanguageGroup == LGRPID_GEORGIAN) ||
  4200. (pLG->LanguageGroup == LGRPID_HEBREW) ||
  4201. (pLG->LanguageGroup == LGRPID_INDIC) ||
  4202. (pLG->LanguageGroup == LGRPID_VIETNAMESE) ||
  4203. (pLG->LanguageGroup == LGRPID_THAI))
  4204. {
  4205. pLG->LanguageCollection = COMPLEX_COLLECTION;
  4206. }
  4207. else
  4208. {
  4209. pLG->LanguageCollection = BASIC_COLLECTION;
  4210. }
  4211. //
  4212. // Get the appropriate display string.
  4213. //
  4214. if (!SetupGetStringField(&Context, 1, pLG->pszName, MAX_PATH, NULL))
  4215. {
  4216. GlobalUnlock(hLanguageGroup);
  4217. GlobalFree(hLanguageGroup);
  4218. continue;
  4219. }
  4220. //
  4221. // Get the list of locales for this language group.
  4222. //
  4223. if (Intl_GetLocaleList(pLG) == FALSE)
  4224. {
  4225. return (FALSE);
  4226. }
  4227. //
  4228. // Add the language group to the front of the linked list.
  4229. //
  4230. pLG->pNext = pLanguageGroups;
  4231. pLanguageGroups = pLG;
  4232. }
  4233. }
  4234. //
  4235. // Return success.
  4236. //
  4237. return (TRUE);
  4238. }
  4239. ////////////////////////////////////////////////////////////////////////////
  4240. //
  4241. // Intl_EnumInstalledLanguageGroups
  4242. //
  4243. ////////////////////////////////////////////////////////////////////////////
  4244. BOOL Intl_EnumInstalledLanguageGroups()
  4245. {
  4246. HKEY hKey;
  4247. TCHAR szValue[MAX_PATH];
  4248. TCHAR szData[MAX_PATH];
  4249. TCHAR szDefault[SIZE_64];
  4250. DWORD dwIndex, cchValue, cbData;
  4251. LONG rc;
  4252. UINT LanguageGroup, OriginalGroup, DefaultGroup, UILanguageGroup;
  4253. LPLANGUAGEGROUP pLG;
  4254. LCID Locale;
  4255. LANGID Language;
  4256. int Ctr;
  4257. //
  4258. // Get the original install language so that we can mark that
  4259. // language group as permanent.
  4260. //
  4261. Language = GetSystemDefaultUILanguage();
  4262. if (SUBLANGID(Language) == SUBLANG_NEUTRAL)
  4263. {
  4264. Language = MAKELANGID(PRIMARYLANGID(Language), SUBLANG_DEFAULT);
  4265. }
  4266. if ((OriginalGroup = Intl_GetLanguageGroup(Language)) == 0)
  4267. {
  4268. OriginalGroup = 1;
  4269. }
  4270. //
  4271. // Get the default system locale so that we can mark that language
  4272. // group as permanent. During gui mode setup, read the system locale from
  4273. // the registry to make the info on the setup page consistent with intl.cpl.
  4274. // SysLocaleID will be the registry value in case of setup.
  4275. //
  4276. Locale = SysLocaleID;
  4277. if (Locale == (LCID)Language)
  4278. {
  4279. DefaultGroup = OriginalGroup;
  4280. }
  4281. else
  4282. {
  4283. if ((DefaultGroup = Intl_GetLanguageGroup(Locale)) == 0)
  4284. {
  4285. DefaultGroup = 1;
  4286. }
  4287. }
  4288. //
  4289. // Get the UI language's language groups to disable the user from
  4290. // un-installing them. MUISETUP makes sure that each installed UI
  4291. // language has its language group installed.
  4292. //
  4293. Intl_GetUILanguageGroups(&UILangGroup);
  4294. //
  4295. // Open the HKLM\SYSTEM\CurrentControlSet\Control\Nls\Language Groups
  4296. // key.
  4297. //
  4298. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  4299. c_szLanguageGroups,
  4300. 0,
  4301. KEY_READ,
  4302. &hKey ) != ERROR_SUCCESS)
  4303. {
  4304. return (FALSE);
  4305. }
  4306. //
  4307. // Enumerate the values in the Language Groups key.
  4308. //
  4309. dwIndex = 0;
  4310. cchValue = sizeof(szValue) / sizeof(TCHAR);
  4311. szValue[0] = TEXT('\0');
  4312. cbData = sizeof(szData);
  4313. szData[0] = TEXT('\0');
  4314. rc = RegEnumValue( hKey,
  4315. dwIndex,
  4316. szValue,
  4317. &cchValue,
  4318. NULL,
  4319. NULL,
  4320. (LPBYTE)szData,
  4321. &cbData );
  4322. while (rc == ERROR_SUCCESS)
  4323. {
  4324. //
  4325. // If the language group contains data, then it is installed.
  4326. //
  4327. if ((szData[0] != 0) &&
  4328. (LanguageGroup = TransNum(szValue)))
  4329. {
  4330. //
  4331. // Find the language group in the linked list and mark it as
  4332. // originally installed.
  4333. //
  4334. pLG = pLanguageGroups;
  4335. while (pLG)
  4336. {
  4337. if (pLG->LanguageGroup == LanguageGroup)
  4338. {
  4339. pLG->wStatus |= ML_INSTALL;
  4340. //
  4341. // If this is a language group for a UI language that's
  4342. // installed, then disable the un-installation of this
  4343. // language group.
  4344. //
  4345. Ctr = 0;
  4346. while (Ctr < UILangGroup.iCount)
  4347. {
  4348. if (UILangGroup.lgrp[Ctr] == LanguageGroup)
  4349. {
  4350. pLG->wStatus |= ML_PERMANENT;
  4351. break;
  4352. }
  4353. Ctr++;
  4354. }
  4355. if (pLG->LanguageGroup == OriginalGroup)
  4356. {
  4357. pLG->wStatus |= ML_PERMANENT;
  4358. }
  4359. if (pLG->LanguageGroup == DefaultGroup)
  4360. {
  4361. pLG->wStatus |= (ML_PERMANENT | ML_DEFAULT);
  4362. if (LoadString(hInstance, IDS_DEFAULT, szDefault, SIZE_64))
  4363. {
  4364. lstrcat(pLG->pszName, szDefault);
  4365. }
  4366. }
  4367. break;
  4368. }
  4369. pLG = pLG->pNext;
  4370. }
  4371. }
  4372. //
  4373. // Get the next enum value.
  4374. //
  4375. dwIndex++;
  4376. cchValue = sizeof(szValue) / sizeof(TCHAR);
  4377. szValue[0] = TEXT('\0');
  4378. cbData = sizeof(szData);
  4379. szData[0] = TEXT('\0');
  4380. rc = RegEnumValue( hKey,
  4381. dwIndex,
  4382. szValue,
  4383. &cchValue,
  4384. NULL,
  4385. NULL,
  4386. (LPBYTE)szData,
  4387. &cbData );
  4388. }
  4389. //
  4390. // Close the registry key handle.
  4391. //
  4392. RegCloseKey(hKey);
  4393. //
  4394. // Return success.
  4395. //
  4396. return (TRUE);
  4397. }
  4398. ////////////////////////////////////////////////////////////////////////////
  4399. //
  4400. // Intl_LanguageGroupDirExist
  4401. //
  4402. ////////////////////////////////////////////////////////////////////////////
  4403. BOOL Intl_LanguageGroupDirExist(
  4404. PTSTR pszLangDir)
  4405. {
  4406. TCHAR szLanguageGroupDir[MAX_PATH];
  4407. WIN32_FIND_DATA FindData;
  4408. HANDLE FindHandle;
  4409. TCHAR SavedChar;
  4410. //
  4411. // If it doesn't start with lang, then this is a core language.
  4412. //
  4413. SavedChar = pszLangDir[4];
  4414. pszLangDir[4] = TEXT('\0');
  4415. if (lstrcmp(pszLangDir, TEXT("lang")))
  4416. {
  4417. return (TRUE);
  4418. }
  4419. pszLangDir[4] = SavedChar;
  4420. //
  4421. // Format the path to the language group directory.
  4422. //
  4423. lstrcpy(szLanguageGroupDir, pSetupSourcePathWithArchitecture);
  4424. lstrcat(szLanguageGroupDir, TEXT("\\"));
  4425. lstrcat(szLanguageGroupDir, pszLangDir);
  4426. //
  4427. // See if the language group directory exists.
  4428. //
  4429. FindHandle = FindFirstFile(szLanguageGroupDir, &FindData);
  4430. if (FindHandle != INVALID_HANDLE_VALUE)
  4431. {
  4432. FindClose(FindHandle);
  4433. if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  4434. {
  4435. //
  4436. // Return success.
  4437. //
  4438. return (TRUE);
  4439. }
  4440. }
  4441. //
  4442. // Return failure.
  4443. //
  4444. return (FALSE);
  4445. }
  4446. ////////////////////////////////////////////////////////////////////////////
  4447. //
  4448. // Intl_LanguageGroupFilesExist
  4449. //
  4450. ////////////////////////////////////////////////////////////////////////////
  4451. BOOL Intl_LanguageGroupFilesExist()
  4452. {
  4453. TCHAR szLanguageGroupDir[MAX_PATH];
  4454. WIN32_FIND_DATA FindData;
  4455. HANDLE FindHandle;
  4456. //
  4457. // Format the path to the language group directory. Add the wildcard
  4458. // to search for any files located in the lang directory.
  4459. //
  4460. lstrcpy(szLanguageGroupDir, pSetupSourcePathWithArchitecture);
  4461. lstrcat(szLanguageGroupDir, TEXT("\\Lang\\*"));
  4462. //
  4463. // See if at least one file exists.
  4464. //
  4465. FindHandle = FindFirstFile(szLanguageGroupDir, &FindData);
  4466. if (FindHandle != INVALID_HANDLE_VALUE)
  4467. {
  4468. FindClose(FindHandle);
  4469. //
  4470. // Return success.
  4471. //
  4472. return (TRUE);
  4473. }
  4474. //
  4475. // Return failure.
  4476. //
  4477. return (FALSE);
  4478. }
  4479. ////////////////////////////////////////////////////////////////////////////
  4480. //
  4481. // Intl_GetLocaleList
  4482. //
  4483. ////////////////////////////////////////////////////////////////////////////
  4484. BOOL Intl_GetLocaleList(
  4485. LPLANGUAGEGROUP pLG)
  4486. {
  4487. TCHAR szSection[MAX_PATH];
  4488. INFCONTEXT Context;
  4489. int LineCount, LineNum;
  4490. LCID Locale;
  4491. //
  4492. // Get the inf section name.
  4493. //
  4494. wsprintf(szSection, TEXT("%ws%d"), szLocaleListPrefix, pLG->LanguageGroup);
  4495. //
  4496. // Get the number of locales for the language group.
  4497. //
  4498. LineCount = (UINT)SetupGetLineCount(g_hIntlInf, szSection);
  4499. if (LineCount <= 0)
  4500. {
  4501. return (FALSE);
  4502. }
  4503. //
  4504. // Add each locale in the list to the language group node.
  4505. //
  4506. for (LineNum = 0; LineNum < LineCount; LineNum++)
  4507. {
  4508. if (SetupGetLineByIndex(g_hIntlInf, szSection, LineNum, &Context) &&
  4509. SetupGetIntField(&Context, 0, &Locale))
  4510. {
  4511. if (SORTIDFROMLCID(Locale))
  4512. {
  4513. //
  4514. // Add the locale to the alternate sort list for this
  4515. // language group.
  4516. //
  4517. if (pLG->NumAltSorts >= MAX_PATH)
  4518. {
  4519. return (FALSE);
  4520. }
  4521. pLG->pAltSortList[pLG->NumAltSorts] = Locale;
  4522. (pLG->NumAltSorts)++;
  4523. }
  4524. else
  4525. {
  4526. //
  4527. // Add the locale to the locale list for this
  4528. // language group.
  4529. //
  4530. if (pLG->NumLocales >= MAX_PATH)
  4531. {
  4532. return (FALSE);
  4533. }
  4534. pLG->pLocaleList[pLG->NumLocales] = Locale;
  4535. (pLG->NumLocales)++;
  4536. }
  4537. }
  4538. }
  4539. //
  4540. // Return success.
  4541. //
  4542. return (TRUE);
  4543. }
  4544. ////////////////////////////////////////////////////////////////////////////
  4545. //
  4546. // Region_GetLocaleLanguageGroup
  4547. //
  4548. // Reads the Language Group Id of the given language.
  4549. //
  4550. ////////////////////////////////////////////////////////////////////////////
  4551. DWORD Intl_GetLanguageGroup(
  4552. LCID lcid)
  4553. {
  4554. TCHAR szValue[MAX_PATH];
  4555. TCHAR szData[MAX_PATH];
  4556. HKEY hKey;
  4557. DWORD cbData;
  4558. wsprintf(szValue, TEXT("%8.8x"), lcid);
  4559. szData[0] = 0;
  4560. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  4561. c_szInstalledLocales,
  4562. 0,
  4563. KEY_READ,
  4564. &hKey ) == ERROR_SUCCESS)
  4565. {
  4566. cbData = sizeof(szData);
  4567. RegQueryValueEx(hKey, szValue, NULL, NULL, (LPBYTE)szData, &cbData);
  4568. RegCloseKey(hKey);
  4569. }
  4570. return (TransNum(szData));
  4571. }
  4572. ////////////////////////////////////////////////////////////////////////////
  4573. //
  4574. // Intl_GetUILanguageGroups
  4575. //
  4576. // Reads the language groups of all the UI languages installed on this
  4577. // machine.
  4578. //
  4579. ////////////////////////////////////////////////////////////////////////////
  4580. BOOL Intl_GetUILanguageGroups(
  4581. PUILANGUAGEGROUP pUILanguageGroup)
  4582. {
  4583. //
  4584. // Enumerate the installed UI languages.
  4585. //
  4586. pUILanguageGroup->iCount = 0L;
  4587. EnumUILanguages(Intl_EnumUILanguagesProc, 0, (LONG_PTR)pUILanguageGroup);
  4588. //
  4589. // Return success.
  4590. //
  4591. return (TRUE);
  4592. }
  4593. ////////////////////////////////////////////////////////////////////////////
  4594. //
  4595. // Intl_EnumUILanguagesProc
  4596. //
  4597. ////////////////////////////////////////////////////////////////////////////
  4598. BOOL CALLBACK Intl_EnumUILanguagesProc(
  4599. LPWSTR pwszUILanguage,
  4600. LONG_PTR lParam)
  4601. {
  4602. int Ctr = 0;
  4603. LGRPID lgrp;
  4604. PUILANGUAGEGROUP pUILangGroup = (PUILANGUAGEGROUP)lParam;
  4605. LCID UILanguage = TransNum(pwszUILanguage);
  4606. if (UILanguage)
  4607. {
  4608. if ((lgrp = Intl_GetLanguageGroup(UILanguage)) == 0)
  4609. {
  4610. lgrp = 1; // default;
  4611. }
  4612. while (Ctr < pUILangGroup->iCount)
  4613. {
  4614. if (pUILangGroup->lgrp[Ctr] == lgrp)
  4615. {
  4616. break;
  4617. }
  4618. Ctr++;
  4619. }
  4620. //
  4621. // Theoritically, we won't go over 64 language groups!
  4622. //
  4623. if ((Ctr == pUILangGroup->iCount) && (Ctr < MAX_UI_LANG_GROUPS))
  4624. {
  4625. pUILangGroup->lgrp[Ctr] = lgrp;
  4626. pUILangGroup->iCount++;
  4627. }
  4628. }
  4629. return (TRUE);
  4630. }
  4631. ////////////////////////////////////////////////////////////////////////////
  4632. //
  4633. // Intl_SaveValuesToDefault
  4634. //
  4635. // This function copies the current user settings under the srcKey to
  4636. // the Default user under the destKey.
  4637. //
  4638. ////////////////////////////////////////////////////////////////////////////
  4639. void Intl_SaveValuesToDefault(
  4640. LPCTSTR srcKey,
  4641. LPCTSTR destKey)
  4642. {
  4643. HKEY hkeyLayouts;
  4644. HKEY hkeyLayouts_DefUser;
  4645. //
  4646. // 1. Open the Current user key.
  4647. //
  4648. if (RegOpenKeyEx( HKEY_CURRENT_USER,
  4649. srcKey,
  4650. 0,
  4651. KEY_ALL_ACCESS,
  4652. &hkeyLayouts ) != ERROR_SUCCESS)
  4653. {
  4654. return;
  4655. }
  4656. //
  4657. // 2. Open the .Default hive key.
  4658. //
  4659. if (RegOpenKeyEx( HKEY_USERS,
  4660. destKey,
  4661. 0,
  4662. KEY_ALL_ACCESS,
  4663. &hkeyLayouts_DefUser ) != ERROR_SUCCESS)
  4664. {
  4665. RegCloseKey(hkeyLayouts);
  4666. return;
  4667. }
  4668. //
  4669. // 3. Delete .Default key values.
  4670. //
  4671. Intl_DeleteRegKeyValues(hkeyLayouts_DefUser);
  4672. //
  4673. // 4. Delete .Default subkeys.
  4674. //
  4675. Intl_DeleteRegSubKeys(hkeyLayouts_DefUser);
  4676. //
  4677. // 5. Copy tree.
  4678. //
  4679. Intl_CreateRegTree(hkeyLayouts, hkeyLayouts_DefUser);
  4680. //
  4681. // 6. Clean up
  4682. //
  4683. RegCloseKey(hkeyLayouts_DefUser);
  4684. RegCloseKey(hkeyLayouts);
  4685. }
  4686. ////////////////////////////////////////////////////////////////////////////
  4687. //
  4688. // Intl_SaveValuesToNtUserFile
  4689. //
  4690. // This function copy current user setting under the srcKey to the Default
  4691. // user hive under the destKey.
  4692. //
  4693. ////////////////////////////////////////////////////////////////////////////
  4694. void Intl_SaveValuesToNtUserFile(
  4695. HKEY hSourceRegKey,
  4696. LPCTSTR srcKey,
  4697. LPCTSTR destKey)
  4698. {
  4699. HKEY hRegKey;
  4700. HKEY hHive;
  4701. BOOLEAN wasEnabled;
  4702. //
  4703. // 1. Open the Current user key.
  4704. //
  4705. if (RegOpenKeyEx( hSourceRegKey,
  4706. srcKey,
  4707. 0,
  4708. KEY_READ,
  4709. &hRegKey ) != ERROR_SUCCESS)
  4710. {
  4711. return;
  4712. }
  4713. //
  4714. // 2. Load the hive to a temporary key location.
  4715. //
  4716. if ((hHive = Intl_LoadNtUserHive( TEXT("TempKey"),
  4717. destKey,
  4718. &wasEnabled )) == NULL)
  4719. {
  4720. RegCloseKey(hRegKey);
  4721. return;
  4722. }
  4723. //
  4724. // 3. Delete .Default key values.
  4725. //
  4726. Intl_DeleteRegKeyValues(hHive);
  4727. //
  4728. // 4. Delete .Default subkeys.
  4729. //
  4730. Intl_DeleteRegSubKeys(hHive);
  4731. //
  4732. // 5. Copy tree.
  4733. //
  4734. Intl_CreateRegTree(hRegKey, hHive);
  4735. //
  4736. // 6. Clean up.
  4737. //
  4738. RegCloseKey(hHive);
  4739. Intl_UnloadNtUserHive(TEXT("TempKey"), &wasEnabled);
  4740. RegCloseKey(hRegKey);
  4741. }
  4742. ////////////////////////////////////////////////////////////////////////////
  4743. //
  4744. // Intl_IsSetupMode
  4745. //
  4746. // Look into the registry if we are currently in setup mode.
  4747. //
  4748. ////////////////////////////////////////////////////////////////////////////
  4749. BOOL Intl_IsSetupMode()
  4750. {
  4751. HKEY hKey;
  4752. DWORD fSystemSetupInProgress = 0;
  4753. DWORD cbData = 0;
  4754. //
  4755. // Open the registry key used by setup
  4756. //
  4757. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  4758. c_szSetupKey,
  4759. 0,
  4760. KEY_READ,
  4761. &hKey ) != ERROR_SUCCESS)
  4762. {
  4763. return (FALSE);
  4764. }
  4765. //
  4766. // Query for the value indicating that we are in setup.
  4767. //
  4768. cbData = sizeof(fSystemSetupInProgress);
  4769. if (RegQueryValueEx( hKey,
  4770. szSetupInProgress,
  4771. NULL,
  4772. NULL,
  4773. (LPBYTE)&fSystemSetupInProgress,
  4774. &cbData ) != ERROR_SUCCESS)
  4775. {
  4776. RegCloseKey(hKey);
  4777. return (FALSE);
  4778. }
  4779. //
  4780. // Clean up
  4781. //
  4782. RegCloseKey(hKey);
  4783. //
  4784. // Check the value
  4785. //
  4786. if (fSystemSetupInProgress)
  4787. {
  4788. //
  4789. // In setup mode...
  4790. //
  4791. if (g_bLog)
  4792. {
  4793. Intl_LogSimpleMessage(IDS_LOG_SETUP_MODE, NULL);
  4794. }
  4795. return (TRUE);
  4796. }
  4797. return (FALSE);
  4798. }
  4799. ////////////////////////////////////////////////////////////////////////////
  4800. //
  4801. // Intl_IsWinntUpgrade
  4802. //
  4803. // Look into the registry if we are currently in winnt upgrade.
  4804. //
  4805. ////////////////////////////////////////////////////////////////////////////
  4806. BOOL Intl_IsWinntUpgrade()
  4807. {
  4808. HKEY hKey;
  4809. DWORD fUpgradeInProgress = 0;
  4810. DWORD cbData = 0;
  4811. //
  4812. // Verify that we're in setup first.
  4813. //
  4814. if (!g_bSetupCase)
  4815. {
  4816. return (FALSE);
  4817. }
  4818. //
  4819. // Open the registry key used by setup.
  4820. //
  4821. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  4822. c_szSetupKey,
  4823. 0,
  4824. KEY_READ,
  4825. &hKey ) != ERROR_SUCCESS)
  4826. {
  4827. return (FALSE);
  4828. }
  4829. //
  4830. // Query for the value indicating that we are in setup.
  4831. //
  4832. cbData = sizeof(fUpgradeInProgress);
  4833. if (RegQueryValueEx( hKey,
  4834. szSetupUpgrade,
  4835. NULL,
  4836. NULL,
  4837. (LPBYTE)&fUpgradeInProgress,
  4838. &cbData ) != ERROR_SUCCESS)
  4839. {
  4840. RegCloseKey(hKey);
  4841. return (FALSE);
  4842. }
  4843. //
  4844. // Clean up.
  4845. //
  4846. RegCloseKey(hKey);
  4847. //
  4848. // Check the value.
  4849. //
  4850. if (fUpgradeInProgress)
  4851. {
  4852. //
  4853. // Upgrade scenario.
  4854. //
  4855. if (g_bLog)
  4856. {
  4857. Intl_LogSimpleMessage(IDS_LOG_UPGRADE_SCENARIO, NULL);
  4858. }
  4859. return (TRUE);
  4860. }
  4861. return (FALSE);
  4862. }
  4863. ////////////////////////////////////////////////////////////////////////////
  4864. //
  4865. // Intl_IsUIFontSubstitute
  4866. //
  4867. // Look into the registry if we need to substitute the font.
  4868. //
  4869. ////////////////////////////////////////////////////////////////////////////
  4870. BOOL Intl_IsUIFontSubstitute()
  4871. {
  4872. HKEY hKey;
  4873. DWORD fUIFontSubstitute = 0;
  4874. DWORD cbData = 0;
  4875. //
  4876. // Command line call, no need to check registry
  4877. //
  4878. if (g_bMatchUIFont)
  4879. {
  4880. return (TRUE);
  4881. }
  4882. //
  4883. // Open the registry key used MUI font substitution.
  4884. //
  4885. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  4886. c_szMUILanguages,
  4887. 0,
  4888. KEY_READ,
  4889. &hKey ) != ERROR_SUCCESS)
  4890. {
  4891. return (FALSE);
  4892. }
  4893. //
  4894. // Query for the value indicating that we need to apply font
  4895. // substitution.
  4896. //
  4897. cbData = sizeof(fUIFontSubstitute);
  4898. if (RegQueryValueEx( hKey,
  4899. szUIFontSubstitute,
  4900. NULL,
  4901. NULL,
  4902. (LPBYTE)&fUIFontSubstitute,
  4903. &cbData ) != ERROR_SUCCESS)
  4904. {
  4905. RegCloseKey(hKey);
  4906. return (FALSE);
  4907. }
  4908. //
  4909. // Clean up.
  4910. //
  4911. RegCloseKey(hKey);
  4912. //
  4913. // Check the value.
  4914. //
  4915. if (fUIFontSubstitute)
  4916. {
  4917. //
  4918. // Upgrade scenario.
  4919. //
  4920. if (g_bLog)
  4921. {
  4922. Intl_LogSimpleMessage(IDS_LOG_FONT_SUBSTITUTE, NULL);
  4923. }
  4924. return (TRUE);
  4925. }
  4926. return (FALSE);
  4927. }
  4928. ////////////////////////////////////////////////////////////////////////////
  4929. //
  4930. // Intl_ApplyFontSubstitute
  4931. //
  4932. // Search into the intl.inf file to see of the SystemLocale need font
  4933. // substitution.
  4934. //
  4935. ////////////////////////////////////////////////////////////////////////////
  4936. VOID Intl_ApplyFontSubstitute(LCID SystemLocale)
  4937. {
  4938. HINF hIntlInf;
  4939. TCHAR szLCID[25];
  4940. INFCONTEXT Context;
  4941. TCHAR szFont[MAX_PATH] = {0};
  4942. TCHAR szFontSubst[MAX_PATH] = {0};
  4943. HKEY hKey;
  4944. //
  4945. // Open the Intl.inf file.
  4946. //
  4947. if (Intl_OpenIntlInfFile(&hIntlInf))
  4948. {
  4949. //
  4950. // Get the locale.
  4951. //
  4952. wsprintf(szLCID, TEXT("%08x"), SystemLocale);
  4953. //
  4954. // Look for the Font Substitute section.
  4955. //
  4956. if (SetupFindFirstLine( hIntlInf,
  4957. szFontSubstitute,
  4958. szLCID,
  4959. &Context ))
  4960. {
  4961. //
  4962. // Look for the Font and Font Substitute
  4963. //
  4964. if (!SetupGetStringField( &Context,
  4965. 1,
  4966. szFont,
  4967. MAX_PATH,
  4968. NULL ) ||
  4969. !SetupGetStringField( &Context,
  4970. 2,
  4971. szFontSubst,
  4972. MAX_PATH,
  4973. NULL ))
  4974. {
  4975. //
  4976. // Clean up.
  4977. //
  4978. Intl_CloseInfFile(hIntlInf);
  4979. return;
  4980. }
  4981. }
  4982. else
  4983. {
  4984. //
  4985. // Nothing to do for this specific locale. Clean up.
  4986. //
  4987. Intl_CloseInfFile(hIntlInf);
  4988. return;
  4989. }
  4990. }
  4991. else
  4992. {
  4993. return;
  4994. }
  4995. //
  4996. // Close the Intl.inf file
  4997. //
  4998. Intl_CloseInfFile(hIntlInf);
  4999. //
  5000. // Proceed with the font replacement.
  5001. //
  5002. if (szFont[0] && szFontSubst[0])
  5003. {
  5004. //
  5005. // Open the Font Substitute registry key.
  5006. //
  5007. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  5008. c_szFontSubstitute,
  5009. 0L,
  5010. KEY_READ | KEY_WRITE,
  5011. &hKey ) == ERROR_SUCCESS)
  5012. {
  5013. //
  5014. // Set the Font value with the Font Substitute.
  5015. //
  5016. RegSetValueEx( hKey,
  5017. szFont,
  5018. 0L,
  5019. REG_SZ,
  5020. (LPBYTE)szFontSubst,
  5021. (lstrlen(szFontSubst) + 1) * sizeof(TCHAR) );
  5022. RegCloseKey(hKey);
  5023. }
  5024. }
  5025. }
  5026. ////////////////////////////////////////////////////////////////////////////
  5027. //
  5028. // Intl_OpenLogFile
  5029. //
  5030. // Opens the Region and Languages Options log for writing.
  5031. //
  5032. ////////////////////////////////////////////////////////////////////////////
  5033. HANDLE Intl_OpenLogFile()
  5034. {
  5035. DWORD dwSize;
  5036. DWORD dwUnicodeHeader;
  5037. HANDLE hFile;
  5038. SECURITY_ATTRIBUTES SecurityAttributes;
  5039. TCHAR lpPath[MAX_PATH];
  5040. GetWindowsDirectory(lpPath, MAX_PATH);
  5041. _tcscat(lpPath, TEXT("\\regopt.log"));
  5042. SecurityAttributes.nLength = sizeof(SecurityAttributes);
  5043. SecurityAttributes.lpSecurityDescriptor = NULL;
  5044. SecurityAttributes.bInheritHandle = FALSE;
  5045. hFile = CreateFile( lpPath,
  5046. GENERIC_WRITE,
  5047. 0,
  5048. &SecurityAttributes,
  5049. OPEN_ALWAYS,
  5050. FILE_ATTRIBUTE_NORMAL,
  5051. NULL );
  5052. #ifdef UNICODE
  5053. //
  5054. // If the file did not already exist, add the unicode header.
  5055. //
  5056. if (GetLastError() == 0)
  5057. {
  5058. dwUnicodeHeader = 0xFEFF;
  5059. WriteFile(hFile, &dwUnicodeHeader, 2, &dwSize, NULL);
  5060. }
  5061. #endif
  5062. return (hFile);
  5063. }
  5064. ////////////////////////////////////////////////////////////////////////////
  5065. //
  5066. // Intl_LogMessage
  5067. //
  5068. // Writes lpMessage to the Region and Languages Options log.
  5069. //
  5070. ////////////////////////////////////////////////////////////////////////////
  5071. BOOL Intl_LogMessage(
  5072. LPCTSTR lpMessage)
  5073. {
  5074. DWORD dwBytesWritten;
  5075. HANDLE hFile;
  5076. if (!g_bLog)
  5077. {
  5078. return (FALSE);
  5079. }
  5080. if (lpMessage == NULL)
  5081. {
  5082. return (TRUE);
  5083. }
  5084. hFile = Intl_OpenLogFile();
  5085. if (hFile == INVALID_HANDLE_VALUE)
  5086. {
  5087. return (FALSE);
  5088. }
  5089. SetFilePointer(hFile, 0, NULL, FILE_END);
  5090. WriteFile( hFile,
  5091. lpMessage,
  5092. _tcslen(lpMessage) * sizeof(TCHAR),
  5093. &dwBytesWritten,
  5094. NULL );
  5095. SetFilePointer(hFile, 0, NULL, FILE_END);
  5096. WriteFile( hFile,
  5097. TEXT("\r\n"),
  5098. _tcslen(TEXT("\r\n")) * sizeof(TCHAR),
  5099. &dwBytesWritten,
  5100. NULL );
  5101. CloseHandle(hFile);
  5102. return (TRUE);
  5103. }
  5104. ////////////////////////////////////////////////////////////////////////////
  5105. //
  5106. // Intl_LogUnattendFile
  5107. //
  5108. // Writes the unattended mode file to the setup log.
  5109. //
  5110. ////////////////////////////////////////////////////////////////////////////
  5111. void Intl_LogUnattendFile(
  5112. LPCTSTR pFileName)
  5113. {
  5114. DWORD dwSize;
  5115. HANDLE hFile;
  5116. OFSTRUCT fileInfo;
  5117. BOOL bResult;
  5118. CHAR inBuffer[MAX_PATH] = {0};
  5119. DWORD nBytesRead;
  5120. WCHAR outBufferW[MAX_PATH] = {0};
  5121. int nWCharRead;
  5122. DWORD status;
  5123. //
  5124. // Open the unattended mode file.
  5125. //
  5126. if ((hFile = CreateFile( pFileName,
  5127. GENERIC_READ,
  5128. 0,
  5129. NULL,
  5130. OPEN_EXISTING,
  5131. FILE_ATTRIBUTE_NORMAL,
  5132. NULL )) == INVALID_HANDLE_VALUE)
  5133. {
  5134. return;
  5135. }
  5136. //
  5137. // Write the header.
  5138. //
  5139. Intl_LogSimpleMessage(IDS_LOG_UNAT_HEADER, NULL);
  5140. //
  5141. // Read the unattended mode file in 259 byte chunks.
  5142. //
  5143. while (bResult = ReadFile( hFile,
  5144. (LPVOID)&inBuffer,
  5145. MAX_PATH - 1,
  5146. &nBytesRead,
  5147. NULL ) && (nBytesRead > 0))
  5148. {
  5149. //
  5150. // Null terminated string.
  5151. //
  5152. inBuffer[nBytesRead] = '\0';
  5153. //
  5154. // Convert the ansi data to unicode.
  5155. //
  5156. nWCharRead = MultiByteToWideChar( CP_ACP,
  5157. MB_PRECOMPOSED,
  5158. inBuffer,
  5159. nBytesRead,
  5160. outBufferW,
  5161. MAX_PATH );
  5162. //
  5163. // Write to the log file.
  5164. //
  5165. if (nWCharRead)
  5166. {
  5167. Intl_LogMessage((LPCTSTR)outBufferW);
  5168. }
  5169. }
  5170. //
  5171. // Write the footer.
  5172. //
  5173. Intl_LogSimpleMessage(IDS_LOG_UNAT_FOOTER, NULL);
  5174. //
  5175. // Cleanup.
  5176. //
  5177. CloseHandle(hFile);
  5178. }
  5179. ////////////////////////////////////////////////////////////////////////////
  5180. //
  5181. // Intl_LogSimpleMessage
  5182. //
  5183. // Writes a simple message to the log file.
  5184. //
  5185. ////////////////////////////////////////////////////////////////////////////
  5186. void Intl_LogSimpleMessage(
  5187. UINT LogId,
  5188. LPCTSTR pAppend)
  5189. {
  5190. TCHAR szLogBuffer[4 * MAX_PATH];
  5191. LoadString(hInstance, LogId, szLogBuffer, ARRAYSIZE(szLogBuffer) - 1);
  5192. if (pAppend)
  5193. {
  5194. _tcscat(szLogBuffer, pAppend);
  5195. }
  5196. Intl_LogMessage(szLogBuffer);
  5197. }
  5198. ////////////////////////////////////////////////////////////////////////////
  5199. //
  5200. // Intl_LogFormatMessage
  5201. //
  5202. // Writes an error message using FormatMessage to the log file.
  5203. //
  5204. ////////////////////////////////////////////////////////////////////////////
  5205. void Intl_LogFormatMessage(
  5206. UINT LogId)
  5207. {
  5208. LPVOID lpMsgBuf = NULL;
  5209. TCHAR szLogBuffer[4 * MAX_PATH];
  5210. //
  5211. // Get the message for the last error.
  5212. //
  5213. FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
  5214. FORMAT_MESSAGE_FROM_SYSTEM |
  5215. FORMAT_MESSAGE_IGNORE_INSERTS,
  5216. NULL,
  5217. GetLastError(),
  5218. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  5219. (LPTSTR) &lpMsgBuf,
  5220. 0,
  5221. NULL );
  5222. //
  5223. // Load the log message.
  5224. //
  5225. LoadString( hInstance,
  5226. LogId,
  5227. szLogBuffer,
  5228. ARRAYSIZE(szLogBuffer) - 1 );
  5229. //
  5230. // Concatenate the log message and the last error.
  5231. //
  5232. _tcscat(szLogBuffer, lpMsgBuf);
  5233. //
  5234. // Log the message to the log file.
  5235. //
  5236. Intl_LogMessage(szLogBuffer);
  5237. //
  5238. // Free the buffer created by FormatMessage.
  5239. //
  5240. if (lpMsgBuf)
  5241. {
  5242. LocalFree(lpMsgBuf);
  5243. }
  5244. }
  5245. ////////////////////////////////////////////////////////////////////////////
  5246. //
  5247. // Intl_SaveDefaultUserSettings
  5248. //
  5249. // This function will get information from the the current user and write it in
  5250. // the .DEFAULT and NTUSER.DAT file.
  5251. //
  5252. ////////////////////////////////////////////////////////////////////////////
  5253. void Intl_SaveDefaultUserSettings()
  5254. {
  5255. //
  5256. // Check if the Default user settings have been saved already.
  5257. //
  5258. if (g_bSettingsChanged)
  5259. {
  5260. DWORD dwDisposition;
  5261. HKEY hDesKey, hSrcKey;
  5262. //
  5263. // Set the UI Language for ALL new users of this machine.
  5264. //
  5265. Intl_ChangeUILangForAllUsers(Intl_GetPendingUILanguage());
  5266. //
  5267. // Copy the International keys and subkeys.
  5268. //
  5269. Intl_SaveValuesToDefault(c_szCPanelIntl, c_szCPanelIntl_DefUser);
  5270. Intl_SaveValuesToNtUserFile(HKEY_CURRENT_USER, c_szCPanelIntl, c_szCPanelIntl);
  5271. //
  5272. // Copy only the CTFMON information.
  5273. //
  5274. if(RegOpenKeyEx( HKEY_CURRENT_USER,
  5275. c_szCtfmon,
  5276. 0,
  5277. KEY_ALL_ACCESS,
  5278. &hSrcKey) == ERROR_SUCCESS)
  5279. {
  5280. if(RegOpenKeyEx( HKEY_USERS,
  5281. c_szCtfmon_DefUser,
  5282. 0,
  5283. KEY_ALL_ACCESS,
  5284. &hDesKey) == ERROR_SUCCESS)
  5285. {
  5286. DWORD dwValueLength, dwType;
  5287. TCHAR szValue[REGSTR_MAX_VALUE_LENGTH];
  5288. //
  5289. // Get the source value if exist.
  5290. //
  5291. szValue[0] = 0;
  5292. dwValueLength = sizeof(szValue);
  5293. if(RegQueryValueEx( hSrcKey,
  5294. szCtfmonValue,
  5295. NULL,
  5296. &dwType,
  5297. (LPBYTE)szValue,
  5298. &dwValueLength) == ERROR_SUCCESS)
  5299. {
  5300. //
  5301. // Set the destination value.
  5302. //
  5303. RegSetValueEx( hDesKey,
  5304. szCtfmonValue,
  5305. 0L,
  5306. dwType,
  5307. (CONST BYTE *)szValue,
  5308. dwValueLength);
  5309. }
  5310. CloseHandle(hDesKey);
  5311. }
  5312. CloseHandle(hSrcKey);
  5313. }
  5314. Intl_SaveValuesToNtUserFile(HKEY_CURRENT_USER, c_szCtfmon, c_szCtfmon);
  5315. //
  5316. // Copy the Keyboard Layouts keys and subkeys.
  5317. //
  5318. Intl_SaveValuesToDefault(c_szKbdLayouts, c_szKbdLayouts_DefUser);
  5319. Intl_SaveValuesToNtUserFile(HKEY_CURRENT_USER, c_szKbdLayouts, c_szKbdLayouts);
  5320. //
  5321. // Copy the Input Method keys and subkeys.
  5322. //
  5323. Intl_SaveValuesToDefault(c_szInputMethod, c_szInputMethod_DefUser);
  5324. Intl_SaveValuesToNtUserFile(HKEY_CURRENT_USER, c_szInputMethod, c_szInputMethod);
  5325. //
  5326. // Copy the Tips keys and subkeys. Make sure that the CTF
  5327. // destination key exist.
  5328. //
  5329. if (RegCreateKeyEx( HKEY_USERS,
  5330. c_szInputTips_DefUser,
  5331. 0,
  5332. NULL,
  5333. REG_OPTION_NON_VOLATILE,
  5334. KEY_ALL_ACCESS,
  5335. NULL,
  5336. &hDesKey,
  5337. &dwDisposition ) == ERROR_SUCCESS)
  5338. {
  5339. CloseHandle(hDesKey);
  5340. Intl_SaveValuesToDefault(c_szInputTips, c_szInputTips_DefUser);
  5341. Intl_SaveValuesToNtUserFile(HKEY_CURRENT_USER, c_szInputTips, c_szInputTips);
  5342. }
  5343. //
  5344. // Settings saved.
  5345. //
  5346. g_bSettingsChanged = FALSE;
  5347. }
  5348. }
  5349. ////////////////////////////////////////////////////////////////////////////
  5350. //
  5351. // Intl_SaveDefaultUserInputSettings
  5352. //
  5353. // This function copy .Default user input-related setting to ntuser.dat.
  5354. // There are four things to copy to make keyboard layout work for
  5355. // new users:
  5356. // * "Software\\Microsoft\\Windows\\CurrentVersion\\Run\\ctfmon.exe" (if any)
  5357. // * "Keyboard Layout"
  5358. // * "Control Panel\\Input Method"
  5359. // * "Software\\Microsoft\\CTF" (if any)
  5360. //
  5361. ////////////////////////////////////////////////////////////////////////////
  5362. BOOL Intl_SaveDefaultUserInputSettings()
  5363. {
  5364. HKEY hDesKey;
  5365. DWORD dwDisposition;
  5366. //
  5367. // The following call will copy everything under Windows\CurrentVersion\Run
  5368. // to ntuser.dat.
  5369. //
  5370. Intl_SaveValuesToNtUserFile(HKEY_USERS, c_szCtfmon_DefUser, c_szCtfmon);
  5371. //
  5372. // Copy the Keyboard Layouts keys and subkeys.
  5373. //
  5374. Intl_SaveValuesToNtUserFile(HKEY_USERS, c_szKbdLayouts_DefUser, c_szKbdLayouts);
  5375. //
  5376. // Copy the Input Method keys and subkeys.
  5377. //
  5378. Intl_SaveValuesToNtUserFile(HKEY_USERS, c_szInputMethod_DefUser, c_szInputMethod);
  5379. //
  5380. // Copy the Tips keys and subkeys. Make sure that the CTF
  5381. // destination key exist.
  5382. //
  5383. if (RegCreateKeyEx( HKEY_USERS,
  5384. c_szInputTips_DefUser,
  5385. 0,
  5386. NULL,
  5387. REG_OPTION_NON_VOLATILE,
  5388. KEY_READ,
  5389. NULL,
  5390. &hDesKey,
  5391. &dwDisposition ) == ERROR_SUCCESS)
  5392. {
  5393. CloseHandle(hDesKey);
  5394. Intl_SaveValuesToNtUserFile(HKEY_USERS, c_szInputTips_DefUser, c_szInputTips);
  5395. }
  5396. return (TRUE);
  5397. }
  5398. ////////////////////////////////////////////////////////////////////////////
  5399. //
  5400. // Intl_IsMUIFileVersionSameAsOS
  5401. //
  5402. ////////////////////////////////////////////////////////////////////////////
  5403. #define MUISETUP_EXE_RELATIVE_PATH TEXT("mui\\muisetup.exe")
  5404. #define MUISETUP_INF_RELATIVE_PATH TEXT("mui\\mui.inf")
  5405. BOOL Intl_IsMUISetupVersionSameAsOS()
  5406. {
  5407. BOOL bSpUpgrade = FALSE;
  5408. DWORD dwDummy = 0;
  5409. DWORD dwBufSize = 0;
  5410. UINT uiLen = 0;
  5411. BYTE *pbBuffer = NULL;
  5412. VS_FIXEDFILEINFO *pvsFileInfo;
  5413. BOOL bResult = TRUE;
  5414. TCHAR tempmsg[MAX_PATH];
  5415. TCHAR build[MAX_PATH];
  5416. TCHAR szAppPath[MAX_PATH];
  5417. TCHAR szInfPath[MAX_PATH];
  5418. GetSystemWindowsDirectory(szAppPath, ARRAYSIZE(szAppPath));
  5419. GetSystemWindowsDirectory(szInfPath, ARRAYSIZE(szInfPath));
  5420. //
  5421. // Invoke muisetup to uninstall MUI languages.
  5422. //
  5423. if ((PathAppend(szAppPath, MUISETUP_EXE_RELATIVE_PATH) && Intl_FileExists(szAppPath)) &&
  5424. (PathAppend(szInfPath, MUISETUP_INF_RELATIVE_PATH) && Intl_FileExists(szInfPath)))
  5425. {
  5426. dwBufSize = GetFileVersionInfoSize(szAppPath, &dwDummy);
  5427. if (dwBufSize > 0)
  5428. {
  5429. // allocate enough buffer to store the file version info
  5430. pbBuffer = (BYTE*) LocalAlloc(LPTR, dwBufSize+1);
  5431. if (NULL == pbBuffer)
  5432. {
  5433. goto Exit;
  5434. }
  5435. else
  5436. {
  5437. // Get the file version info
  5438. if (!GetFileVersionInfo(szAppPath, dwDummy, dwBufSize, pbBuffer))
  5439. {
  5440. goto Exit;
  5441. }
  5442. else
  5443. {
  5444. // get the version from the file version info using VerQueryValue
  5445. if (!VerQueryValue(pbBuffer, TEXT("\\"), (LPVOID *) &pvsFileInfo, &uiLen))
  5446. {
  5447. goto Exit;
  5448. }
  5449. }
  5450. }
  5451. }
  5452. else
  5453. {
  5454. goto Exit;
  5455. }
  5456. // read the mui.inf version from mui.inf
  5457. GetPrivateProfileString( TEXT("Buildnumber"),
  5458. NULL,
  5459. TEXT("0"),
  5460. tempmsg,
  5461. ARRAYSIZE(tempmsg),
  5462. szInfPath);
  5463. wsprintf(build, TEXT("%d"), HIWORD(pvsFileInfo->dwFileVersionLS));
  5464. if (_tcscmp(tempmsg, build))
  5465. {
  5466. bSpUpgrade = FALSE;
  5467. }
  5468. else
  5469. {
  5470. bSpUpgrade = TRUE;
  5471. }
  5472. }
  5473. Exit:
  5474. if (pbBuffer)
  5475. {
  5476. LocalFree(pbBuffer);
  5477. }
  5478. return bSpUpgrade;
  5479. }
  5480. ////////////////////////////////////////////////////////////////////////////
  5481. //
  5482. // Intl_IsLIP
  5483. //
  5484. ////////////////////////////////////////////////////////////////////////////
  5485. BOOL Intl_IsLIP()
  5486. {
  5487. BOOL bResult = TRUE;
  5488. UINT iLangCount = 0;
  5489. HKEY hKey;
  5490. TCHAR szValue[MAX_PATH];
  5491. TCHAR szData[MAX_PATH];
  5492. DWORD dwIndex, cchValue, cbData;
  5493. DWORD UILang;
  5494. DWORD dwType;
  5495. LONG rc;
  5496. //
  5497. // First check for the LIP System Key, if it is there, then we are done
  5498. //
  5499. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  5500. c_szLIPInstalled,
  5501. 0,
  5502. KEY_READ,
  5503. &hKey ) == ERROR_SUCCESS)
  5504. {
  5505. RegCloseKey(hKey);
  5506. return (TRUE);
  5507. }
  5508. //
  5509. // if not found, then open the registry key used MUI to doublecheck
  5510. // for LIP enabled system
  5511. //
  5512. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  5513. c_szMUILanguages,
  5514. 0,
  5515. KEY_READ,
  5516. &hKey ) != ERROR_SUCCESS)
  5517. {
  5518. return (FALSE);
  5519. }
  5520. //
  5521. // Enumerate the values in the MUILanguages key.
  5522. //
  5523. dwIndex = 0;
  5524. cchValue = sizeof(szValue) / sizeof(TCHAR);
  5525. szValue[0] = TEXT('\0');
  5526. cbData = sizeof(szData);
  5527. szData[0] = TEXT('\0');
  5528. rc = RegEnumValue( hKey,
  5529. dwIndex,
  5530. szValue,
  5531. &cchValue,
  5532. NULL,
  5533. &dwType,
  5534. (LPBYTE)szData,
  5535. &cbData );
  5536. while (rc == ERROR_SUCCESS)
  5537. {
  5538. //
  5539. // If the UI language contains data, then it is installed.
  5540. //
  5541. if ((szData[0] != 0) &&
  5542. (dwType == REG_SZ) &&
  5543. (UILang = TransNum(szValue)) &&
  5544. (GetLocaleInfo(UILang, LOCALE_SNATIVELANGNAME, szData, MAX_PATH)) &&
  5545. (IsValidUILanguage((LANGID)UILang)))
  5546. {
  5547. //
  5548. // if English 0409 key is found, we have a MUI system and not LIP
  5549. //
  5550. if (UILang == 0x0409)
  5551. {
  5552. bResult = FALSE;
  5553. break;
  5554. }
  5555. //
  5556. // If there are more than one language installed, or then it is
  5557. // also not a LIP system - this can be 0409 + any other language also.
  5558. //
  5559. iLangCount= iLangCount + 1;
  5560. if (iLangCount > 1)
  5561. {
  5562. bResult = FALSE;
  5563. break;
  5564. }
  5565. }
  5566. //
  5567. // Get the next enum value.
  5568. //
  5569. dwIndex++;
  5570. cchValue = sizeof(szValue) / sizeof(TCHAR);
  5571. szValue[0] = TEXT('\0');
  5572. cbData = sizeof(szData);
  5573. szData[0] = TEXT('\0');
  5574. rc = RegEnumValue( hKey,
  5575. dwIndex,
  5576. szValue,
  5577. &cchValue,
  5578. NULL,
  5579. &dwType,
  5580. (LPBYTE)szData,
  5581. &cbData );
  5582. }
  5583. //
  5584. // Clean up.
  5585. //
  5586. RegCloseKey(hKey);
  5587. return bResult;
  5588. }
  5589. ////////////////////////////////////////////////////////////////////////////
  5590. //
  5591. // Intl_RemoveMUIFile
  5592. //
  5593. ////////////////////////////////////////////////////////////////////////////
  5594. void Intl_RemoveMUIFile()
  5595. {
  5596. TCHAR szAppPath[MAX_PATH];
  5597. GetSystemWindowsDirectory(szAppPath, ARRAYSIZE(szAppPath));
  5598. //
  5599. // Invoke muisetup to uninstall MUI languages.
  5600. //
  5601. if (PathAppend(szAppPath, MUISETUP_EXE_RELATIVE_PATH) &&
  5602. Intl_FileExists(szAppPath))
  5603. {
  5604. //
  5605. // Only remove MUI if we are not in an SP OS upgrade scenario
  5606. //
  5607. if (!Intl_IsMUISetupVersionSameAsOS() && !Intl_IsLIP())
  5608. {
  5609. SHELLEXECUTEINFO ExecInfo = {0};
  5610. //
  5611. // Don't delete muisetup.exe, this code is only for xpsp
  5612. //
  5613. /*
  5614. SHFILEOPSTRUCT shFile =
  5615. {
  5616. NULL, FO_DELETE, szAppPath, NULL, FOF_NOCONFIRMATION|FOF_SILENT|FOF_NOERRORUI, 0, 0, 0
  5617. };
  5618. */
  5619. ExecInfo.lpParameters = TEXT("/u /r /s");
  5620. ExecInfo.fMask = SEE_MASK_FLAG_NO_UI;
  5621. ExecInfo.lpFile = szAppPath;
  5622. ExecInfo.nShow = SW_SHOWNORMAL;
  5623. ExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  5624. ShellExecuteEx(&ExecInfo);
  5625. /*
  5626. //
  5627. // An additional NULL character must be appended for this
  5628. // multi-string buffer.
  5629. //
  5630. szAppPath[lstrlen(szAppPath) + 1] = 0x00;
  5631. SHFileOperation(&shFile);
  5632. */
  5633. }
  5634. }
  5635. }
  5636. ////////////////////////////////////////////////////////////////////////////
  5637. //
  5638. // Intl_CallTextServices
  5639. //
  5640. ////////////////////////////////////////////////////////////////////////////
  5641. void Intl_CallTextServices()
  5642. {
  5643. TCHAR szAppPath[MAX_PATH];
  5644. GetSystemDirectory(szAppPath, ARRAYSIZE(szAppPath));
  5645. //
  5646. // Invoke the Input applet.
  5647. //
  5648. if (PathAppend(szAppPath, TEXT("rundll32.exe")) &&
  5649. Intl_FileExists(szAppPath))
  5650. {
  5651. SHELLEXECUTEINFO ExecInfo = {0};
  5652. ExecInfo.lpParameters = TEXT("shell32.dll,Control_RunDLL input.dll");
  5653. ExecInfo.lpFile = szAppPath;
  5654. ExecInfo.nShow = SW_SHOWNORMAL;
  5655. ExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  5656. ShellExecuteEx(&ExecInfo);
  5657. }
  5658. }
  5659. ////////////////////////////////////////////////////////////////////////////
  5660. //
  5661. // Intl_GetPendingUILanguage
  5662. //
  5663. // Look into the registry for the pending UI Language. This function is
  5664. // used for the default user case.
  5665. //
  5666. ////////////////////////////////////////////////////////////////////////////
  5667. LANGID Intl_GetPendingUILanguage()
  5668. {
  5669. HKEY hKey;
  5670. LANGID dwDefaultUILanguage = 0;
  5671. DWORD cbData = 0;
  5672. TCHAR szBuffer[MAX_PATH];
  5673. //
  5674. // Open the registry key used by setup.
  5675. //
  5676. if (RegOpenKeyEx( HKEY_CURRENT_USER,
  5677. c_szCPanelDesktop,
  5678. 0,
  5679. KEY_READ,
  5680. &hKey ) != ERROR_SUCCESS)
  5681. {
  5682. return (GetUserDefaultUILanguage());
  5683. }
  5684. //
  5685. // Query the pending MUI Language.
  5686. //
  5687. cbData = ARRAYSIZE(szBuffer);
  5688. if (RegQueryValueEx( hKey,
  5689. szMUILangPending,
  5690. NULL,
  5691. NULL,
  5692. (LPBYTE)szBuffer,
  5693. &cbData ) != ERROR_SUCCESS)
  5694. {
  5695. RegCloseKey(hKey);
  5696. return (GetUserDefaultUILanguage());
  5697. }
  5698. else
  5699. {
  5700. if ((dwDefaultUILanguage = (LANGID)TransNum(szBuffer)) == 0)
  5701. {
  5702. RegCloseKey(hKey);
  5703. return (GetUserDefaultUILanguage());
  5704. }
  5705. else
  5706. {
  5707. RegCloseKey(hKey);
  5708. return ((LANGID)dwDefaultUILanguage);
  5709. }
  5710. }
  5711. }
  5712. ////////////////////////////////////////////////////////////////////////////////////
  5713. //
  5714. // GetDotDefaultUILanguage
  5715. //
  5716. // Retrieve the UI language stored in the HKCU\.Default.
  5717. // This is the default UI language for new users.
  5718. //
  5719. ////////////////////////////////////////////////////////////////////////////////////
  5720. LANGID Intl_GetDotDefaultUILanguage()
  5721. {
  5722. HKEY hKey;
  5723. DWORD dwKeyType;
  5724. DWORD dwSize;
  5725. BOOL success = FALSE;
  5726. TCHAR szBuffer[MAX_PATH];
  5727. LANGID langID;
  5728. //
  5729. // Get the value in .DEFAULT.
  5730. //
  5731. if (RegOpenKeyEx( HKEY_USERS,
  5732. c_szCPanelDesktop_DefUser,
  5733. 0L,
  5734. KEY_READ,
  5735. &hKey ) == ERROR_SUCCESS)
  5736. {
  5737. dwSize = sizeof(szBuffer) * sizeof(TCHAR);
  5738. if (RegQueryValueEx( hKey,
  5739. c_szMUIValue,
  5740. 0L,
  5741. &dwKeyType,
  5742. (LPBYTE)szBuffer,
  5743. &dwSize) == ERROR_SUCCESS)
  5744. {
  5745. if (dwKeyType == REG_SZ)
  5746. {
  5747. langID = (LANGID)_tcstol(szBuffer, NULL, 16);
  5748. success = TRUE;
  5749. }
  5750. }
  5751. RegCloseKey(hKey);
  5752. }
  5753. if (!success)
  5754. {
  5755. return (GetUserDefaultUILanguage());
  5756. }
  5757. return (langID);
  5758. }
  5759. ////////////////////////////////////////////////////////////////////////////
  5760. //
  5761. // Set the specified control to be left-to-right or right-to-left reading order.
  5762. //
  5763. // bUseRightToLeft==FALSE: Use left-to-right reading order
  5764. // bUseRightToLeft==TRUE: Use right-to-left reading order
  5765. //
  5766. ////////////////////////////////////////////////////////////////////////////
  5767. void SetControlReadingOrder(BOOL bUseRightToLeft, HWND hwnd)
  5768. {
  5769. BOOL bCurrentRTL;
  5770. if (IsRtLLocale(GetUserDefaultUILanguage()))
  5771. {
  5772. // If the current UI langauge is RTL, the dailog is already localized as RTL.
  5773. // In this case, don't change the direction of the control.
  5774. return;
  5775. }
  5776. bCurrentRTL = (GetWindowLongPtr(hwnd, GWL_EXSTYLE) & (WS_EX_RTLREADING)) != 0;
  5777. if (bCurrentRTL != bUseRightToLeft)
  5778. {
  5779. // Reverse the WS_EX_RTLREADING and WS_EX_RIGHT bit.
  5780. SetWindowLongPtr(hwnd, GWL_EXSTYLE, GetWindowLongPtr(hwnd, GWL_EXSTYLE) ^ (WS_EX_RTLREADING | WS_EX_RIGHT));
  5781. InvalidateRect(hwnd, NULL, FALSE);
  5782. }
  5783. }