#include #include #include #include "common.h" #include "chs.h" extern TCHAR ImeDataDirectory[MAX_PATH]; extern TCHAR szMsgBuf[]; extern BOOL g_bCHSWin98; BYTE EmbName[IMENUM][MAXIMENAME]={ "winpy.emb", "winsp.emb", "winzm.emb" // "winbx.emb" }; BYTE XEmbName[IMENUM][MAXIMENAME]={ "winxpy.emb", "winxsp.emb", "winxzm.emb" // "winxbx.emb" }; BOOL IsSizeReasonable(DWORD dwSize) { DWORD dwTemp = (dwSize - sizeof(WORD)) / sizeof(REC95); if (((dwSize - sizeof(WORD)) - (dwTemp * sizeof(REC95))) == 0) { return TRUE; } else { return FALSE; } } /******************************Public*Routine******************************\ * OpenEMBFile * * Get Win95 IME phrase data from system directory. * * Arguments: * * UCHAR * FileName - EMB file name. * * Return Value: * * HANDLE: Success - file handle of EMB file. Fail - 0; * * History: * \**************************************************************************/ HANDLE OpenEMBFile(UCHAR * FileName) { HFILE hf; TCHAR FilePath[MAX_PATH]; lstrcpy(FilePath, ImeDataDirectory); lstrcat(FilePath, FileName); hf = _lopen(FilePath,OF_READ); if (hf == HFILE_ERROR) { DebugMsg(("OpenEMBFile,[%s] failed!\r\n",FileName)); return 0; } else { DebugMsg(("OpenEMBFile,[%s] OK!\r\n",FileName)); return (HANDLE)hf; } } /******************************Public*Routine******************************\ * ImeDataConvertChs * * Convert Windows 95 IME phrase data to Windows NT 5.0. * * Arguments: * * HANDLE hSource - source file handle. * HANDLE hTarget - target file handle. * * Return Value: * * BOOL: TRUE-Success, FALSE-FAIL. * * History: * \**************************************************************************/ BOOL ImeDataConvertChs(HFILE hSource, HFILE hTarget) { HANDLE hPhrase95, hPhraseNT; BYTE *szPhrase95; WCHAR *szPhraseNT; DWORD fsize; BOOL bReturn = TRUE; int i; hPhrase95 = GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT, sizeof(REC95)*MAXNUMBER_EMB+sizeof(WORD)); hPhraseNT = GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT, sizeof(RECNT)*MAXNUMBER_EMB+sizeof(WORD)); if (!hPhraseNT || !hPhrase95 ) { DebugMsg(("ImeDataConvertChs failed!,!hPhraseNT || !hPhrase95 \r\n")); bReturn = FALSE; goto Convert_Finish; } szPhrase95 = GlobalLock(hPhrase95); szPhraseNT = GlobalLock(hPhraseNT); fsize = _lread(hSource,szPhrase95,sizeof(REC95)*MAXNUMBER_EMB+sizeof(WORD)); if (fsize != *((WORD*)&szPhrase95[0])*sizeof(REC95)+2) { DebugMsg(("ImeDataConvertChs ,Warnning fsize ! %d, rec no = %d\r\n",fsize,*((WORD *) szPhrase95))); if (IsSizeReasonable(fsize)) { *((WORD *) szPhrase95) = (WORD)((fsize - sizeof(WORD)) / sizeof(REC95)); DebugMsg(("ImeDataConvertChs ,Fixed rec number = %d\r\n",*((WORD *) szPhrase95))); } else { DebugMsg(("ImeDataConvertChs ,Data file maybe wrong !\r\n")); bReturn = FALSE; goto Convert_Finish; } } //phrase count szPhraseNT[0] = *((WORD*)&szPhrase95[0]); for (i=0; i