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.

375 lines
9.5 KiB

  1. #---------------------------------------------------------------------
  2. package ReadSetupFiles;
  3. #
  4. # Copyright (c) Microsoft Corporation. All rights reserved.
  5. #
  6. # Used to find and parse common setup files like
  7. # dosnet.inf, excdosnt.inf and drvindex.inf
  8. #
  9. #---------------------------------------------------------------------
  10. use strict;
  11. # Local include path
  12. use lib $ENV{ "RazzleToolPath" };
  13. use lib $ENV{ "RazzleToolPath" } . "\\PostBuildScripts";
  14. # Local includes
  15. use Logmsg;
  16. #
  17. # Function:
  18. # GetSetupDir
  19. #
  20. # Arguments:
  21. #
  22. # Sku (scalar) - sku to return setup dir for
  23. #
  24. # Purpose:
  25. # Returns the relative setup dir associated with the sku
  26. # per = perinf, pro=., bla=blainf, sbs=sbsinf, srv=srvinf, ads=entinf, dtc=dtcinf
  27. #
  28. # Returns:
  29. # String representing setup dir
  30. # UNDEF on failure
  31. sub GetSetupDir
  32. {
  33. my ( $Sku ) = @_;
  34. # Pro (wks) setup info is found at the root
  35. if ( $Sku =~ /^pro$/i ) {
  36. return ".";
  37. } elsif ( $Sku =~ /^ads$/i ) {
  38. # ADS used to be called ENT and the files are
  39. # still found under the old name
  40. return "entinf";
  41. } elsif ( $Sku =~ /^per$/i ||
  42. $Sku =~ /^bla$/i ||
  43. $Sku =~ /^sbs$/i ||
  44. $Sku =~ /^srv$/i ||
  45. $Sku =~ /^dtc$/i ) {
  46. return $Sku . "inf";
  47. } else {
  48. # Unrecognized SKU
  49. return ();
  50. }
  51. }
  52. #
  53. # Function:
  54. # ReadDosnet
  55. #
  56. # Arguments:
  57. #
  58. # RootPath (scalar) - path to the flat binaries\release share
  59. #
  60. # Sku (scalar) - per, pro, bla, sbs, srv, ads, dtc
  61. #
  62. # Architecture (scalar) - x86, amd64, ia64
  63. #
  64. # Files (array by ref) - Fills array in with files referenced from
  65. # primary location
  66. #
  67. # Wowfiles (array by ref) - Fills array in with files referenced from
  68. # secondary location (Win64 WOW files)
  69. #
  70. # Purpose:
  71. # Reads in a dosnet.inf file, returning the standard files
  72. #
  73. # Returns:
  74. # 1 if successful, undef otherwise
  75. #
  76. sub ReadDosnet
  77. {
  78. my ($RootPath, $Sku, $Architecture, $Files, $WowFiles,$TabletPCFiles) = @_;
  79. my ($DosnetPath, $RelativeSetupDir);
  80. my (@FullDosnetLines);
  81. $RelativeSetupDir = GetSetupDir( $Sku );
  82. if ( ! defined $RelativeSetupDir ) {
  83. errmsg( "Unrecognized SKU \"$Sku\"." );
  84. return ();
  85. }
  86. $RootPath =~ s/\\$//;
  87. $DosnetPath = $RootPath . "\\" . $RelativeSetupDir . "\\dosnet.inf";
  88. # Attempt to open the dosnet file
  89. unless ( open DOSNET, $DosnetPath ) {
  90. errmsg( "Failed to open $DosnetPath for reading." );
  91. return ();
  92. }
  93. @FullDosnetLines = <DOSNET>;
  94. close DOSNET;
  95. return ParseDosnetFile( \@FullDosnetLines, $Architecture, $Files, $WowFiles ,$TabletPCFiles );
  96. }
  97. #
  98. # Function:
  99. # ParseDosnetFile
  100. #
  101. # Arguments:
  102. # DosnetLines (array by ref) - ref to array containing contents
  103. # of a dosnet-style file
  104. #
  105. # Architecture (scalar) - x86, amd64, ia64
  106. #
  107. # Files (array by ref) - ref to array of files referenced from
  108. # the primary location will be stored
  109. #
  110. # WowFiles (array by ref) - ref to array of files referenced from
  111. # secondary location (WOW files for win64)
  112. # TabletPC (array by ref) - ref to array of files for abletPC files on
  113. # x86
  114. #
  115. # Purpose:
  116. # Contains the logic to parse a dosnet file
  117. #
  118. # Returns:
  119. # 1 if successful, undef otherwise
  120. #
  121. sub ParseDosnetFile
  122. {
  123. my ( $DosnetLines, $Architecture, $Files, $WowFiles ,$TabletPCFiles) = @_;
  124. my ($ReadFlag, $Line, $fIsWowFile, $fIsTabletPCFile);
  125. my (%CheckForRedundantFiles, %CheckForRedundantWowFiles,%CheckForRedundantTabletPCFiles);
  126. undef $ReadFlag;
  127. foreach $Line ( @$DosnetLines ) {
  128. chomp( $Line );
  129. next if ( ( length( $Line ) == 0 ) ||
  130. ( substr( $Line, 0, 1 ) eq ";" ) ||
  131. ( substr( $Line, 0, 1 ) eq "#" ) ||
  132. ( substr( $Line, 0, 2 ) eq "@*" ) );
  133. if ( $Line =~ /^\[/ ) { undef $ReadFlag; }
  134. if ( ( $Line =~ /^\[Files\]/ ) ||
  135. ( $Line =~ /^\[SourceDisksFiles\]/ ) ) {
  136. $ReadFlag = 1;
  137. } elsif ( $Line =~ /^\[SourceDisksFiles\.$Architecture\]/ ) {
  138. $ReadFlag = 1;
  139. } elsif ( $ReadFlag ) {
  140. my ($MyName, $SrcDir, $Junk);
  141. # Determine if this is a WOW file
  142. # and strip the source directory
  143. undef $fIsWowFile;
  144. undef $fIsTabletPCFile;
  145. if ( $Line =~ s/^d2\,// ) {
  146. if ( lc$ENV{_BUILDARCH} eq "ia64" ) {
  147. $fIsWowFile = 1;
  148. }
  149. else {
  150. $fIsTabletPCFile=1;
  151. }
  152. } else {
  153. $Line =~ s/^d1\,//;
  154. }
  155. ( $MyName, $SrcDir ) = split( /\,/, $Line );
  156. ( $MyName, $Junk ) = split( /\s/, $MyName );
  157. if ( $fIsWowFile ) {
  158. if ( ($CheckForRedundantWowFiles{ lc $MyName }++) > 1 ) {
  159. logmsg( "WARNING: redundant WOW file $MyName found." );
  160. } else {
  161. push @$WowFiles, $MyName;
  162. }
  163. }
  164. elsif ($fIsTabletPCFile) {
  165. if ( ($CheckForRedundantTabletPCFiles{ lc $MyName }++) > 1 ) {
  166. logmsg( "WARNING: redundant TabletPC file $MyName found." );
  167. } else {
  168. push @$TabletPCFiles, $MyName;
  169. }
  170. }
  171. else {
  172. if ( ($CheckForRedundantFiles{ lc $MyName }++) > 1 ) {
  173. logmsg( "WARNING: redundant file $MyName found." );
  174. } else {
  175. push @$Files, $MyName;
  176. }
  177. }
  178. }
  179. }
  180. return 1;
  181. }
  182. #
  183. # Function:
  184. # ReadExcDosnet
  185. #
  186. # Arguments:
  187. #
  188. # RootPath (scalar) - path to the flat binaries\release share
  189. #
  190. # Sku (scalar) - per, pro, bla, sbs, srv, ads, dtc
  191. #
  192. # Files (array by ref) - Fills array in with files listed in excdosnt.inf
  193. #
  194. # Purpose:
  195. # Reads in an excdosnt.inf file, returning the standard files
  196. #
  197. # Returns:
  198. # 1 if successful, undef otherwise
  199. #
  200. sub ReadExcDosnet
  201. {
  202. my ( $RootPath, $Sku, $Files ) = @_;
  203. my ($ExcDosnetPath, $RelativeSetupDir);
  204. my (@FullExcDosnetLines);
  205. $RelativeSetupDir = GetSetupDir( $Sku );
  206. if ( ! defined $RelativeSetupDir ) {
  207. errmsg( "Unrecognized SKU \"$Sku\"." );
  208. return ();
  209. }
  210. $RootPath =~ s/\\$//;
  211. $ExcDosnetPath = $RootPath . "\\" . $RelativeSetupDir . "\\excdosnt.inf";
  212. # Attempt to open the excdosnt file
  213. unless ( open EXCDOSNET, $ExcDosnetPath ) {
  214. errmsg( "Failed to open $ExcDosnetPath for reading." );
  215. return ();
  216. }
  217. @FullExcDosnetLines = <EXCDOSNET>;
  218. close EXCDOSNET;
  219. # Seems to work OK to parse excdosnt file as a dosnet file
  220. return ParseExcDosnetFile( \@FullExcDosnetLines, $Files );
  221. }
  222. #
  223. # Function:
  224. # ParseExcDosnetFile
  225. #
  226. # Arguments:
  227. # ExcDosnetLines (array by ref) - ref to array containing contents
  228. # of an excdosnt-style file
  229. #
  230. # Files (array by ref) - ref to array of files listed in excdosnt.inf
  231. #
  232. # Purpose:
  233. # Contains the logic to parse an excdosnt file
  234. #
  235. # Returns:
  236. # 1 if successful, undef otherwise
  237. #
  238. sub ParseExcDosnetFile
  239. {
  240. my ( $ExcDosnetLines, $Files ) = @_;
  241. my ($ReadFlag, $Line);
  242. my %CheckForRedundantFiles;
  243. undef $ReadFlag;
  244. foreach $Line ( @$ExcDosnetLines ) {
  245. chomp( $Line );
  246. if ( $Line =~ /^\[Files\]/ ) {
  247. $ReadFlag = 1;
  248. } elsif ( $ReadFlag ) {
  249. if ( ($CheckForRedundantFiles{ lc $Line }++) > 1 ) {
  250. logmsg( "WARNING: redundant file $Line found." );
  251. } else {
  252. push @$Files, $Line;
  253. }
  254. }
  255. }
  256. return 1;
  257. }
  258. #
  259. # Function:
  260. # ReadDrvIndex
  261. #
  262. # Arguments:
  263. #
  264. # RootPath (scalar) - path to the flat binaries\release share
  265. #
  266. # Sku (scalar) - per, pro, bla, sbs, srv, ads, dtc
  267. #
  268. # Files (array by ref) - Fills array in with files listed in drvindex.inf
  269. #
  270. # Purpose:
  271. # Reads in a drvindex.inf file, returning the files
  272. #
  273. # Returns:
  274. # 1 if successful, undef otherwise
  275. #
  276. sub ReadDrvIndex
  277. {
  278. my ( $RootPath, $Sku, $Files ) = @_;
  279. my ($DrvIndexPath, $RelativeSetupDir);
  280. my (@FullDrvIndexLines);
  281. $RelativeSetupDir = GetSetupDir( $Sku );
  282. if ( ! defined $RelativeSetupDir ) {
  283. errmsg( "Unrecognized SKU \"$Sku\"." );
  284. return ();
  285. }
  286. $RootPath =~ s/\\$//;
  287. $DrvIndexPath = $RootPath . "\\" . $RelativeSetupDir . "\\drvindex.inf";
  288. # Attempt to open the drvindex file
  289. unless ( open DRVINDEX, $DrvIndexPath ) {
  290. errmsg( "Failed to open $DrvIndexPath for reading." );
  291. return ();
  292. }
  293. @FullDrvIndexLines = <DRVINDEX>;
  294. close DRVINDEX;
  295. # Seems to work OK to parse excdosnt file as a dosnet file
  296. return ParseDrvIndexFile( \@FullDrvIndexLines, $Files );
  297. }
  298. #
  299. # Function:
  300. # ParseDrvIndexFile
  301. #
  302. # Arguments:
  303. # DrvIndexLines (array by ref) - ref to array containing contents
  304. # of a drvindex-style file
  305. #
  306. # Files (array by ref) - ref to array of files listed in drvindex.inf
  307. #
  308. # Purpose:
  309. # Contains the logic to parse a drvindex file
  310. #
  311. # Returns:
  312. # 1 if successful, undef otherwise
  313. #
  314. sub ParseDrvIndexFile
  315. {
  316. my ( $DrvIndexLines, $Files ) = @_;
  317. my ($ReadFlag, $Line);
  318. my %CheckForRedundantFiles;
  319. undef $ReadFlag;
  320. foreach $Line ( @$DrvIndexLines ) {
  321. chomp( $Line );
  322. next if ( 0 == length($Line) || $Line =~ /^\;/ );
  323. if ( $Line =~ /\[driver\]/ ) {
  324. $ReadFlag = 1;
  325. } elsif ( $Line =~ /\[/ ) {
  326. undef $ReadFlag;
  327. } elsif ( $ReadFlag ) {
  328. if ( ($CheckForRedundantFiles{ lc $Line }++) > 1 ) {
  329. logmsg( "WARNING: redundant file $Line found." );
  330. } else {
  331. push @$Files, $Line;
  332. }
  333. }
  334. }
  335. return 1;
  336. }
  337. 1;