deep-wine-runner/AutoConfig.py

203 lines
8.1 KiB
Python
Raw Normal View History

2022-08-25 21:47:42 +08:00
#!/usr/bin/env python3
2022-08-26 14:41:08 +08:00
# 使用系统默认的 python3 运行
###########################################################################################
2023-04-24 21:42:33 +08:00
# 作者gfdgd xi
2022-10-25 21:54:56 +08:00
# 版本2.4.0
# 更新时间2022年10月25日
2022-08-26 14:41:08 +08:00
# 感谢:感谢 wine 以及 deepin-wine 团队,提供了 wine 和 deepin-wine 给大家使用,让我能做这个程序
# 基于 Python3 构建
###########################################################################################
#################
# 引入所需的库
#################
2022-08-24 17:41:30 +08:00
import os
2022-08-25 21:47:42 +08:00
import sys
2022-10-25 21:54:56 +08:00
import base64
2022-08-25 21:47:42 +08:00
import json
import traceback
2023-04-05 16:53:09 +08:00
import updatekiller
2023-01-03 22:33:49 +08:00
import urllib.request
2022-09-24 19:54:08 +08:00
import req as requests
2022-08-25 21:47:42 +08:00
import PyQt5.QtWidgets as QtWidgets
from UI.AutoConfig import *
2022-08-27 02:00:41 +08:00
from Model import *
try:
import PyQt5.QtWebEngineWidgets as QtWebEngineWidgets
webeng = True
except:
print("未安装此依赖库")
webeng = False
2022-08-24 17:41:30 +08:00
2022-11-05 16:54:42 +08:00
urlSourcesList = [
2023-05-08 20:56:48 +08:00
"http://www.gfdgdxi.top/deep-wine-runner-auto-configuration-script/", # Github 源
2022-11-05 16:54:42 +08:00
"https://gitee.com/gfdgd-xi/deep-wine-runner-auto-configuration-script/raw/master/", # Gitee 源
2023-05-08 20:56:48 +08:00
"https://code.gitlink.org.cn/gfdgd_xi/wine-runner-list/raw/branch/master/auto", # Gitlink 源
2022-11-06 17:35:41 +08:00
"http://gfdgdxi.msns.cn/wine-runner-list/auto/", # 备用源1纯 IPv6 源
2023-01-03 13:40:59 +08:00
"http://gfdgdxi.free.idcfengye.com/deep-wine-runner-auto-configuration-script/", # 备用源2
"http://gfdgdxi.free.idcfengye.com/wine-runner-list/auto/", # 备用源 3
2022-11-05 08:50:19 +08:00
"http://127.0.0.1/wine-runner-list/auto/" # 本地测试源
2022-11-05 16:54:42 +08:00
]
urlSources = urlSourcesList[0]
2022-08-25 21:47:42 +08:00
lists = []
2023-01-03 13:40:59 +08:00
2022-10-26 21:50:59 +08:00
2023-01-03 13:40:59 +08:00
all = 0
now = 0
2022-08-24 17:41:30 +08:00
2022-10-24 22:11:03 +08:00
2022-08-25 21:47:42 +08:00
class Connect:
def SearchBotton_Clicked():
nmodel = QtGui.QStandardItemModel(window)
if ui.searchThings.text() == "":
# 显示全部内容
for i in lists:
nmodel.appendRow(QtGui.QStandardItem(i[0]))
ui.searchList.setModel(nmodel)
return
for i in lists:
# 显示筛选的内容
if ui.searchThings.text().upper() in i[0].upper():
2022-08-25 21:47:42 +08:00
nmodel.appendRow(QtGui.QStandardItem(i[0]))
ui.searchList.setModel(nmodel)
2022-08-24 17:41:30 +08:00
2022-08-25 21:47:42 +08:00
def RunBotton_Clicked():
# 获取选中项
try:
choose = ui.searchList.selectionModel().selectedIndexes()[0].data()
except:
QtWidgets.QMessageBox.critical(window, "错误", "您未选择任何配置文件")
return
fileName = ""
for i in lists:
print(i)
if i[0] == choose:
fileName = i[1]
break
# 下载脚本
2022-09-29 21:42:18 +08:00
things = ""
2022-08-25 21:47:42 +08:00
try:
print(f"{urlSources}/{fileName}")
file = open("/tmp/wine-runner-auto-config.wsh", "w")
2022-09-29 21:42:18 +08:00
things = requests.get(f"{urlSources}/{fileName}").text
file.write(things)
2022-08-25 21:47:42 +08:00
file.close()
except:
traceback.print_exc()
QtWidgets.QMessageBox.critical(window, "错误", "无法获取配置文件")
return
2022-09-29 21:42:18 +08:00
# 判断版本以启动对应的解释器
# 做到新旧兼容
2022-10-02 21:59:53 +08:00
if "($" in things:
2022-09-29 21:42:18 +08:00
print("a")
OpenTerminal(f"env WINE='{wine}' WINEPREFIX='{wineprefix}' '{programPath}/ConfigLanguareRunner.py' '/tmp/wine-runner-auto-config.wsh' --system")
2022-08-25 21:47:42 +08:00
# 执行脚本
2022-09-29 21:42:18 +08:00
print(f"env WINE='{wine}' WINEPREFIX='{wineprefix}' '{programPath}/AutoShell/main.py' '/tmp/wine-runner-auto-config.wsh'")
2022-09-29 21:18:15 +08:00
OpenTerminal(f"env WINE='{wine}' WINEPREFIX='{wineprefix}' '{programPath}/AutoShell/main.py' '/tmp/wine-runner-auto-config.wsh'")
2022-08-27 02:00:41 +08:00
#process = QtCore.QProcess()
#process.start(f"{programPath}/launch.sh", ["deepin-terminal", "-e", "env", f"WINE={wine}", f"WINEPREFIX={wineprefix}", f"{programPath}/ConfigLanguareRunner.py", "/tmp/wine-runner-auto-config.wsh", "--system"])
#process.waitForFinished()
2022-08-24 17:41:30 +08:00
2022-08-26 12:11:34 +08:00
def OpenFile_Triggered():
path = QtWidgets.QFileDialog.getOpenFileName(window, "提示", homePath, "配置文件(*.sh *.wsh);;全部文件(*.*)")
if path[0] == "":
return
2022-09-29 21:42:18 +08:00
try:
things = ""
with open(path) as file:
things = file.read()
except:
traceback.print_exc()
# 判断版本以启动对应的解释器
# 做到新旧兼容
2022-10-02 21:59:53 +08:00
if "($" in things:
2022-09-29 21:42:18 +08:00
OpenTerminal(f"env WINE='{wine}' WINEPREFIX='{wineprefix}' '{programPath}/ConfigLanguareRunner.py' '{path[0]}' --system")
2022-08-26 12:11:34 +08:00
# 执行脚本
OpenTerminal(f"env WINEARCH='{os.getenv('WINEARCH')}' WINEDEBUG='{os.getenv('WINEDEBUG')}' WINE='{wine}' WINEPREFIX='{wineprefix}' '{programPath}/AutoShell/main.py' '{path[0]}'")
2022-08-27 02:00:41 +08:00
#process = QtCore.QProcess()
#process.start(f"{programPath}/launch.sh", ["deepin-terminal", "-e", "env", f"WINE={wine}", f"WINEPREFIX={wineprefix}", f"{programPath}/ConfigLanguareRunner.py", path[0], "--system"])
#process.waitForFinished()
2022-08-24 17:41:30 +08:00
2022-08-26 12:11:34 +08:00
# 读取文本文档
def readtxt(path):
f = open(path, "r") # 设置文件对象
str = f.read() # 获取内容
f.close() # 关闭文本对象
return str # 返回结果
2022-08-24 17:41:30 +08:00
2022-11-05 16:54:42 +08:00
def ChangeSources():
global urlSources
2023-05-08 20:56:48 +08:00
sources = [ui.actionGitee, ui.actionGithub, ui.actionGitlink, ui.action_IPv6, ui.action_2, ui.action_3, ui.action]
2022-11-05 16:54:42 +08:00
for i in range(0, len(sources)):
if sources[i].isChecked():
urlSources = urlSourcesList[i]
# 解析云列表
try:
# 获取列表
lists = json.loads(requests.get(f"{urlSources}/list.json").text)
# 解释列表并显示在 GUI 上
nmodel = QtGui.QStandardItemModel(window)
for i in lists:
nmodel.appendRow(QtGui.QStandardItem(i[0]))
ui.searchList.setModel(nmodel)
except:
traceback.print_exc()
QtWidgets.QMessageBox.critical(window, "提示", "无法连接服务器")
break
2022-08-25 21:47:42 +08:00
if __name__ == "__main__":
2022-08-26 12:11:34 +08:00
homePath = os.path.expanduser('~')
2022-08-25 21:47:42 +08:00
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
2022-08-26 12:11:34 +08:00
information = json.loads(readtxt(f"{programPath}/information.json"))
version = information["Version"]
wine = "deepin-wine6-stable"
wineprefix = f"{homePath}/.wine"
try:
wine = sys.argv[1]
wineprefix = sys.argv[2]
except:
pass
2022-08-25 21:47:42 +08:00
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
2023-01-03 13:40:59 +08:00
pinLunLayout = QtWidgets.QHBoxLayout()
2022-08-25 21:47:42 +08:00
ui.setupUi(window)
2022-08-26 12:11:34 +08:00
window.setWindowTitle(f"Wine 运行器 {version}——容器自动配置部署脚本")
2022-09-29 21:42:18 +08:00
window.setWindowIcon(QtGui.QIcon(f"{programPath}/deepin-wine-runner.svg"))
iconPath = "{}/deepin-wine-runner.svg".format(programPath)
2022-08-25 21:47:42 +08:00
window.show()
2022-11-05 16:54:42 +08:00
#ui.actionGitlink.setExclusive(True)
sourcesGroup = QtWidgets.QActionGroup(window)
2023-05-08 20:56:48 +08:00
2022-11-05 16:54:42 +08:00
sourcesGroup.addAction(ui.actionGitee)
sourcesGroup.addAction(ui.actionGithub)
2023-05-08 20:56:48 +08:00
sourcesGroup.addAction(ui.actionGitlink)
sourcesGroup.addAction(ui.action_IPv6)
2022-11-06 17:35:41 +08:00
sourcesGroup.addAction(ui.action_2)
sourcesGroup.addAction(ui.action_3)
2022-11-05 16:54:42 +08:00
sourcesGroup.addAction(ui.action)
sourcesGroup.triggered.connect(ChangeSources)
sourcesGroup.setExclusive(True)
#for i in [ui.actionGitlink, ui.actionGitee, ui.actionGithub, ui.action_IPv6, ui.action]:
#i.triggered.connect(ChangeSources)
#pass
2022-08-25 21:47:42 +08:00
# 连接信号和槽
ui.saerchBotton.clicked.connect(Connect.SearchBotton_Clicked)
2023-01-03 22:33:49 +08:00
#ui.uploadFen.clicked.connect(UploadFen)
2022-08-25 21:47:42 +08:00
ui.runBotton.clicked.connect(Connect.RunBotton_Clicked)
2022-08-26 12:11:34 +08:00
ui.openFile.triggered.connect(Connect.OpenFile_Triggered)
ui.exitProgram.triggered.connect(window.close)
2022-08-25 21:47:42 +08:00
# 解析云列表
try:
# 获取列表
lists = json.loads(requests.get(f"{urlSources}/list.json").text)
# 解释列表并显示在 GUI 上
nmodel = QtGui.QStandardItemModel(window)
for i in lists:
nmodel.appendRow(QtGui.QStandardItem(i[0]))
ui.searchList.setModel(nmodel)
except:
traceback.print_exc()
QtWidgets.QMessageBox.critical(window, "提示", "无法连接服务器")
2022-08-25 21:47:42 +08:00
app.exec_()