2022-12-08 16:06:23 +08:00
|
|
|
#!/usr/bin/python3
|
2022-08-26 00:20:49 +08:00
|
|
|
#
|
2022-08-24 01:54:24 +08:00
|
|
|
# This file is part of MagiskOnWSALocal.
|
|
|
|
#
|
|
|
|
# MagiskOnWSALocal is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# MagiskOnWSALocal is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with MagiskOnWSALocal. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#
|
2023-01-11 17:05:56 +08:00
|
|
|
# Copyright (C) 2023 LSPosed Contributors
|
2022-08-24 01:54:24 +08:00
|
|
|
#
|
|
|
|
|
2022-08-14 10:43:35 +08:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import zipfile
|
|
|
|
from pathlib import Path
|
2023-01-03 16:47:58 +08:00
|
|
|
import re
|
2023-03-18 13:56:49 +08:00
|
|
|
import shutil
|
2022-08-14 10:43:35 +08:00
|
|
|
|
|
|
|
arch = sys.argv[1]
|
|
|
|
|
|
|
|
zip_name = ""
|
2022-08-26 02:33:27 +08:00
|
|
|
wsa_zip_path= Path(sys.argv[2]).resolve()
|
2023-03-18 13:56:49 +08:00
|
|
|
rootdir = Path(sys.argv[3]).resolve()
|
|
|
|
env_file = Path(sys.argv[4]).resolve()
|
|
|
|
|
|
|
|
workdir = rootdir / "wsa"
|
2023-01-03 16:47:58 +08:00
|
|
|
archdir = Path(workdir / arch)
|
2023-03-18 13:56:49 +08:00
|
|
|
|
|
|
|
if not Path(rootdir).is_dir():
|
|
|
|
rootdir.mkdir()
|
|
|
|
|
|
|
|
if Path(workdir).is_dir():
|
|
|
|
shutil.rmtree(workdir)
|
|
|
|
else:
|
|
|
|
workdir.unlink(missing_ok=True)
|
|
|
|
|
2022-09-17 21:15:44 +08:00
|
|
|
if not Path(workdir).is_dir():
|
|
|
|
workdir.mkdir()
|
2023-03-18 13:56:49 +08:00
|
|
|
|
2023-01-03 16:47:58 +08:00
|
|
|
if not Path(archdir).is_dir():
|
|
|
|
archdir.mkdir()
|
2022-08-26 02:33:27 +08:00
|
|
|
with zipfile.ZipFile(wsa_zip_path) as zip:
|
2022-08-14 10:43:35 +08:00
|
|
|
for f in zip.filelist:
|
|
|
|
if arch in f.filename.lower():
|
|
|
|
zip_name = f.filename
|
2022-08-21 22:30:32 +02:00
|
|
|
output_name = zip_name[11:-5]
|
2022-09-17 21:15:44 +08:00
|
|
|
if not Path(workdir / zip_name).is_file():
|
2022-08-14 10:43:35 +08:00
|
|
|
zip_path = workdir / zip_name
|
2022-08-23 13:04:16 +08:00
|
|
|
print(f"unzipping to {workdir}", flush=True)
|
2022-08-14 10:43:35 +08:00
|
|
|
zip.extract(f, workdir)
|
|
|
|
ver_no = zip_name.split("_")
|
|
|
|
long_ver = ver_no[1]
|
|
|
|
ver = long_ver.split(".")
|
|
|
|
main_ver = ver[0]
|
|
|
|
rel = ver_no[3].split(".")
|
2022-12-08 16:06:23 +08:00
|
|
|
rel_long = str(rel[0])
|
2023-03-18 13:56:49 +08:00
|
|
|
with open(env_file, 'a') as environ_file:
|
2022-12-08 16:06:23 +08:00
|
|
|
environ_file.write(f'WSA_VER={long_ver}\n')
|
|
|
|
environ_file.write(f'WSA_MAIN_VER={main_ver}\n')
|
|
|
|
environ_file.write(f'WSA_REL={rel_long}\n')
|
2022-08-14 10:43:35 +08:00
|
|
|
if 'language' in f.filename.lower() or 'scale' in f.filename.lower():
|
2023-03-18 13:56:49 +08:00
|
|
|
name = f.filename.split("_")[2].split(".")[0]
|
2022-08-14 10:43:35 +08:00
|
|
|
zip.extract(f, workdir)
|
|
|
|
with zipfile.ZipFile(workdir / f.filename) as l:
|
|
|
|
for g in l.filelist:
|
|
|
|
if g.filename == 'resources.pri':
|
2023-03-18 17:49:49 +08:00
|
|
|
g.filename = f'resources.{name}.pri'
|
|
|
|
l.extract(g, workdir / archdir / 'pri')
|
2022-08-14 10:43:35 +08:00
|
|
|
elif g.filename == 'AppxManifest.xml':
|
2023-03-18 17:49:49 +08:00
|
|
|
g.filename = f'resources.{name}.xml'
|
|
|
|
l.extract(g, workdir / archdir / 'xml')
|
2023-01-03 16:52:07 +08:00
|
|
|
elif re.search(u'Images/.+\.png', g.filename):
|
2023-01-03 16:47:58 +08:00
|
|
|
l.extract(g, archdir)
|
2022-08-14 10:43:35 +08:00
|
|
|
with zipfile.ZipFile(zip_path) as zip:
|
2023-01-03 16:47:58 +08:00
|
|
|
print(f"unzipping from {zip_path}", flush=True)
|
|
|
|
zip.extractall(archdir)
|