diff options
-rwxr-xr-x | perl-install/scanner.pm | 92 | ||||
-rwxr-xr-x | perl-install/standalone/scannerdrake | 114 |
2 files changed, 167 insertions, 39 deletions
diff --git a/perl-install/scanner.pm b/perl-install/scanner.pm index 85341e10c..018ed3fb8 100755 --- a/perl-install/scanner.pm +++ b/perl-install/scanner.pm @@ -77,6 +77,40 @@ sub add2dll { output("$sanedir/dll.conf", @dllconf); } +sub setfirmware { + my ($backend, $firmwareline) = @_; + my @driverconf = cat_("$sanedir/$backend.conf"); + handle_configs::set_directive(\@driverconf, $firmwareline, 0); + output("$sanedir/$backend.conf", @driverconf); +} + +sub installfirmware { + # Install the firmware file in /usr/share/sane/firmware + my ($firmware) = @_; + return "" if !$firmware; + # Install firmware + run_program::rooted($::prefix, "mkdir", "-p", + "/usr/share/sane/firmware") || do { + $in->ask_warn('Scannerdrake', + N("Could not create directory /usr/share/sane/firmware!")); + return ""; + }; + run_program::rooted($::prefix, "cp", "-f", "$firmware", + "/usr/share/sane/firmware") || do { + $in->ask_warn('Scannerdrake', + N("Could not copy firmware file %s to /usr/share/sane/firmware!", $firmware)); + return ""; + }; + $firmware =~ s!^(.*)(/[^/]+)$!/usr/share/sane/firmware$2!; + run_program::rooted($::prefix, "chmod", "644", + $firmware) || do { + $in->ask_warn('Scannerdrake', + N("Could not set permissions of firmware file %s!", $firmware)); + return ""; + }; + return $firmware; +} + sub configured() { my @res; my $parportscannerfound = 0; @@ -88,20 +122,28 @@ sub configured() { # Extract port and description my $port = $1; my $description = $2; + # Remove duplicate scanners appearing through saned and the + # "net" backend + next if $port =~ /^net:(localhost|127.0.0.1):/; # Is the scanner hooked to a parallel or serial port? if ($port =~ /(parport|pt_drv|parallel|ttys)/i) { $parportscannerfound = 1; } - # Remove duplicate scanners appearing through saned and the - # "net" backend - next if $port =~ /^net:(localhost|127.0.0.1):/; + # Determine which SANE backend the scanner in question uses + $port =~ /^([^:]+):/; + my $backend = $1; + # Does the scanner need a firmware file + my $firmwareline = firmwareline($backend); # Store collected data push @res, { port => $port, val => { DESCRIPTION => $description, - } - }; + ($backend ? ( BACKEND => $backend ) : ()), + ($firmwareline ? + ( FIRMWARELINE => $firmwareline ) : ()), + } + } } } close LIST; @@ -362,6 +404,32 @@ sub get_usb_ids_for_port { } } +sub readconfiglinetemplates { + # Read templates for configuration file lines + my %configlines; + my $backend; + foreach my $line (cat_("$scannerDBdir/scannerconfigs")) { + chomp $line; + if ($line =~ /^\s*SERVER\s+(\S+)\s*$/) { + $backend = $1; + } elsif ($backend) { + push @{$configlines{$backend}}, $line; + } + } + return \%configlines; +} + +sub firmwareline { + # Determine whether the given SANE backend supports a firmware file + # and return the line needed in the config file + my ($backend) = @_; + # Read templates for configuration file lines + my %configlines = %{readconfiglinetemplates()}; + # Does the backend support a line for the firmware? + my @firmwarelines = (grep { s/^FIRMWARELINE // } @{$configlines{$backend}}); + return join("\n", @firmwarelines); +} + sub readScannerDB { my ($file) = @_; my ($card, %cards); @@ -454,16 +522,7 @@ sub updateScannerDBfromSane { }; # Read templates for configuration file lines - my %configlines; - my $backend; - foreach my $line (cat_("$scannerDBdir/scannerconfigs")) { - chomp $line; - if ($line =~ /^\s*SERVER\s+(\S+)\s*$/) { - $backend = $1; - } elsif ($backend) { - push @{$configlines{$backend}}, $line; - } - } + my %configlines = %{readconfiglinetemplates()}; foreach my $ff (glob_("$sanesrcdir/doc/descriptions/*.desc"), glob_("$sanesrcdir/doc/descriptions-external/*.desc"), "UNSUPPORTED") { my $f = $ff; @@ -500,7 +559,8 @@ sub updateScannerDBfromSane { # interfaces of this scanner foreach my $line (@{$configlines{$backend}}) { my $i = $1 if $line =~ /^\s*(\S*?)LINE/; - if (!$i || $intf =~ /$i/i) { + if (!$i || $i eq "FIRMWARE" || + $intf =~ /$i/i) { $to_add .= "$line\n"; } } diff --git a/perl-install/standalone/scannerdrake b/perl-install/standalone/scannerdrake index 1e1b3b086..dba6455ed 100755 --- a/perl-install/standalone/scannerdrake +++ b/perl-install/standalone/scannerdrake @@ -159,7 +159,7 @@ sub installfirmware { # Tell user about firmware installation $in->ask_from('Scannerdrake', N("It is possible that your %s needs its Firmware to be uploaded everytime when it is turned on.", removeverticalbar($model)) . " " . - N("If this is the case, you can make this be done automatically for you.") . " " . + N("If this is the case, you can make this be done automatically.") . " " . N("To do so, you need to supply the firmware file for your scanner so that it can be installed.") . " " . N("You find the file on the CD or floppy coming with the scanner, on the manufacturer's home page, or on your Windows partition."), [ @@ -190,31 +190,89 @@ sub installfirmware { $firmware)); } - if ($firmware) { - # Install firmware - run_program::rooted($::prefix, "mkdir", "-p", - "/usr/share/sane/firmware") || do { - $in->ask_warn('Scannerdrake', - N("Could not create directory /usr/share/sane/firmware!")); - return ""; - }; - run_program::rooted($::prefix, "cp", "-f", "$firmware", - "/usr/share/sane/firmware") || do { - $in->ask_warn('Scannerdrake', - N("Could not copy firmware file %s to /usr/share/sane/firmware!", $firmware)); - return ""; - }; - $firmware =~ s!^(.*)(/[^/]+)$!/usr/share/sane/firmware$2!; - run_program::rooted($::prefix, "chmod", "644", - $firmware) || do { - $in->ask_warn('Scannerdrake', - N("Could not set permissions of firmware file %s!", $firmware)); - return ""; - }; - } + # Install the firmware file in /usr/share/sane/firmware + $firmware = scanner::installfirmware($firmware); return $firmware; } +sub updatefirmware { + my (@configured) = @_; + my $firmware; + my @scanners = + map { + $_->{val}{DESCRIPTION} + } grep { + $_->{val}{FIRMWARELINE} + } @configured; + my ($scannerchoice, $mediachoice); + while (1) { + # Tell user about firmware installation + $in->ask_from('Scannerdrake', + ($#scanners > 0 ? + N("It is possible that your scanners need their firmware to be uploaded everytime when they are turned on.") : + N("It is possible that your %s needs its firmware to be uploaded everytime when it is turned on.", $scanners[0])) . " " . + N("If this is the case, you can make this be done automatically.") . " " . + ($#scanners > 0 ? + N("To do so, you need to supply the firmware files for your scanners so that it can be installed.") : + N("To do so, you need to supply the firmware file for your scanner so that it can be installed.")) . " " . + N("You find the file on the CD or floppy coming with the scanner, on the manufacturer's home page, or on your Windows partition.") . "\n" . + N("If you have already installed your scanner's firmware you can update the firmware here by supplying the new firmware file."), + [ + { label => N("Install firmware for the"), + val => \$scannerchoice, + list => \@scanners, + not_edit => 1, sort => 1 }, + { label => N("Install firmware file from"), + val => \$mediachoice, + list => [N("CD-ROM"), + N("Floppy Disk"), + N("Other place")], + not_edit => 1, sort => 0 }, + ], + ) or return 0; + my $dir; + if ($mediachoice eq N("CD-ROM")) { + $dir = "/mnt/cdrom"; + } elsif ($mediachoice eq N("Floppy Disk")) { + $dir = "/mnt/floppy"; + } elsif ($mediachoice eq N("Other place")) { + $dir = "/mnt"; + } else { + return 0; + } + # Let user select a firmware file from a floppy, hard disk, ... + $firmware = $in->ask_file(N("Select firmware file for the %s", + $scannerchoice), "$dir"); + last if !$firmware || (-r $firmware); + $in->ask_warn('Scannerdrake', + N("The firmware file %s does not exist or is unreadable!", + $firmware)); + + } + + return 0 if !$firmware; + + # Install the firmware file in /usr/share/sane/firmware + $firmware = scanner::installfirmware($firmware); + + # Enter the path to the firmware in the appropriate config file + foreach (@configured) { + next if $_->{val}{DESCRIPTION} ne $scannerchoice; + my $backend = $_->{val}{BACKEND}; + my $firmwareline =$_->{val}{FIRMWARELINE}; + $firmwareline =~ s/\$FIRMWARE/$firmware/sg; + scanner::setfirmware($backend, $firmwareline); + last; + } + + # Success message + $in->ask_warn('Scannerdrake', + N("The firmware file for your %s was successfully installed.", + $scannerchoice)); + + return 1; +} + sub tryConfScanner { # take care if interactive output is needed (unsupported, parallel..) my ($model, $port, $vendor, $product) = @_; @@ -358,6 +416,13 @@ sub mainwindow { $buttonclicked = "manualadd"; 1; } }, + ( (grep { $_->{val}{FIRMWARELINE} } @configured) ? + { val => N("Install/Update firmware files"), + type => 'button', + clicked_may_quit => sub { + $buttonclicked = "firmware"; + 1; + } } : () ), { val => N("Scanner sharing"), type => 'button', clicked_may_quit => sub { @@ -394,6 +459,9 @@ sub mainwindow { } elsif ($buttonclicked eq "sharing") { # Show dialog to set up scanner sharing $changed = sharewindow(@configured); + } elsif ($buttonclicked eq "firmware") { + # Show dialog to select the firmware file + updatefirmware(@configured); } elsif ($buttonclicked eq "quit") { # We have clicked "Quit" $maindone = 1; |