ShellPkg/CommandLib: Locate proper UnicodeCollation instance

Original code locates the first UnicodeCollation instance in
DXE Core protocol database.
It's not correct considering multiple UnicodeCollation instances
exist in system.
The patch changes logic to find the one that matches the current
system language.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com.
This commit is contained in:
Ruiyu Ni 2018-01-26 16:41:37 +08:00
parent 41a9c3fd11
commit d65f2cea36
2 changed files with 69 additions and 14 deletions

View File

@ -1,7 +1,7 @@
/** @file
Provides interface to shell internal functions for shell commands.
Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
@ -72,14 +72,70 @@ CommandInit(
VOID
)
{
UINTN NumHandles;
EFI_HANDLE *Handles;
EFI_UNICODE_COLLATION_PROTOCOL *Uc;
CHAR8 *BestLanguage;
UINTN Index;
EFI_STATUS Status;
CHAR8 *PlatformLang;
GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);
if (PlatformLang == NULL) {
return EFI_UNSUPPORTED;
}
if (gUnicodeCollation == NULL) {
Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);
if (EFI_ERROR(Status)) {
return (EFI_DEVICE_ERROR);
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiUnicodeCollation2ProtocolGuid,
NULL,
&NumHandles,
&Handles
);
if (EFI_ERROR (Status)) {
NumHandles = 0;
Handles = NULL;
}
for (Index = 0; Index < NumHandles; Index++) {
//
// Open Unicode Collation Protocol
//
Status = gBS->OpenProtocol (
Handles[Index],
&gEfiUnicodeCollation2ProtocolGuid,
(VOID **) &Uc,
gImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
continue;
}
//
// Find the best matching matching language from the supported languages
// of Unicode Collation2 protocol.
//
BestLanguage = GetBestLanguage (
Uc->SupportedLanguages,
FALSE,
PlatformLang,
NULL
);
if (BestLanguage != NULL) {
FreePool (BestLanguage);
gUnicodeCollation = Uc;
break;
}
}
return (EFI_SUCCESS);
if (Handles != NULL) {
FreePool (Handles);
}
FreePool (PlatformLang);
}
return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;
}
/**
@ -112,11 +168,9 @@ ShellCommandLibConstructor (
mProfileListSize = 0;
mProfileList = NULL;
if (gUnicodeCollation == NULL) {
Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);
if (EFI_ERROR(Status)) {
return (EFI_DEVICE_ERROR);
}
Status = CommandInit ();
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
return (RETURN_SUCCESS);

View File

@ -1,7 +1,7 @@
/** @file
Provides interface to shell internal functions for shell commands.
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@ -19,6 +19,7 @@
#include <Uefi.h>
#include <Guid/FileInfo.h>
#include <Guid/GlobalVariable.h>
#include <Protocol/SimpleFileSystem.h>
#include <Protocol/LoadedImage.h>