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.

61 lines
1.3 KiB

  1. package Compare;
  2. use strict;
  3. use Carp;
  4. use BinComp;
  5. use CabComp;
  6. use MsiComp;
  7. use InfComp;
  8. sub new {
  9. my $class = shift;
  10. my $self = bless {}, $class;
  11. $self->_init;
  12. return $self;
  13. }
  14. sub _init {
  15. my $self = shift;
  16. $self->AddHandler( qr/\.(msi|msm)$/i, new MsiComp );
  17. $self->AddHandler( qr/\.cab$/i, new CabComp );
  18. $self->AddHandler( qr/\.(inf|sif)$/i, new InfComp );
  19. $self->AddHandler( qr//, new BinComp );
  20. }
  21. sub AddHandler {
  22. my $self = shift;
  23. my $regex = shift;
  24. my $comparator = shift;
  25. push @{$self->{HANDLERS}}, [$regex, $comparator];
  26. }
  27. sub Compare {
  28. my $self = shift;
  29. my ($src, $dst, $file) = @_;
  30. # try each handler in registered order, use the first one that matches
  31. for my $handler (@{$self->{HANDLERS}}) {
  32. if ($file =~ /$handler->[0]/) {
  33. $self->{LAST} = $handler->[1];
  34. return $handler->[1]->compare("$src\\$file", "$dst\\$file");
  35. }
  36. }
  37. # fall through and return undef if not handler is found
  38. return;
  39. }
  40. # pass through to the last used object
  41. sub GetLastError {
  42. my $self = shift;
  43. if (!defined $self->{LAST}) { return }
  44. return $self->{LAST}->GetLastError;
  45. }
  46. sub GetLastDiff {
  47. my $self = shift;
  48. if (!defined $self->{LAST}) { return }
  49. return $self->{LAST}->GetLastDiff;
  50. }
  51. 1;