echo off
SET scrver=ver 1.02
SET moddate=2015.9.24
REM Script now installs/upgrades GravityBox as well

REM Test to catch when script is "Run as Administrator"
REM Windows will change current dir to c:\WINDOWS\SYSTEM, so we need to
REM change back to folder where FLASH.BAT resides
REM %0 is the drive/path/filename of this batch file. 
REM %~dp0 expands to the drive and path of this batch file

echo **%0 Started from %cd% - Date=%date% Time=%time% OS=%os% Username=%username% > log1.txt
echo **Contents of %cd%: >> log1.txt
dir /B >> log1.txt
REM Kill any running adb processes
taskkill /f /im adb.exe >NUL 2>NUL  
color E
cls
echo.
echo             ***********************************************
echo             *  InstallXFandInstaller.BAT     %scrver%     *
echo             *       Xposed Framework V74 installer        * 
echo             *          for Teclast X98 Air II/3G          *
echo             *                                             *
echo             *              modified                       *
echo             *              %moddate%  TecKnight           *
echo             ***********************************************
echo.
echo IMPORTANT !!
echo  - Requirements: 
echo.      Rooted X98 Air device running Android 5.0 
echo.      Busybox installed
echo  - Your BATTERY must be charged to 50%% or higher !!
echo  - Your X98 device must be booted into Android and connected to this PC via USB
echo  - On X98 device-"Settings->Developer options->USB debugging" must be checked
echo.
echo If all above requirements are met, press ENTER to proceed
echo Otherwise, press CTRL-C to abort
pause > nul
echo '
echo ' Connecting to X98 Air device..
echo ' Connecting to X98 Air device.. >> log1.txt
echo '
echo **running "adb devices" output= > log2.txt
adb devices >> log2.txt
type log2.txt
adb wait-for-devices
echo '
echo ' Pushing Xposed Framework files to temp folder..
echo ' Pushing Xposed Framework files to temp folder.. >> log2.txt
echo '
echo **running "adb push updzip\xposed-sdk21-x86\system /data/local/tmp/system" output= > log3.txt
adb push updzip\xposed-sdk21-x86\system /data/local/tmp/system/ 2>> log3.txt
echo **running "adb push binaries\installer /data/local/tmp/" output= >> log3.txt
adb push binaries\installer /data/local/tmp/ 2>> log3.txt
echo **running "adb shell su -c chmod 755 /data/local/tmp/installer" output= >> log3.txt
adb shell "su -c chmod 755 /data/local/tmp/installer" 2>> log3.txt
echo '
echo ' Installing Xposed Framework V74 ..
echo ' Installing Xposed Framework V74 .. >> log3.txt
echo '
echo **running "adb shell su -c /data/local/tmp/installer" output= > log4.txt
adb shell "su -c /data/local/tmp/installer" 2>> log4.txt

echo **running "adb install -r updzip\XposedInstaller_3.0_alpha4.apk" output= >> log4.txt
adb install -r updzip\XposedInstaller_3.0_alpha4.apk >> log4.txt

echo **running "adb install -r updzip\com.ceco.lollipop.gravitybox_v520_f13fb7.apk" output= >> log4.txt
adb install -r updzip\com.ceco.lollipop.gravitybox_v520_f13fb7.apk >> log4.txt

echo '
echo ' Installed Xposed Framework V74 and Xposed Installer, rebooting ..
echo ' Installed Xposed Framework V74 and Xposed Installer, rebooting .. >> log4.txt
echo '
taskkill /f /im adb.exe >NUL 2>NUL
copy /B log1.txt XFILog.txt >NUL
if exist log2.txt copy /B XFILog.txt+log2.txt XFILog.txt >NUL
if exist log3.txt copy /B XFILog.txt+log3.txt XFILog.txt >NUL
if exist log4.txt copy /B XFILog.txt+log4.txt XFILog.txt >NUL
del log*.txt

adb reboot
