Skip to content

Commit

Permalink
优化MAA设置逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
DLmaster361 committed Oct 8, 2024
1 parent 732129b commit c71389f
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 52 deletions.
198 changes: 162 additions & 36 deletions AUTO_MAA.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
QWidget,
QApplication,
QInputDialog,
QFileDialog,
QMessageBox,
QLineEdit,
QTableWidget,
Expand Down Expand Up @@ -352,39 +353,79 @@ def run(self):
if not "未通过人工排查" in self.data[uid][11]:
self.data[uid][11] = "未通过人工排查|" + self.data[uid][11]
error_uid.append(uid)
if not self.if_run:
os.system("taskkill /F /T /PID " + str(maa.pid))
# 更新用户数据
days = [self.data[_][2] for _ in all_uid]
lasts = [self.data[_][4] for _ in all_uid]
notes = [self.data[_][11] for _ in all_uid]
numbs = [self.data[_][12] for _ in all_uid]
self.update_user_info.emit(all_uid, days, lasts, notes, numbs)
# 保存运行日志
end_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(self.app_path + "/log.txt", "w", encoding="utf-8") as f:
print("任务开始时间:" + begin_time + ",结束时间:" + end_time, file=f)
print(
"已完成数:"
+ str(len(over_uid))
+ ",未完成数:"
+ str(len(error_uid) + len(wait_uid))
+ "\n",
file=f,
)
if len(error_uid) != 0:
print(self.mode[2:4] + "未成功的用户:", file=f)
print("\n".join([self.data[_][0] for _ in error_uid]), file=f)
wait_uid = [_ for _ in all_uid if (not _ in over_uid + error_uid)]
if len(wait_uid) != 0:
print("\n未开始" + self.mode[2:4] + "的用户:", file=f)
print("\n".join([self.data[_][0] for _ in wait_uid]), file=f)
# 恢复GUI运行面板
with open(self.app_path + "/log.txt", "r", encoding="utf-8") as f:
end_log = f.read()
self.update_gui.emit("", "", "", "", end_log)
self.accomplish.emit()
self.if_run = False
# 设置MAA模式
elif self.mode == "设置MAA":
# 配置MAA
self.set_maa("设置MAA", "")
# 创建MAA任务
maa = subprocess.Popen([self.maa_path])
# 记录当前时间
start_time = datetime.datetime.now()
# 监测MAA运行状态
while self.if_run:
# 获取MAA日志
logs = []
if_log_start = False
with open(self.log_path, "r", encoding="utf-8") as f:
for entry in f:
if not if_log_start:
try:
entry_time = datetime.datetime.strptime(
entry[1:20], "%Y-%m-%d %H:%M:%S"
)
if entry_time > start_time:
if_log_start = True
logs.append(entry)
except ValueError:
pass
else:
logs.append(entry)
# 合并日志
log = "".join(logs)
# 判断MAA程序运行状态
result = self.if_maa_success(log, "设置MAA")
if result == "Success!":
break
elif result == "Wait":
# 检测时间间隔
time.sleep(1)
self.accomplish.emit()
self.if_run = False
if self.mode in ["日常代理", "人工排查"]:
# 关闭可能未正常退出的MAA进程
if not self.if_run:
os.system("taskkill /F /T /PID " + str(maa.pid))
# 更新用户数据
days = [self.data[_][2] for _ in all_uid]
lasts = [self.data[_][4] for _ in all_uid]
notes = [self.data[_][11] for _ in all_uid]
numbs = [self.data[_][12] for _ in all_uid]
self.update_user_info.emit(all_uid, days, lasts, notes, numbs)
# 保存运行日志
end_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(self.app_path + "/log.txt", "w", encoding="utf-8") as f:
print("任务开始时间:" + begin_time + ",结束时间:" + end_time, file=f)
print(
"已完成数:"
+ str(len(over_uid))
+ ",未完成数:"
+ str(len(error_uid) + len(wait_uid))
+ "\n",
file=f,
)
if len(error_uid) != 0:
print(self.mode[2:4] + "未成功的用户:", file=f)
print("\n".join([self.data[_][0] for _ in error_uid]), file=f)
wait_uid = [_ for _ in all_uid if (not _ in over_uid + error_uid)]
if len(wait_uid) != 0:
print("\n未开始" + self.mode[2:4] + "的用户:", file=f)
print("\n".join([self.data[_][0] for _ in wait_uid]), file=f)
# 恢复GUI运行面板
with open(self.app_path + "/log.txt", "r", encoding="utf-8") as f:
end_log = f.read()
self.update_gui.emit("", "", "", "", end_log)
self.accomplish.emit()
self.if_run = False

def if_maa_success(self, log, mode):
"""判断MAA程序运行状态"""
Expand Down Expand Up @@ -418,6 +459,11 @@ def if_maa_success(self, log, mode):
return "您中止了本次任务\n正在中止相关程序\n请等待"
else:
return "Wait"
elif mode == "设置MAA":
if "MaaAssistantArknights GUI exited" in log:
return "Success!"
else:
return "Wait"

