From bd4ebdc3dcb05833aab0d787cc10e4c15f028116 Mon Sep 17 00:00:00 2001 From: Varstahl Date: Wed, 3 Jul 2019 19:37:51 +0200 Subject: [PATCH] Enhanced Windows wrapper script --- scripts/windows/apktool.bat | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/scripts/windows/apktool.bat b/scripts/windows/apktool.bat index 0747c0eb..634d95db 100755 --- a/scripts/windows/apktool.bat +++ b/scripts/windows/apktool.bat @@ -1,5 +1,36 @@ @echo off -if "%PATH_BASE%" == "" set PATH_BASE=%PATH% -set PATH=%CD%;%PATH_BASE%; +setlocal +set BASENAME=apktool_ chcp 65001 2>nul >nul -java -jar -Duser.language=en -Dfile.encoding=UTF8 "%~dp0\apktool.jar" %* + +rem Find the highest version .jar available in the same directory as the script +setlocal EnableDelayedExpansion +pushd "%~dp0" +if exist apktool.jar ( + set BASENAME=apktool + goto skipversioned +) +set max=0 +for /f "tokens=1* delims=-_.0" %%A in ('dir /b /a-d %BASENAME%*.jar') do if %%~B gtr !max! set max=%%~nB +:skipversioned +popd +setlocal DisableDelayedExpansion + +rem Find out if the commandline is a parameterless .jar or directory, for fast unpack/repack +if "%~1"=="" goto load +if not "%~2"=="" goto load +set ATTR=%~a1 +if "%ATTR:~0,1%"=="d" ( + rem Directory, rebuild + set fastCommand=b +) +if "%ATTR:~0,1%"=="-" if "%~x1"==".apk" ( + rem APK file, unpack + set fastCommand=d +) + +:load +java -jar -Duser.language=en -Dfile.encoding=UTF8 "%~dp0%BASENAME%%max%.jar" %fastCommand% %* + +rem Pause when ran non interactively +for /f "tokens=2" %%# in ("%cmdcmdline%") do if /i "%%#" equ "/c" pause