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.

708 lines
21 KiB

  1. /*************************************************
  2. * upimeres.c *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. #include <windows.h> // required for all Windows applications
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <io.h>
  11. #include <winnls.h>
  12. #include <winerror.h>
  13. #include <wchar.h>
  14. #include "upimeres.h"
  15. #ifdef UNICODE
  16. TCHAR ERR_INVALID_BMP_MSG[] = {0x975E, 0x6CD5, 0x0042, 0x0049, 0x0054, 0x004D, 0x0041, 0x0050, 0x6587, 0x4EF6, 0x002C, 0x0020, 0x9009, 0x7528, 0x7CFB, 0x7EDF, 0x0042, 0x0049, 0x0054, 0x004D, 0x0041, 0x0050, 0x3002, 0x0000};
  17. TCHAR ERR_INVALID_ICON_MSG[] = { 0x975E, 0x6CD5, 0x0049, 0x0043, 0x004F, 0x004E, 0x6587, 0x4EF6, 0x002C, 0x0020, 0x9009, 0x7528, 0x7CFB, 0x7EDF, 0x0049, 0x0043, 0x004F, 0x004E, 0x3002, 0x0000};
  18. TCHAR ERR_NO_BMP_MSG[] = { 0x9009, 0x7528, 0x7CFB, 0x7EDF, 0x0042, 0x0049, 0x0054, 0x004D, 0x0041, 0x0050, 0x3002, 0x0000};
  19. TCHAR ERR_NO_ICON_MSG[] = { 0x9009, 0x7528, 0x7CFB, 0x7EDF, 0x0049, 0x0043, 0x004F, 0x004E, 0x3002, 0x0000};
  20. TCHAR ERR_CANNOT_UPRES_MSG[] = {0x65E0, 0x6CD5, 0x751F, 0x6210, 0x8F93, 0x5165, 0x6CD5, 0xFF01, 0x0000};
  21. TCHAR MSG_TITLE[] = {0x8B66, 0x544A, 0x0000};
  22. #else
  23. #define ERR_INVALID_BMP_MSG "�Ƿ�BITMAP�ļ�, ѡ��ϵͳBITMAP��"
  24. #define ERR_INVALID_ICON_MSG "�Ƿ�ICON�ļ�, ѡ��ϵͳICON��"
  25. #define ERR_NO_BMP_MSG "ѡ��ϵͳBITMAP��"
  26. #define ERR_NO_ICON_MSG "ѡ��ϵͳICON��"
  27. #define ERR_CANNOT_UPRES_MSG "�޷��������뷨��"
  28. #define MSG_TITLE "����"
  29. #endif //UNICODE
  30. typedef TCHAR UNALIGNED FAR *LPUNATCHAR;
  31. extern HWND HwndCrtImeDlg;
  32. WORD GenWideName(LPCTSTR pszSBName, TCHAR *lpVerString)
  33. {
  34. WORD length;
  35. #ifdef UNICODE
  36. lstrcpy(lpVerString, pszSBName);
  37. length = (WORD)lstrlen(lpVerString);
  38. #else
  39. length= (WORD)MultiByteToWideChar(CP_ACP, 0, pszSBName, lstrlen(pszSBName), lpVerString, sizeof(lpVerString)/sizeof(TCHAR));
  40. #endif
  41. return length+1; //end with zero
  42. }
  43. long MakeVerInfo(
  44. LPCTSTR pszImeFileName,
  45. LPCTSTR pszOrgName,
  46. LPCTSTR pszImeName,
  47. BYTE *lpResData
  48. )
  49. {
  50. BYTE *pVerData, *pOldVerData;
  51. TCHAR lpwImeFileName[128], lpwOrgName[128], lpwImeName[128];
  52. HGLOBAL hResData;
  53. WORD length;
  54. signed int difflen,newlen,i,l;
  55. VERDATA ImeVerData[VER_BLOCK_NUM] = {
  56. {0x0304, 0x0034, 0x0004, 0x0024, FALSE},
  57. {0x0262, 0x0000, 0x0060, 0x0020, FALSE},
  58. {0x023e, 0x0000, 0x0084, 0x0014, FALSE},
  59. {0x004c, 0x0016, 0x009c, 0x001c, TRUE},
  60. {0x0040, 0x000c, 0x00e8, 0x0024, TRUE},
  61. {0x0032, 0x0009, 0x0128, 0x001c, FALSE},
  62. {0x0038, 0x000c, 0x015c, 0x001c, TRUE},
  63. {0x0080, 0x002e, 0x0194, 0x0020, FALSE},
  64. {0x003e, 0x000b, 0x0214, 0x0024, TRUE},
  65. {0x0038, 0x000c, 0x0254, 0x001c, TRUE},
  66. {0x0036, 0x0009, 0x028c, 0x0020, FALSE},
  67. {0x0044, 0x0000, 0x02c4, 0x001c, FALSE},
  68. {0x0024, 0x0004, 0x02e4, 0x001c, FALSE},
  69. };
  70. memset(lpwOrgName, 0, 128);
  71. memset(lpwImeName, 0, 128);
  72. memset(lpwImeFileName, 0, 128);
  73. //REPLACE CompanyName string
  74. length = GenWideName(pszOrgName, lpwOrgName);
  75. ImeVerData[VER_COMP_NAME].cbValue = length;
  76. ImeVerData[VER_COMP_NAME].cbBlock =
  77. ImeVerData[VER_COMP_NAME].wKeyNameSize +
  78. length*sizeof(WCHAR) + 2*sizeof(WORD);
  79. //replace FileDescription string
  80. length = GenWideName(pszImeName, lpwImeName);
  81. ImeVerData[VER_FILE_DES].cbValue = length;
  82. ImeVerData[VER_FILE_DES].cbBlock =
  83. ImeVerData[VER_FILE_DES].wKeyNameSize +
  84. length*sizeof(WCHAR) + 2*sizeof(WORD);
  85. //replace InternalName string
  86. length = GenWideName(pszImeName, lpwImeName);
  87. ImeVerData[VER_INTL_NAME].cbValue = length;
  88. ImeVerData[VER_INTL_NAME].cbBlock =
  89. ImeVerData[VER_INTL_NAME].wKeyNameSize +
  90. length*sizeof(WCHAR) + 2*sizeof(WORD);
  91. //replace OriginalFileName string
  92. length = GenWideName(pszImeFileName, lpwImeFileName);
  93. ImeVerData[VER_ORG_FILE_NAME].cbValue = length;
  94. ImeVerData[VER_ORG_FILE_NAME].cbBlock =
  95. ImeVerData[VER_ORG_FILE_NAME].wKeyNameSize +
  96. length*sizeof(WCHAR) + 2*sizeof(WORD);
  97. //replace ProductName string
  98. length = GenWideName(pszImeName, lpwImeName);
  99. ImeVerData[VER_PRD_NAME].cbValue = length;
  100. ImeVerData[VER_PRD_NAME].cbBlock =
  101. ImeVerData[VER_PRD_NAME].wKeyNameSize +
  102. length*sizeof(WCHAR) + 2*sizeof(WORD);
  103. //begin writeback all data
  104. //we assume the size of ver will never over 0x400
  105. pVerData = malloc(0x400);
  106. if ( pVerData == NULL )
  107. {
  108. return 0;
  109. }
  110. memset(pVerData, 0, 0x400);
  111. hResData = LoadResource(NULL, FindResource(NULL,TEXT("VERDATA"), RT_RCDATA));
  112. if ( hResData == NULL )
  113. {
  114. free(pVerData);
  115. return 0;
  116. }
  117. pOldVerData = LockResource(hResData);
  118. if ( pOldVerData == NULL )
  119. {
  120. free(pVerData);
  121. UnlockResource(hResData);
  122. return 0;
  123. }
  124. l = VER_HEAD_LEN;
  125. memcpy(&pVerData[0],&pOldVerData[0], VER_HEAD_LEN);
  126. for( i = VER_COMP_NAME; i < VER_VAR_FILE_INFO; i++){
  127. memcpy(&pVerData[l], &ImeVerData[i].cbBlock, sizeof(WORD));
  128. l+=sizeof(WORD);
  129. memcpy(&pVerData[l], &ImeVerData[i].cbValue, sizeof(WORD));
  130. l+=sizeof(WORD);
  131. memcpy(&pVerData[l], &pOldVerData[(ImeVerData[i].wKeyOffset)],ImeVerData[i].wKeyNameSize);
  132. l+=ImeVerData[i].wKeyNameSize;
  133. if(ImeVerData[i].fUpdate){
  134. switch(i){
  135. case VER_FILE_DES:
  136. case VER_INTL_NAME:
  137. case VER_PRD_NAME:
  138. memcpy(&pVerData[l], lpwImeName, lstrlen(lpwImeName)*sizeof(WCHAR));
  139. l+=ImeVerData[i].cbValue*sizeof(WCHAR);
  140. break;
  141. case VER_COMP_NAME:
  142. memcpy(&pVerData[l], lpwOrgName, lstrlen(lpwOrgName)*sizeof(WCHAR));
  143. l+=ImeVerData[i].cbValue*sizeof(WCHAR);
  144. break;
  145. case VER_ORG_FILE_NAME:
  146. memcpy(&pVerData[l], lpwImeFileName, lstrlen(lpwImeFileName)*sizeof(WCHAR));
  147. l+=ImeVerData[i].cbValue*sizeof(WCHAR);
  148. break;
  149. }
  150. }else{
  151. memcpy(&pVerData[l],
  152. &pOldVerData[ImeVerData[i].wKeyOffset+ImeVerData[i].wKeyNameSize],
  153. ImeVerData[i].cbValue*sizeof(WCHAR));
  154. l+=ImeVerData[i].cbValue*sizeof(WCHAR);
  155. }
  156. difflen = REMAINDER(l, CBLONG);
  157. l += difflen;
  158. }
  159. newlen = l - VER_STR_INFO_OFF - difflen;
  160. memcpy(&pVerData[VER_STR_INFO_OFF], &newlen, sizeof(WORD));
  161. newlen = l - VER_LANG_OFF - difflen;
  162. memcpy(&pVerData[VER_LANG_OFF], &newlen, sizeof(WORD));
  163. memcpy(&pVerData[l],&pOldVerData[VER_VAR_FILE_INFO_OFF], VER_TAIL_LEN);
  164. l+= VER_TAIL_LEN;
  165. memcpy(&pVerData[0], &l, sizeof(WORD));
  166. memcpy(lpResData, pVerData, l);
  167. UnlockResource(hResData);
  168. return ImeVerData[VER_ROOT].cbBlock;
  169. }
  170. BOOL UpdateImeBmp(
  171. LPCTSTR pszImeDesName, //destination IME file name
  172. LPCTSTR pszImeBmpName, //Bitmap file name
  173. HANDLE hUpdateRes)
  174. {
  175. HFILE imagefh = HFILE_ERROR;
  176. OFSTRUCT OpenBuf;
  177. BOOL result;
  178. WORD error;
  179. BYTE lpResData[0x2000];
  180. ULONG ResDataSize;
  181. error = NO_ERROR;
  182. if(pszImeBmpName == NULL || lstrlen(pszImeBmpName) == 0){ //prepare for update bitmap
  183. error = ERR_RES_NO_BMP;
  184. goto END_ERROR;
  185. }else{
  186. #ifdef UNICODE
  187. //
  188. // Because OpenFile( ) accepts only PSTR as its first parameter.
  189. // so we must convert this unicode string to Multi Byte String
  190. //
  191. CHAR pszImeBmpNameA[MAX_PATH];
  192. WideCharToMultiByte(CP_ACP,
  193. 0,
  194. pszImeBmpName,
  195. -1,
  196. pszImeBmpNameA,
  197. MAX_PATH,
  198. NULL,
  199. NULL);
  200. imagefh = (HFILE)OpenFile( pszImeBmpNameA, &OpenBuf, OF_READ | OF_SHARE_EXCLUSIVE);
  201. #else
  202. imagefh = (HFILE)OpenFile( pszImeBmpName, &OpenBuf, OF_READ | OF_SHARE_EXCLUSIVE);
  203. #endif
  204. if(imagefh == HFILE_ERROR){
  205. error = ERR_RES_INVALID_BMP;
  206. goto END_ERROR; //go on next resource update
  207. }
  208. ResDataSize = GetFileSize((HANDLE)ULongToPtr((DWORD)imagefh),NULL);
  209. //according to the file size check if it is a 20*20 bmp
  210. if(ResDataSize != BMP_20_SIZE){
  211. error = ERR_RES_INVALID_BMP;
  212. goto END_ERROR;
  213. }
  214. ResDataSize -= sizeof(BITMAPFILEHEADER);
  215. if(_llseek(imagefh, sizeof(BITMAPFILEHEADER), 0)!=sizeof(BITMAPFILEHEADER)){
  216. error = ERR_RES_INVALID_BMP;
  217. goto END_ERROR; //go on next resource update
  218. }
  219. if(_lread(imagefh, lpResData, ResDataSize)!=ResDataSize){
  220. error = ERR_RES_INVALID_BMP;
  221. goto END_ERROR; //go on next resource update
  222. }
  223. result = UpdateResource(hUpdateRes, /* update resource handle */
  224. RT_BITMAP, /* change bitmap resource */
  225. BMPNAME, /* bitmap name */
  226. MAKELANGID(LANG_CHINESE,
  227. SUBLANG_CHINESE_SIMPLIFIED), /* neutral language ID */
  228. lpResData, /* ptr to resource info */
  229. ResDataSize); /* size of resource info. */
  230. if(!result){
  231. error = ERR_CANNOT_UPRES;
  232. goto END_ERROR;
  233. }
  234. }
  235. END_ERROR:
  236. if(imagefh != HFILE_ERROR)
  237. _lclose(imagefh);
  238. switch(error){
  239. case NO_ERROR:
  240. return TRUE;
  241. case ERR_RES_INVALID_BMP:
  242. //SHOW MSG
  243. MessageBox(HwndCrtImeDlg,ERR_INVALID_BMP_MSG, MSG_TITLE, MB_OK | MB_ICONINFORMATION);
  244. return TRUE;
  245. case ERR_RES_NO_BMP:
  246. //SHOW MSG
  247. MessageBox(HwndCrtImeDlg,ERR_NO_BMP_MSG, MSG_TITLE, MB_OK | MB_ICONINFORMATION);
  248. return TRUE;
  249. // case ERROR_NOT_ENOUGH_MEMORY:
  250. case ERR_CANNOT_UPRES:
  251. default:
  252. //SHOW MSG
  253. MessageBox(HwndCrtImeDlg,ERR_CANNOT_UPRES_MSG, MSG_TITLE, MB_OK|MB_ICONSTOP);
  254. return FALSE;
  255. }
  256. }
  257. BOOL UpdateImeIcon(
  258. LPCTSTR pszImeDesName, //destination IME file name
  259. LPCTSTR pszImeIconName, //Bitmap file name
  260. HANDLE hUpdateRes)
  261. {
  262. HFILE imagefh = HFILE_ERROR;
  263. OFSTRUCT OpenBuf;
  264. BOOL result;
  265. WORD error;
  266. BYTE lpResData[0x2000];
  267. ULONG ResDataSize,i;
  268. //begin update ICON file
  269. error = NO_ERROR;
  270. if(pszImeIconName==NULL || lstrlen(pszImeIconName) ==0){
  271. error = ERR_RES_NO_ICON;
  272. goto END_ERROR;
  273. }else{
  274. ICONHEADER IconHeader;
  275. ICONDIRENTRY IconDirEntry;
  276. #ifdef UNICODE
  277. //
  278. // Because OpenFile( ) accepts only PSTR as its first parameter.
  279. // so we must convert this unicode string to Multi Byte String
  280. //
  281. CHAR pszImeIconNameA[MAX_PATH];
  282. WideCharToMultiByte(CP_ACP,
  283. 0,
  284. pszImeIconName,
  285. -1,
  286. pszImeIconNameA,
  287. MAX_PATH,
  288. NULL,
  289. NULL);
  290. imagefh = (HFILE)OpenFile( pszImeIconNameA, &OpenBuf, OF_READ | OF_SHARE_EXCLUSIVE);
  291. #else
  292. imagefh = (HFILE)OpenFile( pszImeIconName, &OpenBuf, OF_READ | OF_SHARE_EXCLUSIVE);
  293. #endif
  294. if(imagefh == HFILE_ERROR){
  295. error = ERR_RES_INVALID_ICON;
  296. goto END_ERROR;
  297. }
  298. ResDataSize = sizeof(ICONDIRENTRY)+3*sizeof(WORD);
  299. if(_llseek(imagefh, 0, 0) != 0 ){
  300. error = ERR_RES_INVALID_ICON;
  301. goto END_ERROR; //go on next resource update
  302. }
  303. memset(&IconHeader, 0, ResDataSize);
  304. if(_lread(imagefh, &IconHeader, 3*sizeof(WORD))!=3*sizeof(WORD)){
  305. error = ERR_RES_INVALID_ICON;
  306. goto END_ERROR;
  307. }
  308. if(_lread(imagefh, &IconHeader.idEntries[0], sizeof(ICONDIRENTRY))!=sizeof(ICONDIRENTRY)){
  309. error = ERR_RES_INVALID_ICON;
  310. goto END_ERROR;
  311. }
  312. if(IconHeader.idEntries[0].bWidth == 16 && IconHeader.idEntries[0].bHeight == 16){
  313. IconHeader.idCount = 0;
  314. IconDirEntry = IconHeader.idEntries[0];
  315. }
  316. for(i=1;i<IconHeader.idCount;i++){
  317. if(_lread(imagefh,&IconDirEntry, sizeof(ICONDIRENTRY))!=sizeof(ICONDIRENTRY)){
  318. error = ERR_RES_INVALID_ICON;
  319. goto END_ERROR;
  320. }
  321. if(IconDirEntry.bWidth == 16 && IconDirEntry.bHeight == 16){
  322. IconHeader.idCount = 0;
  323. break;
  324. }
  325. }
  326. if(IconHeader.idCount > 0){
  327. error = ERR_RES_INVALID_ICON;
  328. goto END_ERROR;
  329. }
  330. if(_llseek(imagefh, IconDirEntry.dwImageOffset, 0)!=(LONG)(IconDirEntry.dwImageOffset) ){
  331. error = ERR_RES_INVALID_ICON;
  332. goto END_ERROR;
  333. }
  334. if(_lread(imagefh, lpResData, IconDirEntry.dwBytesInRes)!=IconDirEntry.dwBytesInRes){
  335. error = ERR_RES_INVALID_ICON;
  336. goto END_ERROR;
  337. }
  338. result = UpdateResource(hUpdateRes, /* update resource handle */
  339. RT_ICON, /* change dialog box resource */
  340. MAKEINTRESOURCE(2), /* icon name , we have to use 2 instead of "IMEICO" */
  341. MAKELANGID(LANG_CHINESE,
  342. SUBLANG_CHINESE_SIMPLIFIED), /* neutral language ID */
  343. lpResData, /* ptr to resource info */
  344. IconDirEntry.dwBytesInRes); /* size of resource info. */
  345. if(!result){
  346. error = ERR_CANNOT_UPRES;
  347. goto END_ERROR;
  348. }
  349. }
  350. END_ERROR:
  351. if(imagefh != HFILE_ERROR)
  352. {
  353. _lclose(imagefh);
  354. }
  355. switch(error){
  356. case NO_ERROR:
  357. return TRUE;
  358. case ERR_RES_INVALID_ICON:
  359. //SHOW MSG
  360. MessageBox(HwndCrtImeDlg,ERR_INVALID_ICON_MSG, MSG_TITLE, MB_OK | MB_ICONINFORMATION);
  361. return TRUE;
  362. case ERR_RES_NO_ICON:
  363. //SHOW MSG
  364. MessageBox(HwndCrtImeDlg,ERR_NO_ICON_MSG, MSG_TITLE, MB_OK | MB_ICONINFORMATION);
  365. return TRUE;
  366. case ERR_CANNOT_UPRES:
  367. default:
  368. //SHOW MSG
  369. MessageBox(HwndCrtImeDlg,ERR_CANNOT_UPRES_MSG, MSG_TITLE, MB_OK|MB_ICONSTOP);
  370. return FALSE;
  371. }
  372. }
  373. BOOL UpdateImeVerInfo(
  374. LPCTSTR pszImeDesName,
  375. LPCTSTR pszImeVerInfo,
  376. LPCTSTR pszImeDevCorpName,
  377. HANDLE hUpdateRes)
  378. {
  379. BOOL result;
  380. WORD error;
  381. BYTE lpResData[0x2000];
  382. ULONG ResDataSize;
  383. int cch;
  384. LPTSTR p;
  385. error = NO_ERROR;
  386. //begin update version info
  387. if(pszImeVerInfo ==NULL || lstrlen(pszImeVerInfo)==0){
  388. error = ERR_RES_NO_VER;
  389. goto END_ERROR;
  390. }
  391. cch = lstrlen(pszImeDesName);
  392. p = (LPTSTR)pszImeDesName + (INT_PTR)cch;
  393. while ((*(LPUNATCHAR)p) != TEXT('\\') && p >= pszImeDesName)
  394. p--;
  395. p++;
  396. //we assume the size of ver will never over 0x400
  397. ResDataSize = MakeVerInfo(p,pszImeDevCorpName,pszImeVerInfo, lpResData);
  398. if(error == NO_ERROR){
  399. result = UpdateResource(hUpdateRes, /* update resource handle */
  400. RT_VERSION, /* change version resource */
  401. MAKEINTRESOURCE(VS_VERSION_INFO), /* dialog box name */
  402. MAKELANGID(LANG_CHINESE,
  403. SUBLANG_CHINESE_SIMPLIFIED), /* neutral language ID */
  404. lpResData, /* ptr to resource info */
  405. ResDataSize); /* size of resource info. */
  406. if(!result){
  407. error = ERR_CANNOT_UPRES;
  408. goto END_ERROR;
  409. }
  410. }
  411. END_ERROR:
  412. switch(error){
  413. case NO_ERROR:
  414. return TRUE;
  415. case ERR_RES_INVALID_VER:
  416. //SHOW MSG
  417. return TRUE;
  418. case ERR_RES_NO_VER:
  419. //SHOW MSG
  420. return TRUE;
  421. case ERR_CANNOT_UPRES:
  422. default:
  423. //SHOW MSG
  424. MessageBox(HwndCrtImeDlg,ERR_CANNOT_UPRES_MSG, MSG_TITLE, MB_OK|MB_ICONSTOP);
  425. return FALSE;
  426. }
  427. }
  428. BOOL UpdateImeStr(
  429. LPCTSTR pszImeDesName,
  430. LPCTSTR pszImeVerInfo,
  431. LPCTSTR pszImeDevCorpName,
  432. HANDLE hUpdateRes)
  433. {
  434. BOOL result;
  435. WORD error;
  436. TCHAR lpwImeVerInfo[128], lpwImeDevCorpName[128], lpwImeMBName[128];
  437. WORD length;
  438. BYTE lpBuff[0x200];
  439. TCHAR name[20],*p;
  440. INT_PTR cbResSize;
  441. int cch;
  442. error = NO_ERROR;
  443. //begin update version info
  444. if(pszImeVerInfo ==NULL || lstrlen(pszImeVerInfo)==0){
  445. error = ERR_RES_NO_VER;
  446. goto END_ERROR;
  447. }
  448. if(pszImeDevCorpName ==NULL || lstrlen(pszImeDevCorpName)==0){
  449. error = ERR_RES_NO_VER;
  450. goto END_ERROR;
  451. }
  452. if(error == NO_ERROR){
  453. memset(lpBuff, 0, 0x200);
  454. cbResSize = 0;
  455. //write in IDS_VER_INFO
  456. length = (WORD)lstrlen(pszImeVerInfo);
  457. #ifdef UNICODE
  458. lstrcpy(lpwImeVerInfo, pszImeVerInfo);
  459. #else
  460. length = (WORD)MultiByteToWideChar(CP_ACP,
  461. 0,
  462. pszImeVerInfo,
  463. lstrlen(pszImeVerInfo),
  464. lpwImeVerInfo,
  465. length*sizeof(WCHAR));
  466. #endif
  467. memcpy((BYTE *)lpBuff, &length, sizeof(WORD));
  468. cbResSize += sizeof(WORD);
  469. memcpy((BYTE *)(lpBuff+cbResSize),
  470. (BYTE *)lpwImeVerInfo,
  471. length*sizeof(WCHAR));
  472. cbResSize += length*sizeof(WCHAR);
  473. //write in IDS_ORG_NAME
  474. length = (WORD)lstrlen(pszImeDevCorpName);
  475. #ifdef UNICODE
  476. lstrcpy(lpwImeDevCorpName, pszImeDevCorpName);
  477. #else
  478. length = (WORD)MultiByteToWideChar(936,
  479. 0,
  480. pszImeDevCorpName,
  481. lstrlen(pszImeDevCorpName),
  482. lpwImeDevCorpName,
  483. length*sizeof(WCHAR));
  484. #endif
  485. memcpy((BYTE *)(lpBuff+cbResSize), &length, sizeof(WORD));
  486. cbResSize += sizeof(WORD);
  487. memcpy((BYTE *)(lpBuff+cbResSize),
  488. (BYTE *)lpwImeDevCorpName,
  489. length*sizeof(WCHAR));
  490. cbResSize += length*sizeof(WCHAR);
  491. //write in IDS_IMEMBFILENAME
  492. cch = lstrlen(pszImeDesName);
  493. p = (LPTSTR)pszImeDesName+cch;
  494. while (*p != TEXT('\\') && p >= pszImeDesName)
  495. p--;
  496. p++;
  497. lstrcpy(name, p);
  498. p = name;
  499. while(*p != TEXT('.') && *p != TEXT('\0'))
  500. p++;
  501. lstrcpy(p, TEXT(".MB"));
  502. length = (WORD)lstrlen(name);
  503. #ifdef UNICODE
  504. lstrcpy(lpwImeMBName, name);
  505. #else
  506. length = (WORD)MultiByteToWideChar(936,
  507. 0,
  508. name,
  509. lstrlen(name),
  510. lpwImeMBName,
  511. length*sizeof(WCHAR));
  512. #endif
  513. memcpy((BYTE *)(lpBuff+cbResSize), &length, sizeof(WORD));
  514. cbResSize += sizeof(WORD);
  515. memcpy((BYTE *)(lpBuff+cbResSize),
  516. (BYTE *)lpwImeMBName,
  517. length*sizeof(WCHAR));
  518. cbResSize += length*sizeof(WCHAR);
  519. memcpy((BYTE *)(lpBuff+cbResSize), &length, sizeof(WORD));
  520. cbResSize += sizeof(WORD);
  521. memcpy((BYTE *)(lpBuff+cbResSize),
  522. (BYTE *)lpwImeMBName,
  523. length*sizeof(WCHAR));
  524. cbResSize += length*sizeof(WCHAR);
  525. result = UpdateResource(hUpdateRes, // update resource handle
  526. RT_STRING, // change version resource
  527. MAKEINTRESOURCE(STR_ID), // dialog box name
  528. MAKELANGID(LANG_CHINESE,
  529. SUBLANG_CHINESE_SIMPLIFIED),//neutrallanguage ID
  530. (LPVOID)lpBuff, // ptr to resource info
  531. (LONG)cbResSize); // size of resource info.
  532. if(!result){
  533. error = ERR_CANNOT_UPRES;
  534. goto END_ERROR;
  535. }
  536. }
  537. END_ERROR:
  538. switch(error){
  539. case NO_ERROR:
  540. return TRUE;
  541. case ERR_RES_INVALID_VER:
  542. return TRUE;
  543. case ERR_RES_NO_VER:
  544. return TRUE;
  545. case ERR_CANNOT_UPRES:
  546. MessageBox(HwndCrtImeDlg,
  547. ERR_CANNOT_UPRES_MSG,
  548. MSG_TITLE,
  549. MB_OK|MB_ICONSTOP);
  550. return FALSE;
  551. default:
  552. MessageBox(HwndCrtImeDlg,
  553. ERR_CANNOT_UPRES_MSG,
  554. MSG_TITLE,
  555. MB_OK|MB_ICONSTOP);
  556. return FALSE;
  557. }
  558. }
  559. //UPDATE ImeInitData
  560. BOOL UpdateImeInitData(
  561. LPCTSTR pszImeDesName,
  562. WORD wImeData,
  563. HANDLE hUpdateRes)
  564. {
  565. BOOL result;
  566. WORD error;
  567. error = NO_ERROR;
  568. if(error == NO_ERROR){
  569. result = UpdateResource(hUpdateRes, /* update resource handle */
  570. RT_RCDATA, /* change version resource */
  571. DATANAME, /* dialog box name */
  572. MAKELANGID(LANG_CHINESE,
  573. SUBLANG_CHINESE_SIMPLIFIED), /* neutral language ID */
  574. (LPVOID)&wImeData, /* ptr to resource info */
  575. sizeof(WORD)); /* size of resource info. */
  576. if(!result){
  577. error = ERR_CANNOT_UPRES;
  578. goto END_ERROR;
  579. }
  580. }
  581. END_ERROR:
  582. switch(error){
  583. case NO_ERROR:
  584. return TRUE;
  585. case ERR_RES_INVALID_VER:
  586. //SHOW MSG
  587. return TRUE;
  588. case ERR_RES_NO_VER:
  589. //SHOW MSG
  590. return TRUE;
  591. case ERR_CANNOT_UPRES:
  592. default:
  593. //SHOW MSG
  594. MessageBox(HwndCrtImeDlg,ERR_CANNOT_UPRES_MSG, MSG_TITLE, MB_OK|MB_ICONSTOP);
  595. return FALSE;
  596. }
  597. }
  598. BOOL ImeUpdateRes(
  599. LPCTSTR pszImeDesName, //destination IME file name
  600. LPCTSTR pszImeBmpName, //Bitmap file name
  601. LPCTSTR pszImeIconName, //Icon file name
  602. LPCTSTR pszImeVerInfo, //version infomation string
  603. LPCTSTR pszImeDevCorpName, //Ime inventer corp/person name
  604. WORD wImeData //Ime initial data
  605. ){
  606. HANDLE hUpdateRes; /* update resource handle */
  607. if(pszImeDesName == NULL || lstrlen(pszImeDesName)==0){
  608. return FALSE;
  609. }
  610. hUpdateRes = BeginUpdateResource(pszImeDesName, FALSE);
  611. if(hUpdateRes ==NULL){
  612. return FALSE;
  613. }
  614. if(!UpdateImeBmp(pszImeDesName,pszImeBmpName,hUpdateRes))
  615. return FALSE;
  616. if(!UpdateImeIcon(pszImeDesName,pszImeIconName,hUpdateRes))
  617. return FALSE;
  618. if(!UpdateImeVerInfo(pszImeDesName,pszImeVerInfo,pszImeDevCorpName,hUpdateRes))
  619. return FALSE;
  620. if(!UpdateImeStr(pszImeDesName,pszImeVerInfo,pszImeDevCorpName,hUpdateRes))
  621. return FALSE;
  622. if(!UpdateImeInitData(pszImeDesName,wImeData,hUpdateRes))
  623. return FALSE;
  624. if (!EndUpdateResource(hUpdateRes, FALSE)) {
  625. return FALSE;
  626. }
  627. return TRUE;
  628. }