-
Notifications
You must be signed in to change notification settings - Fork 42
/
0.py
253 lines (217 loc) · 7.71 KB
/
0.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import os
import re
import sys
import datetime
from time import sleep
import hashlib
import win32gui
import win32con
import win32api
import win32com.client
import requests
# win环境下的快速开发脚本
# 检查localConfig.py是否存在
if not os.path.exists("localConfig.py"):
print("localConfig.py不存在,已自动创建,请配置路径")
with open("localConfig.py", "w", encoding="utf-8") as f:
f.write(
"# main工程路径: \n"
+ "# 例: mainProjectPath = r"
+ r'"C:\Users\DazeCake\Documents\Tools\懒人精灵3.8.3\script\main"'
+ "\n"
+ 'mainProjectPath = r""\n'
+ "# 打包的main.lr路径: \n"
+ "# 例: lrPath = r"
+ r'"C:\Users\DazeCake\Documents\Tools\懒人精灵3.8.3\out\main.lr"'
+ "\n"
+ 'lrPath = r""\n\n'
+ "# 热更新token: \n"
+ 'token = ""\n'
)
exit()
# 检查localConfig.py是否配置
import localConfig as lc
if lc.mainProjectPath == "" or lc.lrPath == "":
print("localConfig.py未配置,请配置路径")
exit()
else:
path = lc.mainProjectPath
pkgPath = lc.lrPath
class WindowMgr:
"""Encapsulates some calls to the winapi for window management"""
def __init__(self):
"""Constructor"""
self._handle = None
def find_window(self, class_name, window_name=None):
"""基于类名来查找窗口"""
self._handle = win32gui.FindWindow(class_name, window_name)
def _window_enum_callback(self, hwnd, class_name_wildcard_list):
"""传递给win32gui.EnumWindows(),检查所有打开的顶级窗口"""
class_name, wildcard = class_name_wildcard_list
if re.match(wildcard, str(win32gui.GetWindowText(hwnd))) is not None:
self._handle = hwnd
def find_window_wildcard(self, class_name, wildcard):
"""根据类名,查找一个顶级窗口,确保其类名相符,且标题可以用正则表达式匹配对应的通配符"""
self._handle = None
win32gui.EnumWindows(self._window_enum_callback, [class_name, wildcard])
return self._handle
def set_foreground(self):
"""put the window in the foreground"""
win32gui.SetForegroundWindow(self._handle)
def get_hwnd(self):
"""return hwnd for further use"""
return self._handle
def run(now=True):
"""自动运行调试 需提前打开任意lua文件"""
myWindowMgr = WindowMgr()
hwnd = myWindowMgr.find_window_wildcard(None, ".*?懒人精灵 - .*?")
if hwnd != None:
win32gui.BringWindowToTop(hwnd)
# 先发送一个alt事件,否则会报错导致后面的设置无效:pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available')
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("%")
# 设置为当前活动窗口
win32gui.SetForegroundWindow(hwnd)
# 最大化窗口
# win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
# F6
win32api.keybd_event(117, win32api.MapVirtualKey(117, 0), 0, 0)
win32api.keybd_event(
117, win32api.MapVirtualKey(117, 0), win32con.KEYEVENTF_KEYUP, 0
)
sleep(0.1)
# F5
if now:
win32api.keybd_event(116, win32api.MapVirtualKey(116, 0), 0, 0)
win32api.keybd_event(
116, win32api.MapVirtualKey(116, 0), win32con.KEYEVENTF_KEYUP, 0
)
def save():
"""保存到懒人精灵工程文件夹"""
with open("main.lua", "r", encoding="utf-8") as f:
lines = f.readlines()
ss = ""
for line in lines:
if re.match('release_date = ".*"', line):
line = (
'release_date = "'
+ str(datetime.datetime.now().strftime("%m.%d %H:%M"))
+ '"\n'
)
ss += line
with open("main.lua", "w", encoding="utf-8") as f:
f.write(ss)
# 获取当前目录下所有的.lua文件
lua_files = [f for f in os.listdir(".") if f.endswith(".lua")]
for lua_file in lua_files:
# 把lua_file以utf-8的格式打开,然后以GB18030的格式写入到"D:\ArkLights\main\脚本"目录下
with open(lua_file, "r", encoding="utf-8") as f:
with open(
os.path.join(path, "脚本", lua_file), "w", encoding="GB18030"
) as f1:
f1.write(f.read())
# 获取当前目录下所有的.ui文件
ui_files = [f for f in os.listdir(".") if f.endswith(".ui")]
for ui_file in ui_files:
# 把ui_file以utf-8的格式打开,然后以GB18030的格式写入到path+界面目录下
with open(ui_file, "r", encoding="utf-8") as f:
with open(os.path.join(path, "界面", ui_file), "w", encoding="GB18030") as f1:
f1.write(f.read())
print("保存完成")
def saverun():
"""保存并运行"""
save()
run()
def release(type):
if type == "RELEASE":
save()
run(False)
newLrMD5 = input("请输入md5值: ")
# 输出pkgPath的文件的md5
md5 = hashlib.md5()
with open(pkgPath, "rb") as f:
md5.update(f.read())
md5Text = md5.hexdigest()
# 判断输入值是否与md5Text相等
if newLrMD5 == md5Text:
print("md5值正确")
# 上传
upload(md5Text, type, "false")
else:
print("md5值错误")
elif type == "SKILL":
upload("", type, "false")
def upload(md5, type, force):
token = lc.token
if token == "":
print("token未配置,请配置token")
exit()
upFile = ""
if type == "RELEASE":
upFile = pkgPath
elif type == "SKILL":
upFile = r"res\skill.zip"
md5 = hashlib.md5()
with open(upFile, "rb") as f:
md5.update(f.read())
md5Text = md5.hexdigest()
url = (
"http://ark.aegirtech.com:8080/uploadHotUpdatePackage?token="
+ token
+ "&md5="
+ md5Text
+ "&type="
+ type
+ "&force="
+ force
)
fileName = ""
if type == "RELEASE":
fileName = "script.lr"
elif type == "SKILL":
fileName = "skill.zip"
payload = {}
files = [("fille", (fileName, open(upFile, "rb"), "application/octet-stream"))]
headers = {"User-Agent": "Apifox/1.0.0 (https://apifox.com)"}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.json().get("msg"))
def statistician():
token = lc.token
if token == "":
print("token未配置,请配置token")
exit()
url = "http://ark.aegirtech.com:8080/getStatistician?token=" + token
response = requests.request("GET", url)
info = response.json()["data"]
print("============统计信息============")
print("24h下载量: \t" + str(info["downloadCount"]))
print("终端数量: \t" + str(info["alCount"]))
print("账号数量: \t" + str(info["accountCount"]))
print("活跃终端数量: \t" + str(info["activeAlCount"]))
print("活跃账号数量: \t" + str(info["activeAccountCount"]))
if __name__ == "__main__":
try:
arg = sys.argv[1]
if arg == "run":
run()
elif arg == "save":
save()
elif arg == "saverun":
saverun()
elif arg == "r":
release("RELEASE")
elif arg == "rs":
release("SKILL")
elif arg == "s":
statistician()
except Exception as e:
print("缺少正确参数或没有启用管理员权限")
print(
"""
run: 运行
save: 保存
saverun: 保存并运行
r: 发布脚本
rs: 发布技能图标
"""
)