def set_maa(self, mode, uid):
"""配置MAA运行参数"""
Expand Down Expand Up @@ -460,11 +506,12 @@ def set_maa(self, mode, uid):
] = "False" # 自动肉鸽
data["Configurations"]["Default"][
"TaskQueue.Reclamation.IsChecked"
] = "False" # 生息演算 # 人工排查配置
if mode == "人工排查_仅切换账号":
] = "False" # 生息演算
# 人工排查配置
elif mode == "人工排查_仅切换账号":
data["Configurations"]["Default"][
"MainFunction.PostActions"
] = "8" # 完成后无退出MAA
] = "8" # 完成后退出MAA
data["Configurations"]["Default"][
"Start.RunDirectly"
] = "True" # 启动MAA后直接运行
Expand Down Expand Up @@ -498,6 +545,41 @@ def set_maa(self, mode, uid):
data["Configurations"]["Default"][
"TaskQueue.Reclamation.IsChecked"
] = "False" # 生息演算
# 设置MAA配置
elif mode == "设置MAA":
data["Configurations"]["Default"][
"MainFunction.PostActions"
] = "0" # 完成后无动作
data["Configurations"]["Default"][
"Start.RunDirectly"
] = "False" # 启动MAA后直接运行
data["Configurations"]["Default"][
"Start.StartEmulator"
] = "False" # 启动MAA后自动开启模拟器
data["Configurations"]["Default"][
"TaskQueue.WakeUp.IsChecked"
] = "False" # 开始唤醒
data["Configurations"]["Default"][
"TaskQueue.Recruiting.IsChecked"
] = "False" # 自动公招
data["Configurations"]["Default"][
"TaskQueue.Base.IsChecked"
] = "False" # 基建换班
data["Configurations"]["Default"][
"TaskQueue.Combat.IsChecked"
] = "False" # 刷理智
data["Configurations"]["Default"][
"TaskQueue.Mission.IsChecked"
] = "False" # 领取奖励
data["Configurations"]["Default"][
"TaskQueue.Mall.IsChecked"
] = "False" # 获取信用及购物
data["Configurations"]["Default"][
"TaskQueue.AutoRoguelike.IsChecked"
] = "False" # 自动肉鸽
data["Configurations"]["Default"][
"TaskQueue.Reclamation.IsChecked"
] = "False" # 生息演算
# 剿灭代理配置
elif mode == "日常代理_剿灭":
data["Configurations"]["Default"][
Expand Down Expand Up @@ -846,6 +928,12 @@ def __init__(self, PASSWARD=""):
self.maa_path = self.ui.findChild(QLineEdit, "lineEdit_MAApath")
self.maa_path.textChanged.connect(self.change_config)

self.get_maa_path = self.ui.findChild(QPushButton, "pushButton_getMAApath")
self.get_maa_path.clicked.connect(lambda: self.read("file_path"))

self.set_maa = self.ui.findChild(QPushButton, "pushButton_setMAA")
self.set_maa.clicked.connect(self.maa_set_starter)

self.routine = self.ui.findChild(QSpinBox, "spinBox_routine")
self.routine.valueChanged.connect(self.change_config)

Expand Down Expand Up @@ -1403,6 +1491,11 @@ def read(self, operation):
self.MaaRunner.question_choice = "Yes"
elif choice == QMessageBox.No:
self.MaaRunner.question_choice = "No"
# 读入文件目录
elif operation == "file_path":
file_path = QFileDialog.getExistingDirectory(self.ui, "选择MAA文件夹")
if file_path != "":
self.maa_path.setText(file_path)

def closeEvent(self, event):
"""清理残余进程"""
Expand All @@ -1429,6 +1522,8 @@ def routine_starter(self):
QMessageBox.critical(self.ui, "错误", "MAA路径未设置!")
return None
# 运行过程中修改部分组件
self.MaaRunner.accomplish.disconnect()
self.MaaRunner.accomplish.connect(self.routine_ender)
self.check_start.setEnabled(False)
self.run_now.clicked.disconnect()
self.run_now.setText("结束运行")
Expand Down Expand Up @@ -1468,6 +1563,8 @@ def check_starter(self):
QMessageBox.critical(self.ui, "错误", "MAA路径未设置!")
return None
# 运行过程中修改部分组件
self.MaaRunner.accomplish.disconnect()
self.MaaRunner.accomplish.connect(self.check_ender)
self.run_now.setEnabled(False)
self.check_start.clicked.disconnect()
self.check_start.setText("中止排查")
Expand All @@ -1488,6 +1585,35 @@ def check_starter(self):
self.MainTimer.is_maa_run = True
self.MaaRunner.start()

def maa_set_ender(self):
"""中止MAA设置进程"""
self.MaaRunner.if_run = False
self.MaaRunner.wait()
self.MainTimer.is_maa_run = False
self.set_maa.setEnabled(True)

def maa_set_starter(self):
"""启动MaaRunner线程进行MAA设置"""
if self.config["Default"]["MaaSet.path"] == "":
QMessageBox.critical(self.ui, "错误", "MAA路径未设置!")
return None
# 运行过程中修改部分组件
self.MaaRunner.accomplish.disconnect()
self.MaaRunner.accomplish.connect(self.maa_set_ender)
self.set_maa.setEnabled(False)
# 配置参数
self.MaaRunner.set_path = (
self.config["Default"]["MaaSet.path"] + "/config/gui.json"
)
self.MaaRunner.log_path = (
self.config["Default"]["MaaSet.path"] + "/debug/gui.log"
)
self.MaaRunner.maa_path = self.config["Default"]["MaaSet.path"] + "/MAA.exe"
self.MaaRunner.mode = "设置MAA"
# 启动执行线程
self.MainTimer.is_maa_run = True
self.MaaRunner.start()

def give_config(self):
"""同步配置文件到子线程"""
self.MainTimer.config = self.config
Expand Down
39 changes: 34 additions & 5 deletions gui/ui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tab_users">
<property name="enabled">
Expand Down Expand Up @@ -543,9 +543,9 @@
<property name="title">
<string>调度台</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="2,5">
<item>
<layout class="QVBoxLayout" name="verticalLayout_9" stretch="1,1,3,3,2">
<layout class="QVBoxLayout" name="verticalLayout_9" stretch="0,1,3,3,2">
<item>
<widget class="QFrame" name="frame_main">
<property name="frameShape">
Expand Down Expand Up @@ -732,7 +732,7 @@
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<layout class="QHBoxLayout" name="horizontalLayout_4" stretch="0,20,2,1,2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
Expand All @@ -743,6 +743,33 @@
<item>
<widget class="QLineEdit" name="lineEdit_MAApath"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_getMAApath">
<property name="text">
<string>浏览</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_setMAA">
<property name="text">
<string>设置MAA</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -1012,10 +1039,12 @@ li.checked::marker { content: &quot;\2612&quot;; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;致用户:&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt; 这是AUTO_MAA_v3.1.1,项目基本完成可视化。&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt; 这是AUTO_MAA_v3.1.3_beta,项目基本完成可视化。&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt; 正式版去除了命令行窗口,但这不意味着BUG不会出现。由于用户与项目贡献者的稀缺,我们无法确保正式版足够完善,还望谅解。&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt; 当遇到严重漏洞,请前往官网检查是否有新的版本或包发布。如有,请更新到最新版本后再次尝试。&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt; 您可以通过官方仓库 &lt;a href=&quot;https://github.com/DLmaster361/AUTO_MAA/&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007ad6;&quot;&gt;DLmaster361/AUTO_MAA&lt;/span&gt;&lt;/a&gt; 发布Issues求助。&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt; 官方QQ群:957750551&lt;/p&gt;
Expand Down
8 changes: 4 additions & 4 deletions res/info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ VSVersionInfo(
ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0.
filevers=(3, 1, 3, 0),
filevers=(3, 1, 3, 1),
prodvers=(0, 0, 0, 0),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f,
Expand All @@ -31,13 +31,13 @@ VSVersionInfo(
[StringStruct('Comments', 'https://github.com/DLmaster361/AUTO_MAA/'),
StringStruct('CompanyName', 'AUTO_MAA Team'),
StringStruct('FileDescription', 'AUTO_MAA Component'),
StringStruct('FileVersion', '3.1.3.0'),
StringStruct('FileVersion', '3.1.3.1'),
StringStruct('InternalName', 'AUTO_MAA'),
StringStruct('LegalCopyright', 'Copyright © 2024 DLmaster361'),
StringStruct('OriginalFilename', 'AUTO_MAA.py'),
StringStruct('ProductName', 'AUTO_MAA'),
StringStruct('ProductVersion', 'v3.1.3.0'),
StringStruct('Assembly Version', 'v3.1.3.0')])
StringStruct('ProductVersion', 'v3.1.3.1'),
StringStruct('Assembly Version', 'v3.1.3.1')])
])
]
)
12 changes: 5 additions & 7 deletions 更新说明.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
v3.1.3
v3.1.3_beta
## 新增功能
- 人工排查功能上线
- MAA设置逻辑优化
## 修复BUG
- 添加对内部任务失败的识别
- 修复未完成用户无法正确加载的问题
- accomplish槽函数绑定逻辑修复
## 程序优化
- 优化log文件读取策略,可以读取无时间戳的日志
- 优化MAA运行判定,为后续开发打基础
- 变量名符合pep8规范
## 更新说明
- 项目初始阶段,不会提供专门的版本更新程序,您需要手动更新程序。
- v2.1.5及以前的用户,由于新版本采用全新的架构,您需要手动输入之前的信息。
- v3.0_Beta版用户,直接用`AUTO_MAA.exe`替代`gui.exe`后,将原文件夹下的`gui文件夹`用新版本对应文件替换,重新设置每个用户的`自定义基建`选项(输入`-`以关闭该功能,输入自定义基建配置文件地址以开启该功能)。
- v3.1~v3.1.2版用户,将原文件夹下除`data文件夹`和`config文件夹`外的内容用新版本对应文件替换即可。
- v3.1~v3.1.3版用户,将原文件夹下除`data文件夹`和`config文件夹`外的内容用新版本对应文件替换即可。
- 新用户请忽略本说明。

0 comments on commit c71389f

Please sign in to comment.