#!/Perl/bin/Perl.exe require File::Spec; use File::Basename; use strict; use ExtUtils::MakeMaker; use LWP::Simple qw(getstore $ua is_success); if ($ENV{HTTP_proxy_user} and $ENV{HTTP_proxy_pass} and $ENV{HTTP_proxy} =~ /^http:\/\/([^@]+)$/) { my $proxy ="http://$ENV{HTTP_proxy_user}:$ENV{HTTP_proxy_pass}\@" . $1; print "setting user/pass into proxy_env...\n"; $ua->proxy(['http'], $proxy); } my $ans = prompt("\nDo you want to alter ParserDetails.ini?", 'yes'); my $perl = $^X; $perl = Win32::GetShortPathName($perl) if $perl =~ / /; if ($ans =~ /^y/i) { my @args; eval {require XML::SAX}; die qq{XML::SAX must be installed first} if $@; my $dir = File::Basename::dirname($INC{'XML/SAX.pm'}); my $ini = File::Spec->catfile($dir, 'SAX', 'ParserDetails.ini'); unless (-e $ini) { @args = ($perl, '-MExtUtils::Command', '-e', 'touch', $ini); system(@args) == 0 or die "system @args failed: $?"; } @args = ($perl, '-MXML::SAX', '-e', q{"XML::SAX->add_parser(q(XML::SAX::ExpatXS))->save_parsers()"}); print "@args\n"; system(@args) == 0 or die "system @args failed: $?"; } my $lib = 'libexpat.dll'; my $version = '2.0.0'; my $default = '/Perl/bin'; my $guess = '/Perl/bin'; my $recommended = 'yes'; if (my $hit = search_for($lib, $guess)) { print <<"END"; A copy of the needed library $lib was found in $hit. If this is compatible with the version ($version) used to compile the Perl module, all that is needed to complete the installation is to ensure $hit is in your PATH environment variable. END $recommended = 'no'; } if ($recommended eq 'yes') { print <<"END"; The library $lib is needed to complete the installation, and should be placed in a directory somewhere in your PATH environment variable. I can fetch and install this for you, if you don\'t already have it. END } my $proceed = prompt("Fetch $lib?", $recommended); suggest_manual("Aborting download of $lib.", 'warn') unless ($proceed =~ /^y/i); my $remote = 'http://theoryx5.uwinnipeg.ca/ppmpackages/scripts/' . $lib; print "Fetching $remote ... "; die "Fetching file failed" unless (is_success(getstore($remote, $lib))); print " done!\n"; suggest_manual("Cannot find $lib", 'fatal') unless -f $lib; my $base = prompt("Where should $lib be placed?", $default); $base =~ s/$lib$//i; $base =~ s!\\!/!g; $base =~ s!/$!!; unless (-d $base) { my $ans = prompt("$base does not exist. Create it?", 'no'); if ($ans =~ /^y/i) { mkdir $base; suggest_manual("Could not create $base: $!", 'fatal') unless (-d $base); } else { suggest_manual("Will not create $base.", 'fatal'); } } if (-f "$base/$lib") { my $ans = prompt("$base/$lib exists. Overwrite?", 'no'); if ($ans =~ /^n/i) { suggest_manual("Will not overwrite $base/$lib.", 'fatal'); } } use File::Copy; move($lib, "$base/$lib"); suggest_manual("Moving $lib to $base failed: $!", 'fatal') unless (-f "$base/$lib"); print "$lib has been successfully installed to $base\n"; sleep(5); sub suggest_manual { my ($msg, $type) = @_; print $msg, "\n"; print "Installation of $lib not completed.\n" if ($type eq 'fatal'); sleep (5); exit(0); } sub search_for { my ($lib, $guess) = @_; return $guess if (-e File::Spec->catfile($guess, $lib)); my $hit; SEARCH: { my $candidate; for (File::Spec->path) { $candidate = File::Spec->catfile($_, $lib); if (-e $candidate) { $hit = $candidate; last SEARCH; } } my @drives = drives(); last SEARCH unless (@drives > 0); for (@drives) { $candidate = File::Spec->catfile($_, $guess, $lib); if (-e $candidate) { $hit = $candidate; last SEARCH; } } } return $hit ? dirname($hit) : undef; } sub drives { my @drives = (); eval{require Win32API::File;}; return map {"$_:\\"} ('C' .. 'Z') if $@; my @r = Win32API::File::getLogicalDrives(); return unless @r > 0; foreach (@r) { my $t = Win32API::File::GetDriveType($_); push @drives, $_ if ($t == 3 or $t == 4); } return @drives > 0 ? @drives : undef; }