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.

1158 lines
35 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM removerc.cmd
  5. REM Move resource from US binaries to MUI resource binaries
  6. REM Read $nttree\\build_logs\\LgNeutral\\lgntobuildlist.txt which generated by lgndata.cmd
  7. REM
  8. REM Copyright (c) Microsoft Corporation. All rights reserved.
  9. REM
  10. REM ------------------------------------------------------------------
  11. perl -x "%~f0" %*
  12. goto :EOF
  13. #!perl
  14. use strict;
  15. use File::Basename;
  16. use IO::File;
  17. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  18. use lib $ENV{RAZZLETOOLPATH};
  19. use PbuildEnv;
  20. use ParseArgs;
  21. use Logmsg;
  22. use cksku;
  23. BEGIN {
  24. $ENV{SCRIPT_NAME} = 'removerc.cmd';
  25. }
  26. sub Usage { print<<USAGE; exit(1) }
  27. removerc
  28. Move resource from US binaries to MUI resource binaries.
  29. If CMF is enabled, add MUI resource to CMF.
  30. Read nttree\\build_logs\\LgNeutral\\lgntobuildlist.txt which generated by lgndata.cmd
  31. USAGE
  32. # Global variables
  33. my(@FILE_LIST);
  34. my ( $Neutral_LogDir, $LGNToBuildList);
  35. my( $LogFilename, $TempDir, $Rsrc_Temp );
  36. my( $CodeBinDir, $OrigBinDir, $RCBinDir, $CMFBinDir, $CodeBinPath, $OrigBinPath, $RCBinPath, $RenamedRCBinPath,$CMFBinPath, $CMFFilePath);
  37. my( $nttree, $razpath, $TempDir);
  38. my ($LGNStatus);
  39. my ($STS_Freshs, $STS_OK, $STS_ToBuildList, $STS_BuildList, $STS_Copy, $STS_RemoveRC, $STS_Unknown);
  40. my($lang, $fNeedGenerateCMF, %RenameTable);
  41. my(%CDDataSKUs, %INFPathSKUs);
  42. ##################
  43. #
  44. # parse command line
  45. #
  46. ##################
  47. parseargs( '?' => \&Usage,
  48. 'l:' => \$lang
  49. );
  50. &Main();
  51. #
  52. # Check if Language Neutral is enabled or not
  53. #
  54. sub IsLGNActivated()
  55. {
  56. my ($MUI_MAGIC, $Result);
  57. $Result = 0;
  58. $MUI_MAGIC= $ENV{ "MUI_MAGIC" };
  59. if ( defined($MUI_MAGIC))
  60. {
  61. $Result=1;
  62. }
  63. return $Result
  64. }
  65. #
  66. # Check if we need generate CMF (Compact Resource File)
  67. #
  68. sub IsCMFActivated()
  69. {
  70. my ($MUI_MAGIC_CMF, $Result);
  71. $Result = 0;
  72. $MUI_MAGIC_CMF= $ENV{ "MUI_MAGIC_CMF" };
  73. if ( defined($MUI_MAGIC_CMF))
  74. {
  75. $Result=1;
  76. }
  77. return $Result
  78. }
  79. sub Main {
  80. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  81. # Begin Main code section
  82. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  83. # Return when you want to exit on error
  84. #
  85. my ($Mylang );
  86. if (! &IsLGNActivated())
  87. {
  88. return 0;
  89. }
  90. #
  91. # $lang must be set. Default is usa
  92. #
  93. if ( ! defined($lang))
  94. {
  95. $lang = $ENV{LANG};
  96. if (! defined($lang))
  97. {
  98. $lang="usa";
  99. }
  100. }
  101. $Mylang="\L$lang";
  102. if ( $Mylang ne "usa")
  103. {
  104. return 0;
  105. }
  106. #
  107. # Should we generate CMF (Compact resource file ?)
  108. #
  109. $fNeedGenerateCMF=&IsCMFActivated();
  110. $Logmsg::DEBUG = 0; # set to 1 to activate logging of dbgmsg's
  111. $LogFilename = $ENV{ "LOGFILE" };
  112. if ( ! defined( $LogFilename ) )
  113. {
  114. $TempDir = $ENV{ "TMP" };
  115. $LogFilename = "$TempDir\\$0.log";
  116. }
  117. $CodeBinDir=$ENV{ "CodeBinDir" };
  118. if ( ! defined( $CodeBinDir) )
  119. {
  120. $CodeBinDir="CodeBin";
  121. }
  122. $RCBinDir=$ENV{ "RcBinDir" };
  123. if ( ! defined( $RCBinDir) )
  124. {
  125. $RCBinDir="RCBin";
  126. }
  127. $OrigBinDir=$ENV{ "OrigBinDir" };
  128. if ( ! defined( $OrigBinDir) )
  129. {
  130. $OrigBinDir="OrigBin";
  131. }
  132. $CMFBinDir=$ENV{ "CMFBinDir" };
  133. if ( ! defined( $CMFBinDir) )
  134. {
  135. $CMFBinDir="CMFBin";
  136. }
  137. timemsg( "Beginning ...");
  138. # set up paths to important files
  139. $nttree = $ENV{ "_NTPostBld" };
  140. $razpath= $ENV{ "RazzleToolPath" };
  141. $TempDir = $ENV{ "TMP" };
  142. $Rsrc_Temp="$TempDir\\Rsrc_temp";
  143. $Neutral_LogDir = $nttree."\\build_logs\\LgNeutral";
  144. $LGNToBuildList = $Neutral_LogDir."\\lgntobuildlist.txt";
  145. $LGNStatus = $Neutral_LogDir."\\lgnStatusLock.txt";
  146. $OrigBinPath = "$Neutral_LogDir\\$OrigBinDir";
  147. $CodeBinPath="$Neutral_LogDir\\$CodeBinDir";
  148. $RCBinPath ="$Neutral_LogDir\\$RCBinDir";
  149. $RenamedRCBinPath="$Neutral_LogDir\\RenamedRCBin";
  150. $CMFBinPath ="$Neutral_LogDir\\$CMFBinDir";
  151. $CMFFilePath= "$CMFBinPath\\CompMUI.CMF";
  152. $STS_Freshs = "Fresh";
  153. $STS_OK = "OK";
  154. $STS_ToBuildList="ToBuildList";
  155. $STS_RemoveRC="RemoveRC";
  156. $STS_BuildList="BuildList";
  157. $STS_Copy="CopyBin";
  158. $STS_Unknown="Unknown";
  159. # Create three BIN folder if they do not exist
  160. # Home for LGN
  161. if (! -d $Neutral_LogDir )
  162. {
  163. errmsg("Fatal: $Neutral_LogDir doesn't exist");
  164. exit(1);
  165. }
  166. # Origional Binary
  167. if (! -d $OrigBinPath)
  168. {
  169. if (system("md $OrigBinPath") != 0)
  170. {
  171. errmsg("Fatal: can't create $OrigBinPath");
  172. exit(1);
  173. }
  174. }
  175. # Binary with resource moved out
  176. if (! -d $CodeBinPath)
  177. {
  178. if (system("md $CodeBinPath") != 0)
  179. {
  180. errmsg("Fatal: can't create CodeBinPath");
  181. exit(1);
  182. }
  183. }
  184. # Binary contains resource only
  185. if (! -d $RCBinPath)
  186. {
  187. if (system("md $RCBinPath") != 0)
  188. {
  189. errmsg("Fatal: can't create $RCBinPath");
  190. exit(1);
  191. }
  192. }
  193. if ($fNeedGenerateCMF)
  194. {
  195. if (! -d $RenamedRCBinPath)
  196. {
  197. if (system("md $RenamedRCBinPath") != 0)
  198. {
  199. errmsg("Fatal: can't create $RenamedRCBinPath");
  200. exit(1);
  201. }
  202. }
  203. }
  204. unless ( -d $CMFBinPath)
  205. {
  206. if (system("md $CMFBinPath") != 0)
  207. {
  208. errmsg("Fatal: can't create $CMFBinPath");
  209. exit(1);
  210. }
  211. }
  212. #
  213. # ToBuildList should be created by lgndata.cmd.
  214. # logndata.cmd will be called by pbuild with -g parameter to generate the said list
  215. #
  216. unless ( -e $LGNToBuildList)
  217. {
  218. logmsg(" No files to be processed because $LGNToBuildList doesn't exist");
  219. exit(0);
  220. }
  221. #
  222. # Put binaries be processed in array @FILE_LIST
  223. #
  224. if (!&MakeSourceFileList())
  225. {
  226. errmsg ("Could not get the filtered contents of the source directory.");
  227. }
  228. #
  229. # If CMF is enabled, we have to create rename table because some mui files should be renamed before it added to CMF
  230. #
  231. if ($fNeedGenerateCMF)
  232. {
  233. BuildRename4CMF();
  234. }
  235. #
  236. # Generate resource dlls from the files in the source file list
  237. # call muirct.exe to process binaries listed in @FILE_LIST
  238. #
  239. if (!&GenLGNResDlls())
  240. {
  241. errmsg ("Error(s) occurs in moving resource out of binaries");
  242. }
  243. #
  244. # Done
  245. #
  246. LogStatus($STS_RemoveRC);
  247. timemsg( "Finished." );
  248. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  249. # End Main code section
  250. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  251. }
  252. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  253. #
  254. # MakeSourceFileListl - gets list of appropriate files to process from $LGNToBuildList
  255. #
  256. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  257. sub MakeSourceFileList
  258. {
  259. my (@Bufs, $Result, $Line);
  260. $Result = 0;
  261. unless ( open(INFILE, $LGNToBuildList))
  262. {
  263. errmsg("Fatal: Can't open $LGNToBuildList");
  264. return $Result;
  265. }
  266. @Bufs=<INFILE>;
  267. close(INFILE);
  268. foreach $Line (@Bufs)
  269. {
  270. chomp($Line);
  271. $Line =~ s/\s//g;
  272. if (length($Line) == 0)
  273. {
  274. next;
  275. }
  276. push(@FILE_LIST, $Line);
  277. }
  278. $Result = 1;
  279. return $Result;
  280. }
  281. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  282. #
  283. # IsFusionResource --- Check if the binary contains fusion resource (#24)
  284. #
  285. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  286. sub IsFusionResource
  287. {
  288. my ($FileName) = @_;
  289. my (@Rsrc_Record,@Qualified,$Num, $Result);
  290. #logmsg("rsrc.exe $FileName >$Rsrc_Temp ");
  291. $Result = 0;
  292. #
  293. # Call RSRC to check
  294. #
  295. system("rsrc.exe $FileName >$Rsrc_Temp 2>nul");
  296. unless (open(RSRCFILE, $Rsrc_Temp))
  297. {
  298. errmsg("Can't open RSRC for $FileName");
  299. return $Result;
  300. }
  301. @Rsrc_Record=<RSRCFILE>;
  302. close (RSRCFILE);
  303. #
  304. # Scan the output of rsrc.exe.
  305. #
  306. @Qualified=grep /^\s{3}18/ , @Rsrc_Record;
  307. $Num=scalar(@Qualified);
  308. if ($Num > 0 )
  309. {
  310. $Result = 1;
  311. }
  312. return $Result;
  313. }
  314. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  315. #
  316. # MakeSourceFileList_All - gets list of appropriate files to process from $nttree
  317. # Not used in this moment.
  318. #
  319. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  320. sub MakeSourceFileListlAll
  321. {
  322. logmsg ("Get list of appropriate files to process.");
  323. my(@files,$filename);
  324. # Initial messages
  325. logmsg ("--------------------------------------------------------");
  326. logmsg ("Move resource out of US binaries to MUI resource binaries");
  327. logmsg ("--------------------------------------------------------");
  328. # Get contents of source directory
  329. if(!opendir(LOCBINDIR, $nttree)) {
  330. errmsg ("Can't open $nttree");
  331. return 0;
  332. }
  333. # Skip files won't contain resource. We also skip drivers(*.drv *.sys) because MUI currently doesn't support it
  334. @files = grep !/\.(gpd|icm|ppd|bmp|txt|cab|cat|hlp|chm|chq|cnt|mfl|drv|sys|gif|cur|fon|sf2|jpg|p4|nls|uce|wmz|ttf|mof)$/i, readdir LOCBINDIR;
  335. close(LOCBINDIR);
  336. #
  337. # Filter out non-binaries, store in global @FILE_LIST
  338. # (muirct.exe gives errors on text files, and produces annoying
  339. #
  340. @FILE_LIST = ();
  341. foreach (@files)
  342. {
  343. chomp($_);
  344. $_ =~ s/\s//g;
  345. if (length($_) == 0)
  346. {
  347. next;
  348. }
  349. if(-B "$nttree\\$_")
  350. {
  351. push(@FILE_LIST, "$nttree\\$_");
  352. }
  353. }
  354. logmsg ("Success: Get list of appropriate files to process.");
  355. return 1;
  356. }
  357. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  358. #
  359. # GenResDlls - loops over the file list, performs muirct.exe, and logs output
  360. # Work around fusion issue ---- Resource type #24
  361. #
  362. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  363. sub GenLGNResDlls
  364. {
  365. logmsg ("Loop over the file list, perform muirct.exe , and log output");
  366. my( $Line, $error, $resdlls_created, @resdlls, $total_resdlls);
  367. my( $muirct_command, $source, $source_new, $mui_new);
  368. my ($error,@trash, $Backup);
  369. # Process each (binary) file in the source directory
  370. $resdlls_created = 0;
  371. foreach $Line (@FILE_LIST)
  372. {
  373. chomp($Line);
  374. $Line =~ s/\s//g;
  375. if (length($Line) == 0)
  376. {
  377. next;
  378. }
  379. $source = "$nttree\\$Line";
  380. $source_new = "$CodeBinPath\\$Line";
  381. $mui_new = "$RCBinPath\\$Line.mui";
  382. logmsg("$muirct_command");
  383. if (-e $source_new)
  384. {
  385. system("del $source_new");
  386. }
  387. if (-e $mui_new)
  388. {
  389. system("del $mui_new");
  390. }
  391. if (&IsFusionResource($source))
  392. {
  393. # Keep: Icon(3) version(16)
  394. # stay: 24 TYPELIB REGINST
  395. #$muirct_command = "muirct.exe -l 0x0409 -k 16 -y 3 12 13 14 15 -p 24 TYPELIB $source $source_new $mui_new";
  396. $muirct_command = "muirct.exe -l 0x0409 -k 16 -c $source -o 4 5 6 9 10 11 16 REGINST HTML MOFDATA 23 240 1024 2110 $source $source_new $mui_new";
  397. }
  398. else
  399. {
  400. #$muirct_command = "muirct.exe -l 0x0409 -k 16 -y 3 12 13 14 15 -p TYPELIB $source $source_new $mui_new";
  401. $muirct_command = "muirct.exe -l 0x0409 -k 16 -c $source -o 4 5 6 9 10 11 16 REGINST HTML MOFDATA 23 240 1024 2110 $source $source_new $mui_new";
  402. }
  403. @trash=`$muirct_command`;
  404. if ( ! -e $mui_new)
  405. {
  406. if ( -e $source_new)
  407. {
  408. system("del $source_new");
  409. }
  410. }
  411. else
  412. {
  413. if ( ! -e $source_new)
  414. {
  415. if ( -e $mui_new)
  416. {
  417. system("del $mui_new");
  418. }
  419. }
  420. else
  421. {
  422. $resdlls_created++;
  423. $Backup="$OrigBinPath\\$Line";
  424. #
  425. # Backup origional binary to $OrigBinPath
  426. #
  427. system("copy/y $source $Backup");
  428. #
  429. # ADD this mui file to CMF file if CMF is enabled
  430. #
  431. if ($fNeedGenerateCMF)
  432. {
  433. AddtoCMF($resdlls_created,$Line);
  434. }
  435. }
  436. }
  437. }
  438. # Final messages
  439. logmsg ("RESULTS: muirct: Process Succeeded");
  440. logmsg ("Number of resource-only dlls created in:...........($resdlls_created)");
  441. return 1;
  442. }
  443. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  444. #
  445. # GenResDlls_ALL - loops over the file list, performs muirct.exe, and logs output
  446. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  447. sub GenResDlls_All
  448. {
  449. logmsg ("Loop over the file list, perform muirct.exe , and log output");
  450. my( $error, $resdlls_created, @resdlls, $total_resdlls);
  451. my( $muirct_command, $source, $source_new, $mui_new);
  452. my ($error,@trash);
  453. # Process each (binary) file in the source directory
  454. $resdlls_created = 0;
  455. foreach $_ (@FILE_LIST)
  456. {
  457. $_ =~ s/\s//g;
  458. if (length($_) == 0)
  459. {
  460. next;
  461. }
  462. $source = $_;
  463. if ($_ =~ /\Q$nttree\E\\(.*)/)
  464. {
  465. $source_new = "$CodeBinPath\\$1";
  466. $mui_new = "$RCBinPath\\$1.mui";
  467. logmsg("$muirct_command");
  468. $muirct_command = "muirct.exe -l 0x0409 -k 16 $source $source_new $mui_new";
  469. @trash = `$muirct_command`;
  470. $error = $?/256;
  471. if(!$error)
  472. {
  473. $resdlls_created++;
  474. }
  475. }
  476. }
  477. # Get total number of resource-only dlls in destination directory
  478. if(!opendir(TARGETDIR, $RCBinPath))
  479. {
  480. wrnmsg ("WARNING: Can't open $RCBinPath");
  481. }
  482. @resdlls = grep /\.mui$/, readdir TARGETDIR;
  483. close(TARGETDIR);
  484. $total_resdlls = scalar(@resdlls);
  485. # Final messages
  486. logmsg ("RESULTS: Process Succeeded");
  487. logmsg ("Number of resource-only dlls created in:...........($resdlls_created)");
  488. logmsg (" $RCBinPath");
  489. logmsg ("Total number of resource-only dlls in:.............($total_resdlls)");
  490. logmsg (" $RCBinPath");
  491. return 1;
  492. }
  493. #
  494. # Log the state of LGN processing so it can be restart anytime correctly
  495. #
  496. sub LogStatus
  497. {
  498. my ($TheStatus) = @_;
  499. my ($Result);
  500. $Result = 0;
  501. unless (open(OUTFILE, ">$LGNStatus"))
  502. {
  503. errmsg("Fatal: can't create status file $LGNStatus");
  504. return $Result;
  505. }
  506. print (OUTFILE "$TheStatus\n");
  507. close(OUTFILE);
  508. $Result = 1;
  509. return $Result;
  510. }
  511. #
  512. # Add one MUI resource file to CMF.
  513. #
  514. sub AddtoCMF
  515. {
  516. my ($Counter,$BinaryName) = @_;
  517. my ($MUIPath, $muirct_command, $muirct_command0, @trash, $IsRenamed, @Renamed);
  518. my ($Number, $Idx, $MUINewPath, $NewName,$CreateIt, $Result,$CodePath, $CodeNewPath);
  519. $Result=0;
  520. if ( defined($RenameTable{$BinaryName}))
  521. {
  522. $IsRenamed=1;
  523. @Renamed=@{$RenameTable{$BinaryName}};
  524. }
  525. else
  526. {
  527. $IsRenamed=0;
  528. }
  529. logmsg("**** Counter : $Counter");
  530. if ($Counter <= 1)
  531. {
  532. if ( -e $CMFFilePath)
  533. {
  534. system("del $CMFFilePath");
  535. }
  536. $muirct_command0 ="muirct.exe -m ";
  537. $CreateIt=0;
  538. }
  539. else
  540. {
  541. $muirct_command0="muirct.exe -a ";
  542. }
  543. if (! $IsRenamed)
  544. {
  545. $MUIPath="$RCBinPath\\$BinaryName.mui";
  546. $muirct_command=$muirct_command0."$MUIPath -f $CMFFilePath -e $CodeBinPath";
  547. #@trash = `$muirct_command`;
  548. `$muirct_command`;
  549. logmsg("$muirct_command");
  550. }
  551. else
  552. {
  553. $Number=scalar(@Renamed);
  554. for ($Idx=0; $Idx < $Number; $Idx++)
  555. {
  556. $NewName=$Renamed[$Idx];
  557. $MUIPath="$RCBinPath\\$BinaryName.mui";
  558. $MUINewPath="$RenamedRCBinPath\\$NewName.mui";
  559. $CodePath="$CodeBinPath\\$BinaryName";
  560. $CodeNewPath="$RenamedRCBinPath\\$NewName";
  561. if (system("copy $MUIPath $MUINewPath") != 0)
  562. {
  563. errmsg("Can't copy renamed file: $MUINewPath");
  564. return $Result;
  565. }
  566. if (system("copy $CodePath $CodeNewPath") != 0)
  567. {
  568. errmsg("Can't copy renamed file: $CodeNewPath");
  569. return $Result;
  570. }
  571. $muirct_command=$muirct_command0."$MUINewPath -f $CMFFilePath -e $RenamedRCBinPath";
  572. #@trash = `$muirct_command`;
  573. `$muirct_command`;
  574. logmsg("$muirct_command");
  575. if (system("copy $CodeNewPath $CodePath") != 0)
  576. {
  577. errmsg("Can't copy back renamed file: $CodeNewPath");
  578. return $Result;
  579. }
  580. if ( ($Counter <= 1) && ($CreateIt == 0))
  581. {
  582. $CreateIt=1;
  583. $muirct_command0="muirct.exe -a ";
  584. }
  585. }
  586. }
  587. $Result=1;
  588. return $Result;
  589. }
  590. #
  591. # Build a rename table for those files will be renamed during setup
  592. # for CMF, we have to check if a file will be renamed. If it's the case, we'll build the renamed one into CMF
  593. #
  594. sub BuildRename4CMF
  595. {
  596. my ($Sku, $Result);
  597. my ($Path_Dosnet, $Path_Txtsetup, $Path_Layout, $Path_Dir);
  598. my ($Path_Dosnet_sign, $Path_Txtsetup_sign, $Path_Layout_sign, $Path_Dir_sign);
  599. $Result=0;
  600. &BuildArray();
  601. foreach $Sku ( keys(%CDDataSKUs))
  602. {
  603. # SKU populated ?
  604. if ($CDDataSKUs{$Sku})
  605. {
  606. if ( !defined($INFPathSKUs{$Sku} ))
  607. {
  608. errmag("Fatal: $Sku has no corr. entry in INFPathSKUs");
  609. return $Result;
  610. }
  611. #
  612. # Read the INFs path for the SKU
  613. #
  614. ($Path_Dosnet,$Path_Txtsetup,$Path_Layout,$Path_Dir, $Path_Dosnet_sign,$Path_Txtsetup_sign,$Path_Layout_sign,$Path_Dir_sign)=@{$INFPathSKUs{$Sku}};
  615. #
  616. # Rename information stored in the layout.inf
  617. #
  618. BuildRenameTableFromLayout($Path_Layout);
  619. }
  620. }
  621. $Result=1;
  622. return $Result;
  623. }
  624. #
  625. # Build Up Rename Table
  626. #
  627. sub BuildRenameTableFromLayout
  628. {
  629. my ($FilePath) = @_;
  630. my (@Items, @ItemsInSection, $Section, $Result, $nStart, $nEnd, $nStartTag1, $nStartTag2,$nStartDirs,$nEndDirs);
  631. my ($nStart_Dir,$nEnd_Dir);
  632. my ($ReplaceDirs, $Replace, $Line, $Entry);
  633. my (@AddedItems, $FileName, $Path, $Idx, $Item_no);
  634. my ($FileRenamed, $nUppbound);
  635. my ($NoAlt, $BldArch, $AltSection,$nAltStart,$nAltEnd);
  636. my ($LGNTagStart, $LGNTagEnd, $LGNDirs);
  637. $Result = 0;
  638. unless ( open(INFILE, $FilePath) )
  639. {
  640. errmsg ("Can't open $FilePath");
  641. return $Result;
  642. }
  643. # Read into @Items
  644. @Items=<INFILE>;
  645. close(INFILE);
  646. $LGNTagStart = "; Following are entries added for Language neutral resource files:\$\$\$ ";
  647. $LGNTagEnd = "; End of entries for Language neutral resource files: \$\$\$";
  648. $LGNDirs = "190 = mui\\fallback\\0409";
  649. #
  650. # First, we have to read [WinntDirectories] section to see if '190 = mui\fallback\0409' is there
  651. #
  652. $Section="WinntDirectories";
  653. $nStartDirs=0;
  654. $nEndDirs=0;
  655. #
  656. # Read [WinntDirectories] Section, position in nStart, nEnd
  657. #
  658. if (!ReadSection($Section,\@Items, \@ItemsInSection, \$nStart_Dir, \$nEnd_Dir, \$nStartDirs, \$nEndDirs,
  659. $LGNDirs,"Nothing"))
  660. {
  661. errmsg("Fatal: Can't find $Section in $FilePath");
  662. return $Result;
  663. }
  664. $Section="SourceDisksFiles";
  665. $nStartTag1=0;
  666. $nStartTag2=0;
  667. #
  668. # Read [SourceDisksFiles] Section, position in nStart, nEnd
  669. #
  670. if (!ReadSection($Section,\@Items, \@ItemsInSection, \$nStart, \$nEnd, \$nStartTag1, \$nStartTag2,
  671. $LGNTagStart,$LGNTagEnd))
  672. {
  673. errmsg("Fatal: Can't find $Section in $FilePath");
  674. return $Result;
  675. }
  676. #
  677. # Read [SourceDisksFiles.<BldArch>] Section. This section contains platform specific files
  678. #
  679. my ($NoAlt, $BldArch, $AltSection);
  680. $NoAlt=0;
  681. $BldArch = $ENV{ "\_BuildArch" };
  682. if ( $BldArch =~ /x86/i )
  683. {
  684. $AltSection= "$Section.x86";
  685. }
  686. elsif ( $BldArch =~ /amd64/i)
  687. {
  688. $AltSection= "$Section.amd64";
  689. }
  690. elsif ( $BldArch =~ /ia64/i )
  691. {
  692. $AltSection= "$Section.ia64";
  693. }
  694. else
  695. {
  696. $AltSection= "$Section.x86";
  697. }
  698. if (!ReadSection($AltSection,\@Items, \@ItemsInSection, \$nAltStart, \$nAltEnd, \$nStartTag1, \$nStartTag2,
  699. $LGNTagStart,$LGNTagEnd))
  700. {
  701. errmsg(" Can't find $AltSection in $FilePath");
  702. $NoAlt=1;
  703. }
  704. #
  705. # Search Tag here
  706. #
  707. $nStartDirs=-1;
  708. $nEndDirs=-1;
  709. $nStartTag1=-1;
  710. $nStartTag2=-1;
  711. $ReplaceDirs="FALSE";
  712. $Replace="FALSE";
  713. $Idx=-1;
  714. foreach (@Items)
  715. {
  716. chomp($_);
  717. $Idx++;
  718. # Find $LGNDirs, position in nStartDirs
  719. if ( $_ eq $LGNDirs)
  720. {
  721. $nStartDirs = $Idx;
  722. }
  723. # Find$ LGN tag, position in nStartTag1, nStartTag2
  724. if ( $_ eq $LGNTagStart)
  725. {
  726. $nStartTag1 = $Idx;
  727. }
  728. if ( $_ eq $LGNTagEnd)
  729. {
  730. $nStartTag2 = $Idx;
  731. }
  732. }
  733. if ($nStartDirs != -1)
  734. {
  735. $ReplaceDirs = "TRUE";
  736. }
  737. if ( ($nStartTag1 != -1) && ($nStartTag2 != -1))
  738. {
  739. $Replace = "TRUE";
  740. }
  741. #
  742. # Build up rename table here !
  743. # Windows sepcify the renaming in txtsetup.txt and layout.inf
  744. #
  745. %RenameTable={};
  746. if ($Replace eq "TRUE")
  747. {
  748. $nUppbound = $nStartTag1;
  749. }
  750. else
  751. {
  752. $nUppbound = $nEnd;
  753. }
  754. if (! &BuildRenameTable(\@Items,$nStart, $nUppbound,\%RenameTable))
  755. {
  756. errmsg("Can't build File Rename Table");
  757. return $Result;
  758. }
  759. if ( ! $NoAlt )
  760. {
  761. if (! &BuildRenameTable(\@Items,$nAltStart, $nAltEnd,\%RenameTable))
  762. {
  763. errmsg("Can't build File Rename Table from $AltSection");
  764. }
  765. }
  766. $Result=1;
  767. return $Result;
  768. }
  769. #
  770. # Search a Section of a INFs. INFs stored in @$pItemsList
  771. #
  772. sub ReadSection
  773. {
  774. my ($Section, $pItemsList, $pItemsInSection, $pnStart, $pnEnd, $pnStartTag1, $pnStartTag2, $Tag1,$Tag2) = @_;
  775. my ($Index, $SectionStart, $SectionEnd, $Line, $Line_Org, $ReadFlag, $Result);
  776. $ReadFlag = "FALSE";
  777. $Index= -1;
  778. $SectionStart = -1;
  779. $SectionEnd = -1;
  780. $Result = 0;
  781. #
  782. # Read The section
  783. #
  784. LINE: foreach $Line_Org (@$pItemsList)
  785. {
  786. $Line = $Line_Org;
  787. chomp($Line);
  788. $Index++;
  789. if ( (length($Line) == 0) || (substr($Line,0,1) eq ";") || (substr($Line,0,1) eq "#") )
  790. {
  791. if ( $ReadFlag eq "TRUE" )
  792. {
  793. push (@$pItemsInSection, $Line_Org);
  794. }
  795. next;
  796. }
  797. if ( $Line =~ /^\[/ )
  798. {
  799. if ( $ReadFlag eq "TRUE")
  800. {
  801. $ReadFlag = "FALSE";
  802. if ( $SectionStart != -1)
  803. {
  804. if ($SectionEnd == -1)
  805. {
  806. $SectionEnd = $Index-1;
  807. }
  808. }
  809. last LINE;
  810. }
  811. }
  812. if ( $Line =~ /^\[$Section\]/ ) # pattern in $Section !!!
  813. {
  814. $ReadFlag = "TRUE";
  815. $SectionStart=$Index;
  816. }
  817. if ($ReadFlag eq "TRUE")
  818. {
  819. # Check if it's a LGN starting Tag
  820. if ( $$pnStartTag1 != 0)
  821. {
  822. if ($Line eq $Tag1)
  823. {
  824. $$pnStartTag1 = $Index;
  825. }
  826. }
  827. # Check if it's a LGN ending Tag
  828. if ( $$pnStartTag2 != 0)
  829. {
  830. if ($Line eq $Tag2)
  831. {
  832. $$pnStartTag2 = $Index;
  833. }
  834. }
  835. push(@$pItemsInSection, $Line_Org);
  836. }
  837. }
  838. if ( $SectionStart != -1)
  839. {
  840. if ( $SectionEnd == -1)
  841. {
  842. $SectionEnd = $Index;
  843. }
  844. $Result = 1;
  845. $$pnStart = $SectionStart;
  846. $$pnEnd = $SectionEnd;
  847. }
  848. return $Result;
  849. }
  850. #
  851. # Scan the entries of txtsetup.sif/layout.inf to find the files to be renamed
  852. #
  853. # If a file is renamed, then its associated mui file should be renamed also
  854. #
  855. sub BuildRenameTable
  856. {
  857. my ($pItems,$nStart, $nEnd,$pRenameTable)= @_;
  858. my ($Line, $Trash, $Idx,$OldName,$NewName);
  859. for ($Idx = $nStart; $Idx <= $nEnd; $Idx++)
  860. {
  861. $Line=$$pItems[$Idx];
  862. chomp($Line);
  863. if ( length($Line) == 0)
  864. {
  865. next;
  866. }
  867. if (substr($Line,0,1) eq ";")
  868. {
  869. next;
  870. }
  871. if ($Line =~ /=\s*[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,([^,]+)/ )
  872. {
  873. $NewName=$1;
  874. ($OldName,$Trash) = split ( /=+/, $Line);
  875. $OldName =~ s/\s//g;
  876. $NewName=~ s/\s//g;
  877. if ( defined( $$pRenameTable{$OldName}))
  878. {
  879. push(@{ $$pRenameTable{$OldName}},$NewName);
  880. }
  881. else
  882. {
  883. $$pRenameTable{$OldName}=[($NewName)];
  884. }
  885. }
  886. }
  887. return 1;
  888. }
  889. sub BuildArray
  890. {
  891. my ($BigDosnet, $PerDosnet, $BlaDosnet, $SbsDosnet, $SrvDosnet , $EntDosnet , $DtcDosnet);
  892. my ($BigDosnet_sign, $PerDosnet_sign, $BlaDosnet_sign, $SbsDosnet_sign, $SrvDosnet_sign , $EntDosnet_sign , $DtcDosnet_sign);
  893. my ($BigTxtsetup, $PerTxtsetup, $BlaTxtsetup, $SbsTxtsetup, $SrvTxtsetup, $EntTxtsetup, $DtcTxtsetup);
  894. my ($BigTxtsetup_sign, $PerTxtsetup_sign, $BlaTxtsetup_sign, $SbsTxtsetup_sign, $SrvTxtsetup_sign, $EntTxtsetup_sign, $DtcTxtsetup_sign);
  895. my ($BigLayout, $PerLayout, $BlaLayout, $SbsLayout, $SrvLayout , $EntLayout, $DtcLayout);
  896. my ($BigLayout_sign, $PerLayout_sign, $BlaLayout_sign, $SbsLayout_sign, $SrvLayout_sign , $EntLayout_sign, $DtcLayout_sign);
  897. my ($Path_Dosnet, $Path_Txtsetup, $Path_Layout, $Path_Dir);
  898. my ($Path_Dosnet_sign, $Path_Txtsetup_sign, $Path_Layout_sign, $Path_Dir_sign);
  899. #
  900. # Get SKUs
  901. #
  902. %CDDataSKUs = map({uc$_ => cksku::CkSku($_, $lang, $ENV{_BuildArch})} qw(PRO PER SRV BLA SBS ADS DTC));
  903. #
  904. # Build Key INFs for SKUs
  905. #
  906. $BigDosnet = $nttree . "\\dosnet.inf";
  907. $PerDosnet = $nttree . "\\perinf\\dosnet.inf";
  908. $BlaDosnet = $nttree . "\\blainf\\dosnet.inf";
  909. $SbsDosnet = $nttree . "\\sbsinf\\dosnet.inf";
  910. $SrvDosnet = $nttree . "\\srvinf\\dosnet.inf";
  911. $EntDosnet = $nttree . "\\entinf\\dosnet.inf";
  912. $DtcDosnet = $nttree . "\\dtcinf\\dosnet.inf";
  913. $BigTxtsetup = $nttree . "\\txtsetup.sif";
  914. $PerTxtsetup = $nttree . "\\perinf\\txtsetup.sif";
  915. $BlaTxtsetup = $nttree . "\\blainf\\txtsetup.sif";
  916. $SbsTxtsetup = $nttree . "\\sbsinf\\txtsetup.sif";
  917. $SrvTxtsetup = $nttree . "\\srvinf\\txtsetup.sif";
  918. $EntTxtsetup = $nttree . "\\entinf\\txtsetup.sif";
  919. $DtcTxtsetup = $nttree . "\\dtcinf\\txtsetup.sif";
  920. $BigLayout = $nttree . "\\layout.inf";
  921. $PerLayout = $nttree . "\\perinf\\layout.inf";
  922. $BlaLayout = $nttree . "\\blainf\\layout.inf";
  923. $SbsLayout = $nttree . "\\sbsinf\\layout.inf";
  924. $SrvLayout = $nttree . "\\srvinf\\layout.inf";
  925. $EntLayout = $nttree . "\\entinf\\layout.inf";
  926. $DtcLayout = $nttree . "\\dtcinf\\layout.inf";
  927. $BigDosnet_sign = $nttree . "\\realsign\\dosnet.inf";
  928. $PerDosnet_sign = $nttree . "\\perinf\\realsign\\dosnet.inf";
  929. $BlaDosnet_sign = $nttree . "\\blainf\\realsign\\dosnet.inf";
  930. $SbsDosnet_sign = $nttree . "\\sbsinf\\realsign\\dosnet.inf";
  931. $SrvDosnet_sign = $nttree . "\\srvinf\\realsign\\dosnet.inf";
  932. $EntDosnet_sign = $nttree . "\\entinf\\realsign\\dosnet.inf";
  933. $DtcDosnet_sign = $nttree . "\\dtcinf\\realsign\\dosnet.inf";
  934. $BigTxtsetup_sign = $nttree . "\\realsign\\txtsetup.sif";
  935. $PerTxtsetup_sign = $nttree . "\\perinf\\realsign\\txtsetup.sif";
  936. $BlaTxtsetup_sign = $nttree . "\\blainf\\realsign\\txtsetup.sif";
  937. $SbsTxtsetup_sign = $nttree . "\\sbsinf\\realsign\\txtsetup.sif";
  938. $SrvTxtsetup_sign = $nttree . "\\srvinf\\realsign\\txtsetup.sif";
  939. $EntTxtsetup_sign = $nttree . "\\entinf\\realsign\\txtsetup.sif";
  940. $DtcTxtsetup_sign = $nttree . "\\dtcinf\\realsign\\txtsetup.sif";
  941. $BigLayout_sign = $nttree . "\\realsign\\layout.inf";
  942. $PerLayout_sign = $nttree . "\\perinf\\realsign\\layout.inf";
  943. $BlaLayout_sign = $nttree . "\\blainf\\realsign\\layout.inf";
  944. $SbsLayout_sign = $nttree . "\\sbsinf\\realsign\\layout.inf";
  945. $SrvLayout_sign = $nttree . "\\srvinf\\realsign\\layout.inf";
  946. $EntLayout_sign = $nttree . "\\entinf\\realsign\\layout.inf";
  947. $DtcLayout_sign = $nttree . "\\dtcinf\\realsign\\layout.inf";
  948. # PRO
  949. $Path_Dosnet =$BigDosnet;
  950. $Path_Txtsetup =$BigTxtsetup;
  951. $Path_Layout =$BigLayout;
  952. $Path_Dir ="ProInf";
  953. $Path_Dosnet_sign =$BigDosnet_sign;
  954. $Path_Txtsetup_sign =$BigTxtsetup_sign;
  955. $Path_Layout_sign =$BigLayout_sign;
  956. $Path_Dir_sign ="ProInf\\realsign";
  957. $INFPathSKUs{"PRO"} = [ ($Path_Dosnet,$Path_Txtsetup,$Path_Layout,$Path_Dir, $Path_Dosnet_sign,$Path_Txtsetup_sign,$Path_Layout_sign,$Path_Dir_sign) ];
  958. #PER
  959. $Path_Dosnet =$PerDosnet;
  960. $Path_Txtsetup =$PerTxtsetup;
  961. $Path_Layout =$PerLayout;
  962. $Path_Dir ="PerInf";
  963. $Path_Dosnet_sign =$PerDosnet_sign;
  964. $Path_Txtsetup_sign =$PerTxtsetup_sign;
  965. $Path_Layout_sign =$PerLayout_sign;
  966. $Path_Dir_sign ="PerInf\\realsign";
  967. $INFPathSKUs{"PER"} = [ ($Path_Dosnet,$Path_Txtsetup,$Path_Layout,$Path_Dir, $Path_Dosnet_sign,$Path_Txtsetup_sign,$Path_Layout_sign,$Path_Dir_sign) ];
  968. #SRV
  969. $Path_Dosnet =$SrvDosnet;
  970. $Path_Txtsetup =$SrvTxtsetup;
  971. $Path_Layout =$SrvLayout;
  972. $Path_Dir ="SrvInf";
  973. $Path_Dosnet_sign =$SrvDosnet_sign;
  974. $Path_Txtsetup_sign =$SrvTxtsetup_sign;
  975. $Path_Layout_sign =$SrvLayout_sign;
  976. $Path_Dir_sign ="SrvInf\\realsign";
  977. $INFPathSKUs{"SRV"} = [ ($Path_Dosnet,$Path_Txtsetup,$Path_Layout,$Path_Dir, $Path_Dosnet_sign,$Path_Txtsetup_sign,$Path_Layout_sign,$Path_Dir_sign) ];
  978. #BLA
  979. $Path_Dosnet =$BlaDosnet;
  980. $Path_Txtsetup =$BlaTxtsetup;
  981. $Path_Layout =$BlaLayout;
  982. $Path_Dir ="BlaInf";
  983. $Path_Dosnet_sign =$BlaDosnet_sign;
  984. $Path_Txtsetup_sign =$BlaTxtsetup_sign;
  985. $Path_Layout_sign =$BlaLayout_sign;
  986. $Path_Dir_sign ="BlaInf\\realsign";
  987. $INFPathSKUs{"BLA"} = [ ($Path_Dosnet,$Path_Txtsetup,$Path_Layout,$Path_Dir, $Path_Dosnet_sign,$Path_Txtsetup_sign,$Path_Layout_sign,$Path_Dir_sign) ];
  988. #SBS
  989. $Path_Dosnet =$SbsDosnet;
  990. $Path_Txtsetup =$SbsTxtsetup;
  991. $Path_Layout =$SbsLayout;
  992. $Path_Dir ="SbsInf";
  993. $Path_Dosnet_sign =$SbsDosnet_sign ;
  994. $Path_Txtsetup_sign =$SbsTxtsetup_sign ;
  995. $Path_Layout_sign =$SbsLayout_sign ;
  996. $Path_Dir_sign ="SbsInf\\realsign";
  997. $INFPathSKUs{"SBS"} = [ ($Path_Dosnet,$Path_Txtsetup,$Path_Layout,$Path_Dir, $Path_Dosnet_sign,$Path_Txtsetup_sign,$Path_Layout_sign,$Path_Dir_sign) ];
  998. #ADS (ENT)
  999. $Path_Dosnet =$EntDosnet;
  1000. $Path_Txtsetup =$EntTxtsetup;
  1001. $Path_Layout =$EntLayout;
  1002. $Path_Dir ="EntInf";
  1003. $Path_Dosnet_sign =$EntDosnet_sign;
  1004. $Path_Txtsetup_sign =$EntTxtsetup_sign;
  1005. $Path_Layout_sign =$EntLayout_sign;
  1006. $Path_Dir_sign ="EntInf\\realsign";
  1007. $INFPathSKUs{"ADS"} = [ ($Path_Dosnet,$Path_Txtsetup,$Path_Layout,$Path_Dir, $Path_Dosnet_sign,$Path_Txtsetup_sign,$Path_Layout_sign,$Path_Dir_sign) ];
  1008. #DTC
  1009. $Path_Dosnet =$DtcDosnet;
  1010. $Path_Txtsetup =$DtcTxtsetup;
  1011. $Path_Layout =$DtcLayout;
  1012. $Path_Dir ="DtcInf";
  1013. $Path_Dosnet_sign =$DtcDosnet_sign;
  1014. $Path_Txtsetup_sign =$DtcTxtsetup_sign;
  1015. $Path_Layout_sign =$DtcLayout_sign;
  1016. $Path_Dir_sign ="DtcInf\\realsign";
  1017. $INFPathSKUs{"DTC"} = [ ($Path_Dosnet,$Path_Txtsetup,$Path_Layout,$Path_Dir, $Path_Dosnet_sign,$Path_Txtsetup_sign,$Path_Layout_sign,$Path_Dir_sign) ];
  1018. return 1;
  1019. }