| 198 | } |
| 199 | |
| 200 | rdcstr FindFileInPath(const rdcstr &file) |
| 201 | { |
| 202 | rdcstr filePath; |
| 203 | |
| 204 | // Search the PATH directory list for the application (like shell where) to get the absolute path |
| 205 | // Return "" if no exectuable found in the PATH list |
| 206 | const DWORD size = 65535; |
| 207 | char envPath[size]; |
| 208 | if(GetEnvironmentVariableA("PATH", envPath, size) == 0) |
| 209 | return filePath; |
| 210 | |
| 211 | char *next = NULL; |
| 212 | const char *pathSeparator = ";"; |
| 213 | const char *path = strtok_s(envPath, pathSeparator, &next); |
| 214 | rdcwstr fileName = StringFormat::UTF82Wide(file); |
| 215 | |
| 216 | while(path) |
| 217 | { |
| 218 | rdcwstr testPath = StringFormat::UTF82Wide(path); |
| 219 | |
| 220 | // Check for the following extensions. If fileName already has one, they will be ignored. |
| 221 | rdcarray<rdcwstr> extensions; |
| 222 | extensions.push_back(L".exe"); |
| 223 | extensions.push_back(L".bat"); |
| 224 | |
| 225 | for(uint32_t i = 0; i < extensions.size(); i++) |
| 226 | { |
| 227 | wchar_t foundPath[512] = {0}; |
| 228 | if(SearchPathW(testPath.c_str(), fileName.c_str(), extensions[i].c_str(), |
| 229 | ARRAY_COUNT(foundPath) - 1, foundPath, NULL) != 0) |
| 230 | { |
| 231 | filePath = StringFormat::Wide2UTF8(foundPath); |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | path = strtok_s(NULL, pathSeparator, &next); |
| 237 | } |
| 238 | |
| 239 | return filePath; |
| 240 | } |
| 241 | |
| 242 | void CreateParentDirectory(const rdcstr &filename) |
| 243 | { |