Skip to content

Commit e475f73

Browse files
authored
build: update apktool.bat to properly handle minor decimal versions when finding highest version (#3913)
Fixed finding correct highest version in windows when minor version is more than one digit (e.g. 2.12.0). Formerly, 2.**.0 is parsed as less than 2.*.0 due to Windows batch limitation of handling only whole integers
1 parent 2102ed9 commit e475f73

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

scripts/windows/apktool.bat

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,51 @@ if exist apktool.jar (
1616
set BASENAME=apktool
1717
goto skipversioned
1818
)
19-
set max=0
20-
for /f "tokens=1* delims=-_.0" %%A in ('dir /b /a-d %BASENAME%*.jar') do if %%~B gtr !max! set max=%%~nB
19+
20+
set BASENAME=apktool
21+
set max_major=0
22+
set max_minor=0
23+
set max_patch=0
24+
25+
rem Loop through all versioned .jar files matching the basename
26+
for %%F in (%BASENAME%*.jar) do (
27+
set "filename=%%~nF"
28+
29+
rem Extract version part (apktool-X.Y.Z)
30+
for /f "tokens=2 delims=_-" %%A in ("!filename!") do (
31+
for /f "tokens=1,2,3 delims=." %%B in ("%%A") do (
32+
set "major=%%B"
33+
set "minor=%%C"
34+
set "patch=%%D"
35+
36+
rem Set Default minor/patch to 0
37+
if "!minor!"=="" set "minor=0"
38+
if "!patch!"=="" set "patch=0"
39+
40+
rem Compare major version
41+
if !major! gtr !max_major! (
42+
set "max_major=!major!"
43+
set "max_minor=!minor!"
44+
set "max_patch=!patch!"
45+
) else if !major! == !max_major! (
46+
rem Compare minor version
47+
if !minor! gtr !max_minor! (
48+
set "max_minor=!minor!"
49+
set "max_patch=!patch!"
50+
) else if !minor! == !max_minor! (
51+
rem Compare patch version
52+
if !patch! gtr !max_patch! (
53+
set "max_patch=!patch!"
54+
)
55+
)
56+
)
57+
)
58+
)
59+
)
60+
61+
rem Construct full version string
62+
set "max=_!max_major!.!max_minor!.!max_patch!"
63+
2164
:skipversioned
2265
popd
2366
setlocal DisableDelayedExpansion

0 commit comments

Comments
 (0)