Skip to content

Commit

Permalink
调度队列逻辑修复
Browse files Browse the repository at this point in the history
  • Loading branch information
DLmaster361 committed Jan 6, 2025
1 parent 684211c commit e79417e
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 104 deletions.
84 changes: 67 additions & 17 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def initialize(self) -> None:

# 检查目录
(self.app_path / "config").mkdir(parents=True, exist_ok=True)
(self.app_path / "data/MAAconfig/simple").mkdir(parents=True, exist_ok=True)
(self.app_path / "data/MAAconfig/beta").mkdir(parents=True, exist_ok=True)
(self.app_path / "data/MAAconfig/Default").mkdir(parents=True, exist_ok=True)
# (self.app_path / "data/MAAconfig/simple").mkdir(parents=True, exist_ok=True)
# (self.app_path / "data/MAAconfig/beta").mkdir(parents=True, exist_ok=True)
# (self.app_path / "data/MAAconfig/Default").mkdir(parents=True, exist_ok=True)

# 生成版本信息文件
if not self.version_path.exists():
Expand All @@ -90,18 +90,29 @@ def initialize(self) -> None:
encoding="utf-8",
)

self.get_config()
self.init_config()
# self.check_database()

def get_config(self) -> None:
"""创建配置类"""
def init_config(self) -> None:
"""初始化配置类"""

self.global_config = GlobalConfig()
qconfig.load(self.config_path, self.global_config)

self.queue_config = QueueConfig()
self.maa_config = MaaConfig()

def init_database(self, mode: str) -> None:
"""初始化用户数据库"""

if mode == "Maa":
self.cur.execute(
"CREATE TABLE adminx(admin text,id text,server text,day int,status text,last date,game text,game_1 text,game_2 text,routine text,annihilation text,infrastructure text,password byte,notes text,numb int,mode text,uid int)"
)
self.cur.execute("CREATE TABLE version(v text)")
self.cur.execute("INSERT INTO version VALUES(?)", ("v1.3",))
self.db.commit()

def check_database(self) -> None:
"""检查用户数据库文件并处理数据库版本更新"""

Expand Down Expand Up @@ -181,17 +192,6 @@ def check_database(self) -> None:
cur.close()
db.close()

def init_database(self, mode: str) -> None:
"""初始化用户数据库"""

if mode == "Maa":
self.cur.execute(
"CREATE TABLE adminx(admin text,id text,server text,day int,status text,last date,game text,game_1 text,game_2 text,routine text,annihilation text,infrastructure text,password byte,notes text,numb int,mode text,uid int)"
)
self.cur.execute("CREATE TABLE version(v text)")
self.cur.execute("INSERT INTO version VALUES(?)", ("v1.3",))
self.db.commit()

def open_database(self, mode: str, index: str = None) -> None:
"""打开数据库"""

Expand All @@ -212,6 +212,56 @@ def close_database(self) -> None:
self.db.close()
self.if_database_opened = False

def clear_maa_config(self) -> None:
"""清空MAA配置"""

self.maa_config.set(self.maa_config.MaaSet_Name, "")
self.maa_config.set(self.maa_config.MaaSet_Path, ".")
self.maa_config.set(self.maa_config.RunSet_AnnihilationTimeLimit, 40)
self.maa_config.set(self.maa_config.RunSet_RoutineTimeLimit, 10)
self.maa_config.set(self.maa_config.RunSet_RunTimesLimit, 3)
self.maa_config.set(self.maa_config.MaaSet_Name, "")
self.maa_config.set(self.maa_config.MaaSet_Name, "")
self.maa_config.set(self.maa_config.MaaSet_Name, "")

def clear_queue_config(self) -> None:
"""清空队列配置"""

self.queue_config.set(self.queue_config.queueSet_Name, "")
self.queue_config.set(self.queue_config.queueSet_Enabled, False)

