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.

477 lines
14 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM MUICommInf.cmd
  5. REM Parse MUI component INF and comment out those lines contain files don't exist
  6. REM
  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. require Exporter;
  24. BEGIN {
  25. $ENV{SCRIPT_NAME} = 'Comminf.cmd';
  26. }
  27. sub Usage { print<<USAGE; exit(1) }
  28. MUIcommINF
  29. -m:Path_of_INF
  30. -d:Mofified_INF_Path
  31. -s:Default Install Section
  32. -p:Bin Path
  33. -o:yes (overwrite file)
  34. Parse MUI component INF and cooment out those lines contain files don't exist
  35. USAGE
  36. my ($INFPath, $INF_Mod_Path, $DefaultInstallSection, $BinPath, $OverwriteFlag, $Overwrite, $Progname, $_BuildArch, $_NTPOSTBLD, $RAZZLETOOLPATH);
  37. my (@Items, $Dirty);
  38. my ($LogFilename, $TempDir);
  39. $Progname=$0;
  40. parseargs( '?' => \&Usage,
  41. 'm:' => \$INFPath,
  42. 'd:' => \$INF_Mod_Path,
  43. 's:' => \$DefaultInstallSection,
  44. 'p:' => \$BinPath,
  45. 'o:' => \$OverwriteFlag
  46. );
  47. $Overwrite=0;
  48. if (defined ($OverwriteFlag))
  49. {
  50. $OverwriteFlag="\L$OverwriteFlag";
  51. if ( $OverwriteFlag eq "yes")
  52. {
  53. $Overwrite=1;
  54. }
  55. }
  56. &main();
  57. sub main
  58. {
  59. my ($Line);
  60. $Dirty=0;
  61. $LogFilename = $ENV{ "LOGFILE" };
  62. if ( ! defined( $LogFilename ) )
  63. {
  64. $TempDir = $ENV{ "TMP" };
  65. $LogFilename = "$TempDir\\$Progname.log";
  66. }
  67. if ($ENV{_BuildArch}=~/x86/i)
  68. {
  69. $_BuildArch="i386";
  70. }
  71. else
  72. {
  73. $_BuildArch=$ENV{_BuildArch};
  74. }
  75. $_NTPOSTBLD=$ENV{_NTPOSTBLD};
  76. #
  77. #
  78. #
  79. $RAZZLETOOLPATH=$ENV{RazzleToolPath};
  80. if (! defined($DefaultInstallSection))
  81. {
  82. logthemsg("$Progname: ** Warning: Default install section is not set");
  83. exit 3;
  84. }
  85. if (! -e $INFPath)
  86. {
  87. logthemsg("$Progname: ** Warning: $INFPath doesn't exist");
  88. exit 1;
  89. }
  90. if (! -d $BinPath)
  91. {
  92. logthemsg("$Progname: ** Warning: Bin folder $BinPath doesn't exist");
  93. exit 2;
  94. }
  95. unless (open(INFILE,$INFPath))
  96. {
  97. logthemsg("$Progname: ** Warning: Can't open $INFPath for Read");
  98. exit 1;
  99. }
  100. @Items=<INFILE>;
  101. close(INFILE);
  102. &DoTheChange();
  103. #
  104. # Rewrite the INF file if we commented out some lines
  105. #
  106. if (($Dirty) && ($Overwrite))
  107. {
  108. unless(open(OUTFILE,">$INF_Mod_Path"))
  109. {
  110. logthemsg("$Progname: ** Fatal: can't rewrite $INF_Mod_Path");
  111. exit 4;
  112. }
  113. foreach $Line (@Items)
  114. {
  115. print(OUTFILE "$Line");
  116. }
  117. close(OUTFILE);
  118. logthemsg("$Progname: $INF_Mod_Path is rewritten");
  119. }
  120. exit 0;
  121. }
  122. sub DoTheChange
  123. {
  124. my (@ComponentFileInstall, $ComponentInstall, $Start_idx, $End_idx, $Result);
  125. my ($ComponentFileCopySections, $CopyFileSectionName, @ComponentFileList, $total_files_copied,$file_errors);
  126. my (%TheStringSection);
  127. $Result=0;
  128. if ( !&GetTheSection($DefaultInstallSection,\@Items,\@ComponentFileInstall,\$Start_idx,\$End_idx))
  129. {
  130. logthemsg("$Progname: ** Warning: can't find Default Insatll Section : $DefaultInstallSection from $INFPath");
  131. return $Result;
  132. }
  133. &BuildUpStringSection(\%TheStringSection);
  134. #
  135. # Read the default install section
  136. #
  137. foreach $ComponentInstall (@ComponentFileInstall)
  138. {
  139. #logthemsg ($ComponentInstall);
  140. #
  141. #Parse CopyFiles list
  142. #
  143. if ($ComponentInstall =~ /.*CopyFiles.*=(.*)/i)
  144. {
  145. $ComponentFileCopySections = $1;
  146. #Loop through all sections
  147. while ($ComponentFileCopySections ne "")
  148. {
  149. if ($ComponentFileCopySections =~ /([^\,]*),(.*)/i)
  150. {
  151. $ComponentFileCopySections = $2;
  152. $CopyFileSectionName = $1;
  153. }
  154. else
  155. {
  156. $CopyFileSectionName = $ComponentFileCopySections;
  157. $ComponentFileCopySections = "";
  158. }
  159. @ComponentFileList=();
  160. if ( !&GetTheSection($CopyFileSectionName,\@Items,\@ComponentFileList,\$Start_idx,\$End_idx))
  161. {
  162. logthemsg("$Progname: ** Warning: can't find Section : $CopyFileSectionName from $INFPath");
  163. return $Result;
  164. }
  165. &CheckCopyFileList($BinPath,\$Dirty,$Start_idx,$End_idx,\@Items,\$total_files_copied,\$file_errors,\%TheStringSection);
  166. }
  167. }
  168. }
  169. }
  170. sub CheckCopyFileList
  171. {
  172. my ($SrcRootDir, $Dirty, $StartIdx, $EndIdx, $FileList, $total_files_copied,$file_errors, $pTheStringSection) = @_;
  173. my ($Idx, $Line,$SrcFile,$SrcCopyFile);
  174. my ($Replaced, $SrcFileNew, $Doit, $DoCnt, $TheLine);
  175. $$file_errors = 0;
  176. $$total_files_copied = 0;
  177. #Loop through all control file entries
  178. for ($Idx=$StartIdx; $Idx <= $EndIdx; $Idx++)
  179. {
  180. $SrcFile=$$FileList[$Idx];
  181. chomp $SrcFile;
  182. if ($SrcFile !~ /\w/)
  183. {
  184. next;
  185. }
  186. if (substr($SrcFile,0,1) eq ";")
  187. {
  188. next;
  189. }
  190. $$total_files_copied+=1;
  191. #
  192. # Source file could be in the format of "[original file], [compressed file]"
  193. #
  194. if ($SrcFile =~ /(.*),\s*(.*)\s*/)
  195. {
  196. $SrcFile = $2;
  197. }
  198. #Make sure source file doesn't contain MUI extension
  199. if ($SrcFile =~ /(.*)\.mu_/i ||$SrcFile =~ /(.*)\.mui/i )
  200. {
  201. $SrcFile = $1;
  202. }
  203. #
  204. # Check if $SrcFile contains strings as %string1%%string2%....
  205. #
  206. #%DATAFILE2%%LCID2%.dat
  207. $Doit=1;
  208. $DoCnt=0;
  209. $SrcFileNew=$SrcFile;
  210. while( ($Doit) && ($SrcFileNew =~ /(.*)%(.*)%(.*)/))
  211. {
  212. if ( defined ($$pTheStringSection{$2}))
  213. {
  214. $Replaced=$$pTheStringSection{$2};
  215. $SrcFileNew=$1.$Replaced.$3;
  216. $DoCnt++;
  217. }
  218. else
  219. {
  220. logthemsg("**** Can't map:$2*");
  221. $SrcFileNew=$SrcFile;
  222. $Doit=0;
  223. }
  224. }
  225. if (($Doit) && ($DoCnt))
  226. {
  227. logthemsg("$SrcFile is mapped to $SrcFileNew");
  228. #
  229. # We want to also replace this line so that MSI can handle easily
  230. #
  231. $Line=$$FileList[$Idx];
  232. $Line =~ s/$SrcFile/$SrcFileNew/g;
  233. $TheLine=$Idx+1;
  234. logthemsg("Line_no:$TheLine is changed from $$FileList[$Idx] to $Line");
  235. $$FileList[$Idx]=$Line;
  236. $$Dirty+=1;
  237. }
  238. $SrcFile=$SrcFileNew;
  239. $SrcCopyFile = "$SrcRootDir\\$SrcFile";
  240. if (!(-e $SrcCopyFile))
  241. {
  242. $SrcCopyFile = "$SrcRootDir\\dump\\$SrcFile";
  243. }
  244. if (!(-e $SrcCopyFile))
  245. {
  246. $SrcCopyFile = "$SrcRootDir\\netfx\\$SrcFile";
  247. }
  248. if (!(-e $SrcCopyFile))
  249. {
  250. $SrcCopyFile = "$SrcRootDir\\mui\\drop\\$SrcFile";
  251. }
  252. if (!(-e $SrcCopyFile))
  253. {
  254. $SrcCopyFile = "$SrcRootDir\\uddi\\system32\\$SrcFile";
  255. }
  256. if (!(-e $SrcCopyFile))
  257. {
  258. $SrcCopyFile = "$SrcRootDir\\uddi\\resources\\$SrcFile";
  259. }
  260. if (!(-e $SrcCopyFile))
  261. {
  262. $SrcCopyFile = "$SrcRootDir\\uddi\\help\\$SrcFile";
  263. }
  264. if (!(-e $SrcCopyFile))
  265. {
  266. $SrcCopyFile = "$SrcRootDir\\uddi\\webroot\\help\\default\\$SrcFile";
  267. }
  268. if (!(-e $SrcCopyFile))
  269. {
  270. $SrcCopyFile = "$SrcRootDir\\uddi\\webroot\\help\\default\\images\\$SrcFile";
  271. }
  272. #
  273. # For ia64, we need to try some extral step to get external files
  274. # from wow64 or i386 release server
  275. if (!(-e $SrcCopyFile) && ($_BuildArch =~ /ia64/i))
  276. {
  277. if (!(-e $SrcCopyFile))
  278. {
  279. $SrcCopyFile = "$SrcRootDir\\wowbins_uncomp\\$SrcFile";
  280. }
  281. if (!(-e $SrcCopyFile))
  282. {
  283. $SrcCopyFile = "$SrcRootDir\\wowbins\\$SrcFile";
  284. }
  285. if (-e "$_NTPOSTBLD\\build_logs\\cplocation.txt" && !(-e $SrcCopyFile))
  286. {
  287. if (open (X86_BIN, "$_NTPOSTBLD\\build_logs\\cplocation.txt"))
  288. {
  289. $SrcRootDir = <X86_BIN>;
  290. chomp ($SrcRootDir);
  291. $SrcCopyFile = "$SrcRootDir\\$SrcFile";
  292. if (!(-e $SrcCopyFile))
  293. {
  294. $SrcCopyFile = "$SrcRootDir\\dump\\$SrcFile";
  295. }
  296. if (!(-e $SrcCopyFile))
  297. {
  298. $SrcCopyFile = "$SrcRootDir\\mui\\drop\\$SrcFile";
  299. }
  300. logthemsg("$Progname: ** Copy $SrcCopyFile from i386 release");
  301. close (X86_BIN);
  302. }
  303. }
  304. }
  305. if ( ( ! -e $SrcCopyFile) && (!($SrcCopyFile =~ /\.inf/i)) )
  306. {
  307. #
  308. #
  309. # File doesn't exist, cooment out this line
  310. #
  311. $$Dirty+=1;
  312. $Line=$$FileList[$Idx];
  313. $Line=';'.$Line;
  314. $$FileList[$Idx]=$Line;
  315. $$file_errors+=1;
  316. $TheLine=$Idx+1;
  317. logthemsg("Line no: $TheLine is commented out=> $Line ");
  318. }
  319. }
  320. return $$file_errors;
  321. }
  322. #-----------------------------------------------------------------------------
  323. # Build the hash for the string in [Strings] sections of a INF file
  324. #-----------------------------------------------------------------------------
  325. sub BuildUpStringSection
  326. {
  327. my ($pTheStringSection) = @_;
  328. my (@StringItems, $Section, $Line, $Counter, $Start_idx,$End_idx);
  329. $Section='Strings';
  330. %$pTheStringSection={};
  331. $Counter=0;
  332. if ( !&GetTheSection($Section,\@Items,\@StringItems,\$Start_idx,\$End_idx))
  333. {
  334. return $Counter;
  335. }
  336. ;
  337. foreach $Line (@StringItems)
  338. {
  339. chomp($Line);
  340. if (length($Line) == 0)
  341. {
  342. next;
  343. }
  344. if ($Line !~ /\w/)
  345. {
  346. next;
  347. }
  348. if (substr($Line,0,1) eq ";")
  349. {
  350. next;
  351. }
  352. #logmsg("StringLine:$Line");
  353. if ( $Line =~ /\s*(\S+)\s*=\s*(\S*)/ )
  354. {
  355. $$pTheStringSection {$1} = $2;
  356. $Counter++;
  357. #logmsg("*****$1\\$2****");
  358. }
  359. }
  360. return $Counter;
  361. }
  362. sub GetTheSection
  363. {
  364. my ($SectioName, $pItems, $pSectionContent, $Start_Idx, $End_Idx) = @_;
  365. my ($Idx, $Limit, $InSection, $LeadingChar, $Line, $Pattern, $Result);
  366. $Idx=0;
  367. $InSection=0;
  368. $Limit=scalar(@$pItems);
  369. $Pattern='^\[' . $SectioName . '\]$';
  370. $$Start_Idx = -1;
  371. $$End_Idx = -1;
  372. $Result=0;
  373. for ($Idx=0; $Idx < $Limit; $Idx++)
  374. {
  375. $Line=$$pItems[$Idx];
  376. $LeadingChar=substr($Line,0,1);
  377. if ($LeadingChar ne ";")
  378. {
  379. if ($LeadingChar eq "[")
  380. {
  381. if ( $Line =~ /$Pattern/i )
  382. {
  383. if ( ! $InSection)
  384. {
  385. $InSection = 1;
  386. }
  387. }
  388. else
  389. {
  390. if ($InSection)
  391. {
  392. $$End_Idx=$Idx-1;
  393. $InSection=0;
  394. }
  395. }
  396. next;
  397. }
  398. if ($InSection)
  399. {
  400. if ($$Start_Idx == -1)
  401. {
  402. $$Start_Idx=$Idx;
  403. }
  404. push(@$pSectionContent,$Line);
  405. }
  406. }
  407. }
  408. if ($InSection && ($$End_Idx== -1 ))
  409. {
  410. $$End_Idx=$Idx-1;
  411. }
  412. if (($$Start_Idx != -1) && ($$End_Idx != -1))
  413. {
  414. $Result=1;
  415. }
  416. return $Result;
  417. }
  418. sub logthemsg
  419. {
  420. my ($Msgs) = @_;
  421. logmsg("$Msgs");
  422. }