-
Notifications
You must be signed in to change notification settings - Fork 15
/
InstallMono.py
executable file
·130 lines (122 loc) · 5.57 KB
/
InstallMono.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
# 使用系统默认的 python3 运行
###########################################################################################
# 作者:gfdgd xi
# 版本:2.1.0
# 更新时间:2022年08月25日
# 感谢:感谢 wine 以及 deepin-wine 团队,提供了 wine 和 deepin-wine 给大家使用,让我能做这个程序
# 基于 Python3 构建
###########################################################################################
#################
# 引入所需的库
#################
import os
import sys
import updatekiller
import traceback
try:
import pyquery
except:
os.system("python3 -m pip install --upgrade pyquery --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple --break-system-packages")
if "--help" in sys.argv:
print("作者:gfdgd xi")
print("版本:1.0.0")
print("本程序可以更方便的在 wine 容器中安装 mono、gecko")
sys.exit()
if len(sys.argv) <= 3 or sys.argv[1] == "" or sys.argv[2] == "" or sys.argv[3] == "":
print("您未指定需要安装 gecko 或者 mono 的容器和使用的 wine,无法继续")
print("参数:")
print("XXX 参数一 参数二 参数三 参数四(可略)")
print("参数一为需要安装的容器,参数二为需要使用的wine,参数三为安装gecko或mono(gecko/mono),参数四为是否缓存(可略),四个参数位置不能颠倒")
sys.exit()
if sys.argv[3] == "mono":
print('''
m m
## ## mmm m mm mmm
# ## # #" "# #" # #" "#
# "" # # # # # # #
# # "#m#" # # "#m#"
''')
else:
print('''
mmm #
m" " mmm mmm # m mmm
# mm #" # #" " # m" #" "#
# # #"""" # #"# # #
"mmm" "#mm" "#mm" # "m "#m#"
''')
homePath = os.path.expanduser('~')
try:
exitInputShow = int(os.getenv("ENTERNOTSHOW"))
except:
exitInputShow = True
try:
# 获取最新版本的版本号
programVersionList = pyquery.PyQuery(url=f"http://mirrors.ustc.edu.cn/wine/wine/wine-{sys.argv[3]}/")
except:
print("无法连接下载服务器,将使用本地缓存")
if not os.path.exists(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi") or not os.path.exists(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/information.txt"):
print("无本地缓存数据,无法进行、结束")
if exitInputShow:
input("按回车键退出")
exit()
file = open(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/information.txt", "r")
version = file.read().replace("\n", "")
print("安装版本:", version)
os.system(f"WINEPREFIX='{sys.argv[1]}' {sys.argv[2]} msiexec /i \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi\"")
if exitInputShow:
input("安装结束,按回车键退出")
exit()
programVersion = programVersionList("a:last-child").attr.href
# 获取最新版本安装包的URL
programUrl = pyquery.PyQuery(url=f"http://mirrors.ustc.edu.cn/wine/wine/wine-{sys.argv[3]}/{programVersion}")
programDownloadUrl = ""
programFileName = ""
for i in programUrl("a").items():
if i.attr.href[-4:] == ".msi":
programDownloadUrl = f"http://mirrors.ustc.edu.cn/wine/wine/wine-{sys.argv[3]}/{programVersion}{i.attr.href}"
programFileName = i.attr.href
break
if programDownloadUrl == "":
print("无法获取链接,无法继续")
sys.exit()
print(f"当前选择的程序获取路径:{programDownloadUrl}")
if not os.path.exists(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}"):
os.makedirs(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}")
if len(sys.argv) <= 4:
choice = True
else:
choice = (sys.argv[3] == "1")
if os.path.exists(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi") and os.path.exists(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/information.txt") and choice:
print("版本号校验")
file = open(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/information.txt", "r")
version = file.read().replace("\n", "")
if version == programVersion.replace("\n", ""):
print("缓存版本:", version.replace("/", ""))
print("已经缓存,使用本地版本")
file.close()
os.system(f"WINEPREFIX='{sys.argv[1]}' {sys.argv[2]} msiexec /i \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi\"")
if exitInputShow:
input("安装结束,按回车键退出")
exit()
file = open(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/information.txt", "w+")
print("开始下载")
os.system(f"rm -rf \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi\"")
os.system("mkdir -p /tmp/winegeckomonoinstall")
os.system(f"aria2c -x 16 -s 16 -d \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}\" -o install.msi \"{programDownloadUrl}\"")
print("开始安装")
os.system(f"WINEPREFIX='{sys.argv[1]}' {sys.argv[2]} msiexec /i \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi\"")
try:
if sys.argv[4] == "1":
print("写入缓存")
file.write(programVersion)
file.close()
else:
print("删除临时文件")
os.system(f"rm -rf \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}\"")
except:
print("写入缓存")
file.write(programVersion)
file.close()
if exitInputShow:
input("安装结束,按回车键退出")