diff --git a/engine/services/hardware_service.cc b/engine/services/hardware_service.cc index a0fb93878..b4300d828 100644 --- a/engine/services/hardware_service.cc +++ b/engine/services/hardware_service.cc @@ -60,7 +60,8 @@ bool HardwareService::Restart(const std::string& host, int port) { namespace luh = logging_utils_helper; if (!ahc_) return true; - auto exe = commands::GetCortexServerBinary(); + auto exe = file_manager_utils::Subtract( + file_manager_utils::GetExecutablePath(), cortex_utils::GetCurrentPath()); auto get_config_file_path = []() -> std::string { if (file_manager_utils::cortex_config_file_path.empty()) { return file_manager_utils::GetConfigurationPath().string(); @@ -147,10 +148,11 @@ bool HardwareService::Restart(const std::string& host, int port) { file_manager_utils::GetCortexDataPath().wstring(); params += L" --loglevel " + cortex::wc::Utf8ToWstring(luh::LogLevelStr(luh::global_log_level)); - std::wstring exe_w = cortex::wc::Utf8ToWstring(exe); + std::wstring exe_w = exe.wstring(); std::wstring current_path_w = file_manager_utils::GetExecutableFolderContainerPath().wstring(); std::wstring wcmds = current_path_w + L"/" + exe_w + L" " + params; + CTL_DBG("wcmds: " << wcmds); std::vector mutable_cmds(wcmds.begin(), wcmds.end()); mutable_cmds.push_back(L'\0'); // Create child process @@ -200,7 +202,8 @@ bool HardwareService::Restart(const std::string& host, int port) { setenv(name, new_v.c_str(), true); CTL_INF("LD_LIBRARY_PATH: " << getenv(name)); #endif - std::string p = cortex_utils::GetCurrentPath() + "/" + exe; + std::string p = cortex_utils::GetCurrentPath() + "/" + exe.string(); + CTL_INF("server file path: " << p); execl(p.c_str(), exe.c_str(), "--ignore_cout", "--config_file_path", get_config_file_path().c_str(), "--data_folder_path", get_data_folder_path().c_str(), "--loglevel", diff --git a/engine/utils/file_manager_utils.cc b/engine/utils/file_manager_utils.cc index a83c93efa..6c4595e0b 100644 --- a/engine/utils/file_manager_utils.cc +++ b/engine/utils/file_manager_utils.cc @@ -17,14 +17,15 @@ #endif namespace file_manager_utils { -std::filesystem::path GetExecutableFolderContainerPath() { + +std::filesystem::path GetExecutablePath() { #if defined(__APPLE__) && defined(__MACH__) char buffer[1024]; uint32_t size = sizeof(buffer); if (_NSGetExecutablePath(buffer, &size) == 0) { // CTL_DBG("Executable path: " << buffer); - return std::filesystem::path{buffer}.parent_path(); + return std::filesystem::path{buffer}; } else { CTL_ERR("Failed to get executable path"); return std::filesystem::current_path(); @@ -35,7 +36,7 @@ std::filesystem::path GetExecutableFolderContainerPath() { if (len != -1) { buffer[len] = '\0'; // CTL_DBG("Executable path: " << buffer); - return std::filesystem::path{buffer}.parent_path(); + return std::filesystem::path{buffer}; } else { CTL_ERR("Failed to get executable path"); return std::filesystem::current_path(); @@ -44,13 +45,17 @@ std::filesystem::path GetExecutableFolderContainerPath() { wchar_t buffer[MAX_PATH]; GetModuleFileNameW(NULL, buffer, MAX_PATH); // CTL_DBG("Executable path: " << buffer); - return std::filesystem::path{buffer}.parent_path(); + return std::filesystem::path{buffer}; #else LOG_ERROR << "Unsupported platform!"; return std::filesystem::current_path(); #endif } +std::filesystem::path GetExecutableFolderContainerPath() { + return GetExecutablePath().parent_path(); +} + std::filesystem::path GetHomeDirectoryPath() { #ifdef _WIN32 const wchar_t* homeDir = _wgetenv(L"USERPROFILE"); diff --git a/engine/utils/file_manager_utils.h b/engine/utils/file_manager_utils.h index 059fe6ae3..f60edf4b3 100644 --- a/engine/utils/file_manager_utils.h +++ b/engine/utils/file_manager_utils.h @@ -20,6 +20,8 @@ inline std::string cortex_config_file_path; inline std::string cortex_data_folder_path; +std::filesystem::path GetExecutablePath(); + std::filesystem::path GetExecutableFolderContainerPath(); std::filesystem::path GetHomeDirectoryPath();