添加函数(包括打包deb的函数)
This commit is contained in:
parent
7f36a1ff3c
commit
c77bbceeb2
|
@ -4,14 +4,16 @@
|
|||
2. 部分函数需要 root 权限
|
||||
3. 这是 UEngine 运行器的函数重构,所以一些 UEngine 运行器上没有的 bug 可能在这个 API 里有
|
||||
## ProgramInformation
|
||||
用于获取一些程序信息,详细如下(此为变量):
|
||||
| 变量名 | 变量介绍 |
|
||||
用于获取一些程序信息,详细如下(未特殊表明的是变量,否则是函数):
|
||||
| 变量/函数名 | 变量/函数介绍 |
|
||||
|:-:|:-:|
|
||||
| programPath | 获取程序所在路径 |
|
||||
| version | API 版本 |
|
||||
| updateTime | 更新时间 |
|
||||
| websize | 程序官网 |
|
||||
| home | 用户 home(用户文件)目录 |
|
||||
| developer | 参与的开发者列表 |
|
||||
| DesktopPath() | (函数)用户桌面目录 |
|
||||
|
||||
## Check
|
||||
用于检查 API 所需的东西是否完整,详细如下:
|
||||
|
@ -34,8 +36,8 @@ xxx = api.APK("APK 所在路径")
|
|||
具体函数介绍:
|
||||
| 函数名 | 函数介绍 |
|
||||
|:-:|:-:|
|
||||
| xxx.install() | 安装这个 APK 包 |
|
||||
| xxx.uninstall()| 卸载这个 APK 包 |
|
||||
| xxx.install() | 安装这个 APK 包(需要 Root) |
|
||||
| xxx.uninstall()| 卸载这个 APK 包(需要 Root) |
|
||||
| xxx.information()| 获取从 aapt 获取到的 APK 信息 |
|
||||
| xxx.activityName() | 获取 APK 的 Activity 信息 |
|
||||
| xxx.packageName() | 获取 APK 包名 |
|
||||
|
@ -43,31 +45,36 @@ xxx = api.APK("APK 所在路径")
|
|||
| xxx.saveApkIcon("图标保存路径") | 保存 APK 的图标到指定路径 |
|
||||
| xxx.version() | 获取 APK 版本号 |
|
||||
| xxx.saveDesktopFile("图标保存路径", "快捷方式保存路径") | 保存支持 UEngine 启动的 APK 快捷方式 |
|
||||
| xxx.run() | 运行该应用(需要保证已经安装) |
|
||||
| xxx.buildDeb("deb 包保存路径", qianZhui) | 打包为 deb 包(“qianZhui”是布尔值,True代表有前缀为“uengine-dc”,False代表没有前缀) |
|
||||
|
||||
## UEngine
|
||||
用于对 UEngine 进行一点点操控,详细如下:
|
||||
| 函数名 | 函数介绍 |
|
||||
|:-:|:-:|
|
||||
| RemoveUengineCheck() | 删除 UEngine 的检查脚本 |
|
||||
| UengineAppManager() | 显示 UEngine 安装应用程序管理器 |
|
||||
| OpenApp("应用包名", "应用Activity") | 运行指定的应用(需要保证程序已经安装) |
|
||||
| UengineDataClean() | 清空 UEngine 数据(需要 Root) |
|
||||
| RemoveUengineCheck() | 删除 UEngine 的检查脚本(需要 Root) |
|
||||
| CPUCheck() | 检查 CPU 是否支持运行 UEngine |
|
||||
| Services | 用于操控 UEngine 服务的类,见下 |
|
||||
| InternetBridge | 用于操控 UEngine 网络桥接的类,见下 |
|
||||
| Services | 用于操控 UEngine 服务的类,见下(需要 Root) |
|
||||
| InternetBridge | 用于操控 UEngine 网络桥接的类,见下(需要 Root) |
|
||||
### Services
|
||||
关于 UEngine 的服务控制:
|
||||
| 函数名 | 函数介绍 |
|
||||
|:-:|:-:|
|
||||
| Services.Open() | 打开 UEngine 服务 |
|
||||
| Services.Close() | 关闭 UEngine 服务 |
|
||||
| Services.Restart() | 重启 UEngine 服务 |
|
||||
| Services.Open() | 打开 UEngine 服务(需要 Root) |
|
||||
| Services.Close() | 关闭 UEngine 服务(需要 Root) |
|
||||
| Services.Restart() | 重启 UEngine 服务(需要 Root) |
|
||||
### InternetBridge
|
||||
关于 UEngine 的网络桥接控制:
|
||||
| 函数名 | 函数介绍 |
|
||||
|:-:|:-:|
|
||||
| InternetBridge.Open() | 打开 UEngine 网络桥接 |
|
||||
| InternetBridge.Close() | 关闭 UEngine 网络桥接 |
|
||||
| InternetBridge.Restart() | 重启 UEngine 网络桥接 |
|
||||
| InternetBridge.Reload() | 重新加载 UEngine 网络桥接 |
|
||||
| InternetBridge.ForceReload() | 强制加载 UEngine 网络桥接 |
|
||||
| InternetBridge.Open() | 打开 UEngine 网络桥接(需要 Root) |
|
||||
| InternetBridge.Close() | 关闭 UEngine 网络桥接(需要 Root) |
|
||||
| InternetBridge.Restart() | 重启 UEngine 网络桥接(需要 Root) |
|
||||
| InternetBridge.Reload() | 重新加载 UEngine 网络桥接(需要 Root) |
|
||||
| InternetBridge.ForceReload() | 强制加载 UEngine 网络桥接(需要 Root) |
|
||||
## Adb
|
||||
用于对 Adb 的部分操控
|
||||
| 函数名 | 函数介绍 |
|
||||
|
|
184
api/__init__.py
184
api/__init__.py
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import random
|
||||
import shutil
|
||||
import zipfile
|
||||
import traceback
|
||||
|
@ -7,10 +8,25 @@ from getxmlimg import getsavexml
|
|||
|
||||
class ProgramInformation:
|
||||
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
|
||||
version = "1.6.0Alpha1"
|
||||
updateTime = "2022年05月15日"
|
||||
version = "1.6.0Alpha2"
|
||||
updateTime = "2022年05月21日"
|
||||
websize = ["https://gitee.com/gfdgd-xi/uengine-runner", "https://github.com/gfdgd-xi/uengine-runner"]
|
||||
home = os.path.expanduser('~')
|
||||
developer = ["gfdgd xi", "为什么您不喜欢熊出没和阿布呢"]
|
||||
# 获取用户桌面目录
|
||||
def DesktopPath() -> "获取用户桌面目录":
|
||||
for line in open(get_home() + "/.config/user-dirs.dirs"): # 以行来读取配置文件
|
||||
desktop_index = line.find("XDG_DESKTOP_DIR=\"") # 寻找是否有对应项,有返回 0,没有返回 -1
|
||||
if desktop_index != -1: # 如果有对应项
|
||||
break # 结束循环
|
||||
if desktop_index == -1: # 如果是提前结束,值一定≠-1,如果是没有提前结束,值一定=-1
|
||||
return -1
|
||||
else:
|
||||
get = line[17:-2] # 截取桌面目录路径
|
||||
get_index = get.find("$HOME") # 寻找是否有对应的项,需要替换内容
|
||||
if get != -1: # 如果有
|
||||
get = get.replace("$HOME", get_home()) # 则把其替换为用户目录(~)
|
||||
return get # 返回目录
|
||||
|
||||
# 判断程序以正确方式运行
|
||||
class Check:
|
||||
|
@ -27,16 +43,12 @@ class ROOT:
|
|||
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))
|
||||
|
||||
os.system("pkexec /usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg='{}'".format(self.packageName()))
|
||||
def information(self):
|
||||
return subprocess.getoutput("aapt dump badging '{}'".format(self.apkPath))
|
||||
|
||||
def activityName(self):
|
||||
info = self.information()
|
||||
for line in info.split('\n'):
|
||||
|
@ -49,7 +61,6 @@ class APK:
|
|||
line = line.replace("label=", "")
|
||||
line = line.replace("icon=", "")
|
||||
return line
|
||||
|
||||
# 获取 apk 包名
|
||||
def packageName(self):
|
||||
info = self.information()
|
||||
|
@ -61,7 +72,6 @@ class APK:
|
|||
line = line.replace("'", "")
|
||||
line = line.replace(" ", "")
|
||||
return line
|
||||
|
||||
# 获取软件的中文名称
|
||||
def chineseLabel(self) -> "获取软件的中文名称":
|
||||
info = self.information()
|
||||
|
@ -70,7 +80,6 @@ class APK:
|
|||
line = line.replace("application-label:", "")
|
||||
line = line.replace("'", "")
|
||||
return line
|
||||
|
||||
# 保存apk图标
|
||||
def saveApkIcon(self, iconSavePath) -> "保存 apk 文件的图标":
|
||||
try:
|
||||
|
@ -97,7 +106,6 @@ class APK:
|
|||
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'):
|
||||
|
@ -111,7 +119,6 @@ class APK:
|
|||
line = line.replace("'", "")
|
||||
line = line.replace(" ", "")
|
||||
return line
|
||||
|
||||
def saveDesktopFile(self, desktopPath, iconPath):
|
||||
showName = self.chineseLabel()
|
||||
if showName == "" or showName == None:
|
||||
|
@ -130,8 +137,154 @@ class APK:
|
|||
Type=Application
|
||||
'''.format(self.packageName(), self.activityName(), showName, iconPath, showName, showName)
|
||||
File(desktopPath).write(things)
|
||||
def run(self):
|
||||
UEngine.OpenApp(self.packageName(), self.activityName())
|
||||
|
||||
def buildDeb(self, savePath, qianZhui = True):
|
||||
tempPath = "/tmp/uengine-apk-builder-{}".format(int(random.randint(0, 1024)))
|
||||
#RunCommandShow("echo '======================================New===================================='")
|
||||
#RunCommandShow("echo '创建目录'")
|
||||
os.makedirs("{}/DEBIAN".format(tempPath))
|
||||
os.makedirs("{}/usr/share/applications".format(tempPath))
|
||||
os.makedirs("{}/usr/share/uengine/apk".format(tempPath))
|
||||
os.makedirs("{}/usr/share/uengine/icons".format(tempPath))
|
||||
apkPackageName = self.packageName()
|
||||
if qianZhui:
|
||||
apkPackageNameNew = "uengine-dc-" + self.packageName().lower()
|
||||
else:
|
||||
apkPackageNameNew = self.packageName().lower()
|
||||
apkPackageVersion = self.version()
|
||||
if apkPackageVersion[0].upper() == "V":
|
||||
package = list(apkPackageVersion)
|
||||
package.pop(0)
|
||||
apkPackageVersion = "".join(package)
|
||||
apkChineseLabel = self.chineseLabel()
|
||||
apkActivityName = self.activityName()
|
||||
iconSavePath = "{}/usr/share/uengine/icons/{}.png".format(tempPath, apkPackageNameNew)
|
||||
debControl = '''Package: {}
|
||||
Version: {}
|
||||
Architecture: all
|
||||
Maintainer: {}
|
||||
Depends: deepin-elf-verify (>= 0.0.16.7-1), uengine (>= 1.0.1)
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Description: {}\n'''.format(apkPackageNameNew, apkPackageVersion, apkChineseLabel, apkChineseLabel)
|
||||
debPostinst = '''#!/bin/sh
|
||||
|
||||
APK_DIR="/usr/share/uengine/apk"
|
||||
APK_NAME="{}"
|
||||
APK_PATH="$APK_DIR/$APK_NAME"
|
||||
DESKTOP_FILE="{}"
|
||||
|
||||
|
||||
if [ -f $APK_PATH ]; then
|
||||
echo "Installing $APK_NAME"
|
||||
else
|
||||
echo "ERROR: $APK_NAME does not exist."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
session_manager=`ps -ef | grep "uengine session-manager" | grep -v grep`
|
||||
if test -z "$session_manager"; then
|
||||
echo "ERROR: app install failed(session-manager is not running)."
|
||||
sess_dir="/usr/share/uengine/session_install"
|
||||
if [ ! -d $sess_dir ]; then
|
||||
mkdir $sess_dir
|
||||
chmod 777 $sess_dir
|
||||
fi
|
||||
apk_name=${{APK_PATH##*/}}
|
||||
fileName="$sess_dir/$apk_name"
|
||||
echo $DESKTOP_FILE > $fileName
|
||||
abistr=""
|
||||
if test -n "$abistr"; then
|
||||
abi=`echo $abistr |awk -F \= '{{print $2}}'`
|
||||
echo $abi >> $fileName
|
||||
fi
|
||||
chmod 766 $fileName
|
||||
fi
|
||||
|
||||
/usr/bin/uengine-session-launch-helper -- uengine install --apk="$APK_PATH"
|
||||
|
||||
exit 0'''.format(apkPackageNameNew + ".apk", "/usr/share/applications/{}.desktop".format(apkPackageNameNew))
|
||||
debPrerm = '''#!/bin/sh
|
||||
|
||||
APP_NAME="{}"
|
||||
DESKTOP_FILE="{}"
|
||||
|
||||
session_manager=`ps -ef | grep "uengine session-manager" | grep -v grep`
|
||||
if test -z "$session_manager"; then
|
||||
echo "ERROR: app uninstall failed(session-manager is not running)."
|
||||
sess_dir="/usr/share/uengine/session_uninstall"
|
||||
if [ ! -d $sess_dir ]; then
|
||||
mkdir $sess_dir
|
||||
chmod 777 $sess_dir
|
||||
fi
|
||||
fileName="$sess_dir/$APP_NAME"
|
||||
echo $DESKTOP_FILE > $fileName
|
||||
chmod 766 $fileName
|
||||
fi
|
||||
|
||||
echo "Uninstalling $APP_NAME"
|
||||
/usr/bin/uengine-session-launch-helper -- uengine uninstall --pkg="$APP_NAME"
|
||||
|
||||
exit 0'''.format(apkPackageName, "/usr/share/applications/{}.desktop".format(apkPackageNameNew))
|
||||
desktopFile = '''[Desktop Entry]
|
||||
Categories=Other;
|
||||
Exec=uengine launch --action=android.intent.action.MAIN --package={} --component={}
|
||||
Icon=/usr/share/uengine/icons/{}.png
|
||||
Terminal=false
|
||||
Type=Application
|
||||
GenericName={}
|
||||
Name={}
|
||||
'''
|
||||
# RunCommandShow("echo '{}' > '{}/DEBIAN/control'".format(debControl, tempPath))
|
||||
#RunCommandShow("echo 正在写入文件:'{}/DEBIAN/control'".format(tempPath))
|
||||
File("{}/DEBIAN/control".format(tempPath)).write(debControl)
|
||||
#RunCommandShow("echo 正在写入文件:'{}/DEBIAN/postinst'".format(tempPath))
|
||||
File("{}/DEBIAN/postinst".format(tempPath)).write(debPostinst)
|
||||
#RunCommandShow("echo 正在写入文件:'{}/DEBIAN/prerm'".format(tempPath))
|
||||
File("{}/DEBIAN/prerm".format(tempPath)).write(debPrerm)
|
||||
#RunCommandShow("echo 正在写入文件:'/usr/share/applications/{}.desktop'".format(apkPackageNameNew))
|
||||
# write_txt("{}/usr/share/applications/{}.desktop".format(tempPath, apkPackageNameNew), desktopFile)
|
||||
self.saveDesktopFile("{}/usr/share/applications/{}.desktop".format(tempPath, apkPackageNameNew),
|
||||
"{}/usr/share/uengine/icons/{}.png".format(tempPath, apkPackageNameNew))
|
||||
#BuildUengineDesktop(apkPackageName, apkActivityName, apkChineseLabel,
|
||||
# "/usr/share/uengine/icons/{}.png".format(apkPackageNameNew),
|
||||
# "{}/usr/share/applications/{}.desktop".format(tempPath, apkPackageNameNew))
|
||||
#RunCommandShow("echo '复制文件'")
|
||||
#RunCommandShow("echo '写入 APK 软件图标'")
|
||||
#SaveApkIcon(apkPath, iconSavePath)
|
||||
self.saveApkIcon(iconSavePath)
|
||||
#RunCommandShow("echo '复制 APK 文件'")
|
||||
shutil.copy(self.apkPath, "{}/usr/share/uengine/apk/{}.apk".format(tempPath, apkPackageNameNew))
|
||||
#RunCommandShow("cp -rv '{}' '{}/usr/share/uengine/apk/{}.apk'".format(apkPath, tempPath, apkPackageNameNew))
|
||||
#RunCommandShow("echo '正在设置文件权限……'")
|
||||
os.system("chmod 0775 -vR '{}/DEBIAN/postinst'".format(tempPath))
|
||||
os.system("chmod 0775 -vR '{}/DEBIAN/prerm'".format(tempPath))
|
||||
#RunCommandShow("echo '打包 deb 到桌面……'")
|
||||
os.system(
|
||||
"dpkg -b '{}' '{}'".format(tempPath, savePath))
|
||||
#RunCommandShow("echo '正在删除临时目录……'")
|
||||
#shutil.rmtree(tempPath)
|
||||
#RunCommandShow("rm -rfv '{}'".format(tempPath))
|
||||
#RunCommandShow("echo '完成!'")
|
||||
#findApkHistory.append(apkPath)
|
||||
#combobox1['value'] = findApkHistory
|
||||
#write_txt(get_home() + "/.config/uengine-runner/FindApkBuildHistory.json",
|
||||
# str(json.dumps(ListToDictionary(findApkHistory)))) # 将历史记录的数组转换为字典并写入
|
||||
#messagebox.showinfo(title="提示", message="打包完成")
|
||||
#DisabledAndEnbled(False)
|
||||
|
||||
|
||||
class UEngine:
|
||||
def UengineAppManager():
|
||||
os.system("uengine launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity")
|
||||
def OpenApp(appPackage, appActivity):
|
||||
os.system("uengine launch --package={} --component={}".format(appPackage, appActivity))
|
||||
# 清空 uengine 数据
|
||||
def UengineDataClean() -> "清空 uengine 数据":
|
||||
shutil.rmtree("{}/.local/share/applications/uengine/".format(ProgramInformation.home))
|
||||
shutil.rmtree("/data/uengine")
|
||||
def RemoveUengineCheck():
|
||||
os.remove("/usr/share/uengine/uengine-check-runnable.sh")
|
||||
def CPUCheck():
|
||||
|
@ -186,8 +339,13 @@ class File:
|
|||
|
||||
if __name__ == "__main__":
|
||||
print("本 API 不支持直接运行,请通过引入的方式使用此 API")
|
||||
apki = APK("/home/gfdgd_xi/下载/com.mihoyo.cloudgames.ys_1.0.0_liqucn.com.apk")
|
||||
apki = APK("/home/gfdgd_xi/下载/60D3B51B76CCAC313B3F0809FD1A64FD.apk")
|
||||
print(apki.packageName())
|
||||
print(apki.chineseLabel())
|
||||
#print(apki.install())
|
||||
#apki.run()
|
||||
#apki.buildDeb("/home/gfdgd_xi/下载/好奇时间.deb")
|
||||
apki.uninstall()
|
||||
quit()
|
||||
|
||||
if not ROOT.GetRoot():
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
4
main.py
4
main.py
|
@ -3,10 +3,10 @@
|
|||
###########################################################################################
|
||||
# 作者:gfdgd xi<3025613752@qq.com>
|
||||
# 版本:1.6.1
|
||||
# 更新时间:2022年2月6日(要开学了)
|
||||
# 更新时间:2022年5月21日(要开学了)
|
||||
# 感谢:anbox、deepin 和 UOS
|
||||
# 基于 Python3 的 tkinter 构建
|
||||
# 更新:gfdgd xi<3025613752@qq.com>、actionchen<917981399@qq.com>
|
||||
# 更新:gfdgd xi<3025613752@qq.com>、actionchen<917981399@qq.com>、为什么您不喜欢熊出没和阿布呢
|
||||
###########################################################################################
|
||||
#################
|
||||
# 引入所需的库
|
||||
|
|
Loading…
Reference in New Issue