diff options
Diffstat (limited to 'src/Storage.cpp')
-rw-r--r-- | src/Storage.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Storage.cpp b/src/Storage.cpp index cd34b56..c9dfb17 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -1,9 +1,11 @@ #include "../include/Storage.hpp" #include "../include/env.hpp" +#include "../include/StringUtils.hpp" #include <stdio.h> #include <assert.h> #include <json/reader.h> #include <json/writer.h> +#include <unordered_set> #if OS_FAMILY == OS_FAMILY_POSIX #include <pwd.h> @@ -223,4 +225,23 @@ namespace QuickMedia { return true; } + + bool is_program_executable_by_name(const char *name) { + // TODO: Implement for Windows. Windows also uses semicolon instead of colon as a separator + char *env = getenv("PATH"); + std::unordered_set<std::string> paths; + string_split(env, ':', [&paths](const char *str, size_t size) { + paths.insert(std::string(str, size)); + return true; + }); + + for(const std::string &path_str : paths) { + Path path(path_str); + path.join(name); + if(get_file_type(path) == FileType::REGULAR) + return true; + } + + return false; + } }
\ No newline at end of file |