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.

370 lines
11 KiB

  1. ##############################################################
  2. #
  3. # GenFileLayout.pl
  4. #
  5. # Perl script to generate the [File_Layout] section in mui.inx.
  6. #
  7. # Note:
  8. #
  9. # The sciprt does the following:
  10. #
  11. # 1. This script will scan the content of layout.inx
  12. # (in %_NTDRIVE%%_NTROOT%\MergedComponents\SetupInfs\layout.inx)
  13. # and layout.txt
  14. # (in %_NTDRIVE%%_NTROOT%\MergedComponents\SetupInfs\usa\layout.txt).
  15. #
  16. # 2. And then it will figure out the files to be renamed from these two
  17. # files for different platforms (Pro/Server/Advanced Server/DataCenter).
  18. #
  19. # 3. From the file list, it will check the binary folder to see
  20. # if the file to be renamed already exists. If yes, it will
  21. # mark a warning in the output.
  22. #
  23. # 00/12/23 Created by YSLin
  24. #
  25. ##############################################################
  26. if ($#ARGV < 2)
  27. {
  28. PrintUsage();
  29. exit 1;
  30. }
  31. $gLayoutFileName = $ARGV[0];
  32. $gLayoutTxtFileName = $ARGV[1];
  33. $gUSBinDir = $ARGV[2];
  34. if ($#ARGV>=2)
  35. {
  36. $gMUIBinDir = $ARGV[3];
  37. } else
  38. {
  39. $gMUIBinDir = "";
  40. }
  41. #
  42. # The name for the [SourceDisksFiles] section in layout.inx.
  43. #
  44. $gFileLayoutSectionNameCommon = "[SourceDisksFiles]";
  45. $gFileLayoutSectionNamex86 = "[SourceDisksFiles.x86]";
  46. $gFileLayoutSectionNameia64 = "[SourceDisksFiles.ia64]";
  47. $gFileLayoutSectionName = $gFileLayoutSectionNameCommon;
  48. $gProfessionalOption = "P";
  49. $gServerOption = "S";
  50. $gAdvancedServerOption = "A";
  51. $gDataCenterOption = "D";
  52. $gBladeServerOption = "B";
  53. $gSmallBusinessServerOption = "L";
  54. #
  55. # All of the target platforms in mui.inx.
  56. # Currently, they are Professional, Server, and Advanced Server.
  57. #
  58. $gAllPlatforms = "$gProfessionalOption,$gServerOption,$gAdvancedServerOption,$gDataCenterOption,$gBladeServerOption,$gSmallBusinessServerOption";
  59. #
  60. # @p Personal Only
  61. # @w Professional (implies @p)
  62. # @w!p Professional but not Personal
  63. # @@!p Everything except Personal
  64. # @@!d Everything except Data Center
  65. # @s Server (implies @e and @d - and @b and @l too)
  66. # @e Enterprise (implies @d)
  67. # @d Data Center
  68. # @b Blade only
  69. # @s!e @s but NOT @e and @d
  70. # @s!d @s but NOT @d
  71. # @e!d @e but NOT @d
  72. # @s!e!d @s but NOT @e and @d
  73. # @@!d!b everything except for Datacenter and Blade Server
  74. # @l Small Business Server
  75. #
  76. %gPlatforms = (
  77. '@p' , '',
  78. '@w' , $gProfessionalOption,
  79. '@w!p' , $gProfessionalOption,
  80. '@@!p' , "$gProfessionalOption,$gServerOption,$gAdvancedServerOption,$gDataCenterOption,$gBladeServerOption,$gSmallBusinessServerOption",
  81. '@@!d', "$gProfessionalOption,$gServerOption,$gAdvancedServerOption,$gBladeServerOption,$gSmallBusinessServerOption",
  82. '@@' , "$gProfessionalOption,$gServerOption,$gAdvancedServerOption,$gDataCenterOption,$gBladeServerOption,$gSmallBusinessServerOption",
  83. '@s' , "$gServerOption,$gAdvancedServerOption,$gDataCenterOption,$gBladeServerOption,$gSmallBusinessServerOption",
  84. '@e' , "$gAdvancedServerOption,$gDataCenterOption",
  85. '@d' , $gDataCenterOption,
  86. '@b', $gBladeServerOption,
  87. '@l', $gSmallBusinessServerOption,
  88. '@s!e' , "$gServerOption,$gBladeServerOption,$gSmallBusinessServerOption",
  89. '@s!d' , "$gServerOption,$gAdvancedServerOption,$gBladeServerOption,$gSmallBusinessServerOption",
  90. '@e!d' , $gAdvancedServerOption,
  91. '@s!e!b' , "$gServerOption,$gSmallBusinessServerOption",
  92. '@s!d!e' , "$gServerOption,$gBladeServerOption,$gSmallBusinessServerOption",
  93. '@s!e!d' , "$gServerOption,$gBladeServerOption,$gSmallBusinessServerOption",
  94. '@s!e!b!l' ,$gServerOption,
  95. '@@!d!b' , "$gProfessionalOption,$gServerOption,$gAdvancedServerOption,$gSmallBusinessServerOption"
  96. );
  97. #$gPlatforms{'@w'} = $gProfessionalOption;
  98. %gStrings = GetProfileValues($gLayoutTxtFileName, '[Strings]');
  99. $fileCount = 0;
  100. $warnings = 0;
  101. NEXTSECTION:
  102. open LAYOUTFILE, $gLayoutFileName; # | die "Can not open " . $ARGV[0];
  103. $FindFileLayoutSection = 0;
  104. while (<LAYOUTFILE>)
  105. {
  106. #
  107. # Match the [SourceDiskFiles] at the beginning of a line.
  108. # \Q\E is used because "[" & "]" are used in the pattern.
  109. #
  110. if (/^\Q$gFileLayoutSectionName\E/ )
  111. {
  112. $FindFileLayoutSection = 1;
  113. last;
  114. }
  115. }
  116. if (!$FindFileLayoutSection)
  117. {
  118. print "No $gFileLayoutSectionName section is found.\n";
  119. close LAYOUTFILE;
  120. exit 1;
  121. }
  122. while (<LAYOUTFILE>)
  123. {
  124. #
  125. # If another line beginning with "[" is encountered, that's the beginning
  126. # of another secion, we can stop the processing.
  127. #
  128. # Match (Beginning of line)(Optional spaces)([)
  129. #
  130. if (/^\s*\Q[\E/)
  131. {
  132. last;
  133. }
  134. #
  135. # Match (Optional spaces)(Non-space characters):(Non-Spaces characters)(Optional spaces)=(Optional Spaces)(Non-space characters)
  136. # The part before the ":" will be $1.
  137. # The part after ":" and before "=" will be $2.
  138. # The part after the "=" will be $3.
  139. #
  140. if (!/\s*(\S*):(\S*).*=\s*(\S*)/)
  141. {
  142. #
  143. # If the pattern does not match, skip to next line.
  144. #
  145. next;
  146. }
  147. $targetPlatforms = $1;
  148. $fileName = $2;
  149. $fieldData = $3;
  150. #print "$targetPlatforms, $fileName, $fieldData\n";
  151. if ($targetPlatforms =~ /@\*/ || $targetPlatforms =~ /\s*;/)
  152. {
  153. #
  154. # Skip the comment line. A comment line will contain "@*" or begin with ";"
  155. #
  156. next;
  157. }
  158. #
  159. # Split the fields using comma separator.
  160. #
  161. @fields = split /,/, $fieldData;
  162. $renameFile = $fields[10];
  163. my $MUIFileExist = 0;
  164. if ($gMUIBinDir eq "")
  165. {
  166. # Don't check if the file exists in the MUI bin folder,
  167. # so just set the following flag to 1.
  168. $MUIFileExist = 1;
  169. } else
  170. {
  171. # Check if the file exists in the MUI bin folder.
  172. $muiFile = "$gMUIBinDir\\$fileName.mui";
  173. if (-e $muiFile)
  174. {
  175. $MUIFileExist = 1;
  176. } else
  177. {
  178. $muiFile = "$gMUIBinDir\\$fileName";
  179. if (-e $muiFile)
  180. {
  181. $MUIFileExist = 1;
  182. }
  183. }
  184. }
  185. # print "$muiFile\n";
  186. if (length($renameFile) > 0 && $MUIFileExist)
  187. {
  188. # $1 is the target platform, $2 is the [optional] architecture
  189. if ($targetPlatforms =~ /(.*):.*/)
  190. {
  191. $targetPlatforms = $1;
  192. }
  193. #for ($i = 0; $ i <= $#fields; $i++)
  194. #{
  195. # print " [$fields[$i]]\n";
  196. #}
  197. # print " [" . $fields[10] . "]\n";
  198. # print "[". $gPlatforms{$targetPlatforms} . "]\n";
  199. if ($renameFile =~ /.*%(.*)%.*/)
  200. {
  201. # print "!$1!$gStrings{$1}!\n";
  202. $key = $1;
  203. $renameFile =~ s/%$key%/$gStrings{$key}/;
  204. }
  205. $option = $gPlatforms{lc($targetPlatforms)};
  206. if (!(defined $option))
  207. {
  208. print "; WARNING: Unknown platform filter: $targetPlatforms.\n";
  209. next;
  210. }
  211. if (length($option) > 0)
  212. {
  213. $fileCount++;
  214. # Append proper filter flags for different sections, note that here we also make every file available for all SKUs
  215. # since we need mui.inx to be built with every entry in the file layout section appear when it's built for workstation SKU (which
  216. # we are using for all SKUs. The flags after the file are the only thing used by us.
  217. if ($gFileLayoutSectionName eq $gFileLayoutSectionNameCommon)
  218. {
  219. print "@@".":".$fileName . "=" . $renameFile . "," . $option . "\n";
  220. # print $targetPlatforms.":".$fileName . "=" . $renameFile . "," . $option . "\n";
  221. }
  222. elsif ($gFileLayoutSectionName eq $gFileLayoutSectionNamex86)
  223. {
  224. print "@@".":\@i:".$fileName . "=" . $renameFile . "," . $option . "\n";
  225. # print $targetPlatforms.":\@i:".$fileName . "=" . $renameFile . "," . $option . "\n";
  226. }
  227. elsif ($gFileLayoutSectionName eq $gFileLayoutSectionNameia64)
  228. {
  229. print "@@".":\@m:".$fileName . "=" . $renameFile . "," . $option . "\n";
  230. # print $targetPlatforms.":\@m:".$fileName . "=" . $renameFile . "," . $option . "\n";
  231. }
  232. if (-e ($gUSBinDir . "\\" . $renameFile))
  233. {
  234. $warnings++;
  235. printf "; WARNING: $renameFile has the same name\n";
  236. }
  237. }
  238. }
  239. #
  240. # Match (Optional spaces)(Non-space characters):(Non-Spaces characters)(Optional spaces)=(Optional Spaces)(Non-space characters)
  241. # The part before the ":" will be $1.
  242. # The part after ":" and before "=" will be $2.
  243. # The part after the "=" will be $3.
  244. #
  245. /\s*(\S*):(\S*).*=\s*(\S*)/;
  246. $targetPlatforms = $1;
  247. $fileName = $2;
  248. }
  249. close LAYOUTFILE;
  250. if ($gFileLayoutSectionName eq $gFileLayoutSectionNameCommon)
  251. {
  252. $gFileLayoutSectionName = $gFileLayoutSectionNameia64;
  253. print ";$gFileLayoutSectionName\n";
  254. goto NEXTSECTION;
  255. } elsif ($gFileLayoutSectionName eq $gFileLayoutSectionNameia64)
  256. {
  257. $gFileLayoutSectionName = $gFileLayoutSectionNamex86;
  258. print ";$gFileLayoutSectionName\n";
  259. goto NEXTSECTION;
  260. }
  261. print "; Total files to be renamed: $fileCount\n";
  262. if ($warnings > 0)
  263. {
  264. print "; Total files have warnings: $warnings\n";
  265. }
  266. sub PrintUsage
  267. {
  268. print "Usage: perl GenFileLayout.pl <Path to layout.inx> <Path to layout.txt> <US binary direcotry> [Path to MUI binary directory]\n";
  269. print "[Path to MUI binary directory] is optional."
  270. }
  271. sub GetProfileValues
  272. {
  273. my ($profileName, $section) = @_;
  274. my $findSection = 0;
  275. my ($key, $value);
  276. my ($result);
  277. open PROFILE, $profileName;
  278. while (<PROFILE>)
  279. {
  280. #
  281. # Match (Beginning of line)(Optional white spaces)([$section])
  282. #
  283. if (/^\s*\Q$section\E/)
  284. {
  285. $findSection = 1;
  286. last;
  287. }
  288. }
  289. if (!$findSection)
  290. {
  291. print "$section is not found in $profileName.\n";
  292. exit 1;
  293. }
  294. while (<PROFILE>)
  295. {
  296. #
  297. # If another line beginning with "[" is encountered, that's the beginning
  298. # of another secion, we can stop the processing.
  299. #
  300. # Match (Beginning of line)(Optional spaces)([)
  301. #
  302. if (/^\s*\Q[\E/)
  303. {
  304. last;
  305. }
  306. #
  307. # Match (Optional spaces)(Non-space characters)(Optional spaces)=(Optional Spaces)(Non-space character)(Everything after)
  308. # The part before "=" will be $1.
  309. # The part after the "=" will be $2.
  310. #
  311. /\s*(\S*).*=\s*(\S.*)/;
  312. $key = $1;
  313. $value = $2;
  314. #print "[$key]=[$value]\n";
  315. $result{$key} = $value;
  316. }
  317. close PROFILE;
  318. return (%result);
  319. }