# Start the emulator for App Inventor
#!/bin/bash

# This is to try to get around a bug in the Android SDK where
# the emulator won't start and you'll see the message
# NAND: Could not create temp file for system NAND disk image.
# This is a permission problem on /tmp/android. Doing the
# rf here might not work either but it's worth a try.  If this doesn't
# work, you should execute this remove command as root.
rm -rf /tmp/android

# cd to the directory where these commands are
cd `dirname $0`

# create the emulator directory if necessary
APPINVDIR=$HOME/.appinventor
EMUDIR=$HOME/.appinventor/emulator

if [ ! -d $APPINVDIR ]
then
mkdir $APPINVDIR
fi
if [ ! -d $EMUDIR ]
then
mkdir $EMUDIR
fi

# install the prebuilt user data image
EMDATA=Appinventor-emulator-data
DATAFILE=$EMUDIR/$EMDATA
if [ ! -f $DATAFILE ]
then
cp ../extras/$EMDATA $DATAFILE
fi

# create the SD Card
SDCARDFILE=$EMUDIR/sdcard.img
if [ ! -f $SDCARDFILE ]
then
./mksdcard 64M $SDCARDFILE
fi

./emulator -kernel ../from-Android-SDK/platforms/android-8/images/kernel-qemu    \
           -ramdisk ../from-Android-SDK/platforms/android-8/images/ramdisk.img   \
           -system ../from-Android-SDK/platforms/android-8/images/system.img     \
           -partition-size 84 \
           -sdcard $SDCARDFILE \
           -skindir ../from-Android-SDK/platforms/android-8/skins   \
           -skin HVGA-AppInventor   \
           -sysdir /$TMPDIR   \
           -data $DATAFILE \
           -scale 0.7 \
           -no-boot-anim  \
&


