#!/bin/bash
# (C) 2018 Esteban D.Dortta
#
# tools/adb-photo
# YeAPF 0.8.64-11 built on 2021-01-22 16:32 (-3 DST)
# Copyright (C) 2004-2021 Esteban Daniel Dortta - dortta@yahoo.com - MIT License
# 2019-07-19 18:34:19 (-3 DST)
#
# This set of scripts requires adb/android-sdk/cordova installed on your device.
# Has been well tested under Ubuntu 16 and MacOSX 10.11.6
# It is supposed to run on Cygwin

if [ -f www/js/version.js ]; then
  my_dir="$(dirname "$0")"
  source "$my_dir/adb-lib.inc.sh"

  version="$(currentVersion)"

  dev=$1
  if [ -z $dev ]; then
    dev=$firstdev
  fi

  if [ $devcount -eq 0 ]; then
    echo "Please, attach/indicate a device"
  else
    echo "device=$dev"

  	mkdir -p devicePhotos
  	d=`date +%Y%m%d%H%M%S`
	  adb -s $dev shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > devicePhotos/screen-$d.png
  fi
else
	echo "www/js/version.js file not found"
fi