From 691b6a1a29d1a15429c2f7017f536c6fc006f2a5 Mon Sep 17 00:00:00 2001 From: fxliang Date: Fri, 23 Feb 2024 00:02:03 +0800 Subject: [PATCH] fix: could not restart server by calling `WeaselServer.exe` --- WeaselServer/WeaselServer.cpp | 14 ++++++++++++-- WeaselTSF/LanguageBar.cpp | 2 -- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/WeaselServer/WeaselServer.cpp b/WeaselServer/WeaselServer.cpp index 079f795da..a405016e7 100644 --- a/WeaselServer/WeaselServer.cpp +++ b/WeaselServer/WeaselServer.cpp @@ -79,14 +79,24 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lp // command line option /q stops the running server bool quit = !wcscmp(L"/q", lpstrCmdLine) || !wcscmp(L"/quit", lpstrCmdLine); // restart if already running - if(quit) { weasel::Client client; if (client.Connect()) // try to connect to running server { client.ShutdownServer(); + if (quit) + return 0; + int retry = 0; + while (client.Connect() && retry < 10) { + client.ShutdownServer(); + retry++; + Sleep(50); + } + if (retry >= 10) + return 0; } - return 0; + else if (quit) + return 0; } bool check_updates = !wcscmp(L"/update", lpstrCmdLine); diff --git a/WeaselTSF/LanguageBar.cpp b/WeaselTSF/LanguageBar.cpp index 0e02babc2..959362f4a 100644 --- a/WeaselTSF/LanguageBar.cpp +++ b/WeaselTSF/LanguageBar.cpp @@ -315,8 +315,6 @@ void WeaselTSF::_HandleLangBarMenuSelect(UINT wID) { std::wstring dir(szValue); std::thread th([dir]() { - ShellExecuteW(NULL, L"open", (dir + L"\\stop_service.bat").c_str(), NULL, dir.c_str(), SW_HIDE); - Sleep(100); ShellExecuteW(NULL, L"open", (dir + L"\\start_service.bat").c_str(), NULL, dir.c_str(), SW_HIDE); }); th.detach();