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.

169 lines
3.4 KiB

  1. #---------------------------------------------------------------------
  2. package Utils;
  3. #
  4. # Copyright (c) Microsoft Corporation. All rights reserved.
  5. #
  6. # Version:
  7. # 1.00 1/23/2002 JeremyD: tired of copying and pasting
  8. #---------------------------------------------------------------------
  9. use strict;
  10. use vars qw($VERSION);
  11. use IO::File;
  12. use Digest;
  13. use File::Basename;
  14. use File::Path ();
  15. $VERSION = '1.00';
  16. sub inf_dir_name {
  17. my $sku = shift;
  18. $sku = lc $sku;
  19. my $infdir;
  20. if ($sku eq 'pro') {
  21. return;
  22. }
  23. elsif ($sku eq 'ads') {
  24. $infdir = 'entinf';
  25. }
  26. else {
  27. $infdir = "${sku}inf";
  28. }
  29. return $infdir;
  30. }
  31. sub inf_dir {
  32. my $sku = shift;
  33. return join '\\', $ENV{_NTPOSTBLD}, inf_dir_name($sku);
  34. }
  35. sub comp_inf_dir {
  36. my $sku = shift;
  37. return join '\\', $ENV{_NTPOSTBLD}, 'comp', inf_dir_name($sku);
  38. }
  39. sub inf_file {
  40. my $sku = shift;
  41. my $filename = shift;
  42. return join "\\", inf_dir($sku), $filename;
  43. }
  44. sub overlay_skus {
  45. my $sku = shift;
  46. $sku = lc $sku;
  47. my %skus = ( per => ['pro', 'per'],
  48. pro => ['pro'],
  49. srv => ['pro', 'srv'],
  50. bla => ['pro', 'srv', 'bla'],
  51. sbs => ['pro', 'srv', 'sbs'],
  52. ads => ['pro', 'srv', 'ent'],
  53. dtc => ['pro', 'srv', 'ent', 'dtc'] );
  54. return @{$skus{$sku}};
  55. }
  56. sub overlay_dirs {
  57. my $sku = shift;
  58. return map { inf_dir($_) } overlay_skus($sku);
  59. }
  60. sub overlay_file {
  61. my $sku = shift;
  62. my $filename = shift;
  63. for my $overlay_sku (reverse overlay_skus($sku)) {
  64. my $f = inf_file($overlay_sku, $filename);
  65. if (-e $f) {
  66. return $f;
  67. }
  68. }
  69. return;
  70. }
  71. sub arch_dir {
  72. my $arch = shift;
  73. $arch = lc $arch;
  74. return ($arch eq 'x86') ? 'i386' : $arch;
  75. }
  76. sub sys {
  77. my $cmd = shift;
  78. print "$cmd\n";
  79. system($cmd);
  80. if ($?) {
  81. die "ERROR: $cmd ($?)\n";
  82. }
  83. }
  84. my %arch_tags = ( 'x86' => 'i', 'ia64' => 'm', 'amd64' => 'm' );
  85. my %sku_tags = ( 'per' => 'c', 'pro' => 'p', 'srv' => 's',
  86. 'bla' => 'b', 'sbs' => 'l', 'ads' => 'a',
  87. 'dtc' => 'd' );
  88. sub tag_letter {
  89. my $thing = shift;
  90. return $arch_tags{lc $thing} || $sku_tags{lc $thing};
  91. }
  92. sub file_info {
  93. my $file = shift;
  94. my $root = shift;
  95. my $fh = IO::File->new("$file", 'r') or die "Unable to open file $file: $!";
  96. binmode($fh);
  97. my $filename;
  98. if ($file =~ /_$/) {
  99. $fh->seek(0x3c,0);
  100. for (;;) {
  101. my $c = $fh->getc;
  102. if (ord($c) == 0 or $fh->eof) { last }
  103. $filename .= "$c";
  104. }
  105. $fh->seek(0,0);
  106. }
  107. else {
  108. $filename = basename($file);
  109. }
  110. my ($size, $mtime) = ($fh->stat)[7,9];
  111. my $digest = Digest->new('SHA-1')->addfile($fh);
  112. (my $relative_name = $file) =~ s/^\Q$root\E\\//i;
  113. return ($relative_name, $filename, $size, $mtime, $digest->hexdigest);
  114. }
  115. sub mkdir {
  116. my $dir = shift;
  117. File::Path::mkpath($dir);
  118. }
  119. 1;
  120. __END__
  121. =head1 NAME
  122. Utils - a collection of functions use frequently by SP scripts
  123. =head1 DESCRIPTION
  124. This module is temporary until these functions are available in postbuild.
  125. =head1 AUTHOR
  126. JeremyD
  127. =head1 COPYRIGHT
  128. Copyright (c) Microsoft Corporation. All rights reserved.
  129. =cut