Skip to content

Commit

Permalink
Fix merge res
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard20181 committed Jan 3, 2023
1 parent 6199cc9 commit d3a055c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
29 changes: 15 additions & 14 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,20 @@ if [ "$HOST_ARCH" != "x86_64" ] && [ "$HOST_ARCH" != "aarch64" ]; then
exit 1
fi
cd "$(dirname "$0")" || exit 1
trap umount_clean EXIT
# export TMPDIR=$(dirname "$PWD")/WORK_DIR_
if [ "$TMPDIR" ] && [ ! -d "$TMPDIR" ]; then
mkdir -p "$TMPDIR"
fi
WORK_DIR=$(mktemp -d -t wsa-build-XXXXXXXXXX_) || exit 1
DOWNLOAD_DIR=../download
DOWNLOAD_CONF_NAME=download.list
OUTPUT_DIR=../output
MOUNT_DIR="$WORK_DIR"/system
SUDO="$(which sudo 2>/dev/null)"
if [ -z "$SUDO" ]; then
unset SUDO
fi
WSA_WORK_ENV="${WORK_DIR:?}"/ENV
if [ -f "$WSA_WORK_ENV" ]; then rm -f "${WSA_WORK_ENV:?}"; fi
touch "$WSA_WORK_ENV"
export WSA_WORK_ENV
umount_clean() {
echo "Cleanup Work Directory"
if [ -d "$MOUNT_DIR" ]; then
echo "Cleanup Work Directory"
echo "Cleanup Mount Directory"
if [ -d "$MOUNT_DIR/vendor" ]; then
$SUDO umount "$MOUNT_DIR"/vendor
fi
Expand All @@ -68,6 +61,14 @@ umount_clean() {
unset TMPDIR
fi
}
trap umount_clean EXIT
DOWNLOAD_DIR=../download
DOWNLOAD_CONF_NAME=download.list
OUTPUT_DIR=../output
WSA_WORK_ENV="${WORK_DIR:?}"/ENV
if [ -f "$WSA_WORK_ENV" ]; then rm -f "${WSA_WORK_ENV:?}"; fi
touch "$WSA_WORK_ENV"
export WSA_WORK_ENV
clean_download() {
if [ -d "$DOWNLOAD_DIR" ]; then
echo "Cleanup Download Directory"
Expand Down Expand Up @@ -635,9 +636,9 @@ EOF
echo -e "Integrate Magisk done\n"
fi

echo "Merge Language Resources"
cp "$WORK_DIR"/wsa/"$ARCH"/resources.pri "$WORK_DIR"/wsa/pri/en-us.pri \
&& cp "$WORK_DIR"/wsa/"$ARCH"/AppxManifest.xml "$WORK_DIR"/wsa/xml/en-us.xml && {
cp "$WORK_DIR/wsa/$ARCH/resources.pri" "$WORK_DIR"/wsa/pri/en-us.pri \
&& cp "$WORK_DIR/wsa/$ARCH/AppxManifest.xml" "$WORK_DIR"/wsa/xml/en-us.xml && {
echo "Merge Language Resources"
tee "$WORK_DIR"/wsa/priconfig.xml <<EOF
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resources targetOsVersion="10.0.0" majorVersion="1">
Expand All @@ -654,9 +655,9 @@ EOF
else
res_merge_failed=1
fi
[ -z "$res_merge_failed" ] || sed -i -zE "s/<Resources.*Resources>/<Resources>\n$(cat "$WORK_DIR"/wsa/xml/* | grep -Po '<Resource [^>]*/>' | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\$/\\$/g' | sed 's/\//\\\//g')\n<\/Resources>/g" "$WORK_DIR"/wsa/"$ARCH"/AppxManifest.xml && \
[ -z "$res_merge_failed" ] && sed -i -zE "s/<Resources.*Resources>/<Resources>\n$(cat "$WORK_DIR"/wsa/xml/* | grep -Po '<Resource [^>]*/>' | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\$/\\$/g' | sed 's/\//\\\//g')\n<\/Resources>/g" "$WORK_DIR"/wsa/"$ARCH"/AppxManifest.xml && \
echo -e "Merge Language Resources done\n"
} && [ -z "$res_merge_failed" ] || echo -e "Merge Language Resources failed\n" && unset res_merge_failed
} && [ -n "$res_merge_failed" ] && echo -e "Merge Language Resources failed\n" && unset res_merge_failed

echo "Add extra packages"
$SUDO cp -r ../"$ARCH"/system/* "$MOUNT_DIR" || abort
Expand Down
11 changes: 8 additions & 3 deletions scripts/extractWSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import zipfile
import os
from pathlib import Path
import re

warnings.filterwarnings("ignore")

Expand All @@ -32,8 +33,11 @@
zip_name = ""
wsa_zip_path= Path(sys.argv[2]).resolve()
workdir = Path(sys.argv[3]) / "wsa"
archdir = Path(workdir / arch)
if not Path(workdir).is_dir():
workdir.mkdir()
if not Path(archdir).is_dir():
archdir.mkdir()
with zipfile.ZipFile(wsa_zip_path) as zip:
for f in zip.filelist:
if arch in f.filename.lower():
Expand Down Expand Up @@ -64,7 +68,8 @@
elif g.filename == 'AppxManifest.xml':
g.filename = f'{name}.xml'
l.extract(g, workdir / 'xml')
elif re.search(u'Images/.+\.png', g.filename) != None:
l.extract(g, archdir)
with zipfile.ZipFile(zip_path) as zip:
if not Path(workdir / arch).is_dir():
print(f"unzipping from {zip_path}", flush=True)
zip.extractall(workdir / arch)
print(f"unzipping from {zip_path}", flush=True)
zip.extractall(archdir)

0 comments on commit d3a055c

Please sign in to comment.