#!/usr/bin/perl

# Konqueror Plus Compress ver.0.1.0
# 
# Copyright (c) 1999-2000 Japan KDE Users' Group
# 
# All rights reserved.
# 
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, provided that the above
# copyright notice(s) and this permission notice appear in all copies of
# the Software and that both the above copyright notice(s) and this
# permission notice appear in supporting documentation.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

require "$ENV{'KDEDIR'}/lib/konqplus.pl";

$appname = "圧縮";
$target = $ARGV[0];
$target =~ s/\/$// if $target ne "/";

# ファイルを指定せずに実行 → ヘルプ表示
if($target eq ""){
  $msg  = "「$appname」は右クリックメニューで実行します。\n";
  $msg .= "\n";
  $msg .= "対象: すべて\n";
  $msg .= "\n";
  $msg .= "ファイルを gz に圧縮します。\n";
  $msg .= "フォルダは tar.gz に圧縮します。";
  `keasydlg -t "$appname ヘルプ" -n "$msg"`;
  exit;
}

# 初期設定
$path = &dirname($target);
$file = &basename($target);

# チェック
if(!-w $path){
  `keasydlg -t "$appname" -w "書き込み権限がありません。"`;
  exit 1;
}

# 圧縮
chdir $path;
if(-f $file){
  `gzip -c $file > $file.gz`;
}elsif(-d $file){
  `kp_exec -n tar cvzf $file.tar.gz $file`;
}
