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.

364 lines
11 KiB

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