diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-08-22 10:07:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-22 10:07:21 +0200 |
commit | 8a1e5980116355024cd7a7ce0c15db7d4ecb200a (patch) | |
tree | fc40366fb5ad00f6b01e0b796ef85495433bd26f /modules/mono/utils/path_utils.cpp | |
parent | 847183093d2948601cdd82f50a333bdee2d6eef0 (diff) | |
parent | 9c34a02191bc6c560cc2a1bceea943f9bd8aebfa (diff) |
Merge pull request #64089 from neikeq/dotnet6
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); |