#!/usr/bin/perl

use strict;
use warnings;
use File::Copy;
use Data::Dumper;

my $dir_from = shift;
my $dir_to = shift;
my $files_from = shift;
my $files_to = shift;

$files_from =~ s/"//g;
$files_to =~ s/"//g;
$dir_from =~ s/"//g;
$dir_to =~ s/"//g;

if ($files_from eq '-') {
  my $ans = system("xmessage -center -buttons OK:1 -timeout 10 \"NO FILE SELECTED\"");
  exit;
}

my @files = split /;/, $files_from;

my $had_files = 0;

for (@files) {
  if (/\.tgz$/ || /tar\.gz$/) {
    $had_files = 1;
    system("tar zxf \"$_\" --directory \"$dir_to\"");
  }
  elsif (/\.zip$/) {
    $had_files = 1;
    system("unzip -o -d \"$dir_to\" \"$_\"");
  }
}

if (! $had_files) {
  my $ans = system("xmessage -center -buttons OK:1 -timeout 10 \"NO FILES\"");
  exit;
}

system("echo 1 > /tmp/filetools.refresh");

