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.

165 lines
4.0 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM infsize.cmd
  5. REM Adds file sizes to layout.inf
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM
  9. REM ------------------------------------------------------------------
  10. perl -x "%~f0" %*
  11. goto :EOF
  12. #!perl
  13. #line 14
  14. use strict;
  15. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  16. use lib $ENV{RAZZLETOOLPATH} . "\\sp";
  17. use lib $ENV{RAZZLETOOLPATH};
  18. use File::Temp;
  19. use File::Copy;
  20. use Logmsg;
  21. use PbuildEnv;
  22. use ParseArgs;
  23. sub Usage { print<<USAGE; exit(1) }
  24. infsize -i:<inf> [-d:<file>] <path>
  25. -i:<inf> update the layout.inf specified
  26. -d:<file> File containing default sizes (used when file
  27. is not found in <path>). Format of the file
  28. is one entry per line consisting of
  29. <filename>:<default_size>
  30. <path> Find files in specified path
  31. USAGE
  32. my ($inf_file, $default_file );
  33. my @paths;
  34. parseargs('?' => \&Usage,
  35. 'i:' => \$inf_file,
  36. 'd:' => \$default_file,
  37. \@paths );
  38. if ( !$inf_file || !@paths || @ARGV )
  39. {
  40. errmsg( "Invalid parameters" . (@ARGV?": ".(join " ", @ARGV):"") );
  41. Usage();
  42. }
  43. my %default_sizes;
  44. my $line_num;
  45. if ( $default_file )
  46. {
  47. if ( !open DEFAULT, $default_file )
  48. {
  49. errmsg( "Could not open $default_file ($!)" );
  50. exit 1;
  51. }
  52. $line_num = 0;
  53. foreach (<DEFAULT>)
  54. {
  55. $line_num++;
  56. if ( /^\s*$/ ) {next} # skip empty lines
  57. if ( /^\s*;/ ) {next} # skip comments (;)
  58. if ( /^([^:]+):(\d+)\s*$/ )
  59. {
  60. $default_sizes{lc$1} = $2;
  61. }
  62. else
  63. {
  64. wrnmsg( "Unrecognized entry in $default_file at line $line_num: $_" );
  65. }
  66. }
  67. close DEFAULT;
  68. }
  69. my ($fhTMP, $temp_inf) = File::Temp::tempfile( DIR=>$ENV{TEMP} );
  70. if ( !defined $fhTMP )
  71. {
  72. errmsg( "Unable to create temporary file -- fatal" );
  73. exit 1;
  74. }
  75. if ( !open INF, $inf_file )
  76. {
  77. errmsg( "Could not open $inf_file ($!)" );
  78. exit 1;
  79. }
  80. binmode INF;
  81. my $arch = $ENV{_BUILDARCH};
  82. my $fParseLine;
  83. $line_num = 0;
  84. foreach (<INF>)
  85. {
  86. $line_num++;
  87. if (/^\s*$/) {} # ignore empty lines
  88. elsif (/^;/) {} # ignore comments
  89. # Check for new SourceDisksFiles section entries
  90. elsif (/\s*\[SourceDisksFiles(?:\.$arch)?\]/) {$fParseLine = 1}
  91. # Ignore lines in other section entries
  92. elsif( /\s*\[/ ) {undef $fParseLine}
  93. # process lines inside of matching sections
  94. elsif( $fParseLine )
  95. {
  96. # file info
  97. if (/^([^\s=]+)/)
  98. {
  99. # Get size of file
  100. my $file_name = lc $1;
  101. my $file_size = 0;
  102. $file_size = $default_sizes{$file_name} if exists $default_sizes{$file_name};
  103. foreach my $path (@paths) {
  104. if ( -e "$path\\$file_name" ) {
  105. my @stat_info = stat "$path\\$1";
  106. if ( @stat_info ) {
  107. $file_size = $stat_info[7];
  108. last;
  109. } else {
  110. wrnmsg( "Unable to get size info for: $1 ($!)" );
  111. }
  112. }
  113. }
  114. if ( !$file_size ) {
  115. wrnmsg( "Unable to get size info for: $1 (missing". (%default_sizes?" and no default)":")") );
  116. }
  117. # Add/replace size
  118. if ( $file_size &&
  119. !(s/([^\,]*\,[^\,]*\,)(?:\d+)?/$1$file_size/) )
  120. {
  121. wrnmsg("Unrecognized entry in $inf_file in line $line_num: $_" );
  122. }
  123. }
  124. else
  125. {
  126. wrnmsg( "Unrecognized entry in $inf_file at line $line_num: $_" );
  127. }
  128. }
  129. print $fhTMP $_;
  130. }
  131. close INF;
  132. close $fhTMP;
  133. if ( !unlink $inf_file )
  134. {
  135. errmsg( "Could not remove old $inf_file ($!) -- new version is located at $temp_inf" );
  136. exit 1;
  137. }
  138. if ( !copy( $temp_inf, $inf_file ) )
  139. {
  140. errmsg( "Unable to copy new $inf_file ($!) -- new version is located at $temp_inf" );
  141. exit 1;
  142. }
  143. unlink $temp_inf;
  144. exit 0;