#!/bin/sh

# PNGenie 1.00 (2009-07-03)
# process files
# by Matt Sephton http://www.gingerbeardman.com

RES="$1"/Contents/Resources
CDIALOG="$RES/CocoaDialog.app/Contents/MacOS/CocoaDialog"

#download pngout if we need it
"$RES/pngout-downloader.php"

total=$#
let "total = $total - 1"

if [ -n "$2" ]
then
	count=0
	until [ "$*" = "" ]
	do
		let "count = $count + 1"
		let "percent = ($count*100 / $total*100)/100"

		echo "$percent Optimising files: $count of $total"

		"$RES/advpng" -z4q "$2"
		"$RES/optipng" -q "$2"
		if [ -f "$RES/pngout-darwin" ]
		then
			"$RES/pngout-darwin" -q "$2"
		fi

		shift
	done | $CDIALOG progressbar --title "PNGenie"
fi
