From be86d42785e9b7a0e7bb7897ad8dfb5e997e983b Mon Sep 17 00:00:00 2001 From: Howard Wu <40033067+Howard20181@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:57:45 +0800 Subject: [PATCH] Correctly get Magisk version number from zip --- scripts/build.sh | 6 +++--- scripts/extractMagisk.py | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 7ca9534..de9f54b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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 diff --git a/scripts/extractMagisk.py b/scripts/extractMagisk.py index 4c899da..6d6f606 100644 --- a/scripts/extractMagisk.py +++ b/scripts/extractMagisk.py @@ -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(