############################################################################
#
# Copyright (c) 2013 - dsixda (dislam@rocketmail.com)
#
# Android Kitchen is 100% free.  This script file is intended for personal
# and/or educational use only.  It may not be duplicated for monetary
# benefit or any other purpose without the permission of the developer.
#
############################################################################


clear
if [ ! -d WORKING_* ]
then
  echo No working folder found!
  scripts/press_enter
  exit 0
fi


while :
do

  clear

  echo
  echo "Convert update-script/updater-script"
  echo "--------------------------------------"
  echo
  echo "You should know:"
  echo "- An update-script is in 'Amend' format"
  echo "- An updater-script is in 'Edify' format"
  echo

  default_choice=""
  
  cd WORKING_*
  if [ -e META-INF/com/google/android/updater-script ]
  then
    echo "You currently have:"
    echo "META-INF/com/google/android/updater-script"
    echo
    default_choice=1
  elif [ -e META-INF/com/google/android/update-script ]
  then
    echo "You currently have:"
    echo "META-INF/com/google/android/update-script"
    echo
    default_choice=2
  else
    echo "You currently don't have either file in your"
    echo "working folder."
  fi

  cd ..

  echo
  echo "Enter a choice:"
  echo 

  echo "  1 = Convert updater-script to update-script (Amend)"
  echo "  2 = Convert update-script to updater-script (Edify)"
  echo "  0 = Exit"
  echo

  if [ "$default_choice" == "" ]
  then
    echo -n "? "
  else
    echo -n "(default: $default_choice)? "
  fi

  read enterNumber

  if [ "$enterNumber" != "0" ] &&  [ "$enterNumber" != "1" ] &&  [ "$enterNumber" != "2" ] 
  then
    if [ "$default_choice" == "" ]
    then
      echo "Invalid option"
      continue
    else
      enterNumber=$default_choice
    fi
  fi

  if [ "$enterNumber" == "1" ]
  then
    scripts/convert_updater_script
  elif [ "$enterNumber" == "2" ] 
  then
    scripts/convert_update_script
  elif [ "$enterNumber" == "0" ]
  then
    exit 0
  fi

  scripts/press_enter
  exit 0

done
