Skip to content

Commit

Permalink
fix: correct get server name method (#1953)
Browse files Browse the repository at this point in the history
Co-authored-by: vansangpfiev <[email protected]>
  • Loading branch information
vansangpfiev and sangjanai authored Feb 11, 2025
1 parent cdb2446 commit 8b9f6f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
9 changes: 6 additions & 3 deletions engine/services/hardware_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<wchar_t> mutable_cmds(wcmds.begin(), wcmds.end());
mutable_cmds.push_back(L'\0');
// Create child process
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 9 additions & 4 deletions engine/utils/file_manager_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions engine/utils/file_manager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8b9f6f4

Please sign in to comment.