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.

164 lines
3.5 KiB

  1. use strict;
  2. use IO::File;
  3. #
  4. # tok_bldnum.pl
  5. #
  6. # Arguments: property.idt productversion
  7. #
  8. # Purpose:
  9. #
  10. # Returns: 0 if success, non-zero otherwise
  11. #
  12. my( $BuildNumber );
  13. my( $QFENumber );
  14. my( $ProductNumber );
  15. my( $Search ) = "ProductVersion";
  16. my( $File ) = "Property.idt";
  17. my( $Line ) = "";
  18. # use unless as GetBuildNumber returns zero on failure
  19. unless ( $BuildNumber = &GetBuildNumber ) {
  20. print( "Failed to generate build number, exiting ...\n" );
  21. exit( 1 );
  22. }
  23. # use unless as GetQFENumber returns zero on failure
  24. unless ( $QFENumber = &GetQFENumber ) {
  25. print( "Failed to generate QFE number, exiting ...\n" );
  26. exit( 1 );
  27. }
  28. if ($ARGV[0] ne "") {
  29. $File = $ARGV[0];
  30. }
  31. if ($ARGV[1] ne "") {
  32. $Search = $ARGV[1];
  33. }
  34. $ProductNumber = "5.2.$BuildNumber.$QFENumber";
  35. if ( &SearchReplaceInFile ) {
  36. print( "Failed to update ProductVersion.\n" );
  37. exit( 1 );
  38. }
  39. # if we're here, we returned successfully
  40. exit( 0 );
  41. #
  42. # GetBuildNumber
  43. #
  44. # Arguments: none
  45. #
  46. # Purpose: parse ntverp.h from published, return the build number
  47. #
  48. # Returns: the build number if successful, zero otherwise
  49. #
  50. sub GetBuildNumber
  51. {
  52. # find the file
  53. my( $VerFile ) = $ENV{ "SDXROOT" } . "\\public\\sdk\\inc\\ntverp.h";
  54. if ( ! -e $VerFile ) {
  55. print( "$VerFile does not exist ...\n" );
  56. return( 0 );
  57. }
  58. # parse the file
  59. if ( -e $VerFile ) {
  60. # open the file
  61. if ( defined( my $fh = new IO::File $VerFile, "r" ) ) {
  62. my( $ThisLine );
  63. # read through the file
  64. while ( $ThisLine = <$fh> ) {
  65. # see if this is the build number defining line
  66. if ( $ThisLine =~ /#define VER_PRODUCTBUILD\s*\/\* NT \*\/\s*(\d*)/ ) {
  67. # $1 is now the build number
  68. undef( $fh );
  69. return( $1 );
  70. }
  71. }
  72. undef( $fh );
  73. } else {
  74. print( "Failed to open $VerFile ...\n" );
  75. return( 0 );
  76. }
  77. }
  78. # if we're here, we didn't find a build number in the VerFile
  79. print( "Failed to find a build number in $VerFile ..." );
  80. return( 0 );
  81. }
  82. #
  83. # GetQFENumber
  84. #
  85. # Arguments: none
  86. #
  87. # Purpose: parse ntverp.h from published, return the build number
  88. #
  89. # Returns: the QFE number if successful, zero otherwise
  90. #
  91. sub GetQFENumber
  92. {
  93. # find the file
  94. my( $VerFile ) = $ENV{ "SDXROOT" } . "\\public\\sdk\\inc\\ntverp.h";
  95. if ( ! -e $VerFile ) {
  96. print( "$VerFile does not exist ...\n" );
  97. return( 0 );
  98. }
  99. # parse the file
  100. if ( -e $VerFile ) {
  101. # open the file
  102. if ( defined( my $fh = new IO::File $VerFile, "r" ) ) {
  103. my( $ThisLine );
  104. # read through the file
  105. while ( $ThisLine = <$fh> ) {
  106. # see if this is the build number defining line
  107. if ( $ThisLine =~ /#define VER_PRODUCTBUILD_QFE\s*\s*(\d*)/ ) {
  108. # $1 is now the build number
  109. undef( $fh );
  110. return( $1 );
  111. }
  112. }
  113. undef( $fh );
  114. } else {
  115. print( "Failed to open $VerFile ...\n" );
  116. return( 0 );
  117. }
  118. }
  119. # if we're here, we didn't find a build number in the VerFile
  120. print( "Failed to find a build number in $VerFile ..." );
  121. return( 0 );
  122. }
  123. #
  124. # SearchReplaceInFile
  125. #
  126. # Arguments: none
  127. #
  128. # Purpose:
  129. #
  130. # Returns:
  131. #
  132. sub SearchReplaceInFile
  133. {
  134. open FILE, $File;
  135. while (<FILE>) {
  136. $Line = $_;
  137. $Line =~ s/ProductVersion\s\d.\d.\d+.\d/ProductVersion\t$ProductNumber/;
  138. print( $Line );
  139. }
  140. close(FILE);
  141. return( 0 );
  142. }