Archive-Tyd
view release on metacpan or search on metacpan
# Populate the list.
&refresh();
}
sub saveArchive {
my $as = shift || undef;
my $file = $main->getSaveFile (
-defaultextension => 'tyd',
-filetypes => [
[ 'Tyd Archive', ['*.tyd', '*.dat'] ],
[ 'All Files', '*.*' ],
],
-initialdir => '.',
-title => 'Save Archive...',
);
return unless defined $file;
my $password = &password;
return unless defined $password;
unlink ($file) if (-e $file);
my $write = new Archive::Tyd (password => $password);
$write->{files} = $tyd->{files};
$write->writeArchive ($file);
}
sub addFile {
my $file = $main->getOpenFile (
-defaultextension => 'tyd',
-filetypes => [
[ 'Common Files', '*.*' ],
[ 'All Files', '*.*' ],
],
-initialdir => '.',
-title => 'Select File...',
);
return unless defined $file;
$tyd->addFile ($file);
&refresh();
}
sub extractFile {
my $index = $table->selectionGet;
my $file = $table->itemCget ($index,0,-text);
return unless exists $tyd->{files}->{$file};
my ($ext) = $file =~ /\.(\w+)$/i;
print "Ext: $ext\n";
my $target = $main->getSaveFile (
-defaultextension => ".$ext",
-filetypes => [
[ 'Text Document', [ '*.txt' ] ],
[ 'Perl File', [ '*.pl', '*.pm', ] ],
[ 'JPEG Image', [ '*.jpeg', '*.jpg', '*.jpe' ] ],
[ 'GIF Image', [ '*.gif', ] ],
[ 'PNG Image', [ '*.png', ] ],
[ 'BMP Image', [ '*.bmp', ] ],
[ 'All Files', '*.*' ],
],
-initialdir => '.',
-title => 'Extract File...',
);
return unless defined $target;
my $bin = $tyd->readFile ($file);
open (OUT, ">$target");
binmode OUT;
print OUT $bin;
close (OUT);
}
sub delFile {
my $index = $table->selectionGet;
my $file = $table->itemCget ($index,0,-text);
return unless exists $tyd->{files}->{$file};
# Delete the file.
$tyd->deleteFile ($file);
&refresh();
}
sub viewFile {
my $index = $table->selectionGet;
my $file = $table->itemCget ($index,0,-text);
return unless exists $tyd->{files}->{$file};
# Figure out its extension.
if ($file =~ /\.(jpg|jpe|jpeg)$/i) {
my $bin = $tyd->readFile ($file);
my $base = encode_base64 ($bin);
my $image = $main->Photo (-data => $base, -format => 'JPEG');
my $show = $main->DialogBox (
-title => "$file",
-buttons => [ 'Close' ],
);
$show->Label (
-image => $image,
)->pack (-padx => 5, -pady => 5);
$show->Show;
}
elsif ($file =~ /\.gif$/i) {
my $bin = $tyd->readFile ($file);
my $base = encode_base64 ($bin);
my $image = $main->Photo (-data => $base, -format => 'GIF');
my $show = $main->DialogBox (
-title => "$file",
-buttons => [ 'Close' ],
);
$show->Label (
-image => $image,
)->pack (-padx => 5, -pady => 5);
$show->Show;
}
elsif ($file =~ /\.png$/i) {
my $bin = $tyd->readFile ($file);
my $base = encode_base64 ($bin);
my $image = $main->Photo (-data => $base, -format => 'PNG');
my $show = $main->DialogBox (
-title => "$file",
-buttons => [ 'Close' ],
);
$show->Label (
-image => $image,
)->pack (-padx => 5, -pady => 5);
$show->Show;
}
elsif ($file =~ /\.bmp$/i) {
my $bin = $tyd->readFile ($file);
my $base = encode_base64 ($bin);
my $image = $main->Photo (-data => $base, -format => 'BMP');
my $show = $main->DialogBox (
-title => "$file",
-buttons => [ 'Close' ],
);
$show->Label (
-image => $image,
)->pack (-padx => 5, -pady => 5);
$show->Show;
}
elsif ($file =~ /\.(htm|html)$/i) {
my $bin = $tyd->readFile ($file);
open (TMP, ">./tmp.html");
print TMP $bin;
close (TMP);
system ("start tmp.html");
unlink ("./tmp.html");
}
else {
# We'll assume it's text.
my $show = $main->DialogBox (
-title => "$file",
-buttons => [ 'Close' ],
);
my $view = $show->Scrolled ('ROText',
-foreground => '#000000',
-background => '#FFFFFF',
-scrollbars => 'ose',
-wrap => 'word',
)->pack (-fill => 'both', -expand => 1);
$view->insert ('end',$tyd->readFile($file));
$show->Show;
}
( run in 2.162 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )