22
33#include < format>
44
5+ #ifdef _WIN32
6+ #include " MaaUtils/SafeWindows.hpp"
7+ #endif
8+
59#include " MaaUtils/Platform.h"
10+ #include " MaaUtils/StringMisc.hpp"
611#include " MaaUtils/Uuid.h"
712
813MAA_AGENT_NS_BEGIN
@@ -29,12 +34,30 @@ bool Transceiver::handle_image_header(const json::value& j)
2934 return true ;
3035}
3136
37+ static std::string temp_directory ()
38+ {
39+ auto path = std::filesystem::temp_directory_path ();
40+
41+ #ifdef _WIN32
42+ // ZeroMQ IPC 在 Windows 上不支持 Unicode 路径,拉💩
43+ if (GetACP () != CP_UTF8 && std::ranges::any_of (path.native (), [](wchar_t ch) { return ch > 127 ; })) {
44+ path = MaaNS::path (" C:/Temp" );
45+ if (!std::filesystem::exists (path)) {
46+ std::filesystem::create_directories (path);
47+ }
48+ }
49+ #endif
50+
51+ return path_to_utf8_string (path);
52+ }
53+
3254void Transceiver::init_socket (const std::string& identifier, bool bind)
3355{
34- static auto kTempDir = std::filesystem::temp_directory_path ();
35- constexpr std::string_view kAddrFormat = " ipc://{}/maafw-agent-{}.sock" ;
56+ static auto kTempDir = temp_directory ();
3657
37- ipc_addr_ = std::format (kAddrFormat , path_to_utf8_string (kTempDir ), identifier);
58+ std::string path = std::format (" {}/maafw-agent-{}.sock" , kTempDir , identifier);
59+ ipc_addr_ = std::format (" ipc://{}" , path);
60+ ipc_path_ = MaaNS::path (path);
3861
3962 LogInfo << VAR (ipc_addr_) << VAR (identifier);
4063
@@ -68,6 +91,9 @@ void Transceiver::uninit_socket()
6891
6992 zmq_sock_.close ();
7093 zmq_ctx_.close ();
94+
95+ std::error_code ec;
96+ std::filesystem::remove (ipc_path_, ec);
7197}
7298
7399bool Transceiver::alive ()
0 commit comments