diff --git a/Include/Library/OcBootManagementLib.h b/Include/Library/OcBootManagementLib.h index de6c7e15..74b4781f 100755 --- a/Include/Library/OcBootManagementLib.h +++ b/Include/Library/OcBootManagementLib.h @@ -341,7 +341,7 @@ EFI_STATUS /** Exposed custom entry load interface. - Must return allocated file buffer from pool. + Returns allocated file buffer from pool on success. **/ typedef EFI_STATUS @@ -355,6 +355,22 @@ EFI_STATUS OUT EFI_DEVICE_PATH_PROTOCOL **ParentFilePath OPTIONAL ); +/** + Exposed custom entry describe interface. + Return allocated file buffers from pool on success. +**/ +typedef +EFI_STATUS +(EFIAPI *OC_CUSTOM_DESCRIBE) ( + IN VOID *Context, + IN OC_BOOT_ENTRY *ChosenEntry, + IN UINT8 LabelScale OPTIONAL, + OUT VOID **IconData OPTIONAL, + OUT UINT32 *IconDataSize OPTIONAL, + OUT VOID **LabelData OPTIONAL, + OUT UINT32 *LabelDataSize OPTIONAL + ); + /** Custom picker entry. **/ @@ -457,6 +473,10 @@ struct OC_PICKER_CONTEXT_ { // OC_CUSTOM_READ CustomRead; // + // Custom entry describing routine, optional for no custom entries. + // + OC_CUSTOM_DESCRIBE CustomDescribe; + // // Context to pass to CustomRead, optional. // VOID *CustomEntryContext; diff --git a/Platform/OpenCore/OpenCoreMisc.c b/Platform/OpenCore/OpenCoreMisc.c index c6561161..145610e4 100644 --- a/Platform/OpenCore/OpenCoreMisc.c +++ b/Platform/OpenCore/OpenCoreMisc.c @@ -100,7 +100,7 @@ OcToolLoadEntry ( DEBUG_ERROR, "OC: Tool %s%s does not fit path!\n", OPEN_CORE_TOOL_PATH, - ToolPath + ChosenEntry->PathName )); return EFI_NOT_FOUND; } @@ -136,6 +136,96 @@ OcToolLoadEntry ( return EFI_SUCCESS; } +STATIC +EFI_STATUS +EFIAPI +OcToolDescribeEntry ( + IN VOID *Context, + IN OC_BOOT_ENTRY *ChosenEntry, + IN UINT8 LabelScale OPTIONAL, + OUT VOID **IconData OPTIONAL, + OUT UINT32 *IconDataSize OPTIONAL, + OUT VOID **LabelData OPTIONAL, + OUT UINT32 *LabelDataSize OPTIONAL + ) +{ + EFI_STATUS Status; + CHAR16 DescPath[OC_STORAGE_SAFE_PATH_MAX]; + OC_STORAGE_CONTEXT *Storage; + BOOLEAN HasIcon; + BOOLEAN HasLabel; + + Storage = (OC_STORAGE_CONTEXT *) Context; + HasIcon = FALSE; + HasLabel = FALSE; + + if (IconData != NULL && IconDataSize != NULL) { + *IconData = NULL; + *IconDataSize = 0; + + Status = OcUnicodeSafeSPrint ( + DescPath, + sizeof (DescPath), + OPEN_CORE_TOOL_PATH "%s.icns", + ChosenEntry->PathName + ); + if (!EFI_ERROR (Status)) { + if (OcStorageExistsFileUnicode (Context, DescPath)) { + *IconData = OcStorageReadFileUnicode ( + Storage, + DescPath, + IconDataSize + ); + HasIcon = *IconData != NULL; + } + } else { + DEBUG (( + DEBUG_INFO, + "OC: Tool label %s%s.icns does not fit path!\n", + OPEN_CORE_TOOL_PATH, + DescPath + )); + } + } + + if (LabelData != NULL && LabelDataSize != NULL) { + *LabelData = NULL; + *LabelDataSize = 0; + + Status = OcUnicodeSafeSPrint ( + DescPath, + sizeof (DescPath), + OPEN_CORE_TOOL_PATH "%s.lbl%a", + ChosenEntry->PathName, + LabelScale == 2 ? "2x" : "" + ); + if (!EFI_ERROR (Status)) { + if (OcStorageExistsFileUnicode (Context, DescPath)) { + *LabelData = OcStorageReadFileUnicode ( + Storage, + DescPath, + LabelDataSize + ); + HasLabel = *LabelData != NULL; + } + } else { + DEBUG (( + DEBUG_INFO, + "OC: Tool label %s%s.lbl%a does not fit path!\n", + OPEN_CORE_TOOL_PATH, + DescPath, + LabelScale == 2 ? "2x" : "" + )); + } + } + + if (HasIcon || HasLabel) { + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; +} + CONST CHAR8 * OcMiscGetVersionString ( VOID @@ -506,6 +596,7 @@ OcMiscBoot ( Context->ExcludeHandle = LoadHandle; Context->CustomEntryContext = Storage; Context->CustomRead = OcToolLoadEntry; + Context->CustomDescribe = OcToolDescribeEntry; Context->PrivilegeContext = Privilege; Context->RequestPrivilege = OcShowSimplePasswordRequest; Context->ShowMenu = OcShowSimpleBootMenu;