uengine-runner/uengine-useadb

72 lines
2.6 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
#########################################
# 版本1.8.0
# 更新时间2022年07月23日
#########################################
import os
import sys
import traceback
import PyQt5.QtWidgets as QtWidgets
########################
#
########################
# 写入文本文档
def write_txt(path: "路径", things: "内容")->"写入文本文档":
file = open(path, 'w', encoding='UTF-8') # 设置文件对象
file.write(things) # 写入文本
file.close() # 关闭文本对象
# 读取文本文档
def readtxt(path: "路径")->"读取文本文档":
f = open(path, "r") # 设置文件对象
str = f.read() # 获取内容
f.close() # 关闭文本对象
return str # 返回结果
###################
# 判断是不是 root
###################
app = QtWidgets.QApplication(sys.argv)
if os.geteuid() != 0:
print("不是以 root 权限运行本程序!")
QtWidgets.QMessageBox.critical(None, "错误", "不是以 root 权限运行本程序!")
sys.exit(1)
###################
#
###################
try:
if sys.argv[1] == "1" and QtWidgets.QMessageBox.question(None, "提示", "你确定要删除吗?", QtWidgets.QMessageBox.Ok, QtWidgets.QMessageBox.Cancel) == QtWidgets.QMessageBox.Ok:
os.remove("/data/uengine/data/data/misc/adb/adb_keys")
QtWidgets.QMessageBox.information(None, "提示", "完成")
except:
traceback.print_exc()
QtWidgets.QMessageBox.critical(None, "错误", traceback.format_exc())
sys.exit(2)
if sys.argv[1] == "1":
sys.exit(0)
if QtWidgets.QMessageBox.question(None, "提示", '''请阅读以下提示然后确定是否继续:
1、安装后即可使用 adb 连接 UEngine;
2、重置 UEngine 或 adb 就需要重新设置该支持补丁;
3、需要 root 权限;''') == QtWidgets.QMessageBox.No:
sys.exit(0)
# 写入(需要 root
if not os.path.exists("/data/uengine/data/data/misc/adb"):
QtWidgets.QMessageBox.critical(None, "错误", "无法读取 UEngine 数据!")
sys.exit(1)
try:
things = readtxt(sys.argv[2])
adbKey = []
# 提取内容
for i in things.split('\n'):
adbKey.append(i[0: i.find(" ")])
old = ""
if os.path.exists("/data/uengine/data/data/misc/adb/adb_keys"):
old = readtxt("/data/uengine/data/data/misc/adb/adb_keys") + "\n"
write_txt("/data/uengine/data/data/misc/adb/adb_keys", old + "\n".join(adbKey))
QtWidgets.QMessageBox.information(None, "提示", "完成")
except:
traceback.print_exc()
QtWidgets.QMessageBox.information(None, "错误", traceback.format_exc())
sys.exit(2)