From d68f42c3685fdbf9db561672e7baa5ecf7220ff2 Mon Sep 17 00:00:00 2001 From: gfdgd xi <3025613752@qq.com> Date: Sun, 15 May 2022 21:54:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86API=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=BB=A5=E5=8F=8A=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api-test.py | 2 + api/README.md | 67 +++++++++++ api/__init__.py | 143 +++++++++++++++++++++++ api/__pycache__/getxmlimg.cpython-37.pyc | Bin 0 -> 3202 bytes {uengine-runner-api => api}/getxmlimg.py | 0 uengine-runner-api/__init__.py | 23 ---- 6 files changed, 212 insertions(+), 23 deletions(-) create mode 100644 api-test.py create mode 100644 api/README.md create mode 100644 api/__init__.py create mode 100644 api/__pycache__/getxmlimg.cpython-37.pyc rename {uengine-runner-api => api}/getxmlimg.py (100%) delete mode 100644 uengine-runner-api/__init__.py diff --git a/api-test.py b/api-test.py new file mode 100644 index 0000000..79870ba --- /dev/null +++ b/api-test.py @@ -0,0 +1,2 @@ +import api +xxx = api.APK() \ No newline at end of file diff --git a/api/README.md b/api/README.md new file mode 100644 index 0000000..0a331da --- /dev/null +++ b/api/README.md @@ -0,0 +1,67 @@ +# API 介绍 +# 必知 +1. 此 API 只支持可以运行 UEngine 的 Linux 上,Windows 上无法使用 +2. 部分函数需要 root 权限 +3. 这是 UEngine 运行器的函数重构,所以一些 UEngine 运行器上没有的 bug 可能在这个 API 里有 +## ProgramInformation +用于获取一些程序信息,详细如下(此为变量): +| 变量名 | 变量介绍 | +|:-:|:-:| +| programPath | 获取程序所在路径 | +| version | API 版本 | +| updateTime | 更新时间 | +| websize | 程序官网 | + +## Check +用于检查 API 所需的东西是否完整,详细如下: +| 函数名 | 函数介绍 | +|:-:|:-:| +| CheckDepend() | 检查 API 所需的依赖是否完整 | + +## ROOT +用于检查 ROOT 方面问题,详细如下: +| 函数名 | 函数介绍 | +|:-:|:-:| +| GetRoot() | 检查程序/API是否以 ROOT 权限运行 | + +## APK +这是面向对象的写法,所以应用方式也不一样: +```python +import api +xxx = api.APK("APK 所在路径") +``` +具体函数介绍: +| 函数名 | 函数介绍 | +|:-:|:-:| +| xxx.install() | 安装这个 APK 包 | +| xxx.uninstall()| 卸载这个 APK 包 | +| xxx.information()| 获取从 aapt 获取到的 APK 信息 | +| xxx.activityName() | 获取 APK 的 Activity 信息 | +| xxx.packageName() | 获取 APK 包名 | +| xxx.chineseLabel() | 获取 APK 中文名称 | +| xxx.saveApkIcon("图标保存路径") | 保存 APK 的图标到指定路径 | +| xxx.version() | 获取 APK 版本号 | + +## UEngine +用于对 UEngine 进行一点点操控,详细如下: +| 函数名 | 函数介绍 | +|:-:|:-:| +| CPUCheck() | 检查 CPU 是否支持运行 UEngine | +| Services | 用于操控 UEngine 服务的类,见下 | +| InternetBridge | 用于操控 UEngine 网络桥接的类,见下 | +### Services +关于 UEngine 的服务控制: +| 函数名 | 函数介绍 | +|:-:|:-:| +| Services.Open() | 打开 UEngine 服务 | +| Services.Close() | 关闭 UEngine 服务 | +| Services.Restart() | 重启 UEngine 服务 | +### InternetBridge +关于 UEngine 的网络桥接控制: +| 函数名 | 函数介绍 | +|:-:|:-:| +| InternetBridge.Open() | 打开 UEngine 网络桥接 | +| InternetBridge.Close() | 关闭 UEngine 网络桥接 | +| InternetBridge.Restart() | 重启 UEngine 网络桥接 | +| InternetBridge.Reload() | 重新加载 UEngine 网络桥接 | +| InternetBridge.ForceReload() | 强制加载 UEngine 网络桥接 | \ No newline at end of file diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..8809d83 --- /dev/null +++ b/api/__init__.py @@ -0,0 +1,143 @@ +import os +import shutil +import zipfile +import traceback +import subprocess +from getxmlimg import getsavexml + +class ProgramInformation: + programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string + version = "1.6.0Alpha1" + updateTime = "2022年05月15日" + websize = ["https://gitee.com/gfdgd-xi/uengine-runner", "https://github.com/gfdgd-xi/uengine-runner"] + +# 判断程序以正确方式运行 +class Check: + def CheckDepend(): + depend = ["/usr/bin/uengine", "UEngine", "/usr/bin/adb", "adb", "/usr/bin/uengine-session-launch-helper", "UEngine", "/usr/bin/aapt", "aapt"] + for i in range(0, len(depend), 2): + if not os.path.exists(depend[i]): + print("依赖{}不存在".format(depend[i + 1])) + +class ROOT: + def GetRoot(): + return os.geteuid() == 0 + +class APK: + def __init__(self, apkPath): + self.apkPath = apkPath + + def install(self): + os.system("pkexec /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(self.apkPath)) + + def uninstall(self): + os.system("pkexec /usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg='{}'".format(self.apkPath)) + + def information(self): + return subprocess.getoutput("aapt dump badging '{}'".format(self.apkPath)) + + def activityName(self): + info = self.information() + for line in info.split('\n'): + if "launchable-activity" in line: + line = line[0: line.index("label='")] + line = line.replace("launchable-activity: ", "") + line = line.replace("'", "") + line = line.replace(" ", "") + line = line.replace("name=", "") + line = line.replace("label=", "") + line = line.replace("icon=", "") + return line + + # 获取 apk 包名 + def packageName(self): + info = self.information() + for line in info.split('\n'): + if "package:" in line: + line = line[0: line.index("versionCode='")] + line = line.replace("package:", "") + line = line.replace("name=", "") + line = line.replace("'", "") + line = line.replace(" ", "") + return line + + # 获取软件的中文名称 + def chineseLabel(self) -> "获取软件的中文名称": + info = self.information() + for line in info.split('\n'): + if "application-label:" in line: + line = line.replace("application-label:", "") + line = line.replace("'", "") + return line + + # 保存apk图标 + def saveApkIcon(self, iconSavePath) -> "保存 apk 文件的图标": + try: + if os.path.exists(iconSavePath): + os.remove(iconSavePath) + info = self.information() + for line in info.split('\n'): + if "application:" in line: + xmlpath = line.split(":")[-1].split()[-1].split("=")[-1].replace("'", "") + if xmlpath.endswith('.xml'): + xmlsave = getsavexml() + print(xmlpath) + xmlsave.savexml(self.apkPath, xmlpath, iconSavePath) + return + else: + zip = zipfile.ZipFile(self.apkPath) + iconData = zip.read(xmlpath) + with open(iconSavePath, 'w+b') as saveIconFile: + saveIconFile.write(iconData) + return + print("None Icon! Show defult icon") + shutil.copy(ProgramInformation.programPath + "/defult.png", iconSavePath) + except: + traceback.print_exc() + print("Error, show defult icon") + shutil.copy(ProgramInformation.programPath + "/defult.png", iconSavePath) + + def version(self): + info = self.information() + for line in info.split('\n'): + if "package:" in line: + if "compileSdkVersion='" in line: + line = line.replace(line[line.index("compileSdkVersion='"): -1], "") + if "platform" in line: + line = line.replace(line[line.index("platform"): -1], "") + line = line.replace(line[0: line.index("versionName='")], "") + line = line.replace("versionName='", "") + line = line.replace("'", "") + line = line.replace(" ", "") + return line +class UEngine: + def CPUCheck(): + return subprocess.getoutput("uengine check-features") + class Services: + def Open(): + os.system("pkexec systemctl enable uengine-container uengine-session && systemctl start uengine-container uengine-session") + def Close(): + os.system("pkexec systemctl disable uengine-container uengine-session") + def Restart(): + os.system("pkexec systemctl restart uengine*") + + class InternetBridge: + def Open(): + os.system("pkexec uengine-bridge.sh start") + def Close(): + os.system("pkexec uengine-bridge.sh stop") + def Restart(): + os.system("pkexec uengine-bridge.sh restart") + def Reload(): + os.system("pkexec uengine-bridge.sh reload") + def ForceReload(): + os.system("pkexec uengine-bridge.sh force-reload") + +if __name__ == "__main__": + print("本 API 不支持直接运行,请通过引入的方式使用此 API") + apki = APK("/home/gfdgd_xi/下载/com.mihoyo.cloudgames.ys_1.0.0_liqucn.com.apk") + print(apki.packageName()) + quit() + +if not ROOT.GetRoot(): + print("请获取 ROOT 权限以便更好的使用该 API") \ No newline at end of file diff --git a/api/__pycache__/getxmlimg.cpython-37.pyc b/api/__pycache__/getxmlimg.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..79021ab50d040d3e4ab5ae5fd955c94806704893 GIT binary patch literal 3202 zcmai0-ESk+6`wob9@~kN&F&`Ig4|`hl?zEgr~*ZF1uH&;gjR?=AYCC@v%X_z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xTV>bTI=hb5u<=tlf6mqsHOWR* z>S_(L!R=J`F&na?1QY#14%dr74@f;6u;>dBh&U;c_zby7S-oSwG2uuf;@$q|MB!qll7 QH10AQ$`$>kgZDJQ2mHJ!MF0Q* literal 0 HcmV?d00001 diff --git a/uengine-runner-api/getxmlimg.py b/api/getxmlimg.py similarity index 100% rename from uengine-runner-api/getxmlimg.py rename to api/getxmlimg.py diff --git a/uengine-runner-api/__init__.py b/uengine-runner-api/__init__.py deleted file mode 100644 index 226a2c7..0000000 --- a/uengine-runner-api/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -import os -import subprocess -import getxmlimg -# 判断程序以正确方式运行 -class ROOT: - def GetRoot(): - return os.geteuid() == 0 - -class APK: - def __init__(self, apkPath): - self.apkPath = apkPath - - def install(self): - os.system("pkexec /usr/bin/uengine-session-launch-helper -- uengine install --apk='{}'".format(self.apkPath)) - - def information(self): - return subprocess.getoutput("aapt dump badging '{}'".format(self.apkPath)) - -if __name__ == "__main__": - print("本 API 不支持直接运行,请通过引入的方式使用此 API") - quit() -if not ROOT.GetRoot(): - print("请获取 ROOT 权限以便更好的使用该 API") \ No newline at end of file