Correctly get Magisk version number from zip

This commit is contained in:
Howard Wu 2022-12-11 22:57:45 +08:00
parent 50ee54c122
commit be86d42785
2 changed files with 23 additions and 7 deletions

View file

@ -433,8 +433,8 @@ fi
echo "Extract Magisk"
if [ -f "$MAGISK_PATH" ]; then
version=""
versionCode=0
MAGISK_VERSION_NAME=""
MAGISK_VERSION_CODE=0
if ! python3 extractMagisk.py "$ARCH" "$MAGISK_PATH" "$WORK_DIR"; then
echo "Unzip Magisk failed, is the download incomplete?"
CLEAN_DOWNLOAD_MAGISK=1
@ -886,7 +886,7 @@ echo "Generate info"
if [[ "$ROOT_SOL" = "none" ]]; then
name1=""
elif [ "$ROOT_SOL" = "" ] || [ "$ROOT_SOL" = "magisk" ]; then
name1="-with-magisk-$version($versionCode)-$MAGISK_VER"
name1="-with-magisk-$MAGISK_VERSION_NAME($MAGISK_VERSION_CODE)-$MAGISK_VER"
else
name1="-with-$ROOT_SOL-$MAGISK_VER"
fi

View file

@ -19,11 +19,24 @@
#
import sys
import zipfile
from pathlib import Path
import platform
import os
from typing import OrderedDict
class Prop(OrderedDict):
def __init__(self, props: str=...) -> None:
super().__init__()
for i, line in enumerate(props.splitlines(False)):
if '=' in line:
k, v = line.split('=', 2)
self[k] = v
else:
self[f".{i}"] = line
def get(self, key: str) -> str:
return self[key]
is_x86_64 = platform.machine() in ("AMD64", "x86_64")
host_abi = "x64" if is_x86_64 else "arm64"
@ -41,10 +54,13 @@ def extract_as(zip, name, as_name, dir):
zip.extract(info, workdir / dir)
with zipfile.ZipFile(magisk_zip) as zip:
comment = zip.comment.decode('utf-8')
props = Prop(zip.comment.decode().replace('\000', '\n'))
versionName = props.get("version")
versionCode = props.get("versionCode")
print(f"Magisk version: {versionName} ({versionCode})", flush=True)
with open(os.environ['WSA_WORK_ENV'], 'a') as environ_file:
environ_file.write(f'{comment}\n')
print(f'{comment}', flush=True)
environ_file.write(f'MAGISK_VERSION_NAME={versionName}\n')
environ_file.write(f'MAGISK_VERSION_CODE={versionCode}\n')
extract_as(
zip, f"lib/{ abi_map[arch][0] }/libmagisk64.so", "magisk64", "magisk")
extract_as(