self.queue_config.set(self.queue_config.time_TimeEnabled_0, False)
self.queue_config.set(self.queue_config.time_TimeSet_0, "00:00")
self.queue_config.set(self.queue_config.time_TimeEnabled_1, False)
self.queue_config.set(self.queue_config.time_TimeSet_1, "00:00")
self.queue_config.set(self.queue_config.time_TimeEnabled_2, False)
self.queue_config.set(self.queue_config.time_TimeSet_2, "00:00")
self.queue_config.set(self.queue_config.time_TimeEnabled_3, False)
self.queue_config.set(self.queue_config.time_TimeSet_3, "00:00")
self.queue_config.set(self.queue_config.time_TimeEnabled_4, False)
self.queue_config.set(self.queue_config.time_TimeSet_4, "00:00")
self.queue_config.set(self.queue_config.time_TimeEnabled_5, False)
self.queue_config.set(self.queue_config.time_TimeSet_5, "00:00")
self.queue_config.set(self.queue_config.time_TimeEnabled_6, False)
self.queue_config.set(self.queue_config.time_TimeSet_6, "00:00")
self.queue_config.set(self.queue_config.time_TimeEnabled_7, False)
self.queue_config.set(self.queue_config.time_TimeSet_7, "00:00")
self.queue_config.set(self.queue_config.time_TimeEnabled_8, False)
self.queue_config.set(self.queue_config.time_TimeSet_8, "00:00")
self.queue_config.set(self.queue_config.time_TimeEnabled_9, False)
self.queue_config.set(self.queue_config.time_TimeSet_9, "00:00")

self.queue_config.set(self.queue_config.queue_Member_1, "禁用")
self.queue_config.set(self.queue_config.queue_Member_2, "禁用")
self.queue_config.set(self.queue_config.queue_Member_3, "禁用")
self.queue_config.set(self.queue_config.queue_Member_4, "禁用")
self.queue_config.set(self.queue_config.queue_Member_5, "禁用")
self.queue_config.set(self.queue_config.queue_Member_6, "禁用")
self.queue_config.set(self.queue_config.queue_Member_7, "禁用")
self.queue_config.set(self.queue_config.queue_Member_8, "禁用")
self.queue_config.set(self.queue_config.queue_Member_9, "禁用")
self.queue_config.set(self.queue_config.queue_Member_10, "禁用")


class GlobalConfig(QConfig):
"""全局配置"""
Expand Down
3 changes: 3 additions & 0 deletions app/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def __init__(
FluentIcon.BOOK_SHELF,
NavigationItemPosition.TOP,
)
self.stackedWidget.currentChanged.connect(
lambda index: self.queue_manager.refresh() if index == 2 else None
)

# 创建系统托盘及其菜单
self.tray = QSystemTrayIcon(
Expand Down
70 changes: 47 additions & 23 deletions app/ui/member_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
from pathlib import Path
import os
import datetime
import ctypes
import json
import subprocess
import shutil
import win32gui
Expand Down Expand Up @@ -183,21 +183,7 @@ def add_setting_box(self):
self.config.app_path / f"config/MaaConfig/脚本_{index}/config.json",
self.config.maa_config,
)

self.config.maa_config.set(self.config.maa_config.MaaSet_Name, "")
self.config.maa_config.set(self.config.maa_config.MaaSet_Path, ".")
self.config.maa_config.set(
self.config.maa_config.RunSet_AnnihilationTimeLimit, 40
)
self.config.maa_config.set(
self.config.maa_config.RunSet_RoutineTimeLimit, 10
)
self.config.maa_config.set(
self.config.maa_config.RunSet_RunTimesLimit, 3
)
self.config.maa_config.set(self.config.maa_config.MaaSet_Name, "")
self.config.maa_config.set(self.config.maa_config.MaaSet_Name, "")
self.config.maa_config.set(self.config.maa_config.MaaSet_Name, "")
self.config.clear_maa_config()
self.config.maa_config.save()

self.config.open_database("Maa", f"脚本_{index}")
Expand Down Expand Up @@ -229,6 +215,7 @@ def del_setting_box(self):
self.member_manager.clear_SettingBox()

shutil.rmtree(self.config.app_path / f"config/{type[0]}Config/{name}")
self.change_queue(name, "禁用")
for member in move_list:
if (
self.config.app_path / f"config/{member[1]}Config/{member[0]}"
Expand All @@ -237,8 +224,9 @@ def del_setting_box(self):
self.config.app_path / f"config/{member[1]}Config/{member[0]}"
).rename(
self.config.app_path
/ f"config/{member[1]}Config/{member[0][:3]}{int(member[0][3:])-1}",
/ f"config/{member[1]}Config/脚本_{int(member[0][3:])-1}",
)
self.change_queue(member[0], f"脚本_{int(member[0][3:])-1}")

self.member_manager.show_SettingBox(index)

