generated from MaaXYZ/MaaPracticeBoilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.py
102 lines (79 loc) · 2.48 KB
/
install.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
from pathlib import Path
import shutil
import sys
import json
import os
os.system(f"pip install {'pywin32'}")
from win32com.client import Dispatch
from configure import configure_ocr_model
working_dir = Path(__file__).parent
install_path = working_dir / Path("install")
version = len(sys.argv) > 1 and sys.argv[1] or "v0.1.2"
os.system('chcp 65001')
def install_deps():
if not (working_dir / "deps" / "bin").exists():
print("Please download the MaaFramework to \"deps\" first.")
print("请先下载 MaaFramework 到 \"deps\"。")
sys.exit(1)
shutil.copytree(
working_dir / "deps" / "bin",
install_path,
ignore=shutil.ignore_patterns(
"*MaaDbgControlUnit*",
"*MaaThriftControlUnit*",
"*MaaRpc*",
"*MaaHttp*",
),
dirs_exist_ok=True,
)
shutil.copytree(
working_dir / "deps" / "share" / "MaaAgentBinary",
install_path / "MaaAgentBinary",
dirs_exist_ok=True,
)
def install_resource():
configure_ocr_model()
shutil.copytree(
working_dir / "assets" / "resource",
install_path / "resource",
dirs_exist_ok=True,
)
shutil.copy2(
working_dir / "assets" / "interface.json",
install_path,
)
shutil.copytree(
working_dir / "assets" / "python",
install_path / "python",
dirs_exist_ok=True,
)
with open(install_path / "interface.json", "r", encoding="utf-8") as f:
interface = json.load(f)
interface["version"] = version
with open(install_path / "interface.json", "w", encoding="utf-8") as f:
json.dump(interface, f, ensure_ascii=False, indent=4)
def install_chores():
shutil.copy2(
working_dir / "README.md",
install_path,
)
shutil.copy2(
working_dir / "LICENSE",
install_path,
)
def create_shortcut():
target = str(install_path / "python" / "Autofishing.exe")
shortcut_path = str(install_path / "Autofishing.lnk")
icon_path = str(install_path / "python" / "icon.ico")
shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(shortcut_path)
shortcut.Targetpath = target
shortcut.IconLocation = icon_path
shortcut.WorkingDirectory = str(install_path / "python") # 设置起始位置
shortcut.save()
if __name__ == "__main__":
install_deps()
install_resource()
install_chores()
create_shortcut()
print(f"Install to {install_path} successfully.")