| 344 | } |
| 345 | |
| 346 | al::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 |
no test coverage detected