#!/bin/bash

# Configuration
INSPIRE_PATH=/Applications/Promethean/Activsoftware\ Inspire
INSPIRE_APP_PATH=$INSPIRE_PATH/Inspire.app
SHARED_PROM_PATH=/Users/Shared/Promethean
DEFAULT_RES_PATH=$SHARED_PROM_PATH/Activinspire\ Resources

inspire_check () 
{
	INI_PATH=$INSPIRE_APP_PATH/Contents/Promethean/ActivInspire.ini
	if [ -e "$INI_PATH" ] ; then
		RES_PATH=`grep currentSharedResPath "$INI_PATH" | cut -d'=' -f2`
		[ -z "$RES_PATH" ] && RES_PATH=`grep defaultSharedResPath "$INI_PATH" | cut -d'=' -f2`
	fi	
}

res_path_check ()
{
	[ -e "$INSPIRE_PATH/SharedResPath.txt" ] && RES_PATH=`cat "$INSPIRE_PATH/SharedResPath.txt"`
}	

vthree_check ()
{
	[ -z "$RES_PATH" ] && RES_PATH=`"$VTHREE_SCRIPT"`
}

# Retrieve the current resources path if present, otherwise,
# Check for V3 settings, or use default
inspire_check
[ -z "$RES_PATH" ] && res_path_check
[ -z "$RES_PATH" ] && VTHREE_SCRIPT="$1/Contents/Resources/vthreeresfinder" && vthree_check
[ -z "$RES_PATH" ] && RES_PATH=$DEFAULT_RES_PATH

# Tell Inspire.app where the resources are located
[ ! -d "$INSPIRE_PATH" ] && mkdir -pm 0775 "$INSPIRE_PATH"
echo -n "$RES_PATH" > "$INSPIRE_PATH"/ResLocation.txt
echo -n "$RES_PATH" > "$INSPIRE_PATH"/SharedResPath.txt

# Debugging...
echo "RES_PATH=$RES_PATH"
	
exit 0