Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/task/Okww/AutoProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,13 @@ async def set_okww(self) -> None:

mas_config_dir = self._okww_mas_config_dir()
if self.script_config.get("Script", "ConfigPathMode") == "Folder":
tmp_dst = self.script_config_path.with_name(
self.script_config_path.name + ".tmp"
)
shutil.rmtree(tmp_dst, ignore_errors=True)
shutil.copytree(mas_config_dir, tmp_dst, dirs_exist_ok=True)
shutil.rmtree(self.script_config_path, ignore_errors=True)
shutil.copytree(mas_config_dir, self.script_config_path, dirs_exist_ok=True)
tmp_dst.rename(self.script_config_path)
elif self.script_config.get("Script", "ConfigPathMode") == "File":
shutil.copy(
mas_config_dir / self.script_config_path.name,
Expand Down
40 changes: 30 additions & 10 deletions app/task/Okww/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def __init__(self, script_info: ScriptItem):
self.task_info = script_info.task_info
self.script_info = script_info
self.check_result = "-"
self.temp_path: Path | None = None
self.script_config_path: Path | None = None

async def check(self) -> str:
if self.task_info.mode not in METHOD_BOOK:
Expand Down Expand Up @@ -120,7 +122,6 @@ async def prepare(self):
if self.task_info.mode == "AutoProxy":
self.script_config_path = Path(self.script_config.get("Script", "ConfigPath"))
self.temp_path = Path.cwd() / f"data/{self.script_info.script_id}/Temp"
shutil.rmtree(self.temp_path, ignore_errors=True)
self.temp_path.mkdir(parents=True, exist_ok=True)
if self.script_config_path.exists():
if self.script_config.get("Script", "ConfigPathMode") == "Folder":
Expand Down Expand Up @@ -170,13 +171,18 @@ async def final_task(self):
return

if self.task_info.mode == "AutoProxy":
if hasattr(self, "temp_path") and self.temp_path.exists():
if self.temp_path and self.temp_path.exists():
if self.script_config.get("Script", "ConfigPathMode") == "Folder":
logger.info(f"复原 OK-WW 脚本配置文件: {self.temp_path}")
shutil.rmtree(self.script_config_path, ignore_errors=True)
tmp_dst = self.script_config_path.with_name(
self.script_config_path.name + ".tmp"
)
shutil.rmtree(tmp_dst, ignore_errors=True)
shutil.copytree(
self.temp_path, self.script_config_path, dirs_exist_ok=True
self.temp_path, tmp_dst, dirs_exist_ok=True
)
shutil.rmtree(self.script_config_path, ignore_errors=True)
tmp_dst.rename(self.script_config_path)
elif (
self.script_config.get("Script", "ConfigPathMode") == "File"
and (self.temp_path / "config.temp").exists()
Expand All @@ -192,36 +198,50 @@ async def final_task(self):
if script_cfg.is_locked:
await script_cfg.unlock()

if self.task_info.mode == "AutoProxy" and hasattr(self, "user_config"):
if self.task_info.mode == "AutoProxy":
await script_cfg.UserData.load(await self.user_config.toDict())

self.script_info.status = "完成"
finally:
if script_cfg.is_locked:
with suppress(Exception):
await script_cfg.unlock()

self.script_info.status = "完成"

async def on_crash(self, e: Exception):
self.script_info.status = "异常"
logger.exception(f"OK-WW任务出现异常: {e}")
script_uid = uuid.UUID(self.script_info.script_id)
if (
self.task_info.mode == "AutoProxy"
and hasattr(self, "script_config")
and hasattr(self, "temp_path")
and self.temp_path is not None
and self.temp_path.exists()
):
if self.script_config.get("Script", "ConfigPathMode") == "Folder":
shutil.rmtree(self.script_config_path, ignore_errors=True)
tmp_dst = self.script_config_path.with_name(
self.script_config_path.name + ".tmp"
)
shutil.rmtree(tmp_dst, ignore_errors=True)
shutil.copytree(
self.temp_path, self.script_config_path, dirs_exist_ok=True
self.temp_path, tmp_dst, dirs_exist_ok=True
)
shutil.rmtree(self.script_config_path, ignore_errors=True)
tmp_dst.rename(self.script_config_path)
elif (
self.script_config.get("Script", "ConfigPathMode") == "File"
and (self.temp_path / "config.temp").exists()
):
shutil.copy(self.temp_path / "config.temp", self.script_config_path)
shutil.rmtree(self.temp_path, ignore_errors=True)

try:
if self.task_info.mode == "AutoProxy":
await Config.ScriptConfig[script_uid].UserData.load(
await self.user_config.toDict()
)
except Exception:
logger.exception("on_crash 写回 UserConfig 失败,放弃本次状态变更")

script_cfg = Config.ScriptConfig[script_uid]
if script_cfg.is_locked:
with suppress(Exception):
Expand Down
3 changes: 2 additions & 1 deletion res/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"okww专项 重构游戏管理项",
"okww专项 完善用户标签tag",
"okww专项 优化用户配置页面的样式",
"okww专项 调度台展示游戏配置与启动流程日志"
"okww专项 调度台展示游戏配置与启动流程日志",
"okww专项 重构配置优化"
],
"修复BUG": [
"修复静默模式未对M9A本体生效的问题",
Expand Down
Loading