#!/sbin/sh

. /tmp/backuptool.functions

list_files() {
cat <<EOF
app/ApexLauncher/ApexLauncher.apk
app/DriveDroid/DriveDroid.apk
app/FDroid/FDroid.apk
etc/security/cacerts/f9227477.0
EOF
}

list_removals() {
cat <<EOF
app/BasicDreams/BasicDreams.apk
app/Browser/Browser.apk
app/CMFileManager/CMFileManager.apk
app/CMWallpapers/CMWallpapers.apk
app/Email/Email.apk
app/Exchange2/Exchange2.apk
app/Galaxy4/Galaxy4.apk
app/HTMLViewer/HTMLViewer.apk
app/HoloSpiralWallpaper/HoloSpiralWallpaper.apk
app/LiveWallpapers/LiveWallpapers.apk
app/NoiseField/NoiseField.apk
app/PhaseBeam/PhaseBeam.apk
app/PhotoPhase/PhotoPhase.apk
app/PhotoTable/PhotoTable.apk
media/audio/ui/Dock.ogg
media/audio/ui/Effect_Tick.ogg
media/audio/ui/KeypressDelete.ogg
media/audio/ui/KeypressInvalid.ogg
media/audio/ui/KeypressReturn.ogg
media/audio/ui/KeypressSpacebar.ogg
media/audio/ui/KeypressStandard.ogg
media/audio/ui/Lock.ogg
media/audio/ui/LowBattery.ogg
media/audio/ui/Trusted.ogg
media/audio/ui/Undock.ogg
media/audio/ui/Unlock.ogg
media/audio/ui/VideoRecord.ogg
media/audio/ui/WirelessChargingStarted.ogg
media/audio/ui/camera_click.ogg
media/audio/ui/camera_focus.ogg
media/bootanimation.zip
priv-app/CMBugReport/CMBugReport.apk
priv-app/Trebuchet/Trebuchet.apk
EOF
}

case "$1" in
  backup)
    list_files | while read FILE DUMMY; do
      backup_file $S/"$FILE"
    done
  ;;
  restore)
    list_files | while read FILE REPLACEMENT; do
      R=""
      [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
      [ -f "$C/$S/$FILE" ] && restore_file $S/"$FILE" "$R"
    done
  ;;
  pre-backup)
    # Stub
  ;;
  post-backup)
    # Stub
  ;;
  pre-restore)
    # Stub
  ;;
  post-restore)
    list_removals | while read FILE; do
      rm -f $S/"$FILE"
      # Try to remove empty directories
      rmdir $S/"$(dirname "$FILE")"
    done
    sed -i 's/ro.sf.lcd_density=.*/ro.sf.lcd_density=420/g' $S/build.prop
  ;;
esac
