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.

776 lines
22 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: femgrate.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * FEMGRATE, main functions
  7. *
  8. \***************************************************************************/
  9. #include "femgrate.h"
  10. #include <tchar.h>
  11. FUNC_DIR FuncDir[FUNC_NumofFunctions] = {
  12. {'l',FUNC_PatchInLogon},
  13. {'s',FUNC_PatchInSetup},
  14. {'u',FUNC_PatchFEUIFont},
  15. {'p',FUNC_PatchPreload},
  16. {'t',FUNC_PatchTest},
  17. {'c',FUNC_PatchCHSAnsiEMB}
  18. };
  19. HINSTANCE ghInst=NULL;
  20. //
  21. // Function Declaration
  22. //
  23. //
  24. // Max size of a value's data
  25. //
  26. //
  27. // Max number of Functions NO_FUNCTION - 1
  28. //
  29. UINT GetFunctions(
  30. int *pCmdList,
  31. int nNum)
  32. {
  33. int i,j;
  34. int nMaxNum;
  35. int nCommands;
  36. if ((__argc <=1) || nNum < 2)
  37. return 0;
  38. //
  39. // reserved one cell for terminiator
  40. //
  41. nMaxNum = (__argc-1 > nNum-1) ? nNum-1 : __argc-1;
  42. for (nCommands = 0,i=1; i <= nMaxNum; i++) {
  43. if (__argv[i][0] != '-') {
  44. continue;
  45. }
  46. for (j=0; j<FUNC_NumofFunctions ; j++) {
  47. if (FuncDir[j].cFunc == __argv[i][1]) {
  48. pCmdList[nCommands++] = FuncDir[j].nID;
  49. }
  50. }
  51. }
  52. pCmdList[nCommands] = NO_FUNCTION;
  53. return nCommands;
  54. }
  55. //
  56. // In 3.51/4.0, the time zone name displaying on date/time applets was in English
  57. //
  58. // we want to change it back to localization string
  59. //
  60. BOOL FixTimeZone(UINT nLocale)
  61. {
  62. DWORD dwErr,dwType,dwSize;
  63. HKEY hSysKey,hSftKey;
  64. BOOL bOK = FALSE;
  65. TCHAR szStdName[MAX_PATH];
  66. TCHAR szTimeZoneLookup[MAX_PATH];
  67. dwErr = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  68. TEXT("System\\CurrentControlSet\\Control\\TimeZoneInformation"),
  69. 0,
  70. KEY_READ | KEY_WRITE,
  71. &hSysKey );
  72. if (dwErr != ERROR_SUCCESS) {
  73. DebugMsg((DM_VERBOSE,TEXT("[FixTimeZone] Open System\\CurrentControlSet\\Control\\TimeZoneInformation failed !\n")));
  74. goto Err0;
  75. }
  76. dwSize = sizeof(szStdName);
  77. dwErr = RegQueryValueEx(hSysKey,
  78. TEXT("StandardName"),
  79. NULL,
  80. &dwType,
  81. (LPBYTE) szStdName,
  82. &dwSize);
  83. if (dwErr != ERROR_SUCCESS) {
  84. DebugMsg((DM_VERBOSE,TEXT("[FixTimeZone] StandardName doesn't exist !\n")));
  85. bOK = TRUE;
  86. goto Err1;
  87. }
  88. //
  89. // KOR 3.51 used "Japanese Standard Time". It is necessary to change it to "Seul Standard time"
  90. //
  91. // check if system locale is KOR and the length of szStdName is non-zero
  92. //
  93. DebugMsg((DM_VERBOSE,TEXT("[FixTimeZone] locale = %X, dwSize = %d !\n"),nLocale,dwSize));
  94. if ((nLocale == LOCALE_KOR) && dwSize) {
  95. if (lstrcmpi(szStdName,TEXT("Tokyo Standard Time"))== 0) {
  96. lstrcpy(szStdName,TEXT("Korea Standard Time"));
  97. }
  98. }
  99. wsprintf(szTimeZoneLookup,TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\%s"),szStdName);
  100. DebugMsg((DM_VERBOSE,TEXT("[FixTimeZone] Open %s !\n"),szTimeZoneLookup));
  101. dwErr = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  102. szTimeZoneLookup,
  103. 0,
  104. KEY_READ,
  105. &hSftKey );
  106. if (dwErr != ERROR_SUCCESS) {
  107. DebugMsg((DM_VERBOSE,TEXT("[FixTimeZone] %s doesn't exist !\n"),szTimeZoneLookup));
  108. bOK = TRUE;
  109. goto Err1;
  110. }
  111. dwSize = sizeof(szStdName);
  112. dwErr = RegQueryValueEx(hSftKey,
  113. TEXT("Std"),
  114. NULL,
  115. &dwType,
  116. (LPBYTE) szStdName,
  117. &dwSize);
  118. if (dwErr != ERROR_SUCCESS) {
  119. DebugMsg((DM_VERBOSE,TEXT("[FixTimeZone] Query Std failed, abornomal !\n")));
  120. goto Err2;
  121. }
  122. dwErr = RegSetValueEx(hSysKey,
  123. TEXT("StandardName"),
  124. 0,
  125. REG_SZ,
  126. (LPBYTE) szStdName,
  127. (lstrlen(szStdName)+1)*sizeof(TCHAR));
  128. if (dwErr != ERROR_SUCCESS) {
  129. DebugMsg((DM_VERBOSE,TEXT("[FixTimeZone] Set Standardname failed !\n")));
  130. goto Err2;
  131. }
  132. dwSize = sizeof(szStdName);
  133. dwErr = RegQueryValueEx(hSftKey,
  134. TEXT("Dlt"),
  135. NULL,
  136. &dwType,
  137. (LPBYTE) szStdName,
  138. &dwSize);
  139. if (dwErr != ERROR_SUCCESS) {
  140. DebugMsg((DM_VERBOSE,TEXT("[FixTimeZone] Query Dlt failed, abornomal !\n")));
  141. bOK = TRUE;
  142. goto Err2;
  143. }
  144. dwErr = RegSetValueEx(hSysKey,
  145. TEXT("DaylightName"),
  146. 0,
  147. REG_SZ,
  148. (LPBYTE) szStdName,
  149. (lstrlen(szStdName)+1)*sizeof(TCHAR));
  150. if (dwErr != ERROR_SUCCESS) {
  151. DebugMsg((DM_VERBOSE,TEXT("[FixTimeZone] Set DaylightName failed !\n")));
  152. goto Err2;
  153. }
  154. bOK = TRUE;
  155. Err2:
  156. RegCloseKey(hSftKey);
  157. Err1:
  158. RegCloseKey(hSysKey);
  159. Err0:
  160. return bOK;
  161. }
  162. //
  163. // Patch CHT/CHS 3.51 bug
  164. // 1. length of Preload Values is 8, patch to 9
  165. // 2. replace 00000409 with default lang ID
  166. // 3. if default lang ID existed, we don't replace anything
  167. //
  168. BOOL PatchPreloadKeyboard(
  169. BOOL bReplaceDefaultLCID) //if TRUE will replace 409 with default LCID
  170. {
  171. HKEY hkLayoutPreload;
  172. LONG lResult;
  173. int i;
  174. BOOL bFoundDefaultLocale = FALSE;
  175. int nFound0409 = -1;
  176. TCHAR szDefaultLocaleID[KL_NAMELENGTH];
  177. TCHAR szPreloadID[4*sizeof(TCHAR)]; // 3 digits + NULL
  178. TCHAR szLayoutID[KL_NAMELENGTH]; // 9
  179. DWORD dwValueSize;
  180. wsprintf(szDefaultLocaleID,TEXT("%08X"),GetSystemDefaultLCID());
  181. lResult = RegOpenKeyEx(HKEY_CURRENT_USER,
  182. TEXT("keyboard layout\\preload"),
  183. 0,
  184. KEY_READ | KEY_WRITE,
  185. &hkLayoutPreload);
  186. if (lResult != ERROR_SUCCESS) {
  187. return FALSE;
  188. }
  189. for (i=1; i<=999;i++) { // size allows up to 999 preloaded!!!!!
  190. wsprintf(szPreloadID,TEXT("%d"),i);
  191. dwValueSize = 0;
  192. RegQueryValueEx(hkLayoutPreload,
  193. szPreloadID,
  194. NULL,
  195. NULL,
  196. NULL,
  197. &dwValueSize);
  198. if (dwValueSize == 0)
  199. break;
  200. lResult = RegQueryValueEx(hkLayoutPreload,
  201. szPreloadID,
  202. NULL,
  203. NULL,
  204. (LPBYTE) szLayoutID,
  205. &dwValueSize);
  206. //
  207. // First, fix missing NULL terminator
  208. //
  209. if (dwValueSize == (KL_NAMELENGTH - 1)* sizeof(TCHAR)) {
  210. //
  211. // this case is what we want to fix
  212. //
  213. szLayoutID[KL_NAMELENGTH-1] = (TCHAR) 0;
  214. lResult = RegSetValueEx(hkLayoutPreload,
  215. szPreloadID,
  216. 0,
  217. REG_SZ,
  218. (LPBYTE) szLayoutID,
  219. sizeof(TCHAR) * KL_NAMELENGTH);
  220. if (lResult != ERROR_SUCCESS) {
  221. DebugMsg((DM_VERBOSE,TEXT("IMECONV: Failed to set %s = %s \n"),szPreloadID,szLayoutID));
  222. }
  223. }
  224. //
  225. // FOR CHS/CHT, we need check and replace
  226. //
  227. if (bReplaceDefaultLCID) {
  228. //
  229. // Second, fix wrong locale, rule:
  230. // if Default Locale existed (e.q. 00000404 for CHT), do nothing
  231. // else found 00000409, replace it with Default Locale
  232. //
  233. if ((dwValueSize < (KL_NAMELENGTH - 1) * sizeof(TCHAR)) ||
  234. (dwValueSize > (KL_NAMELENGTH) * sizeof(TCHAR))) {
  235. //
  236. // wrong data, ignore it
  237. //
  238. continue;
  239. }
  240. if (bFoundDefaultLocale) {
  241. continue;
  242. }
  243. // if (_tcsncmp(szDefaultLocaleID,szLayoutID,KL_NAMELENGTH-1)==0) {
  244. if (_tcsncmp(L"123",L"123",KL_NAMELENGTH-1)==0) {
  245. bFoundDefaultLocale = TRUE;
  246. continue;
  247. }
  248. if (_tcsncmp(szLayoutID,TEXT("00000409"),KL_NAMELENGTH-1)==0) {
  249. nFound0409 = i;
  250. }
  251. }
  252. }
  253. if (bReplaceDefaultLCID) {
  254. if (!bFoundDefaultLocale) {
  255. if (nFound0409 != -1 ) {
  256. wsprintf(szPreloadID,TEXT("%d"),nFound0409);
  257. lResult = RegSetValueEx(hkLayoutPreload,
  258. szPreloadID,
  259. 0,
  260. REG_SZ,
  261. (LPBYTE) szDefaultLocaleID,
  262. sizeof(TCHAR) * KL_NAMELENGTH);
  263. if (lResult != ERROR_SUCCESS) {
  264. DebugMsg((DM_VERBOSE,TEXT("IMECONV: Failed to set %s = %s \n"),szPreloadID,szLayoutID));
  265. }
  266. }
  267. }
  268. }
  269. RegCloseKey (hkLayoutPreload);
  270. if (i > 999)
  271. return FALSE;
  272. else
  273. return TRUE;
  274. }
  275. const TCHAR g_szCaptionFont[] = TEXT("CaptionFont");
  276. const TCHAR g_szSmCaptionFont[] = TEXT("SmCaptionFont");
  277. const TCHAR g_szMenuFont[] = TEXT("MenuFont");
  278. const TCHAR g_szStatusFont[] = TEXT("StatusFont");
  279. const TCHAR g_szMessageFont[] = TEXT("MessageFont");
  280. const TCHAR g_szIconFont[] = TEXT("IconFont");
  281. const LPCTSTR g_rgpszFontMetrics[] = { g_szCaptionFont,
  282. g_szSmCaptionFont,
  283. g_szMenuFont,
  284. g_szStatusFont,
  285. g_szMessageFont,
  286. g_szIconFont};
  287. BOOL FixIncorrectCharSet(LOGFONT *plf)
  288. {
  289. struct NameCharSet {
  290. char szFaceName[LF_FACESIZE*2];
  291. BYTE bCharSet;
  292. } Pairs[] = {
  293. {"\x74\xad\xbc\xb9\x00\x00",0x81},
  294. {"\xb0\x65\x30\x7d\x0e\x66\xd4\x9a\x00\x00",0x88},
  295. {"\x8b\x5b\x53\x4f\x00\x00",0x86}
  296. };
  297. int i;
  298. for (i=0; i<ARRAYSIZE(Pairs); i++) {
  299. if (lstrcmp(plf->lfFaceName,(LPTSTR)(Pairs[i].szFaceName)) == 0) {
  300. if (plf->lfCharSet != Pairs[i].bCharSet) {
  301. plf->lfCharSet = Pairs[i].bCharSet;
  302. DebugMsg((DM_VERBOSE,TEXT("FixIncorrectCharSet, we found and we fixed. [%X]\n"),Pairs[i].bCharSet));
  303. return TRUE;
  304. }
  305. }
  306. }
  307. DebugMsg((DM_VERBOSE,TEXT("FixIncorrectCharSet, Input %s, %d, no fix needed !\n"),plf->lfFaceName,plf->lfCharSet));
  308. return TRUE;
  309. }
  310. BOOL FixMSPGothic(LOGFONT *plf)
  311. {
  312. int i;
  313. char szMSPGothic[LF_FACESIZE*2] = "\x2D\xFF\x33\xFF\x20\x00\x30\xFF\xB4\x30\xB7\x30\xC3\x30\xAF\x30\x00\x00";
  314. DebugMsg((DM_VERBOSE,TEXT("FixMSPGothic, [%s] == [%s] ?\n"),plf->lfFaceName,szMSPGothic));
  315. if (lstrcmp(plf->lfFaceName,(LPTSTR)szMSPGothic) == 0) {
  316. lstrcpy(plf->lfFaceName,TEXT("MS UI Gothic"));
  317. DebugMsg((DM_VERBOSE,TEXT("FixMSPGothic, we found and we fixed. [%s]\n"),plf->lfFaceName));
  318. return TRUE;
  319. }
  320. return TRUE;
  321. }
  322. BOOL
  323. UpdateUIFont(
  324. BOOL bJapan,
  325. HKEY hkeyMetrics,
  326. LPCTSTR pszValueName,
  327. LOGFONT *plf
  328. )
  329. {
  330. DWORD dwResult = ERROR_SUCCESS;
  331. LOGFONT lfCopy;
  332. BOOL bOkToUpdate = FALSE;
  333. DebugMsg((DM_VERBOSE,TEXT("UpdateUIFont, Starting ...\n")));
  334. //
  335. // First see if this face name should be updated.
  336. //
  337. if (bJapan) {
  338. bOkToUpdate = FixMSPGothic(plf);
  339. } else {
  340. bOkToUpdate = FixIncorrectCharSet(plf);
  341. }
  342. if (bOkToUpdate) {
  343. //
  344. // Yep. Update the face name string in the logfont.
  345. // Also make sure that the point size is 8 or greater
  346. // if we're updating the icon font.
  347. //
  348. DebugMsg((DM_VERBOSE,TEXT("UpdateUIFont, update %s 's charset %X\n"),
  349. plf->lfFaceName, plf->lfCharSet));
  350. dwResult = RegSetValueEx(hkeyMetrics,
  351. pszValueName,
  352. 0,
  353. REG_BINARY,
  354. (const LPBYTE)plf,
  355. sizeof(*plf));
  356. if (ERROR_SUCCESS != dwResult) {
  357. DebugMsg((DM_VERBOSE,TEXT("Error %d setting NC font data for \"%s\"\n"),
  358. dwResult, pszValueName));
  359. return FALSE;
  360. }
  361. }
  362. return TRUE;
  363. }
  364. void FixCurrentSchemeName(HINF hInf)
  365. {
  366. HKEY hkeyAppearance;
  367. TCHAR szCurrentSchemeName[MAX_PATH];
  368. DWORD cbValue;
  369. DWORD dwType;
  370. INFCONTEXT InfContext;
  371. UINT LineCount,LineNo;
  372. LPCTSTR szSectionName = TEXT("CurrentScheme");
  373. LPCTSTR pszStandard;
  374. LPCTSTR pszClassic;
  375. DWORD dwResult = ERROR_SUCCESS;
  376. if(hInf == INVALID_HANDLE_VALUE) {
  377. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentSchemeName] Open femgrate.inf failed !\n")));
  378. goto Exit1;
  379. }
  380. LineCount = (UINT)SetupGetLineCount(hInf,szSectionName);
  381. if((LONG)LineCount <= 0) {
  382. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentSchemeName] line count == 0 !\n")));
  383. goto Exit1;
  384. }
  385. dwResult = RegOpenKeyEx(HKEY_CURRENT_USER,
  386. TEXT("Control Panel\\Appearance"),
  387. 0,
  388. KEY_ALL_ACCESS,
  389. &hkeyAppearance);
  390. if (ERROR_SUCCESS != dwResult ) {
  391. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentSchemeName] Key Control Panel\\Appearance doesn't exist\r\n")));
  392. goto Exit1;
  393. }
  394. cbValue = sizeof(szCurrentSchemeName) * sizeof(TCHAR);
  395. dwResult = RegQueryValueEx(hkeyAppearance,
  396. TEXT("Current"),
  397. NULL,
  398. &dwType,
  399. (LPBYTE)szCurrentSchemeName,
  400. &cbValue);
  401. if (ERROR_SUCCESS != dwResult) {
  402. DebugMsg((DM_VERBOSE,TEXT("[FixCurrentSchemeName] No Current value, not an error !\r\n")));
  403. goto Exit2;
  404. }
  405. for(LineNo=0; LineNo<LineCount; LineNo++) {
  406. if (SetupGetLineByIndex(hInf,szSectionName,LineNo,&InfContext)
  407. && (pszStandard = pSetupGetField(&InfContext,1))
  408. && (pszClassic = pSetupGetField(&InfContext,2))) {
  409. if (lstrcmp(pszStandard,szCurrentSchemeName) == 0) {
  410. lstrcpy(szCurrentSchemeName,pszClassic);
  411. break;
  412. }
  413. }
  414. }
  415. dwResult = RegSetValueEx(hkeyAppearance,
  416. TEXT("Current"),
  417. 0,
  418. REG_SZ,
  419. (LPBYTE)szCurrentSchemeName,
  420. (lstrlen(szCurrentSchemeName)+1) * sizeof(TCHAR));
  421. Exit2:
  422. RegCloseKey(hkeyAppearance);
  423. Exit1:
  424. return;
  425. }
  426. BOOL FixCurrentSchemeData(BOOL bJapan)
  427. {
  428. DWORD dwResult = ERROR_SUCCESS;
  429. HKEY hkeyMetrics;
  430. DebugMsg((DM_VERBOSE,TEXT("DoPatchUIFont, Starting ... \n")));
  431. dwResult = RegOpenKeyEx(HKEY_CURRENT_USER,
  432. TEXT("Control Panel\\Desktop\\WindowMetrics"),
  433. 0,
  434. KEY_ALL_ACCESS,
  435. &hkeyMetrics);
  436. if (ERROR_SUCCESS == dwResult)
  437. {
  438. DWORD cbValue;
  439. DWORD dwType;
  440. LOGFONT lf;
  441. int i;
  442. for (i = 0; i < ARRAYSIZE(g_rgpszFontMetrics); i++)
  443. {
  444. LPCTSTR pszValueName = g_rgpszFontMetrics[i];
  445. //
  446. LOGFONT *plf = NULL;
  447. cbValue = sizeof(lf);
  448. dwResult = RegQueryValueEx(hkeyMetrics,
  449. pszValueName,
  450. NULL,
  451. &dwType,
  452. (LPBYTE)&lf,
  453. &cbValue);
  454. if (ERROR_SUCCESS == dwResult)
  455. {
  456. if (REG_BINARY == dwType)
  457. {
  458. plf = &lf;
  459. if (!UpdateUIFont(bJapan,hkeyMetrics, pszValueName, plf)) {
  460. DebugMsg((DM_VERBOSE,TEXT("DoPatchUIFont,UpdateUIFont failed \n")));
  461. }
  462. } else {
  463. DebugMsg((DM_VERBOSE,TEXT("DoPatchUIFont,not binary format \n")));
  464. }
  465. }
  466. }
  467. DebugMsg((DM_VERBOSE,TEXT("DoPatchUIFont, colsing ... \n")));
  468. RegCloseKey(hkeyMetrics);
  469. }
  470. else if (ERROR_FILE_NOT_FOUND == dwResult)
  471. {
  472. //
  473. // Some keys under HKEY_USERS don't have WindowMetric information.
  474. // Such cases are not processed but are still considered successful.
  475. //
  476. DebugMsg((DM_VERBOSE,TEXT("DoPatchUIFont,Some keys under HKEY_USERS don't have WindowMetric information \n")));
  477. dwResult = ERROR_SUCCESS;
  478. }
  479. else
  480. {
  481. DebugMsg((DM_VERBOSE,TEXT("DoPatchUIFont,Error %d opening key \n"), dwResult));
  482. }
  483. return (TRUE);
  484. }
  485. BOOL FixSchemeProblem(BOOL bJapan, HINF hInf)
  486. {
  487. FixCurrentSchemeData(bJapan);
  488. FixCurrentSchemeName(hInf);
  489. return TRUE;
  490. }
  491. BOOL RenameRegValueName(HINF hInf, BOOL PerUser)
  492. {
  493. LPCTSTR RegRoot,RegPath;
  494. LPCTSTR RegOldVal,RegNewVal;
  495. LONG LineCount,LineNo;
  496. DWORD dwSize,dwType;
  497. INFCONTEXT InfContext;
  498. HKEY Key,KeyRoot;
  499. BOOL bOK;
  500. LPBYTE RegData;
  501. LONG lResult;
  502. TCHAR SectionName[MAX_PATH];
  503. if (PerUser) {
  504. lstrcpy(SectionName,TEXT("RenameRegValueName.PerUser"));
  505. } else {
  506. lstrcpy(SectionName,TEXT("RenameRegValueName.PerSystem"));
  507. }
  508. if(hInf == INVALID_HANDLE_VALUE) {
  509. DebugMsg((DM_VERBOSE,TEXT("[ReplaceRegValueName] Open femgrate.inf failed !\n")));
  510. return FALSE;
  511. }
  512. LineCount = (UINT)SetupGetLineCount(hInf,SectionName);
  513. if((LONG)LineCount <= 0) {
  514. DebugMsg((DM_VERBOSE,TEXT("[ReplaceRegValueName] line count == 0 !\n")));
  515. return FALSE;
  516. }
  517. for(LineNo = 0; LineNo < LineCount; LineNo++) {
  518. if (SetupGetLineByIndex(hInf,SectionName,LineNo,&InfContext)
  519. && (RegRoot = pSetupGetField(&InfContext,1))
  520. && (RegPath = pSetupGetField(&InfContext,2))
  521. && (RegOldVal = pSetupGetField(&InfContext,3))
  522. && (RegNewVal = pSetupGetField(&InfContext,4))) {
  523. if (!LookUpStringInTable(InfRegSpecTohKey,RegRoot,(PUINT)&KeyRoot)) {
  524. continue;
  525. }
  526. lResult = RegOpenKeyEx( KeyRoot,
  527. RegPath,
  528. 0,
  529. KEY_READ | KEY_WRITE,
  530. &Key);
  531. if (lResult != ERROR_SUCCESS) {
  532. continue;
  533. }
  534. dwSize = 0;
  535. lResult = RegQueryValueEx (Key,
  536. RegOldVal,
  537. NULL,
  538. &dwType,
  539. NULL,
  540. &dwSize);
  541. if (lResult != ERROR_SUCCESS) {
  542. goto Err1;
  543. }
  544. RegData = (BYTE *) malloc(dwSize+1);
  545. if (!RegData) {
  546. goto Err1;
  547. }
  548. lResult = RegQueryValueEx (Key,
  549. RegOldVal,
  550. NULL,
  551. &dwType,
  552. RegData,
  553. &dwSize);
  554. lResult = RegSetValueEx (Key,
  555. RegNewVal,
  556. 0,
  557. dwType,
  558. RegData,
  559. dwSize);
  560. if (lResult != ERROR_SUCCESS) {
  561. goto Err2;
  562. }
  563. RegDeleteValue(Key,
  564. RegOldVal);
  565. Err2:
  566. free(RegData);
  567. Err1:
  568. RegCloseKey(Key);
  569. }
  570. }
  571. return TRUE;
  572. }
  573. int WINAPI WinMainFE(
  574. LPSTR lpCmdLine,
  575. UINT uLocale)
  576. {
  577. int Cmds[FUNC_NumofFunctions + 1];
  578. int i;
  579. HINF hMigrateInf;
  580. #ifdef DEBUGLOG
  581. SetupOpenLog (FALSE);
  582. #endif
  583. if (GetFunctions(Cmds,FUNC_NumofFunctions+1) == 0) {
  584. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: There are no valid commands. \n")));
  585. return (1);
  586. }
  587. hMigrateInf = SetupOpenInfFile(
  588. TEXT("femgrate.inf"),
  589. NULL,
  590. INF_STYLE_WIN4,
  591. NULL);
  592. if(hMigrateInf == INVALID_HANDLE_VALUE) {
  593. DebugMsg((DM_VERBOSE,TEXT("[FixCommon] Open femgrate.inf failed !\n")));
  594. return 0;
  595. }
  596. for (i=0; Cmds[i] != NO_FUNCTION && i < FUNC_NumofFunctions+1; i++) {
  597. switch (uLocale) {
  598. case 0x404:
  599. WinMainCHT(Cmds[i],hMigrateInf);
  600. break;
  601. case 0x411:
  602. WinMainJPN(Cmds[i],hMigrateInf);
  603. break;
  604. case 0x412:
  605. WinMainKOR(Cmds[i],hMigrateInf);
  606. break;
  607. case 0x804:
  608. WinMainCHS(Cmds[i],hMigrateInf);
  609. break;
  610. default:
  611. break;
  612. }
  613. }
  614. SetupCloseInfFile(hMigrateInf);
  615. #ifdef DEBUGLOG
  616. SetupCloseLog();
  617. #endif
  618. return (0);
  619. }
  620. int WINAPI WinMain(
  621. HINSTANCE hInstance,
  622. HINSTANCE hPrevInstance,
  623. LPSTR lpCmdLine,
  624. int nCmdShow)
  625. {
  626. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: Start Executing....\n")));
  627. ghInst = hInstance;
  628. //
  629. // In order to share the code for CHT/CHS/KOR, fork here
  630. //
  631. if ((GetInstallLocale() == 0x0412) ||
  632. (GetInstallLocale() == 0x0404) ||
  633. (GetInstallLocale() == 0x0804) ||
  634. (GetInstallLocale() == 0x0411)) {
  635. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: calling WinMainFE %X....\n"),GetInstallLocale()));
  636. return (WinMainFE(lpCmdLine,GetInstallLocale()));
  637. } else {
  638. DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: Not valid locale....\n")));
  639. return 0;
  640. }
  641. }