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.

725 lines
22 KiB

  1. #include <windows.h>
  2. #include <setupapi.h>
  3. #include <malloc.h>
  4. #include "common.h"
  5. #include "chs.h"
  6. extern TCHAR ImeDataDirectory[MAX_PATH];
  7. extern TCHAR szMsgBuf[];
  8. extern BOOL g_bCHSWin98;
  9. BYTE EmbName[IMENUM][MAXIMENAME]={
  10. "winpy.emb",
  11. "winsp.emb",
  12. "winzm.emb"
  13. // "winbx.emb"
  14. };
  15. BYTE XEmbName[IMENUM][MAXIMENAME]={
  16. "winxpy.emb",
  17. "winxsp.emb",
  18. "winxzm.emb"
  19. // "winxbx.emb"
  20. };
  21. BOOL IsSizeReasonable(DWORD dwSize)
  22. {
  23. DWORD dwTemp = (dwSize - sizeof(WORD)) / sizeof(REC95);
  24. if (((dwSize - sizeof(WORD)) - (dwTemp * sizeof(REC95))) == 0) {
  25. return TRUE;
  26. } else {
  27. return FALSE;
  28. }
  29. }
  30. /******************************Public*Routine******************************\
  31. * OpenEMBFile
  32. *
  33. * Get Win95 IME phrase data from system directory.
  34. *
  35. * Arguments:
  36. *
  37. * UCHAR * FileName - EMB file name.
  38. *
  39. * Return Value:
  40. *
  41. * HANDLE: Success - file handle of EMB file. Fail - 0;
  42. *
  43. * History:
  44. *
  45. \**************************************************************************/
  46. HANDLE OpenEMBFile(UCHAR * FileName)
  47. {
  48. HFILE hf;
  49. TCHAR FilePath[MAX_PATH];
  50. lstrcpy(FilePath, ImeDataDirectory);
  51. lstrcat(FilePath, FileName);
  52. hf = _lopen(FilePath,OF_READ);
  53. if (hf == HFILE_ERROR) {
  54. DebugMsg(("OpenEMBFile,[%s] failed!\r\n",FileName));
  55. return 0;
  56. }
  57. else {
  58. DebugMsg(("OpenEMBFile,[%s] OK!\r\n",FileName));
  59. return (HANDLE)hf;
  60. }
  61. }
  62. /******************************Public*Routine******************************\
  63. * ImeDataConvertChs
  64. *
  65. * Convert Windows 95 IME phrase data to Windows NT 5.0.
  66. *
  67. * Arguments:
  68. *
  69. * HANDLE hSource - source file handle.
  70. * HANDLE hTarget - target file handle.
  71. *
  72. * Return Value:
  73. *
  74. * BOOL: TRUE-Success, FALSE-FAIL.
  75. *
  76. * History:
  77. *
  78. \**************************************************************************/
  79. BOOL ImeDataConvertChs(HFILE hSource, HFILE hTarget)
  80. {
  81. HANDLE hPhrase95, hPhraseNT;
  82. BYTE *szPhrase95;
  83. WCHAR *szPhraseNT;
  84. DWORD fsize;
  85. BOOL bReturn = TRUE;
  86. int i;
  87. hPhrase95 = GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,
  88. sizeof(REC95)*MAXNUMBER_EMB+sizeof(WORD));
  89. hPhraseNT = GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,
  90. sizeof(RECNT)*MAXNUMBER_EMB+sizeof(WORD));
  91. if (!hPhraseNT || !hPhrase95 ) {
  92. DebugMsg(("ImeDataConvertChs failed!,!hPhraseNT || !hPhrase95 \r\n"));
  93. bReturn = FALSE;
  94. goto Convert_Finish;
  95. }
  96. szPhrase95 = GlobalLock(hPhrase95);
  97. szPhraseNT = GlobalLock(hPhraseNT);
  98. fsize = _lread(hSource,szPhrase95,sizeof(REC95)*MAXNUMBER_EMB+sizeof(WORD));
  99. if (fsize != *((WORD*)&szPhrase95[0])*sizeof(REC95)+2)
  100. {
  101. DebugMsg(("ImeDataConvertChs ,Warnning fsize ! %d, rec no = %d\r\n",fsize,*((WORD *) szPhrase95)));
  102. if (IsSizeReasonable(fsize)) {
  103. *((WORD *) szPhrase95) = (WORD)((fsize - sizeof(WORD)) / sizeof(REC95));
  104. DebugMsg(("ImeDataConvertChs ,Fixed rec number = %d\r\n",*((WORD *) szPhrase95)));
  105. } else {
  106. DebugMsg(("ImeDataConvertChs ,Data file maybe wrong !\r\n"));
  107. bReturn = FALSE;
  108. goto Convert_Finish;
  109. }
  110. }
  111. //phrase count
  112. szPhraseNT[0] = *((WORD*)&szPhrase95[0]);
  113. for (i=0; i<szPhraseNT[0]; i++)
  114. {
  115. MultiByteToWideChar(936,
  116. MB_PRECOMPOSED,
  117. (LPCSTR)(szPhrase95+sizeof(WORD)+i*sizeof(REC95)),
  118. sizeof(REC95),
  119. (LPWSTR)((LPBYTE)szPhraseNT+ sizeof(WORD) + i*sizeof(RECNT)),
  120. sizeof(RECNT));
  121. }
  122. if (WriteFile((HANDLE)hTarget, szPhraseNT, sizeof(RECNT)*MAXNUMBER_EMB+sizeof(WORD), &fsize, NULL)) {
  123. DebugMsg(("ImeDataConvertChs WriteFile OK\r\n"));
  124. }
  125. else {
  126. DebugMsg(("ImeDataConvertChs WriteFile Failed [%d]\r\n",GetLastError()));
  127. }
  128. Convert_Finish:
  129. if (hPhrase95) {
  130. GlobalUnlock(hPhrase95);
  131. GlobalFree(hPhrase95);
  132. }
  133. if (hPhraseNT) {
  134. GlobalUnlock(hPhraseNT);
  135. GlobalFree(hPhraseNT);
  136. }
  137. return bReturn;
  138. }
  139. BOOL IsFileExist(LPCTSTR lpszFileName)
  140. {
  141. LONG lResult;
  142. lResult = GetFileAttributes(lpszFileName);
  143. if (lResult == 0xFFFFFFFF) { // file does not exist
  144. return FALSE;
  145. } else if (lResult & FILE_ATTRIBUTE_DIRECTORY) {
  146. return FALSE;
  147. } else {
  148. return TRUE;
  149. }
  150. }
  151. LPBYTE MergeGBandGBKEMBWorker(
  152. PBYTE pGBEmbPtr,
  153. PBYTE pGBKEmbPtr)
  154. {
  155. PBYTE pNewBufPtr;
  156. WORD nGBRecNum;
  157. WORD nGBKRecNum;
  158. REC95* pGBRecPtr;
  159. REC95* pGBKRecPtr;
  160. WORD nNewRecNum;
  161. WORD i,j;
  162. if (pGBEmbPtr == NULL || pGBKEmbPtr == NULL) {
  163. return FALSE;
  164. }
  165. nGBRecNum = * ((WORD *) pGBEmbPtr);
  166. pGBRecPtr = (REC95*)(pGBEmbPtr + sizeof(WORD));
  167. nGBKRecNum = * ((WORD *) pGBKEmbPtr);
  168. pGBKRecPtr = (REC95*)(pGBKEmbPtr + sizeof(WORD));
  169. nNewRecNum = 0;
  170. pNewBufPtr = (PBYTE) malloc(sizeof(WORD));
  171. if (pNewBufPtr == NULL) {
  172. return NULL;
  173. }
  174. for (i=0,j=0; i<nGBRecNum && j<nGBKRecNum; ) {
  175. int nResult;
  176. nNewRecNum++;
  177. pNewBufPtr = (PBYTE) realloc(pNewBufPtr,sizeof(WORD)+(nNewRecNum)*sizeof(REC95));
  178. DebugMsg(("MergeGBandGBKEMBWorker,Memory size = [%d]!\r\n",_msize(pNewBufPtr)));
  179. if (pNewBufPtr == NULL) {
  180. DebugMsg(("MergeGBandGBKEMBWorker,realloc error,[%d]!\r\n",GetLastError()));
  181. return NULL;
  182. }
  183. nResult = memcmp(pGBRecPtr[i].CODE,pGBKRecPtr[j].CODE,MAXCODELENTH);
  184. DebugMsg(("1. %s, %s\n2. %s, %s\n%d\n",pGBRecPtr[i].CODE,pGBRecPtr[i].PHRASE,pGBKRecPtr[j].CODE,pGBKRecPtr[j].PHRASE,nResult));
  185. if (nResult < 0) {
  186. CopyMemory(pNewBufPtr+sizeof(WORD)+(nNewRecNum-1)*sizeof(REC95),
  187. &pGBRecPtr[i],
  188. sizeof(REC95));
  189. i++;
  190. } else if (nResult == 0) {
  191. nResult = memcmp(pGBRecPtr[i].PHRASE,pGBKRecPtr[j].PHRASE,MAXWORDLENTH);
  192. if (nResult == 0) {
  193. j++;
  194. }
  195. CopyMemory(pNewBufPtr+sizeof(WORD)+(nNewRecNum-1)*sizeof(REC95),
  196. &pGBRecPtr[i],
  197. sizeof(REC95));
  198. i++;
  199. } else {
  200. memcpy(pNewBufPtr+sizeof(WORD)+(nNewRecNum-1)*sizeof(REC95),
  201. &pGBKRecPtr[j],
  202. sizeof(REC95));
  203. j++;
  204. }
  205. }
  206. DebugMsg(("MergeGBandGBKEMBWorker [%d,%d ] i=%d, j=%d!\r\n",nGBRecNum,nGBKRecNum,i,j));
  207. if (i == nGBRecNum && j == nGBKRecNum) {
  208. * (WORD*)pNewBufPtr = nNewRecNum;
  209. DebugMsg((szMsgBuf,"nNewRecNum = %d",* (WORD*)pNewBufPtr));
  210. return pNewBufPtr;
  211. }
  212. if (i==nGBRecNum) {
  213. for ( ; j<nGBKRecNum;j++) {
  214. nNewRecNum++;
  215. pNewBufPtr = (PBYTE) realloc(pNewBufPtr,sizeof(WORD)+(nNewRecNum)*sizeof(REC95));
  216. if (pNewBufPtr == NULL) {
  217. DebugMsg(("MergeGBandGBKEMBWorker,2.realloc error,[%d]!\r\n",GetLastError()));
  218. return NULL;
  219. }
  220. CopyMemory(pNewBufPtr+sizeof(WORD)+(nNewRecNum-1)*sizeof(REC95),
  221. &pGBKRecPtr[j],
  222. sizeof(REC95));
  223. }
  224. } else {
  225. for ( ; i<nGBRecNum;i++) {
  226. nNewRecNum++;
  227. pNewBufPtr = (PBYTE) realloc(pNewBufPtr,sizeof(WORD)+(nNewRecNum)*sizeof(REC95));
  228. if (pNewBufPtr == NULL) {
  229. DebugMsg(("MergeGBandGBKEMBWorker,3.realloc error,[%d]!\r\n",GetLastError()));
  230. return NULL;
  231. }
  232. CopyMemory(pNewBufPtr+sizeof(WORD)+(nNewRecNum-1)*sizeof(REC95),
  233. &pGBRecPtr[i],
  234. sizeof(REC95));
  235. }
  236. }
  237. *(WORD *)pNewBufPtr = nNewRecNum;
  238. DebugMsg(("nNewRecNum = %d\r\n",* (WORD*)pNewBufPtr));
  239. return pNewBufPtr;
  240. }
  241. BOOL MergeGBandGBKEMBWrapper(
  242. LPCTSTR lpszGBFileName,
  243. LPCTSTR lpszGBKFileName,
  244. LPCTSTR lpszNewFileName)
  245. {
  246. HANDLE hGBEmb;
  247. HANDLE hGBKEmb;
  248. HANDLE hGBEmbMapping;
  249. HANDLE hGBKEmbMapping;
  250. PBYTE pGBEmbPtr;
  251. PBYTE pGBKEmbPtr;
  252. PBYTE pNewFilePtr;
  253. HANDLE hNewFile;
  254. DWORD dwByteWritten;
  255. BOOL bRet =FALSE;
  256. DWORD dwSizeGB,dwSizeGBK,dwHigh;
  257. DebugMsg(("MergeGBandGBKEMBWrapper, Starting ...!\r\n"));
  258. DebugMsg(("MergeGBandGBKEMBWrapper,lpszGBFileName=%s!\r\n",lpszGBFileName));
  259. DebugMsg(("MergeGBandGBKEMBWrapper,lpszGBKFileName=%s!\r\n",lpszGBKFileName));
  260. DebugMsg(("MergeGBandGBKEMBWrapper,lpszNewFileName=%s!\r\n",lpszNewFileName));
  261. hGBEmb = CreateFile(lpszGBFileName,
  262. GENERIC_READ | GENERIC_WRITE,
  263. 0,
  264. NULL,
  265. OPEN_ALWAYS,
  266. FILE_ATTRIBUTE_NORMAL,
  267. NULL);
  268. if (hGBEmb == INVALID_HANDLE_VALUE) {
  269. DebugMsg(("MergeGBandGBKEMBWrapper,CreateFile error=%s,[%d]!\r\n",lpszGBFileName,GetLastError()));
  270. goto Err0;
  271. }
  272. hGBKEmb = CreateFile(lpszGBKFileName,
  273. GENERIC_READ | GENERIC_WRITE,
  274. 0,
  275. NULL,
  276. OPEN_ALWAYS,
  277. FILE_ATTRIBUTE_NORMAL,
  278. NULL);
  279. if (hGBKEmb == INVALID_HANDLE_VALUE) {
  280. DebugMsg(("MergeGBandGBKEMBWrapper,CreateFile error=%s,[%d]!\r\n",lpszGBKFileName,GetLastError()));
  281. goto Err1;
  282. }
  283. hGBEmbMapping = CreateFileMapping(hGBEmb,
  284. NULL,
  285. PAGE_READWRITE,
  286. 0,0,0);
  287. if (hGBEmbMapping == NULL) {
  288. DebugMsg(("MergeGBandGBKEMBWrapper,1. CreateFileMapping error,[%d]!\r\n",GetLastError()));
  289. goto Err2;
  290. }
  291. hGBKEmbMapping = CreateFileMapping(hGBKEmb,
  292. NULL,
  293. PAGE_READWRITE,
  294. 0,0,0);
  295. if (hGBKEmbMapping == NULL) {
  296. DebugMsg(("MergeGBandGBKEMBWrapper,2. CreateFileMapping error,[%d]!\r\n",GetLastError()));
  297. goto Err3;
  298. }
  299. pGBEmbPtr = (PBYTE) MapViewOfFile(hGBEmbMapping,
  300. FILE_MAP_ALL_ACCESS,
  301. 0,0,0);
  302. if (pGBEmbPtr == NULL) {
  303. DebugMsg(("MergeGBandGBKEMBWrapper,1. MapViewOfFile error,[%d]!\r\n",GetLastError()));
  304. goto Err3;
  305. }
  306. pGBKEmbPtr = (PBYTE) MapViewOfFile(hGBKEmbMapping,
  307. FILE_MAP_ALL_ACCESS,
  308. 0,0,0);
  309. if (pGBKEmbPtr == NULL) {
  310. DebugMsg(("MergeGBandGBKEMBWrapper,2. MapViewOfFile error,[%d]!\r\n",GetLastError()));
  311. goto Err4;
  312. }
  313. dwSizeGB = GetFileSize(hGBEmb,&dwHigh);
  314. dwSizeGBK = GetFileSize(hGBKEmb,&dwHigh);
  315. if (dwSizeGB != (sizeof(WORD)+sizeof(REC95) * (*(WORD *)pGBEmbPtr ))) {
  316. DebugMsg(("MergeGBandGBKEMBWrapper: Warnning Real table size is different from info in record\r\n"));
  317. DebugMsg(("[%s] sizeGB = %d, no=%d, calculated = %d\r\n",lpszGBFileName,
  318. dwSizeGB,
  319. *(WORD *)pGBEmbPtr,
  320. sizeof(WORD)+sizeof(REC95) * (*(WORD *)pGBEmbPtr)
  321. ));
  322. if (IsSizeReasonable(dwSizeGB) == FALSE) {
  323. DebugMsg(("MergeGBandGBKEMBWrapper: Fatal error, file size is strange %d we need to give up this %s!\r\n",dwSizeGB,lpszGBFileName));
  324. goto Err5;
  325. }
  326. (*(WORD *)pGBEmbPtr) = (WORD) ((dwSizeGB - sizeof(WORD)) / sizeof(REC95));
  327. DebugMsg((
  328. "MergeGBandGBKEMBWrapper: Adjust record number = %d\r\n",(*(WORD *)pGBEmbPtr)
  329. ));
  330. }
  331. if (dwSizeGBK != (sizeof(WORD)+sizeof(REC95) * (*(WORD *)pGBKEmbPtr ))) {
  332. DebugMsg(("MergeGBandGBKEMBWrapper: Warnning Real table size is different from info in record\r\n"));
  333. DebugMsg(("[%s] sizeGBK = %d, no=%d, calculated = %d\r\n",lpszGBKFileName,
  334. dwSizeGBK,
  335. *(WORD *)pGBKEmbPtr,
  336. sizeof(WORD)+sizeof(REC95) * (*(WORD *)pGBKEmbPtr)
  337. ));
  338. if (IsSizeReasonable(dwSizeGBK) == FALSE) {
  339. DebugMsg(("MergeGBandGBKEMBWrapper: Fatal error, file size is strange %d we need to give up this %s!\r\n",dwSizeGBK,lpszGBKFileName));
  340. goto Err5;
  341. }
  342. (*(WORD *)pGBKEmbPtr) = (WORD) ((dwSizeGBK - sizeof(WORD)) / sizeof(REC95));
  343. DebugMsg(("MergeGBandGBKEMBWrapper: Adjust record number = %d\r\n",(*(WORD *)pGBKEmbPtr)));
  344. }
  345. pNewFilePtr = MergeGBandGBKEMBWorker(pGBEmbPtr,pGBKEmbPtr);
  346. if (pNewFilePtr == NULL) {
  347. DebugMsg(("MergeGBandGBKEMBWrapper,MergeGBandGBKEMBWorker[%s,%s] error,[%d]!\r\n",
  348. lpszGBFileName,lpszGBKFileName,GetLastError()));
  349. goto Err5;
  350. }
  351. hNewFile = CreateFile(lpszNewFileName,
  352. GENERIC_WRITE,
  353. FILE_SHARE_READ,
  354. NULL,
  355. CREATE_ALWAYS,
  356. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
  357. NULL);
  358. if (hNewFile == INVALID_HANDLE_VALUE) {
  359. DebugMsg(("MergeGBandGBKEMBWrapper,CreateFile error %s,[%d]!\r\n",lpszNewFileName,GetLastError()));
  360. goto Err5;
  361. }
  362. if (WriteFile(hNewFile,
  363. pNewFilePtr,
  364. sizeof(WORD)+ *((WORD *) pNewFilePtr) * sizeof(REC95),
  365. &dwByteWritten,
  366. NULL) == 0) {
  367. DebugMsg(("MergeGBandGBKEMBWrapper,WriteFile error %s,[%d]!\r\n",lpszNewFileName,GetLastError()));
  368. goto Err6;
  369. } else {
  370. DebugMsg(("MergeGBandGBKEMBWrapper,WriteFile %s OK !\r\n",lpszNewFileName));
  371. }
  372. free (pNewFilePtr);
  373. bRet = TRUE;
  374. Err6:
  375. CloseHandle(hNewFile);
  376. Err5:
  377. UnmapViewOfFile(pGBKEmbPtr);
  378. Err4:
  379. UnmapViewOfFile(pGBEmbPtr);
  380. Err3:
  381. CloseHandle(hGBEmbMapping);
  382. Err2:
  383. CloseHandle(hGBKEmb);
  384. Err1:
  385. CloseHandle(hGBEmb);
  386. Err0:
  387. DebugMsg(("MergeGBandGBKEMBWrapper, Finished ...!\r\n"));
  388. return bRet;
  389. }
  390. BOOL MergeGBandGBKEMB(LPCTSTR lpszSourcePath)
  391. //
  392. // Warnning, lpszSourcePath, this string must be ended with "\"
  393. //
  394. {
  395. int i;
  396. TCHAR szGBEmbPath[MAX_PATH];
  397. TCHAR szGBKEmbPath[MAX_PATH];
  398. TCHAR szTmpEMBPath[MAX_PATH];
  399. UINT uFileExistingStatus = 0;
  400. DebugMsg(("MergeGBandGBKEMB,Starting ...!\r\n"));
  401. DebugMsg(("MergeGBandGBKEMB, lpszSourcePath = %s!\r\n",lpszSourcePath));
  402. for (i=0; i<IMENUM; i++) {
  403. lstrcpy(szGBEmbPath,lpszSourcePath);
  404. lstrcat(szGBEmbPath,EmbName[i]);
  405. lstrcpy(szGBKEmbPath,lpszSourcePath);
  406. lstrcat(szGBKEmbPath,XEmbName[i]);
  407. if (IsFileExist(szGBEmbPath)) {
  408. uFileExistingStatus |= 1;
  409. DebugMsg(("MergeGBandGBKEMB,EMB %s exsiting !\r\n",szGBEmbPath));
  410. } else {
  411. DebugMsg(("MergeGBandGBKEMB,EMB %s not exsiting !\r\n",szGBEmbPath));
  412. }
  413. if (IsFileExist(szGBKEmbPath)) {
  414. uFileExistingStatus |= 2;
  415. DebugMsg(("MergeGBandGBKEMB,EMB %s exsiting !\r\n",szGBKEmbPath));
  416. } else {
  417. DebugMsg(("MergeGBandGBKEMB,EMB %s not exsiting !\r\n",szGBKEmbPath));
  418. }
  419. lstrcpy(szTmpEMBPath,szGBEmbPath);
  420. lstrcat(szTmpEMBPath,TEXT("_"));
  421. switch (uFileExistingStatus) {
  422. case 1: // only GB emb
  423. if (CopyFile(szGBEmbPath,szTmpEMBPath,FALSE)) {
  424. DebugMsg(("MergeGBandGBKEMB,copy %s to %s OK!\r\n",szGBEmbPath,szTmpEMBPath));
  425. } else {
  426. DebugMsg(("MergeGBandGBKEMB,copy %s to %s failed!\r\n",szGBEmbPath,szTmpEMBPath));
  427. }
  428. break;
  429. case 2: // only GBK emb
  430. if (CopyFile(szGBKEmbPath,szTmpEMBPath,FALSE)) {
  431. DebugMsg(("MergeGBandGBKEMB,copy %s to %s OK!\r\n",szGBKEmbPath,szTmpEMBPath));
  432. } else {
  433. DebugMsg(("MergeGBandGBKEMB,copy %s to %s failed!\r\n",szGBKEmbPath,szTmpEMBPath));
  434. }
  435. break;
  436. case 3: // both
  437. if (MergeGBandGBKEMBWrapper(szGBEmbPath,szGBKEmbPath,szTmpEMBPath)) {
  438. DebugMsg(("MergeGBandGBKEMB,merge %s , %s to %s OK!\r\n",szGBEmbPath,szGBKEmbPath,szTmpEMBPath));
  439. } else {
  440. DebugMsg(("MergeGBandGBKEMB,merge %s , %s to %s failed!\r\n",szGBEmbPath,szGBKEmbPath,szTmpEMBPath));
  441. }
  442. break;
  443. case 0: // none of them
  444. default:
  445. DebugMsg(("MergeGBandGBKEMB,None of them !\r\n"));
  446. continue;
  447. }
  448. }
  449. DebugMsg(("MergeGBandGBKEMB,Finished ...!\r\n"));
  450. return TRUE;
  451. }
  452. // Test above routines.
  453. BOOL ConvertChsImeData(void)
  454. {
  455. HANDLE hs, ht;
  456. int i,len;
  457. TCHAR szName[MAX_PATH];
  458. TCHAR szMergedName[MAX_PATH];
  459. TCHAR szMigTempDir[MAX_PATH];
  460. TCHAR szSys32Dir[MAX_PATH];
  461. LPSTR pszMigTempDirPtr;
  462. LPSTR pszSys32Ptr;
  463. //
  464. // Get Winnt System 32 directory
  465. //
  466. len = GetSystemDirectory((LPSTR)szSys32Dir, MAX_PATH);
  467. if (szSys32Dir[len - 1] != '\\') { // consider C:\ ;
  468. szSys32Dir[len++] = '\\';
  469. szSys32Dir[len] = 0;
  470. }
  471. DebugMsg(("ConvertChsImeData, System Directory = %s !\r\n",szSys32Dir));
  472. //
  473. // detect if IME98 directory there, if it is,
  474. // then just copy files to system32 dir from temporary dir
  475. // because Win98 IME's EMB tables are compatibile with NT
  476. //
  477. lstrcpy(szMigTempDir,ImeDataDirectory);
  478. if (g_bCHSWin98) {
  479. DebugMsg(("ConvertChsImeData ,This is win98 !\r\n"));
  480. pszMigTempDirPtr = szMigTempDir+lstrlen(szMigTempDir);
  481. pszSys32Ptr = szSys32Dir+lstrlen(szSys32Dir);
  482. for (i=0; i<IMENUM; i++) {
  483. lstrcat(pszMigTempDirPtr,EmbName[i]);
  484. lstrcat(pszSys32Ptr,EmbName[i]);
  485. if (CopyFile(szMigTempDir,szSys32Dir,FALSE)) {
  486. DebugMsg(("ConvertChsImeData,copy %s to %s OK!\r\n",szMigTempDir,szSys32Dir));
  487. } else {
  488. DebugMsg(("ConvertChsImeData,doesn't copy %s to %s !\r\n",szMigTempDir,szSys32Dir));
  489. }
  490. *pszMigTempDirPtr = TEXT('\0');
  491. *pszSys32Ptr = TEXT('\0');
  492. }
  493. return TRUE;
  494. }
  495. //
  496. // end of detecting Win98
  497. //
  498. //
  499. // if you're here, then it means we're not doing CHS win98 migration
  500. //
  501. // then we need to convert EMB to be compatibile with NT
  502. //
  503. if (! MergeGBandGBKEMB(ImeDataDirectory)) {
  504. DebugMsg(("ConvertChsImeData, calling MergeGBandGBKEMB failed !\r\n"));
  505. }
  506. else {
  507. DebugMsg(("ConvertChsImeData, calling MergeGBandGBKEMB OK !\r\n"));
  508. }
  509. for (i=0; i< IMENUM; i++)
  510. {
  511. lstrcpy(szMergedName,EmbName[i]);
  512. lstrcat(szMergedName,TEXT("_"));
  513. if (hs = OpenEMBFile(szMergedName))
  514. {
  515. lstrcat(szSys32Dir, EmbName[i]);
  516. ht = CreateFile(szSys32Dir,
  517. GENERIC_WRITE,
  518. 0,
  519. NULL,
  520. CREATE_NEW,
  521. FILE_ATTRIBUTE_ARCHIVE, NULL);
  522. DebugMsg(("ConvertChsImeData, ImeDataConvertChs Old = %s,New = %s!\r\n",szMergedName,szSys32Dir));
  523. ImeDataConvertChs((HFILE)hs, (HFILE)ht);
  524. CloseHandle(hs);
  525. CloseHandle(ht);
  526. szSys32Dir[len]=0;
  527. }
  528. else {
  529. if (GetLastError() != ERROR_FILE_NOT_FOUND) {
  530. DebugMsg(("ConvertChsImeData failed!\r\n"));
  531. return FALSE;
  532. }
  533. }
  534. }
  535. return TRUE;
  536. }
  537. BOOL CHSBackupWinABCUserDict(LPCTSTR lpszSourcePath)
  538. {
  539. TCHAR szDstName[MAX_PATH];
  540. TCHAR szSrcName[MAX_PATH];
  541. int len;
  542. int i;
  543. TCHAR ChsDataFile[4][15]={"winbx.emb",
  544. "winxbx.emb",
  545. "user.rem",
  546. "tmmr.rem"};
  547. for (i=0; i<4; i++) {
  548. lstrcpy(szSrcName,lpszSourcePath);
  549. ConcatenatePaths(szSrcName,ChsDataFile[i],MAX_PATH);
  550. if (! IsFileExist(szSrcName)) {
  551. DebugMsg(("CHSBackupWinABCUserDict, no user dic file, %s!\r\n",szSrcName));
  552. continue;
  553. }
  554. len = GetSystemDirectory((LPSTR)szDstName, MAX_PATH);
  555. ConcatenatePaths(szDstName,ChsDataFile[i],MAX_PATH);
  556. if (CopyFile(szSrcName,szDstName,FALSE)) {
  557. DebugMsg(("CHSBackupWinABCUserDict,copy %s to %s OK!\r\n",szSrcName,szDstName));
  558. } else {
  559. DebugMsg(("CHSBackupWinABCUserDict,copy %s to %s failed!\r\n",szSrcName,szDstName));
  560. }
  561. }
  562. return TRUE;
  563. }
  564. BOOL CHSDeleteGBKKbdLayout()
  565. {
  566. #define ID_LEN 9
  567. TCHAR szKeyboardLayouts[][ID_LEN] = {"E0060804",
  568. "E0070804",
  569. "E0080804"
  570. // "E0090804",
  571. };
  572. HKEY hKey;
  573. LONG lResult;
  574. int i;
  575. lResult = RegOpenKey(HKEY_LOCAL_MACHINE,
  576. TEXT("System\\CurrentControlSet\\Control\\Keyboard Layouts"),
  577. &hKey);
  578. if (lResult != ERROR_SUCCESS) {
  579. DebugMsg(("CHSDeleteGBKKbdLayout, Open keyboard layout registry failed failed [%d] !\r\n",lResult));
  580. return FALSE;
  581. }
  582. for (i=0; i<sizeof(szKeyboardLayouts) / ID_LEN; i++) {
  583. lResult = RegDeleteKey(hKey,szKeyboardLayouts[i]);
  584. if (lResult != ERROR_SUCCESS) {
  585. DebugMsg(("CHSDeleteGBKKbdLayout, Delete key %s failed %X!\r\n",szKeyboardLayouts[i],lResult));
  586. }
  587. else {
  588. DebugMsg(("CHSDeleteGBKKbdLayout, Delete key %s OK %X!\r\n",szKeyboardLayouts[i]));
  589. }
  590. }
  591. RegCloseKey(hKey);
  592. return TRUE;
  593. }