#!/bin/sh

echo "Starting Pattern Design installer preflight script";

TARGET_LOCATION=$2
RUN_DEACTIVATE=0

if [ -f "$TARGET_LOCATION/PAD System 5.0/Pattern/Pattern Design.app/Contents/Resources/dontdelete/dontdelete.act" ] ; then
  echo "Deactivate Pattern Design by selected path";
  "$TARGET_LOCATION"/PAD\ System\ 5.0/Pattern/Pattern\ Design.app/Contents/MacOS/Pattern Updater:
  RUN_DEACTIVATE=1
else 
  if [ -f "/Applications/PAD System 5.0/Pattern/Pattern Design.app/Contents/Resources/dontdelete/dontdelete.act" ] ; then
    echo "Deactivate Pattern Design by default path";
    /Applications/PAD\ System\ 5.0/Pattern/Pattern\ Design.app/Contents/MacOS/Pattern Updater:
    RUN_DEACTIVATE=1
  fi
fi

if (($RUN_DEACTIVATE==0)); then
  if [ -f "$TARGET_LOCATION/PAD System 5.0/Pattern/Pattern Design.app/Contents/MacOS/Pattern" ] ; then
    echo "Deactivate Pattern Design by selected path";
    "$TARGET_LOCATION"/PAD\ System\ 5.0/Pattern/Pattern\ Design.app/Contents/MacOS/Pattern close_all:  
  else 
    if [ -f "/Applications/PAD System 5.0/Pattern/Pattern Design.app/Contents/MacOS/Pattern" ] ; then
      echo "Deactivate Pattern Design by default path";
      /Applications/PAD\ System\ 5.0/Pattern/Pattern\ Design.app/Contents/MacOS/Pattern close_all:
    fi
  fi
fi

echo "Ending Pattern Design installer preflight script";

exit 0;