deep-wine-runner/InstallMono.py

126 lines
5.5 KiB
Python
Raw Normal View History

2022-07-04 22:44:04 +08:00
#!/usr/bin/env python3
# 使用系统默认的 python3 运行
###########################################################################################
# 作者gfdgd xi、为什么您不喜欢熊出没和阿布呢
2022-08-25 21:47:42 +08:00
# 版本2.1.0
# 更新时间2022年08月25日
2022-07-04 22:44:04 +08:00
# 感谢:感谢 wine 以及 deepin-wine 团队,提供了 wine 和 deepin-wine 给大家使用,让我能做这个程序
2022-08-01 16:11:46 +08:00
# 基于 Python3 构建
2022-07-04 22:44:04 +08:00
###########################################################################################
#################
# 引入所需的库
#################
import os
import sys
2022-08-24 17:41:30 +08:00
import traceback
2022-07-04 22:44:04 +08:00
import pyquery
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("参数:")
2022-08-08 15:49:59 +08:00
print("XXX 参数一 参数二 参数三 参数四(可略)")
print("参数一为需要安装的容器参数二为需要使用的wine参数三为安装gecko或monogecko/mono参数四为是否缓存可略四个参数位置不能颠倒")
2022-07-04 22:44:04 +08:00
sys.exit()
2022-08-08 15:49:59 +08:00
2022-08-20 13:35:31 +08:00
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#"
''')
2022-08-08 15:49:59 +08:00
homePath = os.path.expanduser('~')
2022-08-24 17:41:30 +08:00
try:
exitInputShow = int(os.getenv("ENTERNOTSHOW"))
except:
exitInputShow = True
2022-08-08 15:49:59 +08:00
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("无本地缓存数据,无法进行、结束")
2022-08-24 17:41:30 +08:00
if exitInputShow:
input("按回车键退出")
2022-08-08 15:49:59 +08:00
exit()
file = open(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/information.txt", "r")
version = file.read().replace("\n", "")
print("安装版本:", version)
2022-08-25 21:47:42 +08:00
os.system(f"WINEPREFIX='{sys.argv[1]}' '{sys.argv[2]}' msiexec /i \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi\"")
2022-08-24 17:41:30 +08:00
if exitInputShow:
input("安装结束,按回车键退出")
2022-08-08 15:49:59 +08:00
exit()
2022-07-04 22:44:04 +08:00
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}")
2022-08-08 15:49:59 +08:00
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()
2022-08-25 21:47:42 +08:00
os.system(f"WINEPREFIX='{sys.argv[1]}' '{sys.argv[2]}' msiexec /i \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi\"")
2022-08-24 17:41:30 +08:00
if exitInputShow:
input("安装结束,按回车键退出")
2022-08-08 15:49:59 +08:00
exit()
file = open(f"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/information.txt", "w+")
2022-07-04 22:44:04 +08:00
print("开始下载")
2022-08-08 15:49:59 +08:00
os.system(f"rm -rf \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi\"")
2022-07-04 22:44:04 +08:00
os.system("mkdir -p /tmp/winegeckomonoinstall")
2022-08-08 15:49:59 +08:00
os.system(f"aria2c -x 16 -s 16 -d \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}\" -o install.msi \"{programDownloadUrl}\"")
2022-07-04 22:44:04 +08:00
print("开始安装")
2022-08-25 21:47:42 +08:00
os.system(f"WINEPREFIX='{sys.argv[1]}' '{sys.argv[2]}' msiexec /i \"{homePath}/.cache/deepin-wine-runner/{sys.argv[3]}/install.msi\"")
2022-08-08 15:49:59 +08:00
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()
2022-08-24 17:41:30 +08:00
if exitInputShow:
input("安装结束,按回车键退出")