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.

588 lines
17 KiB

  1. //........................................................................
  2. //...
  3. //... RLMAN.C
  4. //...
  5. //... Contains 'main' for rlman.exe.
  6. //........................................................................
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #ifdef RLDOS
  10. #include "dosdefs.h"
  11. #else
  12. #include <windows.h>
  13. #include "windefs.h"
  14. #endif
  15. //#include <tchar.h>
  16. #include "custres.h"
  17. #include "rlmsgtbl.h"
  18. #include "commbase.h"
  19. #include "rlman.h"
  20. #include "exe2res.h"
  21. #include "exeNTres.h"
  22. #include "rlstrngs.h"
  23. #include "projdata.h"
  24. #include "showerrs.h"
  25. #include "resread.h"
  26. #ifndef RLDOS
  27. int Update( char *, char *);
  28. #endif
  29. extern MSTRDATA gMstr; //... Data from Master Project file (MPJ)
  30. extern PROJDATA gProj; //... Data from Project file (PRJ)
  31. HWND hListWnd = NULL;
  32. HWND hMainWnd = NULL;
  33. HWND hStatusWnd = NULL;
  34. int nUpdateMode = 0;
  35. BOOL fCodePageGiven = FALSE; //... Set to TRUE if -p arg given
  36. CHAR szCustFilterSpec[MAXCUSTFILTER];
  37. CHAR szFileTitle[256]="";
  38. extern BOOL gfReplace; //... Set FALSE if -a option is given
  39. extern BOOL gbMaster; //... TRUE if working in a Master Project
  40. extern BOOL gbShowWarnings; //... Display warnining messages if TRUE
  41. extern BOOL gfShowClass; //... Set TRUE to put dlg box elemnt class in
  42. //... token file
  43. extern BOOL gfExtendedTok; //... Set TRUE if -x option is given
  44. extern UCHAR szDHW[]; //... Common buffer, many uses
  45. extern int atoihex( CHAR sz[]);
  46. extern BOOL bRLGui;
  47. CHAR szModule[MAX_PATH];
  48. //............................................................
  49. void Usage( void)
  50. {
  51. int i;
  52. for ( i = IDS_USG_00; i < IDS_USG_END; ++i )
  53. {
  54. LoadStringA( NULL, i, szDHW, DHWSIZE);
  55. CharToOemA( szDHW, szDHW);
  56. fprintf( stderr, "%s\n", szDHW);
  57. }
  58. }
  59. //............................................................
  60. //...
  61. //... This is a stub for console programs
  62. int RLMessageBoxA(
  63. LPCSTR lpError)
  64. {
  65. fprintf( stderr, "RLMan (%s): %s\n", szModule, lpError);
  66. return( IDOK); // Should return something.
  67. }
  68. #ifndef __cdecl
  69. #define __cdecl __cdecl
  70. #endif
  71. //............................................................
  72. void __cdecl main( int argc, char *argv[])
  73. {
  74. BOOL fBuildRes = FALSE;
  75. BOOL fBuildTok = FALSE;
  76. BOOL fExtRes = FALSE;
  77. BOOL bChanged = FALSE;
  78. BOOL fProject = FALSE; //... Set to TRUE if -l arg given
  79. BOOL fNewLanguageGiven = FALSE; //... Set to TRUE if -n arg given
  80. BOOL fOldLanguageGiven = FALSE; //... Set to TRUE if -o arg given
  81. FILE *pfCRFile = NULL;
  82. int iCount = 0;
  83. int iErrorLine = 0;
  84. UINT usError = 0;
  85. WORD wRC = 0;
  86. WORD wResTypeFilter = 0; //... Pass all resource types by default
  87. char *pszMasterFile = NULL;
  88. char *pszProjectFile = NULL;
  89. int chOpt = 0;
  90. bRLGui = FALSE;
  91. wRC = GetCopyright( argv[0], szDHW, DHWSIZE);
  92. if ( wRC != SUCCESS )
  93. {
  94. ShowErr( wRC, NULL, NULL);
  95. DoExit( wRC);
  96. }
  97. CharToOemA( szDHW, szDHW);
  98. fprintf( stderr, "\n%s\n\n", szDHW);
  99. //... Enough args on command line?
  100. if ( argc < 2 )
  101. {
  102. ShowErr( IDS_ERR_01, NULL, NULL);
  103. Usage();
  104. DoExit( IDS_ERR_01);
  105. }
  106. gbMaster = FALSE; //... Build project token file by default.
  107. iCount = 1;
  108. //... Get the switches
  109. while ( iCount < argc && (*argv[ iCount] == '-' || *argv[ iCount] == '/') )
  110. {
  111. switch ( (chOpt = *CharLowerA( &argv[iCount][1])))
  112. {
  113. case '?':
  114. case 'h':
  115. WinHelp( NULL, TEXT("rlman.hlp"), HELP_CONTEXT, IDM_HELPUSAGE);
  116. DoExit( SUCCESS);
  117. break;
  118. case 'e':
  119. if ( fBuildTok != FALSE || fBuildRes != FALSE )
  120. {
  121. ShowErr( IDS_ERR_02, NULL, NULL);
  122. Usage();
  123. DoExit( IDS_ERR_01);
  124. }
  125. fExtRes = TRUE;
  126. gbMaster = FALSE;
  127. fBuildTok = FALSE;
  128. break;
  129. case 't': //... Create token file
  130. if ( fBuildRes != FALSE || fExtRes != FALSE )
  131. {
  132. ShowErr( IDS_ERR_02, NULL, NULL);
  133. Usage();
  134. DoExit( IDS_ERR_01);
  135. }
  136. gbMaster = FALSE;
  137. fProject = FALSE;
  138. fBuildTok = TRUE;
  139. break;
  140. //... Update 1.0 token files to fit upper 1.7 version,
  141. //... it is same as 'm' + 'l' option.
  142. case 'u': //...Update 1.0 token files to fit upper 1.7 version
  143. if ( argc - iCount < 6 )
  144. {
  145. ShowErr( IDS_ERR_01, NULL, NULL);
  146. Usage();
  147. DoExit( IDS_ERR_01);
  148. }
  149. gbMaster = TRUE;
  150. fProject = TRUE;
  151. fBuildTok = TRUE;
  152. pszMasterFile = argv[++iCount];
  153. pszProjectFile = argv[++iCount];
  154. break;
  155. case 'm': //... Build Master token file
  156. if ( argc - iCount < 2 )
  157. {
  158. ShowErr( IDS_ERR_01, NULL, NULL);
  159. Usage();
  160. DoExit( IDS_ERR_01);
  161. }
  162. gbMaster = TRUE;
  163. fProject = FALSE;
  164. fBuildTok = TRUE;
  165. pszMasterFile = argv[ ++iCount];
  166. break;
  167. case 'l': //... Build language project token file
  168. if ( argc - iCount < 2 )
  169. {
  170. ShowErr( IDS_ERR_01, NULL, NULL);
  171. Usage();
  172. DoExit( IDS_ERR_01);
  173. }
  174. fProject = TRUE;
  175. fBuildTok = TRUE;
  176. gbMaster = FALSE;
  177. pszProjectFile = argv[ ++iCount];
  178. break;
  179. case 'a':
  180. case 'r':
  181. if ( fBuildTok != FALSE || fExtRes != FALSE )
  182. {
  183. ShowErr( IDS_ERR_02, NULL, NULL);
  184. Usage();
  185. DoExit( IDS_ERR_02);
  186. }
  187. fBuildRes = TRUE;
  188. gfReplace = (chOpt == 'a') ? FALSE : TRUE;
  189. gbMaster = FALSE;
  190. fProject = FALSE;
  191. break;
  192. case 'n': //... Get ID components of new language
  193. if ( argc - iCount < 2 )
  194. {
  195. ShowErr( IDS_ERR_01, NULL, NULL);
  196. Usage();
  197. DoExit( IDS_ERR_01);
  198. }
  199. else
  200. {
  201. WORD wPri = (WORD)MyAtoi( argv[ ++iCount]);
  202. WORD wSub = (WORD)MyAtoi( argv[ ++iCount]);
  203. gProj.wLanguageID = MAKELANGID( wPri, wSub);
  204. fNewLanguageGiven = TRUE;
  205. }
  206. break;
  207. case 'o': //... Get old language ID components
  208. if ( argc - iCount < 2 )
  209. {
  210. ShowErr( IDS_ERR_01, NULL, NULL);
  211. Usage();
  212. DoExit( IDS_ERR_01);
  213. }
  214. else
  215. {
  216. WORD wPri = (WORD)MyAtoi( argv[ ++iCount]);
  217. WORD wSub = (WORD)MyAtoi( argv[ ++iCount]);
  218. gMstr.wLanguageID = MAKELANGID( wPri, wSub);
  219. fOldLanguageGiven = TRUE;
  220. }
  221. break;
  222. case 'p': //... Get code page number
  223. gMstr.uCodePage = gProj.uCodePage
  224. = (UINT)MyAtoi( argv[ ++iCount]);
  225. fCodePageGiven = TRUE;
  226. break;
  227. case 'c': //... Get custom resource def file name
  228. strcpy( gMstr.szRdfs, argv[ ++iCount]);
  229. pfCRFile = FOPEN( gMstr.szRdfs, "rt");
  230. if ( pfCRFile == NULL )
  231. {
  232. QuitA( IDS_ENGERR_02, gMstr.szRdfs, NULL);
  233. }
  234. wRC = (WORD)ParseResourceDescriptionFile( pfCRFile, &iErrorLine);
  235. if ( wRC )
  236. {
  237. switch ( (int)wRC )
  238. {
  239. case -1:
  240. ShowErr( IDS_ERR_14, NULL, NULL);
  241. break;
  242. case -2:
  243. ShowErr( IDS_ERR_15, NULL, NULL);
  244. break;
  245. case -3:
  246. ShowErr( IDS_ERR_16, NULL, NULL);
  247. break;
  248. } //... END switch ( wRC )
  249. }
  250. FCLOSE( pfCRFile);
  251. break;
  252. case 'f': //... Get res type to retrieve
  253. wResTypeFilter = (WORD)MyAtoi( argv[ ++iCount]);
  254. break;
  255. case 'w':
  256. gbShowWarnings = TRUE;
  257. break;
  258. case 'd':
  259. gfShowClass = TRUE;
  260. break;
  261. case 'x':
  262. gfExtendedTok = TRUE;
  263. break;
  264. default:
  265. ShowErr( IDS_ERR_04, argv[ iCount], NULL);
  266. Usage();
  267. DoExit( IDS_ERR_04);
  268. break;
  269. } //... END switch
  270. iCount++;
  271. } //... END while
  272. lstrcpyA(szModule, argv[ iCount]);
  273. if ( fExtRes )
  274. {
  275. if ( argc - iCount < 2 )
  276. {
  277. ShowErr( IDS_ERR_01, NULL, NULL);
  278. Usage();
  279. DoExit( IDS_ERR_01);
  280. }
  281. ExtractResFromExe32A( argv[ iCount], argv[ iCount + 1], wResTypeFilter);
  282. }
  283. else if ( fBuildTok )
  284. {
  285. if ( ( fProject == FALSE && gbMaster == FALSE) && argc - iCount < 2 )
  286. {
  287. ShowErr( IDS_ERR_01, NULL, NULL);
  288. Usage();
  289. DoExit( IDS_ERR_01);
  290. }
  291. //... check to see if we are updating a
  292. //... Master Token file
  293. if ( gbMaster )
  294. {
  295. OFSTRUCT Of = { 0, 0, 0, 0, 0, ""};
  296. CHAR *pExe, *pMtk;
  297. if ( chOpt == 'u' ) //Update them
  298. {
  299. pExe = argv[iCount++];
  300. pMtk = argv[iCount++];
  301. }
  302. else
  303. {
  304. pExe = argc - iCount < 1 ? NULL : argv[ iCount];
  305. pMtk = argc - iCount < 2 ? NULL : argv[ iCount+1];
  306. }
  307. wRC = (WORD)GetMasterProjectData( pszMasterFile,
  308. pExe,
  309. pMtk,
  310. fOldLanguageGiven);
  311. if ( wRC != SUCCESS )
  312. {
  313. DoExit( wRC);
  314. }
  315. LoadCustResDescriptions( gMstr.szRdfs);
  316. //... check for the special case where Master
  317. //... Token file does not exists. This is
  318. //... possible if the MPJ file was created
  319. //... automatically.
  320. if ( OpenFile( gMstr.szMtk, &Of, OF_EXIST) == HFILE_ERROR )
  321. {
  322. //... Master token file does not exists,
  323. //... so go ahead and create it
  324. wRC = (WORD)GenerateTokFile( gMstr.szMtk,
  325. gMstr.szSrc,
  326. &bChanged,
  327. wResTypeFilter);
  328. SzDateFromFileName( gMstr.szMpjLastRealUpdate, gMstr.szMtk);
  329. }
  330. else
  331. {
  332. //... we are doing an update, so we need to make
  333. //... sure we don't do unecessary upates
  334. SzDateFromFileName( gMstr.szSrcDate, gMstr.szSrc);
  335. if ( strcmp( gMstr.szMpjLastRealUpdate, gMstr.szSrcDate) )
  336. {
  337. wRC = (WORD)GenerateTokFile( gMstr.szMtk,
  338. gMstr.szSrc,
  339. &bChanged,
  340. wResTypeFilter);
  341. //... did we really update anything ??
  342. if( bChanged )
  343. {
  344. SzDateFromFileName( gMstr.szMpjLastRealUpdate, gMstr.szMtk);
  345. }
  346. }
  347. }
  348. //... write out the new mpj data
  349. PutMasterProjectData( pszMasterFile);
  350. }
  351. #ifndef RLDOS
  352. if ( fProject ) //... Are we to update a project?
  353. {
  354. //... Yes
  355. CHAR *pMpj, *pTok;
  356. if ( chOpt == 'u' ) //Update it
  357. {
  358. pMpj = pszMasterFile;
  359. pTok = argv[iCount];
  360. }
  361. else
  362. {
  363. pMpj = argc - iCount < 1 ? NULL : argv[ iCount];
  364. pTok = argc - iCount < 2 ? NULL : argv[ iCount+1];
  365. }
  366. if ( GetProjectData( pszProjectFile,
  367. pMpj,
  368. pTok,
  369. fCodePageGiven,
  370. fNewLanguageGiven) )
  371. {
  372. DoExit( -1);
  373. }
  374. //... Get source and master token file names
  375. //... from the master project file.
  376. wRC = (WORD)GetMasterProjectData( gProj.szMpj,
  377. NULL,
  378. NULL,
  379. fOldLanguageGiven);
  380. if ( wRC != SUCCESS )
  381. {
  382. DoExit( wRC);
  383. }
  384. //... Now we do the actual updating.
  385. wRC = (WORD)Update( gMstr.szMtk, gProj.szTok);
  386. //... If that worked, we update the project file
  387. if ( wRC == 0 )
  388. {
  389. SzDateFromFileName( gProj.szTokDate, (CHAR *)gProj.szTok);
  390. PutProjectData( pszProjectFile);
  391. }
  392. else
  393. {
  394. ShowErr( IDS_ERR_18, gProj.szTok, gMstr.szMtk);
  395. DoExit( IDS_ERR_18);
  396. }
  397. }
  398. #endif // RLDOS
  399. if ( !gbMaster && !fProject )
  400. {
  401. wRC = (WORD)GenerateTokFile( argv[ iCount + 1],
  402. argv[ iCount],
  403. &bChanged,
  404. wResTypeFilter);
  405. }
  406. if ( wRC != 0 )
  407. {
  408. #ifdef RLDOS
  409. ShowErr( IDS_ERR_08, errno, NULL);
  410. DoExit( -1);
  411. #else
  412. usError = GetLastError();
  413. ShowErr( IDS_ERR_08, UlongToPtr(usError), NULL);
  414. switch ( usError )
  415. {
  416. case ERROR_BAD_FORMAT:
  417. ShowErr( IDS_ERR_09, NULL, NULL);
  418. DoExit( IDS_ERR_09);
  419. break;
  420. case ERROR_OPEN_FAILED:
  421. ShowErr( IDS_ERR_10, NULL, NULL);
  422. DoExit( IDS_ERR_10);
  423. break;
  424. case ERROR_EXE_MARKED_INVALID:
  425. case ERROR_INVALID_EXE_SIGNATURE:
  426. ShowErr( IDS_ERR_11, NULL, NULL);
  427. DoExit( IDS_ERR_11);
  428. break;
  429. default:
  430. if ( usError < ERROR_HANDLE_DISK_FULL )
  431. {
  432. ShowErr( IDS_ERR_12, _sys_errlist[ usError], NULL);
  433. DoExit( IDS_ERR_12);
  434. }
  435. DoExit( (int)usError);
  436. } //... END switch
  437. #endif
  438. }
  439. }
  440. else if ( fBuildRes )
  441. {
  442. if ( argc - iCount < 3 )
  443. {
  444. ShowErr( IDS_ERR_01, NULL, NULL);
  445. Usage();
  446. DoExit( IDS_ERR_01);
  447. }
  448. if ( GenerateImageFile( argv[iCount + 2],
  449. argv[iCount],
  450. argv[iCount + 1],
  451. gMstr.szRdfs,
  452. wResTypeFilter) != 1 )
  453. {
  454. ShowErr( IDS_ERR_23, argv[iCount + 2], NULL);
  455. DoExit( IDS_ERR_23);
  456. }
  457. }
  458. else
  459. {
  460. Usage();
  461. DoExit( IDS_ERR_28);
  462. }
  463. DoExit( SUCCESS);
  464. }
  465. //...................................................................
  466. void DoExit( int nErrCode)
  467. {
  468. #ifdef _DEBUG
  469. FreeMemList( NULL);
  470. #endif // _DEBUG
  471. exit( nErrCode);
  472. }