From d4695dc982ef90182b17c85d8cf0f78c39666689 Mon Sep 17 00:00:00 2001 From: Windsland52 <86581225+Windsland52@users.noreply.github.com> Date: Thu, 7 May 2026 00:13:15 +0800 Subject: [PATCH 1/2] fix(Python): pass UTF-8 byte length for log dir option Tasker.set_log_dir encoded the path as UTF-8 but passed the character count to MaaGlobalSetOption. Non-ASCII paths were truncated before native path conversion on Windows, which could surface as an uncaught C++ filesystem exception. Use the encoded byte length and cover set_log_dir with a non-ASCII path in the binding test. --- source/binding/Python/maa/tasker.py | 6 +++--- test/python/binding_test.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/binding/Python/maa/tasker.py b/source/binding/Python/maa/tasker.py index 15c8ee191f..a349fa72b8 100644 --- a/source/binding/Python/maa/tasker.py +++ b/source/binding/Python/maa/tasker.py @@ -645,12 +645,12 @@ def set_log_dir(path: Union[Path, str]) -> bool: Returns: bool: 是否成功 / Whether successful """ - strpath = str(path) + encoded_path = str(path).encode() return bool( Library.framework().MaaGlobalSetOption( MaaOption(MaaGlobalOptionEnum.LogDir), - strpath.encode(), - len(strpath), + encoded_path, + len(encoded_path), ) ) diff --git a/test/python/binding_test.py b/test/python/binding_test.py index 2d7e4a67fa..7e7225dfd1 100644 --- a/test/python/binding_test.py +++ b/test/python/binding_test.py @@ -472,7 +472,8 @@ def test_tasker_api(resource: Resource, controller: DbgController): # 测试全局选项 (静态方法) Tasker.set_save_draw(True) Tasker.set_stdout_level(LoggingLevelEnum.All) - Tasker.set_log_dir("debug") + log_dir = install_dir / "bin" / "debug" / "新建文件夹" + assert Tasker.set_log_dir(log_dir) Tasker.set_debug_mode(True) Tasker.set_save_on_error(True) Tasker.set_draw_quality(85) From aac2aef6e07edb2bdcd73afe1147ca7d40521e6d Mon Sep 17 00:00:00 2001 From: Windsland52 <86581225+Windsland52@users.noreply.github.com> Date: Thu, 7 May 2026 00:17:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=E6=98=8E=E7=A1=AE=20utf-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/binding/Python/maa/tasker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/binding/Python/maa/tasker.py b/source/binding/Python/maa/tasker.py index a349fa72b8..42ec7119dd 100644 --- a/source/binding/Python/maa/tasker.py +++ b/source/binding/Python/maa/tasker.py @@ -645,12 +645,12 @@ def set_log_dir(path: Union[Path, str]) -> bool: Returns: bool: 是否成功 / Whether successful """ - encoded_path = str(path).encode() + encoded_path_bytes = str(path).encode("utf-8") return bool( Library.framework().MaaGlobalSetOption( MaaOption(MaaGlobalOptionEnum.LogDir), - encoded_path, - len(encoded_path), + encoded_path_bytes, + len(encoded_path_bytes), ) )