Leaked source code of windows server 2003
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.

1151 lines
34 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <errno.h>
  5. #include <stdlib.h>
  6. #include "windefs.h"
  7. #include "restok.h"
  8. #include "projdata.h"
  9. #include "showerrs.h"
  10. #include "rlmsgtbl.h"
  11. #include "commbase.h"
  12. #include "custres.h"
  13. #include "rlstrngs.h"
  14. #include "resource.h"
  15. #include "resourc2.h"
  16. #include "resread.h"
  17. #include "langlist.h"
  18. #include "exentres.h"
  19. extern MSTRDATA gMstr;
  20. extern PROJDATA gProj;
  21. extern UCHAR szDHW[];
  22. extern BOOL fCodePageGiven;
  23. extern BOOL gfReplace;
  24. extern HWND hMainWnd;
  25. BOOL bRLGui; //FALSE=RLMan TRUE=RLAdmin RLEdit RLquiked
  26. #ifdef RLRES32
  27. extern PLANGLIST pLangIDList;
  28. #endif
  29. static PLANGDATA pLangList = NULL;
  30. //............................................................
  31. //...RLtools are localized so we would like
  32. //...to get correct locale's Version stamp
  33. BOOL MyVerQueryValue(
  34. LPVOID pBlock,
  35. LPTSTR lpSubBlock,
  36. LPVOID *lplpBuffer,
  37. PUINT puLen)
  38. {
  39. LPWORD lpXlate; // ptr to translations data
  40. DWORD cbValueTranslation=0;
  41. TCHAR szVersionKey[60]; // big enough for anything we need
  42. if( VerQueryValue( pBlock, TEXT("\\VarFileInfo\\Translation"),
  43. (LPVOID*)&lpXlate, &cbValueTranslation) )
  44. {
  45. wsprintf( szVersionKey, TEXT("\\StringFileInfo\\%04X04B0\\%s"),
  46. *lpXlate, lpSubBlock );
  47. if( VerQueryValue ( pBlock, szVersionKey, lplpBuffer, puLen) )
  48. return TRUE;
  49. }
  50. wsprintf( szVersionKey, TEXT("\\StringFileInfo\\%04X04B0\\%s"),
  51. LANGIDFROMLCID(GetThreadLocale()), lpSubBlock );
  52. if( !VerQueryValue (pBlock, szVersionKey, lplpBuffer, puLen) )
  53. {
  54. wsprintf( szVersionKey, TEXT("\\StringFileInfo\\040904B0\\%s"),
  55. lpSubBlock );
  56. if( !VerQueryValue (pBlock, szVersionKey, lplpBuffer, puLen) )
  57. return FALSE;
  58. }
  59. return TRUE;
  60. }
  61. int GetMasterProjectData(
  62. CHAR * pszMasterFile, //... Master Project file name
  63. CHAR * pszSrc, //... Resource source file name or NULL
  64. CHAR * pszMtk, //... Master token file name or NULL
  65. BOOL fLanguageGiven)
  66. {
  67. int nRC = SUCCESS; //... Return code
  68. //... check for the special case where Master
  69. //... Project File does not exist. If it doesn't
  70. //... go ahead and create it.
  71. memset(&gMstr, '\0', sizeof(gMstr));
  72. if ( _access( pszMasterFile, 0) != 0 )
  73. {
  74. if ( ! (pszSrc && pszMtk) )
  75. {
  76. ShowErr( IDS_ERR_03, pszMasterFile, NULL);
  77. nRC = IDS_ERR_03;
  78. }
  79. else
  80. {
  81. //... Get source resource file name
  82. if ( _fullpath( gMstr.szSrc, pszSrc, sizeof( gMstr.szSrc)-1) )
  83. {
  84. //... Get Master token file name and its
  85. //... modification date. Use that same date as
  86. //... the initial date the master project was
  87. //... last updated.
  88. if ( _fullpath( gMstr.szMtk, pszMtk, sizeof( gMstr.szMtk)-1) )
  89. {
  90. SzDateFromFileName( gMstr.szSrcDate, gMstr.szSrc);
  91. lstrcpyA( gMstr.szMpjLastRealUpdate, gMstr.szSrcDate);
  92. //... Create the new Master Project file.
  93. nRC = PutMasterProjectData( pszMasterFile);
  94. }
  95. else
  96. {
  97. ShowErr( IDS_ERR_13, pszMtk, NULL);
  98. nRC = IDS_ERR_13;
  99. }
  100. }
  101. else
  102. {
  103. ShowErr( IDS_ERR_13, pszSrc, NULL);
  104. nRC = IDS_ERR_13;
  105. }
  106. }
  107. }
  108. else
  109. {
  110. FILE *pfMpj = NULL;
  111. if ( (pfMpj = fopen( pszMasterFile, "rt")) == NULL )
  112. {
  113. ShowErr( IDS_ERR_07, pszMasterFile, NULL);
  114. nRC = IDS_ERR_07;
  115. }
  116. else
  117. {
  118. //... Get resource source file name
  119. //... and master token file name
  120. if ( fgets( gMstr.szSrc, sizeof( gMstr.szSrc), pfMpj)
  121. && fgets( gMstr.szMtk, sizeof( gMstr.szMtk), pfMpj) )
  122. {
  123. //... Make sure these two files exist
  124. if ( pszSrc )
  125. {
  126. if ( !_fullpath(gMstr.szSrc,pszSrc,sizeof( gMstr.szSrc)-1) )
  127. {
  128. ShowErr( IDS_ERR_07, pszSrc, NULL);
  129. fclose( pfMpj );
  130. return( IDS_ERR_07 );
  131. }
  132. }
  133. if ( pszMtk )
  134. {
  135. if ( !_fullpath(gMstr.szMtk,pszMtk,sizeof( gMstr.szMtk)-1) )
  136. {
  137. ShowErr( IDS_ERR_07, pszMtk, NULL);
  138. fclose( pfMpj );
  139. return( IDS_ERR_07 );
  140. }
  141. }
  142. //... If -c flag not given, get RDF file name
  143. //... from master project file, else use name
  144. //... from the -c cmd line arg.
  145. if ( gMstr.szRdfs[0] == '\0' )
  146. {
  147. if ( ! fgets( gMstr.szRdfs, sizeof( gMstr.szRdfs), pfMpj) )
  148. {
  149. ShowErr( IDS_ERR_21,
  150. "Master Project",
  151. pszMasterFile);
  152. nRC = IDS_ERR_21;
  153. }
  154. }
  155. else
  156. {
  157. if ( ! fgets( szDHW, DHWSIZE, pfMpj) )
  158. {
  159. ShowErr( IDS_ERR_21,
  160. "Master Project",
  161. pszMasterFile);
  162. nRC = IDS_ERR_21;
  163. }
  164. }
  165. //... Get stored date of source file and
  166. //... date of last master token file update
  167. if ( nRC == 0
  168. && fgets( gMstr.szSrcDate, sizeof( gMstr.szSrcDate), pfMpj)
  169. && fgets( gMstr.szMpjLastRealUpdate,
  170. sizeof( gMstr.szMpjLastRealUpdate),
  171. pfMpj) )
  172. {
  173. WORD wPriID = 0;
  174. WORD wSubID = 0;
  175. UINT uTmpCP = 0;
  176. //... Strip any trailing new-lines from data
  177. StripNewLineA( gMstr.szSrc);
  178. StripNewLineA( gMstr.szMpjLastRealUpdate);
  179. StripNewLineA( gMstr.szMtk);
  180. StripNewLineA( gMstr.szRdfs);
  181. StripNewLineA( gMstr.szSrcDate);
  182. //... Try to get the.MPJ file's Language line.
  183. //... If we find it and the -i arg was not
  184. //... given, use the one found in the file.
  185. if ( fgets( szDHW, DHWSIZE, pfMpj) != NULL //... CP line
  186. && sscanf( szDHW, "Language %hx %hx", &wPriID, &wSubID) == 2 )
  187. {
  188. WORD wTmpID = 0;
  189. wTmpID = MAKELANGID( wPriID, wSubID);
  190. if ( ! fLanguageGiven )
  191. {
  192. gMstr.wLanguageID = wTmpID;
  193. }
  194. }
  195. //... Try to get the.MPJ file's Code Page line.
  196. //... If we find it and the -p arg was not
  197. //... given, use the one found in the file.
  198. if ( fgets( szDHW, DHWSIZE, pfMpj) != NULL //... CP line
  199. && sscanf( szDHW, "CodePage %u", &uTmpCP) == 1 )
  200. {
  201. if ( uTmpCP != gProj.uCodePage && ! fCodePageGiven )
  202. {
  203. gMstr.uCodePage = uTmpCP;
  204. }
  205. }
  206. nRC = SUCCESS;
  207. }
  208. else
  209. {
  210. ShowErr( IDS_ERR_21,
  211. "Master Project",
  212. pszMasterFile);
  213. nRC = IDS_ERR_21;
  214. }
  215. }
  216. else
  217. {
  218. ShowErr( IDS_ERR_22, pszMasterFile, NULL);
  219. nRC = IDS_ERR_22;
  220. }
  221. fclose( pfMpj);
  222. }
  223. }
  224. return( nRC);
  225. }
  226. //............................................................
  227. int PutMasterProjectData(
  228. CHAR *pszMasterFile) //... Master Project File name
  229. {
  230. int nRC = SUCCESS;
  231. FILE *pfMpj = NULL;
  232. if ( (pfMpj = fopen( pszMasterFile, "wt")) == NULL )
  233. {
  234. ShowErr( IDS_ERR_06, pszMasterFile, NULL);
  235. nRC = -1;
  236. }
  237. else
  238. {
  239. fprintf( pfMpj, "%s\n%s\n%s\n%s\n%s\nLanguage %#04hx %#04hx\nCodePage %u",
  240. gMstr.szSrc,
  241. gMstr.szMtk,
  242. gMstr.szRdfs,
  243. gMstr.szSrcDate,
  244. gMstr.szMpjLastRealUpdate,
  245. PRIMARYLANGID( gMstr.wLanguageID),
  246. SUBLANGID( gMstr.wLanguageID),
  247. gMstr.uCodePage);
  248. fclose( pfMpj);
  249. }
  250. return( nRC);
  251. }
  252. //............................................................
  253. int GetProjectData(
  254. CHAR *pszPrj, //... Project file name
  255. CHAR *pszMpj, //... Master Project file name or NULL
  256. CHAR *pszTok, //... Project token file name or NULL
  257. BOOL fCodePageGiven,
  258. BOOL fLanguageGiven)
  259. {
  260. int nRC = SUCCESS;
  261. int iUpdate = 0;
  262. if ( _access( pszPrj, 0) != 0 )
  263. {
  264. if ( ! (pszMpj && pszTok) )
  265. {
  266. ShowErr( IDS_ERR_19, pszPrj, NULL);
  267. Usage();
  268. nRC = IDS_ERR_19;
  269. }
  270. else if ( ! fLanguageGiven )
  271. {
  272. ShowErr( IDS_ERR_24, pszPrj, NULL);
  273. Usage();
  274. nRC = IDS_ERR_24;
  275. }
  276. else
  277. {
  278. if ( _fullpath( gProj.szMpj,
  279. pszMpj,
  280. sizeof( gProj.szMpj)-1) )
  281. {
  282. if ( _fullpath( gProj.szTok,
  283. pszTok,
  284. sizeof( gProj.szTok)-1) )
  285. {
  286. nRC = SUCCESS;
  287. }
  288. else
  289. {
  290. ShowErr( IDS_ERR_13, pszTok, NULL);
  291. nRC = IDS_ERR_13;
  292. }
  293. }
  294. else
  295. {
  296. ShowErr( IDS_ERR_13, pszMpj, NULL);
  297. nRC = IDS_ERR_13;
  298. }
  299. }
  300. }
  301. else
  302. {
  303. FILE *fpPrj = fopen( pszPrj, "rt");
  304. if ( fpPrj != NULL )
  305. {
  306. if ( fgets( gProj.szMpj, sizeof( gProj.szMpj), fpPrj)
  307. && fgets( gProj.szTok, sizeof( gProj.szTok), fpPrj)
  308. && fgets( gProj.szGlo, sizeof( gProj.szGlo), fpPrj)
  309. && fgets( gProj.szTokDate, sizeof( gProj.szTokDate), fpPrj) )
  310. {
  311. UINT uTmpCP = 0;
  312. WORD wPriID = 0;
  313. WORD wSubID = 0;
  314. //... If named, make sure MPJ and TOK files exist
  315. if ( pszMpj )
  316. {
  317. if ( !_fullpath( gProj.szMpj, pszMpj, sizeof( gProj.szMpj)-1) )
  318. {
  319. ShowErr( IDS_ERR_21, pszMpj, NULL);
  320. fclose( fpPrj );
  321. return( IDS_ERR_21);
  322. }
  323. }
  324. if ( pszTok )
  325. {
  326. if ( !_fullpath( gProj.szTok, pszTok, sizeof( gProj.szTok)-1) )
  327. {
  328. ShowErr( IDS_ERR_21, pszTok, NULL);
  329. fclose( fpPrj );
  330. return( IDS_ERR_21);
  331. }
  332. }
  333. StripNewLineA( gProj.szMpj);
  334. StripNewLineA( gProj.szTok);
  335. StripNewLineA( gProj.szGlo);
  336. StripNewLineA( gProj.szTokDate);
  337. //... Try to get the.PRJ file's Code Page line.
  338. //... If we find it and the -p arg was not
  339. //... given, use the one found in the file.
  340. if ( ! fgets( szDHW, DHWSIZE, fpPrj) ) //... CP line
  341. {
  342. iUpdate++;
  343. }
  344. else if ( sscanf( szDHW, "CodePage %u", &uTmpCP) == 1 )
  345. {
  346. if ( uTmpCP != gProj.uCodePage && ! fCodePageGiven )
  347. {
  348. gProj.uCodePage = uTmpCP;
  349. }
  350. }
  351. //... Try to get the.PRJ file's Language line.
  352. //... If we find it and the -i arg was not
  353. //... given, use the one found in the file.
  354. if ( ! fgets( szDHW, DHWSIZE, fpPrj) ) //... LANGID line
  355. {
  356. iUpdate++;
  357. }
  358. else if ( sscanf( szDHW, "Language %hx %hx", &wPriID, &wSubID) == 2 )
  359. {
  360. WORD wTmpID = 0;
  361. wTmpID = MAKELANGID( wPriID, wSubID);
  362. if ( ! fLanguageGiven )
  363. {
  364. gProj.wLanguageID = wTmpID;
  365. }
  366. }
  367. //... Try to get the.PRJ file's Target File line
  368. if ( fgets( szDHW, DHWSIZE, fpPrj) != NULL )
  369. {
  370. lstrcpyA( gProj.szBld, szDHW);
  371. StripNewLineA( gProj.szBld);
  372. }
  373. //... Try to get the.PRJ file's append/replace line
  374. if ( fgets( szDHW, DHWSIZE, fpPrj) != NULL )
  375. {
  376. gfReplace = (*szDHW == 'R') ? TRUE : FALSE;
  377. }
  378. else
  379. {
  380. gfReplace = TRUE;
  381. }
  382. nRC = SUCCESS;
  383. if ( iUpdate )
  384. {
  385. static TCHAR title[50];
  386. static TCHAR szMes[100];
  387. if ( bRLGui )
  388. {
  389. //Ask Update prj for 1.7? //RLadmin RLedit RLquiked
  390. LoadString( NULL,
  391. IDS_UPDATE_YESNO,
  392. szMes,
  393. TCHARSIN( sizeof( szMes)) );
  394. LoadString( NULL,
  395. IDS_UPDATE_TITLE,
  396. title,
  397. TCHARSIN( sizeof( title)) );
  398. if ( MessageBox( hMainWnd,
  399. szMes,title,
  400. MB_ICONQUESTION|MB_YESNO) == IDNO )
  401. {
  402. //User says no, then finish the job.
  403. LoadString( NULL,
  404. IDS_UPDATE_CANCEL,
  405. szMes,
  406. TCHARSIN( sizeof( szMes)) );
  407. MessageBox( hMainWnd,
  408. szMes,
  409. title,
  410. MB_ICONSTOP|MB_OK);
  411. //bye!
  412. nRC = IDS_UPDATE_CANCEL;
  413. }
  414. else
  415. {
  416. //replace Glossary <=> Bins
  417. lstrcpyA( szDHW, gProj.szGlo );
  418. lstrcpyA( gProj.szGlo, gProj.szBld );
  419. lstrcpyA( gProj.szBld, szDHW );
  420. }
  421. }
  422. else //For RLMan
  423. {
  424. //Update Message
  425. RLMessageBoxA( "Updating 1.0 files..." );
  426. //replace Glossary <=> Bins
  427. lstrcpyA( szDHW, gProj.szGlo );
  428. lstrcpyA( gProj.szGlo, gProj.szBld );
  429. lstrcpyA( gProj.szBld, szDHW );
  430. }
  431. }
  432. }
  433. else
  434. {
  435. ShowErr( IDS_ERR_21, pszPrj, NULL);
  436. nRC = IDS_ERR_21;
  437. }
  438. fclose( fpPrj);
  439. }
  440. else
  441. {
  442. ShowErr( IDS_ERR_19, pszPrj, NULL);
  443. nRC = IDS_ERR_19;
  444. }
  445. }
  446. return( nRC);
  447. }
  448. //............................................................
  449. int PutProjectData(
  450. CHAR *pszPrj) //... Project file name
  451. {
  452. int nRC = 0;
  453. FILE *fpPrj = NULL;
  454. fpPrj = fopen( pszPrj, "wt");
  455. if ( fpPrj != NULL )
  456. {
  457. fprintf( fpPrj,
  458. "%s\n%s\n%s\n%s\nCodePage %u\nLanguage %#04x %#04x\n%s\n%s",
  459. gProj.szMpj, // Master Project file
  460. gProj.szTok, // Project Token file
  461. gProj.szGlo, // Project Glossary file
  462. gProj.szTokDate, // Date token file changed
  463. gProj.uCodePage, // Code Page of token file
  464. PRIMARYLANGID( gProj.wLanguageID), // Project resource language
  465. SUBLANGID( gProj.wLanguageID),
  466. gProj.szBld, // Project target file
  467. gfReplace ? "Replace" : "Append"); // Replace master lang?
  468. fclose( fpPrj);
  469. _fullpath( gProj.szPRJ, pszPrj, sizeof( gProj.szPRJ)-1);
  470. }
  471. else
  472. {
  473. ShowErr( IDS_ERR_21, pszPrj, NULL);
  474. nRC = IDS_ERR_21;
  475. }
  476. return( nRC);
  477. }
  478. //............................................................
  479. WORD GetCopyright(
  480. CHAR *pszProg, //... Program name (argv[0])
  481. CHAR *pszOutBuf, //... Buffer for results
  482. WORD wBufLen) //... Length of pszOutBuf
  483. {
  484. BOOL fRC = FALSE;
  485. DWORD dwRC = 0L;
  486. DWORD dwVerSize = 0L; //... Size of file version info buffer
  487. LPSTR *plpszFile = NULL;
  488. LPSTR pszExt = NULL;
  489. WCHAR *pszVer = NULL;
  490. PVOID lpVerBuf = NULL; //... Version info buffer
  491. static CHAR szFile[ MAXFILENAME+3] = "";
  492. //... Figure out the full-path name of prog
  493. //... so GetFileVersionInfoSize() will work.
  494. dwRC = lstrlenA( pszProg);
  495. if ( dwRC < 4 || lstrcmpiA( &pszProg[ dwRC - 4], ".exe") != 0 )
  496. {
  497. pszExt = ".exe";
  498. }
  499. dwRC = SearchPathA( NULL, pszProg, pszExt, sizeof( szFile), szFile, plpszFile);
  500. if ( dwRC == 0 )
  501. {
  502. return( IDS_ERR_25);
  503. }
  504. else if ( dwRC > sizeof( szFile) )
  505. {
  506. return( IDS_ERR_27);
  507. }
  508. // append the extension since SearchPath will not return it
  509. // if we have no extensio then a directory with the same name was returned
  510. // try to append the ext and hope that file will be there
  511. if ( lstrcmpiA( &szFile[dwRC - 4], ".exe") != 0 )
  512. {
  513. lstrcatA( szFile, pszExt );
  514. }
  515. //... Get # bytes in file version info
  516. if ( (dwVerSize = GetFileVersionInfoSizeA( szFile, &dwRC)) == 0L )
  517. {
  518. return( IDS_ERR_26);
  519. }
  520. lpVerBuf = (LPVOID)FALLOC( dwVerSize);
  521. //... Retrieve version info
  522. //... and get the file description
  523. if ( (dwRC = GetFileVersionInfoA( szFile, 0L, dwVerSize, lpVerBuf)) == 0L )
  524. {
  525. RLFREE( lpVerBuf);
  526. return( IDS_ERR_26);
  527. }
  528. if ( (fRC = MyVerQueryValue( lpVerBuf,
  529. TEXT("FileDescription"),
  530. &pszVer,
  531. &dwVerSize)) == FALSE
  532. || (dwRC = WideCharToMultiByte( CP_ACP,
  533. 0,
  534. pszVer,
  535. dwVerSize,
  536. pszOutBuf,
  537. dwVerSize,
  538. NULL,
  539. NULL)) == 0L )
  540. {
  541. RLFREE( lpVerBuf);
  542. return( IDS_ERR_26);
  543. }
  544. strcat( pszOutBuf, " ");
  545. //... Get the file version
  546. if ( (fRC = MyVerQueryValue( lpVerBuf,
  547. TEXT("ProductVersion"),
  548. &pszVer,
  549. &dwVerSize)) == FALSE
  550. || (dwRC = WideCharToMultiByte( CP_ACP,
  551. 0,
  552. pszVer,
  553. dwVerSize,
  554. &pszOutBuf[ lstrlenA( pszOutBuf)],
  555. dwVerSize,
  556. NULL,
  557. NULL)) == 0L )
  558. {
  559. RLFREE( lpVerBuf);
  560. return( IDS_ERR_26);
  561. }
  562. strcat( pszOutBuf, "\n");
  563. //... Get the copyright statement
  564. if ( (fRC = MyVerQueryValue( lpVerBuf,
  565. TEXT("LegalCopyright"),
  566. &pszVer,
  567. &dwVerSize)) == FALSE
  568. || (dwRC = WideCharToMultiByte( CP_ACP,
  569. 0,
  570. pszVer,
  571. dwVerSize,
  572. &pszOutBuf[ lstrlenA( pszOutBuf)],
  573. dwVerSize,
  574. NULL,
  575. NULL)) == 0L )
  576. {
  577. RLFREE( lpVerBuf);
  578. return( IDS_ERR_26);
  579. }
  580. RLFREE( lpVerBuf);
  581. return( SUCCESS);
  582. }
  583. //............................................................
  584. WORD GetInternalName(
  585. CHAR *pszProg, //... Program name (argv[0])
  586. CHAR *pszOutBuf, //... Buffer for results
  587. WORD wBufLen) //... Length of pszOutBuf
  588. {
  589. BOOL fRC = FALSE;
  590. DWORD dwRC = 0L;
  591. DWORD dwVerSize = 0L; //... Size of file version info buffer
  592. LPSTR *plpszFile = NULL;
  593. LPSTR pszExt = NULL;
  594. WCHAR *pszVer = NULL;
  595. PVOID lpVerBuf = NULL; //... Version info buffer
  596. static CHAR szFile[ MAXFILENAME+3] = "";
  597. //... Figure out the full-path name of prog
  598. //... so GetFileVersionInfoSize() will work.
  599. dwRC = lstrlenA( pszProg);
  600. if ( dwRC < 4 || lstrcmpiA( &pszProg[ dwRC - 4], ".exe") != 0 )
  601. {
  602. pszExt = ".exe";
  603. }
  604. dwRC = SearchPathA( NULL, pszProg, pszExt, sizeof( szFile), szFile, plpszFile);
  605. if ( dwRC == 0 )
  606. {
  607. return( IDS_ERR_25);
  608. }
  609. else if ( dwRC > sizeof( szFile) )
  610. {
  611. return( IDS_ERR_27);
  612. }
  613. //... Get # bytes in file version info
  614. if ( (dwVerSize = GetFileVersionInfoSizeA( szFile, &dwVerSize)) == 0L )
  615. {
  616. return( IDS_ERR_26);
  617. }
  618. lpVerBuf = (LPVOID)FALLOC( dwVerSize);
  619. //... Retrieve version info
  620. //... and get the file description
  621. if ( (dwRC = GetFileVersionInfoA( szFile, 0L, dwVerSize, lpVerBuf)) == 0L )
  622. {
  623. RLFREE( lpVerBuf);
  624. return( IDS_ERR_26);
  625. }
  626. if ( (fRC = MyVerQueryValue( lpVerBuf,
  627. TEXT("InternalName"),
  628. &pszVer,
  629. &dwVerSize)) == FALSE
  630. || (dwRC = WideCharToMultiByte( CP_ACP,
  631. 0,
  632. pszVer,
  633. dwVerSize,
  634. pszOutBuf,
  635. dwVerSize,
  636. NULL,
  637. NULL)) == 0L )
  638. {
  639. RLFREE( lpVerBuf);
  640. return( IDS_ERR_26);
  641. }
  642. RLFREE( lpVerBuf);
  643. return( SUCCESS);
  644. }
  645. //............................................................
  646. int MyAtoi( CHAR *pStr)
  647. {
  648. if ( lstrlenA( pStr) > 2
  649. && pStr[0] == '0'
  650. && tolower( pStr[1]) == 'x' )
  651. {
  652. return( atoihex( &pStr[2])); //... in custres.c
  653. }
  654. else
  655. {
  656. return( atoi( pStr));
  657. }
  658. }
  659. //DWORD GetLanguageID( HWND hDlg, PMSTRDATA pMaster, PPROJDATA pProject)
  660. //{
  661. // DWORD dwRC = SUCCESS; //... Assume success
  662. // WORD wPriLangID = 0;
  663. // WORD wSubLangID = 0;
  664. //
  665. //
  666. // if ( pMaster )
  667. // {
  668. // GetDlgItemTextA( hDlg, IDD_PRI_LANG_ID, szDHW, DHWSIZE);
  669. // wPriLangID = MyAtoi( szDHW);
  670. //
  671. // GetDlgItemTextA( hDlg, IDD_SUB_LANG_ID, szDHW, DHWSIZE);
  672. // wSubLangID = MyAtoi( szDHW);
  673. //
  674. // pMaster->wLanguageID = MAKELANGID( wPriLangID, wSubLangID);
  675. // }
  676. //
  677. // if ( pProject )
  678. // {
  679. // GetDlgItemTextA( hDlg, IDD_PROJ_PRI_LANG_ID, szDHW, DHWSIZE);
  680. // wPriLangID = MyAtoi( szDHW);
  681. //
  682. // GetDlgItemTextA( hDlg, IDD_PROJ_SUB_LANG_ID, szDHW, DHWSIZE);
  683. // wSubLangID = MyAtoi( szDHW);
  684. //
  685. // pProject->wLanguageID = MAKELANGID( wPriLangID, wSubLangID);
  686. // }
  687. // return( dwRC);
  688. //}
  689. //.................................................................
  690. //... Set the language component names into the dlg box fields
  691. //
  692. //DWORD SetLanguageID( HWND hDlg, PMSTRDATA pMaster, PPROJDATA pProject)
  693. //{
  694. // DWORD dwRC = SUCCESS; //... Assume success
  695. // WORD wPriLangID = 0;
  696. // WORD wSubLangID = 0;
  697. // LPTSTR pszLangName = NULL;
  698. //
  699. // //... Did we already load the data from
  700. // //... the resources? If not, do so now.
  701. // if ( ! pLangList )
  702. // {
  703. // pLangList = GetLangList();
  704. // }
  705. //
  706. // if ( pMaster )
  707. // {
  708. // wPriLangID = PRIMARYLANGID( pMaster->wLanguageID);
  709. // wSubLangID = SUBLANGID( pMaster->wLanguageID);
  710. //
  711. // if ( (pszLangName = GetLangName( wPriLangID, wSubLangID)) )
  712. // {
  713. // SetDlgItemText( hDlg, IDD_MSTR_LANG_NAME, pszLangName);
  714. // }
  715. // sprintf( szDHW, "%#04x", wPriLangID);
  716. // SetDlgItemTextA( hDlg, IDD_PRI_LANG_ID, szDHW);
  717. //
  718. // sprintf( szDHW, "%#04x", wSubLangID);
  719. // SetDlgItemTextA( hDlg, IDD_SUB_LANG_ID, szDHW);
  720. // }
  721. //
  722. // if ( pProject )
  723. // {
  724. // wPriLangID = PRIMARYLANGID( pProject->wLanguageID);
  725. // wSubLangID = SUBLANGID( pProject->wLanguageID);
  726. //
  727. // if ( (pszLangName = GetLangName( wPriLangID, wSubLangID)) )
  728. // {
  729. // SetDlgItemText( hDlg, IDD_PROJ_LANG_NAME, pszLangName);
  730. // }
  731. // sprintf( szDHW, "%#04x", wPriLangID);
  732. // SetDlgItemTextA( hDlg, IDD_PROJ_PRI_LANG_ID, szDHW);
  733. //
  734. // sprintf( szDHW, "%#04x", wSubLangID);
  735. // SetDlgItemTextA( hDlg, IDD_PROJ_SUB_LANG_ID, szDHW);
  736. // }
  737. // return( dwRC);
  738. //}
  739. //...............................................................
  740. //...
  741. //... Build the list of Language names and component ID values
  742. PLANGDATA GetLangList( void)
  743. {
  744. PLANGDATA pRC = NULL;
  745. HRSRC hResource = FindResourceEx( NULL,
  746. (LPCTSTR)RT_RCDATA,
  747. (LPCTSTR)ID_LANGID_LIST,
  748. MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL));
  749. if ( hResource )
  750. {
  751. HGLOBAL hRes = LoadResource( NULL, hResource);
  752. if ( hRes )
  753. {
  754. PBYTE pRes = (PBYTE)LockResource( hRes);
  755. if ( pRes )
  756. {
  757. int nNameLen = 0;
  758. PLANGDATA pTmp = NULL;
  759. nNameLen = lstrlenA( (LPSTR)pRes);
  760. pRC = (PLANGDATA)FALLOC( sizeof( LANGDATA));
  761. pTmp = pRC;
  762. while ( nNameLen )
  763. {
  764. MultiByteToWideChar( CP_ACP,
  765. MB_PRECOMPOSED,
  766. (LPSTR)pRes,
  767. -1,
  768. pTmp->szLangName,
  769. NAMELENBUFSIZE - 1);
  770. pRes += ++nNameLen;
  771. pTmp->wPriLang = MAKEWORD( *pRes, *(pRes+1) );
  772. pRes += sizeof(WORD);
  773. pTmp->wSubLang = MAKEWORD( *pRes, *(pRes+1) );
  774. pRes += sizeof(WORD);
  775. if ( (nNameLen = lstrlenA( (LPSTR)pRes)) )
  776. {
  777. PLANGDATA pNew = (PLANGDATA)FALLOC( sizeof( LANGDATA));
  778. pTmp->pNext = pNew;
  779. pTmp = pNew;
  780. }
  781. } //... END while( nNameLen )
  782. } //... END if ( pRes )
  783. else
  784. {
  785. DWORD dwErr = GetLastError();
  786. }
  787. } //... END if ( hRes )
  788. else
  789. {
  790. DWORD dwErr = GetLastError();
  791. }
  792. } //... END if ( hSrc )
  793. else
  794. {
  795. DWORD dwErr = GetLastError();
  796. }
  797. return( pRC);
  798. }
  799. //...............................................................
  800. //...
  801. //... Return the name of a language based on the given components
  802. LPTSTR GetLangName( WORD wPriLangID, WORD wSubLangID)
  803. {
  804. LPTSTR pszRC = NULL;
  805. PLANGDATA pLang = NULL;
  806. if ( ! pLangList )
  807. {
  808. pLangList = GetLangList();
  809. }
  810. for ( pLang = pLangList; pLang && ! pszRC; pLang = pLang->pNext )
  811. {
  812. if ( pLang->wPriLang == wPriLangID && pLang->wSubLang == wSubLangID )
  813. {
  814. pszRC = pLang->szLangName;
  815. }
  816. }
  817. return( pszRC);
  818. }
  819. //...............................................................
  820. //...
  821. //... Return the language ID components based on the given name
  822. BOOL GetLangIDs( LPTSTR pszName, PWORD pwPri, PWORD pwSub )
  823. {
  824. BOOL fRC = FALSE;
  825. PLANGDATA pLang = NULL;
  826. if ( ! pLangList )
  827. {
  828. pLangList = GetLangList();
  829. }
  830. for ( pLang = pLangList; pLang && ! fRC; pLang = pLang->pNext )
  831. {
  832. if ( lstrcmp( pLang->szLangName, pszName) == 0 )
  833. {
  834. *pwPri = pLang->wPriLang;
  835. *pwSub = pLang->wSubLang;
  836. fRC = TRUE;
  837. }
  838. }
  839. return( fRC);
  840. }
  841. //...............................................................
  842. //...
  843. //... Fill the given combobox with the names of supported the languages.
  844. LONG FillLangNameBox( HWND hDlg, int nControl)
  845. {
  846. PLANGDATA pLang = NULL;
  847. PLANGLIST pID = NULL;
  848. LONG lRC = -1;
  849. BOOL fListIt = TRUE;
  850. WORD wAddLang = 0;
  851. if ( nControl == IDD_MSTR_LANG_NAME )
  852. {
  853. if ( GetListOfResLangIDs( gMstr.szSrc) != SUCCESS )
  854. {
  855. return( lRC);
  856. }
  857. }
  858. if ( ! pLangList )
  859. {
  860. pLangList = GetLangList();
  861. }
  862. for ( pLang = pLangList; pLang; pLang = pLang->pNext )
  863. {
  864. fListIt = TRUE;
  865. if ( nControl == IDD_MSTR_LANG_NAME )
  866. {
  867. wAddLang = MAKELANGID( pLang->wPriLang, pLang->wSubLang);
  868. fListIt = FALSE;
  869. for ( pID = pLangIDList; pID; pID = pID->pNext )
  870. {
  871. if ( pID->wLang == wAddLang )
  872. {
  873. fListIt = TRUE;
  874. break;
  875. }
  876. }
  877. }
  878. if ( fListIt )
  879. {
  880. lRC = (LONG)SendDlgItemMessage( hDlg,
  881. nControl,
  882. CB_ADDSTRING,
  883. 0,
  884. (LPARAM)pLang->szLangName);
  885. if ( lRC == CB_ERR || lRC == CB_ERRSPACE )
  886. {
  887. QuitT( IDS_ERR_16, NULL, NULL);
  888. }
  889. }
  890. }
  891. if ( nControl == IDD_MSTR_LANG_NAME )
  892. {
  893. FreeLangIDList();
  894. }
  895. return( lRC);
  896. }
  897. void FreeLangList( void)
  898. {
  899. PLANGDATA pTmp = NULL;
  900. while ( pLangList )
  901. {
  902. pTmp = pLangList->pNext;
  903. RLFREE( pLangList);
  904. pLangList = pTmp;
  905. }
  906. #ifdef RLRES32
  907. FreeLangIDList();
  908. #endif
  909. }
  910. //...................................................................
  911. void FillListAndSetLang(
  912. HWND hDlg,
  913. WORD wLangNameList, //... IDD_MSTR_LANG_NAME or IDD_PROJ_LANG_NAME
  914. WORD *pLangID, //... Ptr to gMstr.wLanguageID or gProj.wLanguageID
  915. BOOL *pfSelected) //... Did we select a language here? (Can be NULL)
  916. {
  917. int nSel = FillLangNameBox( hDlg, wLangNameList);
  918. if ( nSel > 0L )
  919. {
  920. LPTSTR pszLangName = NULL;
  921. //... See if the default master language is in the list
  922. if ( (pszLangName = GetLangName( (WORD)(PRIMARYLANGID( *pLangID)),
  923. (WORD)(SUBLANGID( *pLangID)))) != NULL )
  924. {
  925. if ( (nSel = (int)SendDlgItemMessage( hDlg,
  926. wLangNameList,
  927. CB_FINDSTRINGEXACT,
  928. (WPARAM)-1,
  929. (LPARAM)pszLangName)) != CB_ERR )
  930. {
  931. //... default master language is in list
  932. SendDlgItemMessage( hDlg,
  933. wLangNameList,
  934. CB_SETCURSEL,
  935. (WPARAM)nSel,
  936. (LPARAM)0);
  937. if ( pfSelected )
  938. {
  939. *pfSelected = TRUE;
  940. }
  941. }
  942. }
  943. }
  944. else if ( nSel == 0 )
  945. {
  946. //... Use first entry in the list
  947. SendDlgItemMessage( hDlg,
  948. wLangNameList,
  949. CB_SETCURSEL,
  950. (WPARAM)nSel,
  951. (LPARAM)0);
  952. if ( (nSel = (int)SendDlgItemMessage( hDlg,
  953. wLangNameList,
  954. CB_GETLBTEXT,
  955. (WPARAM)nSel,
  956. (LPARAM)(LPTSTR)szDHW)) != CB_ERR )
  957. {
  958. WORD wPri = 0;
  959. WORD wSub = 0;
  960. if ( GetLangIDs( (LPTSTR)szDHW, &wPri, &wSub) )
  961. {
  962. *pLangID = MAKELANGID( wPri, wSub);
  963. if ( pfSelected )
  964. {
  965. *pfSelected = TRUE;
  966. }
  967. }
  968. else
  969. {
  970. nSel = CB_ERR;
  971. }
  972. }
  973. }
  974. if ( nSel == CB_ERR )
  975. {
  976. SetDlgItemText( hDlg, wLangNameList, TEXT("UNKNOWN"));
  977. }
  978. }