Expand All @@ -262,15 +250,17 @@ def left_setting_box(self):
self.member_manager.clear_SettingBox()

(self.config.app_path / f"config/{type_right[0]}Config/脚本_{index}").rename(
self.config.app_path / f"config/{type_right[0]}Config/脚本_0",
self.config.app_path / f"config/{type_right[0]}Config/脚本_0"
)
shutil.move(
str(self.config.app_path / f"config/{type_left[0]}Config/脚本_{index-1}"),
str(self.config.app_path / f"config/{type_left[0]}Config/脚本_{index}"),
self.change_queue(f"脚本_{index}", "脚本_0")
(self.config.app_path / f"config/{type_left[0]}Config/脚本_{index-1}").rename(
self.config.app_path / f"config/{type_left[0]}Config/脚本_{index}"
)
self.change_queue(f"脚本_{index-1}", f"脚本_{index}")
(self.config.app_path / f"config/{type_right[0]}Config/脚本_0").rename(
self.config.app_path / f"config/{type_right[0]}Config/脚本_{index-1}",
self.config.app_path / f"config/{type_right[0]}Config/脚本_{index-1}"
)
self.change_queue("脚本_0", f"脚本_{index-1}")

self.member_manager.show_SettingBox(index - 1)

Expand All @@ -296,12 +286,15 @@ def right_setting_box(self):
(self.config.app_path / f"config/{type_left[0]}Config/脚本_{index}").rename(
self.config.app_path / f"config/{type_left[0]}Config/脚本_0",
)
self.change_queue(f"脚本_{index}", "脚本_0")
(self.config.app_path / f"config/{type_right[0]}Config/脚本_{index+1}").rename(
self.config.app_path / f"config/{type_right[0]}Config/脚本_{index}",
)
self.change_queue(f"脚本_{index+1}", f"脚本_{index}")
(self.config.app_path / f"config/{type_left[0]}Config/脚本_0").rename(
self.config.app_path / f"config/{type_left[0]}Config/脚本_{index+1}",
)
self.change_queue("脚本_0", f"脚本_{index+1}")

self.member_manager.show_SettingBox(index + 1)

Expand Down Expand Up @@ -336,6 +329,23 @@ def show_password(self):
self.key.setIcon(FluentIcon.HIDE)
self.key.setChecked(False)

def change_queue(self, old: str, new: str) -> None:
"""修改调度队列配置文件的队列参数"""

if (self.config.app_path / "config/QueueConfig").exists():
for json_file in (self.config.app_path / "config/QueueConfig").glob(
"*.json"
):
with json_file.open("r", encoding="utf-8") as f:
data = json.load(f)

for i in range(10):
if data["Queue"][f"Member_{i+1}"] == old:
data["Queue"][f"Member_{i+1}"] = new

with json_file.open("w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=4)


class MemberSettingBox(QWidget):

Expand Down Expand Up @@ -367,10 +377,17 @@ def show_SettingBox(self, index) -> None:

member_list = self.search_member()

qconfig.load(
self.config.app_path / "config/临时.json",
self.config.maa_config,
)
self.config.clear_maa_config()
for member in member_list:
if member[1] == "Maa":
self.config.open_database(member[1], member[0])
self.add_MaaSettingBox(int(member[0][3:]))
if (self.config.app_path / "config/临时.json").exists():
(self.config.app_path / "config/临时.json").unlink()

self.switch_SettingBox(index)

Expand Down Expand Up @@ -404,6 +421,13 @@ def clear_SettingBox(self) -> None:
sub_interface.deleteLater()
self.script_list.clear()
self.pivot.clear()
qconfig.load(
self.config.app_path / "config/临时.json",
self.config.maa_config,
)
self.config.clear_maa_config()
if (self.config.app_path / "config/临时.json").exists():
(self.config.app_path / "config/临时.json").unlink()
self.config.close_database()

def add_MaaSettingBox(self, uid: int) -> None:
Expand Down Expand Up @@ -475,7 +499,7 @@ def __init__(self, parent=None, maa_config: MaaConfig = None):
Layout = QVBoxLayout()

self.card_Name = LineEditSettingCard(
"实例名称",
"请输入实例名称",
FluentIcon.EDIT,
"实例名称",
"用于标识MAA实例的名称",
Expand Down
Loading

0 comments on commit e79417e

Please sign in to comment.