Ask user for file path
| 431 | |
| 432 | // Ask user for file path |
| 433 | BOOLEAN AskUserForFilePath(IN CHAR16 *Title OPTIONAL, IN EFI_DEVICE_PATH_PROTOCOL *Root OPTIONAL, OUT EFI_DEVICE_PATH_PROTOCOL **Result) |
| 434 | { |
| 435 | EFI_FILE *Dir = NULL; |
| 436 | if (Result == NULL) { |
| 437 | return FALSE; |
| 438 | } |
| 439 | if (Root != NULL) { |
| 440 | // Get the file path |
| 441 | XStringW DevicePathStr = FileDevicePathToXStringW(Root); |
| 442 | if (DevicePathStr.notEmpty()) { |
| 443 | UINTN Index = 0; |
| 444 | // Check the volumes for a match |
| 445 | for (Index = 0; Index < Volumes.size(); ++Index) { |
| 446 | REFIT_VOLUME *Volume = &Volumes[Index]; |
| 447 | if ((Volume == NULL) || (Volume->RootDir == NULL) || |
| 448 | (Volume->DevicePathString.isEmpty())) { |
| 449 | continue; |
| 450 | } |
| 451 | if (Volume->DevicePathString.length() == 0) { |
| 452 | continue; |
| 453 | } |
| 454 | // If the path begins with this volumes path it matches |
| 455 | if (StrniCmp(DevicePathStr.wc_str(), Volume->DevicePathString.wc_str(), Volume->DevicePathString.length())) { |
| 456 | // Need to |
| 457 | CHAR16 *FilePath = DevicePathStr.data(Volume->DevicePathString.length()); |
| 458 | UINTN FileLength = StrLen(FilePath); |
| 459 | if (FileLength == 0) { |
| 460 | // If there is no path left then open the root |
| 461 | return AskUserForFilePathFromDir(Title, Volume, NULL, Volume->RootDir, Result); |
| 462 | } else { |
| 463 | // Check to make sure this is directory |
| 464 | if (!EFI_ERROR(Volume->RootDir->Open(Volume->RootDir, &Dir, FilePath, EFI_FILE_MODE_READ, 0)) && |
| 465 | (Dir != NULL)) { |
| 466 | // Get file information |
| 467 | EFI_FILE_INFO *Info = EfiLibFileInfo(Dir); |
| 468 | if (Info != NULL) { |
| 469 | // Check if the file is a directory |
| 470 | if ((Info->Attribute & EFI_FILE_DIRECTORY) == 0) { |
| 471 | // Return the passed device path if it is a file |
| 472 | FreePool(Info); |
| 473 | Dir->Close(Dir); |
| 474 | *Result = Root; |
| 475 | return TRUE; |
| 476 | } else { |
| 477 | // Ask user other wise |
| 478 | BOOLEAN Success = AskUserForFilePathFromDir(Title, Volume, FilePath, Dir, Result); |
| 479 | FreePool(Info); |
| 480 | Dir->Close(Dir); |
| 481 | return Success; |
| 482 | } |
| 483 | //FreePool(Info); |
| 484 | } |
| 485 | Dir->Close(Dir); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | } |
nothing calls this directly
no test coverage detected