diff --git a/WCH.cpp b/WCH.cpp index 1fc1d04..fad6c37 100644 --- a/WCH.cpp +++ b/WCH.cpp @@ -25,6 +25,7 @@ extern vector WCH_list_command; extern set> WCH_list_clock; extern set WCH_list_task; extern set> WCH_list_work; +extern wstring WCH_path_exec; extern wstring WCH_title_window; extern HWND WCH_handle_window; extern HWND WCH_handle_tray; @@ -50,7 +51,8 @@ extern Json::Reader JSON_Reader; extern Json::StreamWriterBuilder JSON_SWB; extern unique_ptr JSON_SW; -int32_t wmain([[maybe_unused]] int argc, [[maybe_unused]] wchar_t* argv[]) { +int32_t wmain([[maybe_unused]] int32_t _argc, wchar_t* _argv[]) { + WCH_path_exec = _argv[0]; WCH_Init(); while (true) { if (WCH_cmd_line) { diff --git a/modules/apis.hpp b/modules/apis.hpp index fc94c36..4415c80 100644 --- a/modules/apis.hpp +++ b/modules/apis.hpp @@ -25,6 +25,7 @@ extern vector WCH_list_command; extern set> WCH_list_clock; extern set WCH_list_task; extern set> WCH_list_work; +extern wstring WCH_path_exec; extern wstring WCH_title_window; extern HWND WCH_handle_window; extern HWND WCH_handle_tray; diff --git a/modules/basic.hpp b/modules/basic.hpp index c0ba925..983ae20 100644 --- a/modules/basic.hpp +++ b/modules/basic.hpp @@ -375,6 +375,7 @@ vector WCH_list_command; set> WCH_list_clock; set WCH_list_task; set> WCH_list_work; +wstring WCH_path_exec; wstring WCH_title_window; HWND WCH_handle_window; HWND WCH_handle_tray; @@ -399,6 +400,5 @@ wofstream wfout; Json::Reader JSON_Reader; Json::StreamWriterBuilder JSON_SWB; unique_ptr JSON_SW(JSON_SWB.newStreamWriter()); -wstring WCH_path_program; #endif \ No newline at end of file diff --git a/modules/commands.hpp b/modules/commands.hpp index c751fd5..91c8ea3 100644 --- a/modules/commands.hpp +++ b/modules/commands.hpp @@ -25,6 +25,7 @@ extern vector WCH_list_command; extern set> WCH_list_clock; extern set WCH_list_task; extern set> WCH_list_work; +extern wstring WCH_path_exec; extern wstring WCH_title_window; extern HWND WCH_handle_window; extern HWND WCH_handle_tray; @@ -53,17 +54,6 @@ extern unique_ptr JSON_SW; void WCH_save(); void WCH_check_task_loop(); -void WCH_restart() { - // Restart the program. - if (WCH_list_command.size() != 1) { - WCH_InputCommandIncorrect(); - return; - } - wstring wCommand = L"cd " + WCH_path_program.substr(0, WCH_path_program.rfind(L"\\")) + L" && " + L"start " + WCH_path_program.substr(WCH_path_program.rfind(L"\\") + 1, WCH_path_program.length() - 1); - _wsystem(wCommand.c_str()); - WCH_exit(); -} - void WCH_clear() { // Clear console information. if (WCH_list_command.size() != 1) { @@ -109,6 +99,16 @@ void WCH_exit() { _exit(0); } +void WCH_restart() { + // Restart the program. + if (WCH_list_command.size() != 1) { + WCH_InputCommandIncorrect(); + return; + } + _wsystem((L"START \"\" \"" + WCH_path_exec + L"\"").c_str()); + WCH_exit(); +} + void WCH_hide() { // Hide the window. if (WCH_list_command.size() != 1) { diff --git a/modules/file-process.hpp b/modules/file-process.hpp index a4b49f8..c205261 100644 --- a/modules/file-process.hpp +++ b/modules/file-process.hpp @@ -25,6 +25,7 @@ extern vector WCH_list_command; extern set> WCH_list_clock; extern set WCH_list_task; extern set> WCH_list_work; +extern wstring WCH_path_exec; extern wstring WCH_title_window; extern HWND WCH_handle_window; extern HWND WCH_handle_tray; diff --git a/modules/functions.hpp b/modules/functions.hpp index e6132df..c19f852 100644 --- a/modules/functions.hpp +++ b/modules/functions.hpp @@ -25,6 +25,7 @@ extern vector WCH_list_command; extern set> WCH_list_clock; extern set WCH_list_task; extern set> WCH_list_work; +extern wstring WCH_path_exec; extern wstring WCH_title_window; extern HWND WCH_handle_window; extern HWND WCH_handle_tray; diff --git a/modules/init.hpp b/modules/init.hpp index 8d598f4..9506c16 100644 --- a/modules/init.hpp +++ b/modules/init.hpp @@ -25,6 +25,7 @@ extern vector WCH_list_command; extern set> WCH_list_clock; extern set WCH_list_task; extern set> WCH_list_work; +extern wstring WCH_path_exec; extern wstring WCH_title_window; extern HWND WCH_handle_window; extern HWND WCH_handle_tray; @@ -139,9 +140,6 @@ void WCH_Init_Var() { WCH_title_window.append(L" ("); WCH_title_window.append(WCH_Framework); WCH_title_window.append(L")"); - wchar_t Path[256]; - GetModuleFileName(NULL, Path, sizeof(Path) - 1); - WCH_path_program = Path; } void WCH_Init_Win() { diff --git a/version.hpp b/version.hpp index 6e2d68e..09dab29 100644 --- a/version.hpp +++ b/version.hpp @@ -7,5 +7,5 @@ Contributors: jsh-jsh ren-yc #define WCH_VER_MAIN L"2.1.1" #define WCH_VER_TYPE 1 #if WCH_VER_TYPE != 0 - #define WCH_VER_BUILD 9 + #define WCH_VER_BUILD 10 #endif \ No newline at end of file