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 0000000..79021ab Binary files /dev/null and b/api/__pycache__/getxmlimg.cpython-37.pyc differ 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