diff options
Diffstat (limited to 'modules/mono/utils/path_utils.cpp')
-rw-r--r-- | modules/mono/utils/path_utils.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/mono/utils/path_utils.cpp b/modules/mono/utils/path_utils.cpp index a1905dfcfe..19ad59a1bc 100644 --- a/modules/mono/utils/path_utils.cpp +++ b/modules/mono/utils/path_utils.cpp @@ -51,6 +51,37 @@ namespace path { +String find_executable(const String &p_name) { +#ifdef WINDOWS_ENABLED + Vector<String> exts = OS::get_singleton()->get_environment("PATHEXT").split(ENV_PATH_SEP, false); +#endif + Vector<String> env_path = OS::get_singleton()->get_environment("PATH").split(ENV_PATH_SEP, false); + + if (env_path.is_empty()) { + return String(); + } + + for (int i = 0; i < env_path.size(); i++) { + String p = path::join(env_path[i], p_name); + +#ifdef WINDOWS_ENABLED + for (int j = 0; j < exts.size(); j++) { + String p2 = p + exts[j].to_lower(); // lowercase to reduce risk of case mismatch warning + + if (FileAccess::exists(p2)) { + return p2; + } + } +#else + if (FileAccess::exists(p)) { + return p; + } +#endif + } + + return String(); +} + String cwd() { #ifdef WINDOWS_ENABLED const DWORD expected_size = ::GetCurrentDirectoryW(0, nullptr); |