MCPcopy Create free account
hub / github.com/baldurk/renderdoc / FindFileInPath

Function FindFileInPath

renderdoc/os/win32/win32_stringio.cpp:200–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198}
199
200rdcstr 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
242void CreateParentDirectory(const rdcstr &filename)
243{

Callers 2

getToolPathFunction · 0.50
initAdbFunction · 0.50

Calls 5

UTF82WideFunction · 0.70
Wide2UTF8Function · 0.70
push_backMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected