mirror of
https://github.com/goldenfishs/MRobot.git
synced 2025-07-27 08:49:01 +08:00
137 lines
3.6 KiB
Python
137 lines
3.6 KiB
Python
import os
|
||
import sys
|
||
# 将当前工作目录设置为程序所在的目录,确保无论从哪里执行,其工作目录都正确设置为程序本身的位置,避免路径错误。
|
||
os.chdir(os.path.dirname(sys.executable) if getattr(sys, 'frozen', False)else os.path.dirname(os.path.abspath(__file__)))
|
||
|
||
import pyuac
|
||
if not pyuac.isUserAdmin():
|
||
try:
|
||
pyuac.runAsAdmin(False)
|
||
sys.exit(0)
|
||
except Exception:
|
||
sys.exit(1)
|
||
|
||
import atexit
|
||
import base64
|
||
|
||
|
||
|
||
|
||
def first_run():
|
||
# if not cfg.get_value(base64.b64decode("YXV0b191cGRhdGU=").decode("utf-8")):
|
||
# log.error("首次使用请先打开图形界面 March7th Launcher.exe")
|
||
input("按回车键关闭窗口. . .")
|
||
sys.exit(0)
|
||
|
||
|
||
def run_main_actions():
|
||
while True:
|
||
version.start()
|
||
game.start()
|
||
reward.start_specific("dispatch")
|
||
Daily.start()
|
||
reward.start()
|
||
game.stop(True)
|
||
|
||
|
||
def run_sub_task(action):
|
||
game.start()
|
||
sub_tasks = {
|
||
"daily": lambda: (Daily.run(), reward.start()),
|
||
"power": Power.run,
|
||
"fight": Fight.start,
|
||
"universe": Universe.start,
|
||
"forgottenhall": lambda: challenge.start("memoryofchaos"),
|
||
"purefiction": lambda: challenge.start("purefiction"),
|
||
"apocalyptic": lambda: challenge.start("apocalyptic"),
|
||
"redemption": Redemption.start
|
||
}
|
||
task = sub_tasks.get(action)
|
||
if task:
|
||
task()
|
||
game.stop(False)
|
||
|
||
|
||
def run_sub_task_gui(action):
|
||
gui_tasks = {
|
||
"universe_gui": Universe.gui,
|
||
"fight_gui": Fight.gui
|
||
}
|
||
task = gui_tasks.get(action)
|
||
if task and not task():
|
||
input("按回车键关闭窗口. . .")
|
||
sys.exit(0)
|
||
|
||
|
||
def run_sub_task_update(action):
|
||
update_tasks = {
|
||
"universe_update": Universe.update,
|
||
"fight_update": Fight.update
|
||
}
|
||
task = update_tasks.get(action)
|
||
if task:
|
||
task()
|
||
input("按回车键关闭窗口. . .")
|
||
sys.exit(0)
|
||
|
||
|
||
def run_notify_action():
|
||
notif.notify(cfg.notify_template['TestMessage'], "./assets/app/images/March7th.jpg")
|
||
input("按回车键关闭窗口. . .")
|
||
sys.exit(0)
|
||
|
||
|
||
def main(action=None):
|
||
first_run()
|
||
|
||
# 完整运行
|
||
if action is None or action == "main":
|
||
run_main_actions()
|
||
|
||
# 子任务
|
||
elif action in ["daily", "power", "fight", "universe", "forgottenhall", "purefiction", "apocalyptic", "redemption"]:
|
||
run_sub_task(action)
|
||
|
||
# 子任务 原生图形界面
|
||
elif action in ["universe_gui", "fight_gui"]:
|
||
run_sub_task_gui(action)
|
||
|
||
# 子任务 更新项目
|
||
elif action in ["universe_update", "fight_update"]:
|
||
run_sub_task_update(action)
|
||
|
||
elif action in ["screenshot", "plot"]:
|
||
tool.start(action)
|
||
|
||
elif action == "game":
|
||
game.start()
|
||
|
||
elif action == "notify":
|
||
run_notify_action()
|
||
|
||
else:
|
||
log.error(f"未知任务: {action}")
|
||
input("按回车键关闭窗口. . .")
|
||
sys.exit(1)
|
||
|
||
|
||
# 程序结束时的处理器
|
||
def exit_handler():
|
||
"""注册程序退出时的处理函数,用于清理OCR资源."""
|
||
ocr.exit_ocr()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
try:
|
||
atexit.register(exit_handler)
|
||
main(sys.argv[1]) if len(sys.argv) > 1 else main()
|
||
except KeyboardInterrupt:
|
||
log.error("发生错误: 手动强制停止")
|
||
input("按回车键关闭窗口. . .")
|
||
sys.exit(1)
|
||
except Exception as e:
|
||
log.error(cfg.notify_template['ErrorOccurred'].format(error=e))
|
||
notif.notify(cfg.notify_template['ErrorOccurred'].format(error=e))
|
||
input("按回车键关闭窗口. . .")
|
||
sys.exit(1)
|