MCPcopy Create free account
hub / github.com/crownengine/crown / SearchDataFiles

Function SearchDataFiles

3rdparty/openal/alc/helpers.cpp:346–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344}
345
346al::vector<std::string> SearchDataFiles(const char *ext, const char *subdir)
347{
348 static std::mutex search_lock;
349 std::lock_guard<std::mutex> _{search_lock};
350
351 /* If the path is absolute, use it directly. */
352 al::vector<std::string> results;
353 if(isalpha(subdir[0]) && subdir[1] == ':' && is_slash(subdir[2]))
354 {
355 std::string path{subdir};
356 std::replace(path.begin(), path.end(), '/', '\\');
357 DirectorySearch(path.c_str(), ext, &results);
358 return results;
359 }
360 if(subdir[0] == '\\' && subdir[1] == '\\' && subdir[2] == '?' && subdir[3] == '\\')
361 {
362 DirectorySearch(subdir, ext, &results);
363 return results;
364 }
365
366 std::string path;
367
368 /* Search the app-local directory. */
369 if(auto localpath = al::getenv(L"ALSOFT_LOCAL_PATH"))
370 {
371 path = wstr_to_utf8(localpath->c_str());
372 if(is_slash(path.back()))
373 path.pop_back();
374 }
375 else if(WCHAR *cwdbuf{_wgetcwd(nullptr, 0)})
376 {
377 path = wstr_to_utf8(cwdbuf);
378 if(is_slash(path.back()))
379 path.pop_back();
380 free(cwdbuf);
381 }
382 else
383 path = ".";
384 std::replace(path.begin(), path.end(), '/', '\\');
385 DirectorySearch(path.c_str(), ext, &results);
386
387 /* Search the local and global data dirs. */
388 static const int ids[2]{ CSIDL_APPDATA, CSIDL_COMMON_APPDATA };
389 for(int id : ids)
390 {
391 WCHAR buffer[MAX_PATH];
392 if(SHGetSpecialFolderPathW(nullptr, buffer, id, FALSE) == FALSE)
393 continue;
394
395 path = wstr_to_utf8(buffer);
396 if(!is_slash(path.back()))
397 path += '\\';
398 path += subdir;
399 std::replace(path.begin(), path.end(), '/', '\\');
400
401 DirectorySearch(path.c_str(), ext, &results);
402 }
403

Callers 1

EnumerateHrtfFunction · 0.85

Calls 15

is_slashFunction · 0.85
DirectorySearchFunction · 0.85
wstr_to_utf8Function · 0.85
value_orMethod · 0.80
substrMethod · 0.80
getenvFunction · 0.50
freeFunction · 0.50
getcwdFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
c_strMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected