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.

242 lines
6.8 KiB

  1. ############################################################################
  2. #
  3. # Represents a line from the infsect table.
  4. #
  5. package InfData;
  6. use strict;
  7. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  8. use lib $ENV{RAZZLETOOLPATH} . "\\sp";
  9. use lib $ENV{RAZZLETOOLPATH};
  10. use Logmsg;
  11. # Create a new inf entry by full path name and sku.
  12. sub new {
  13. my $class = shift;
  14. my ($src, $dirid, $path, $name, $mask) = @_;
  15. my $self = {};
  16. # Path
  17. $self->{DIRID} = $dirid; # DirID for the installation path.
  18. $self->{PATH} = $path; # Rest of installation path.
  19. # Inf line
  20. $self->{DEST} = ""; # Destination filename, if different.
  21. $self->{NAME} = $src; # Source filename.
  22. $self->{TEMP} = ""; # Temporary file name.
  23. $self->{FLAG} = 0; # Inf file flags.
  24. # Special data.
  25. $self->{MASK} = $mask; # Skus to install on.
  26. $self->{SPEC} = ""; # Info to find a magic section.
  27. $self->{WHEN} = ""; # When to copy over.
  28. $self->{CMD} = "copy"; # What to do with the file.
  29. # Finish up.
  30. $self = bless $self;
  31. $self->setDest($name);
  32. return $self;
  33. }
  34. sub copy {
  35. my $self = shift;
  36. my $new = InfData->new($self->{NAME},$self->{DIRID},$self->{PATH},$self->getDest(),$self->{MASK});
  37. $new->{SPEC} = $self->{SPEC};
  38. $new->{WHEN} = $self->{WHEN};
  39. return $new;
  40. }
  41. # Add a new product if the path is a match.
  42. sub addBit {
  43. my $self = shift;
  44. my ($new) = @_;
  45. return 0 if $new->{DIRID} != $self->{DIRID};
  46. return 0 if $new->{FLAG} != $self->{FLAG};
  47. return 0 if lc $new->{PATH} ne lc $self->{PATH};
  48. return 0 if lc $new->{DEST} ne lc $self->{DEST};
  49. return 0 if lc $new->{NAME} ne lc $self->{NAME};
  50. return 0 if lc $new->{TEMP} ne lc $self->{TEMP};
  51. return 0 if lc $new->{SPEC} ne lc $self->{SPEC};
  52. return 0 if lc $new->{WHEN} ne lc $self->{WHEN};
  53. $self->{MASK} |= $new->{MASK};
  54. return 1;
  55. }
  56. # Remove an line or part of a line.
  57. sub delBit {
  58. my $self = shift;
  59. my ($new) = @_;
  60. return $self if $new->{DIRID} != $self->{DIRID};
  61. return $self if $new->{FLAG} != $self->{FLAG};
  62. return $self if lc $new->{PATH} ne lc $self->{PATH};
  63. return $self if lc $new->{DEST} ne lc $self->{DEST};
  64. return $self if lc $new->{NAME} ne lc $self->{NAME};
  65. return $self if lc $new->{TEMP} ne lc $self->{TEMP};
  66. return $self if lc $new->{SPEC} ne lc $self->{SPEC};
  67. return $self if lc $new->{WHEN} ne lc $self->{WHEN};
  68. $self->{MASK} &= ~$new->{MASK};
  69. if ( $self->{MASK} == 0 ) { return undef; }
  70. else { return $self; }
  71. }
  72. # Remove an line or part of a line, ignoring source directory.
  73. sub delBit2 {
  74. my $self = shift;
  75. my ($new) = @_;
  76. return $self if $new->{DIRID} != $self->{DIRID};
  77. return $self if $new->{FLAG} != $self->{FLAG};
  78. return $self if lc $new->{PATH} ne lc $self->{PATH};
  79. return $self if lc $new->{DEST} ne lc $self->{DEST};
  80. return $self if lc $new->{TEMP} ne lc $self->{TEMP};
  81. return $self if lc $new->{SPEC} ne lc $self->{SPEC};
  82. return $self if lc $new->{WHEN} ne lc $self->{WHEN};
  83. return $self if lc $new->getSrc() ne lc $self->getSrc();
  84. $self->{MASK} &= ~$new->{MASK};
  85. if ( $self->{MASK} == 0 ) { return undef; }
  86. else { return $self; }
  87. }
  88. # Output a path identifier for this entry.
  89. sub getFullPath {
  90. my $self = shift;
  91. return lc "$self->{DIRID},\"$self->{PATH}\"";
  92. }
  93. # Get the destination filename.
  94. sub getDest {
  95. my $self = shift;
  96. return $self->{DEST} if $self->{DEST} ne "";
  97. $self->{NAME} =~ /^(.*\\)?([^\\]*)$/;
  98. return $2;
  99. }
  100. # Set the destination filename.
  101. sub setDest {
  102. my $self = shift;
  103. my ($dest) = @_;
  104. return if lc $dest eq lc $self->getDest();
  105. $self->{DEST} = $dest;
  106. }
  107. # Set the source filename.
  108. sub setSrc {
  109. my $self = shift;
  110. my ($src) = @_;
  111. return if lc $src eq lc $self->getSrc();
  112. my $dest = $self->getDest();
  113. $self->{NAME} = $src;
  114. $self->{DEST} = "";
  115. $self->setDest($dest);
  116. }
  117. # Get the source filename, no path.
  118. sub getSrc {
  119. my $self = shift;
  120. $self->{NAME} =~ /^(.*\\)?([^\\]*)$/;
  121. return $2;
  122. }
  123. # Get the source directory.
  124. sub getSrcDir {
  125. my $self = shift;
  126. $self->{NAME} =~ /^(.*\\)?([^\\]*)$/;
  127. return (defined $1) ? $1:"";
  128. }
  129. # Set the source directory.
  130. sub setSrcDir {
  131. my $self = shift;
  132. my ($dir) = @_;
  133. $dir .= "\\" if $dir !~ /\\$/;
  134. $self->{NAME} =~ /^(.*\\)?([^\\]*)$/;
  135. $self->{NAME} = "$dir$2";
  136. }
  137. # Set the source directory to root.
  138. sub clearSrcDir {
  139. my $self = shift;
  140. $self->{NAME} = $self->getSrc();
  141. }
  142. # Read in a line from infsect.tbl.
  143. sub readLine {
  144. my $self = shift;
  145. my ($line, $skus) = @_;
  146. # Break into sections.
  147. return 0 if $line !~ /^([^:]*):([^:]*):(\d*),\"([^\"]*)\"(?::([^:]*)(?::([^:]*))?)?/; # "
  148. my $mask = $1;
  149. my $data = $2;
  150. $self->{DIRID} = $3;
  151. $self->{PATH} = $4;
  152. $self->{WHEN} = (defined $5) ? $5:"";
  153. $self->{SPEC} = (defined $6) ? $6:"";
  154. # Generate the mask.
  155. my $bit = 1;
  156. $self->{MASK} = 0;
  157. for (my $i=0; $i<=$#$skus; ++$i) {
  158. $self->{MASK} |= $bit if substr($mask,$i,1) eq $skus->[$i];
  159. $bit = $bit << 1;
  160. }
  161. return 0 if $self->{MASK} == 0;
  162. # Read in the line information.
  163. my $temp;
  164. my $flag;
  165. ($self->{DEST}, $self->{NAME}, $temp, $flag) = split(",", $data);
  166. $self->{DEST} = "" if $self->{DEST} eq $self->{NAME};
  167. $self->{TEMP} = (defined $temp) ? $temp:"";
  168. $self->{FLAG} = (defined $flag) ? $flag:0;
  169. return 1;
  170. }
  171. # Generate a line for infsect.tbl.
  172. sub getLine {
  173. my $self = shift;
  174. my ($skus) = @_;
  175. my $str = "";
  176. # Print out the mask data.
  177. my $mask = $self->{MASK};
  178. foreach my $sku ( @$skus ) {
  179. if ( $mask & 1 ) { $str .= $sku; }
  180. else { $str .= " "; }
  181. $mask = $mask >> 1;
  182. }
  183. # Print the info needed for the inf line.
  184. $str .= ":";
  185. $str .= "$self->{DEST},$self->{NAME}";
  186. $str .= ",$self->{TEMP}" if $self->{FLAG} != 0 or $self->{TEMP} ne "";
  187. $str .= ",$self->{FLAG}" if $self->{FLAG} != 0;
  188. $str .= ":";
  189. # Print the install path.
  190. $str .= $self->getFullPath();
  191. # Print special data.
  192. $str .= ":$self->{WHEN}" if $self->{SPEC} ne "" or $self->{WHEN} ne "";
  193. $str .= ":$self->{SPEC}" if $self->{SPEC} ne "";
  194. return $str;
  195. }
  196. # Generate a line for an inf section.
  197. sub getInfLine {
  198. my $self = shift;
  199. my ($flag) = @_;
  200. $flag = $self->{FLAG} if $flag == 0;
  201. my $dest = $self->getDest();
  202. return $dest if $self->{CMD} eq "del";
  203. my $name = $self->{NAME};
  204. $name =~ s/^\\//;
  205. $name = "" if $name eq $dest;
  206. my $str = "";
  207. $str .= "$dest";
  208. $str .= ",$name" if $flag != 0 or $self->{TEMP} ne "" or $name ne "";
  209. $str .= ",$self->{TEMP}" if $flag != 0 or $self->{TEMP} ne "";
  210. $str .= ",$flag" if $flag != 0;
  211. return $str;
  212. }
  213. 1;