#!/usr/bin/perl

# Konqueror Plus Clean Up ver.0.1.1
# 
# 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 "/";
$delete = "*.bak *~ core *.core #*#";

$make = $KPRC{"Make"};
$make = "make" if $make eq "";

# ファイルを指定せずに実行 → ヘルプ表示
if($target eq ""){
  $msg  = "「$appname」は右クリックメニューで実行します。\n";
  $msg .= "\n";
  $msg .= "対象: フォルダ, ファイルのない空白部分\n";
  $msg .= "\n";
  $msg .= "自動バックアップやコアダンプなどの不要ファイルを削除します。\n";
  $msg .= "Makefile のあるフォルダでは make clean の実行も可能です。";
  `keasydlg -t "$appname ヘルプ" -n "$msg"`;
  exit;
}

# チェック
if(!-d $target){
  `keasydlg -t "$appname" -w "ディレクトリを指定してください。"`;
  exit 1;
}

# make clean を実行するか
if(-f "$target/Makefile"){
  if(`keasydlg -t "$appname" -yn "make clean を実行しますか？"` eq "Yes"){
    chdir $target;
    `kp_exec -n $make clean`;
    exit;
  }
}

# 削除
$msg = "このフォルダにある以下のファイルを削除しますか？\n$delete";
if(`keasydlg -t "$appname" -yn "$msg"` eq "Yes"){
  chdir $target;
  `rm -f $delete`;
}
