#!/bin/sh

# configure.sh #
#############################
#                           #
# Setup Filetypes for Snips #
#                           #
#############################

this_dir=$(dirname $0)
err_file=${this_dir}/config.errors
snips=${this_dir}/Snips
nametype=${this_dir}/Helpers/nametype
addext=${this_dir}/Helpers/addext

echo "[Starting configure script]" > ${err_file}

# Run snips so the file-type gets registered
echo "Running Snips to register mime-type..." >> ${err_file}

if [ ! -e ${snips} ]
then
	echo "ERROR: Cannot find 'Snips' in ${snips}" >> ${err_file}
	config_failed ;
fi

${snips} "--nothing" >> ${err_file} 2>> ${err_file}

Install_status=$?
if [ ${Install_status} != 0 ]
then
	echo "ERROR: ${snips} failed" >> ${err_file}	
	config_failed
fi	


# Name the shortcut
echo "Naming the WindowsShortcut MimeType" >> ${err_file}

if [ ! -e ${nametype} ]
then
	echo "ERROR: Cannot find 'nametype' in ${nametype}" >> ${err_file}
	config_failed
fi

${nametype} "application/x-windows-shortcut" "Windows Shortcut" >> ${err_file} 2>> ${err_file}

Install_status=$?
if [ ${Install_status} != 0 ]
then 
	echo "ERROR: ${nametype} failed" >> ${err_file}	
	config_failed
fi


# Add "lnk" as a valid extension for the mime-type
echo "Adding '.lnk' as extension for windows shortcuts" >> ${err_file}

if [ ! -e ${addext} ]
then
	echo "ERROR: Cannot find 'addext' in ${addext}" >> ${err_file}
	config_failed
fi

${addext} "application/x-windows-shortcut" "lnk" >> ${err_file} 2>> ${err_file}

Install_status=$?
if [ ${Install_status} == 0 ]
then 
	alert "Install Successful"
	rm ${err_file}
else
	echo "ERROR: ${addext} failed" >> ${err_file}	
	config_failed
fi

exit


config_failed()
{
	alert "Configuration Failed see the file config.errors for information"
	/boot/beos/system/Tracker ${err_file} &
	exit
}	
