local util = require("util")
function PLUGIN:PostInstall(ctx)
local rootPath = ctx.rootPath
local os_name = util.getOsName()
local find_cmd
local jar_path
if RUNTIME.osType == "windows" then
find_cmd = string.format('dir /b "%s\\aapt2-*.jar" 2>nul', rootPath)
else
find_cmd = string.format('ls "%s"/aapt2-*.jar 2>/dev/null | head -1', rootPath)
end
local handle = io.popen(find_cmd)
if handle then
jar_path = handle:read("*l")
handle:close()
end
if not jar_path or jar_path == "" then
return
end
if RUNTIME.osType == "windows" and not string.match(jar_path, "^[A-Za-z]:") then
jar_path = rootPath .. "\\" .. jar_path
end
local extract_cmd
if RUNTIME.osType == "windows" then
extract_cmd = string.format(
"powershell -Command \"Expand-Archive -Path '%s' -DestinationPath '%s' -Force\"",
jar_path,
rootPath
)
else
extract_cmd = string.format('unzip -o "%s" -d "%s"', jar_path, rootPath)
end
local result = os.execute(extract_cmd)
if not result then
error("Failed to extract JAR file: " .. jar_path)
end
os.remove(jar_path)
if RUNTIME.osType ~= "windows" then
local aapt2_path = rootPath .. "/aapt2"
os.execute(string.format('chmod +x "%s"', aapt2_path))
end
end