]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Apply GetBestLanguage() in UefiLib to get the driver name from Component Name (2...
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 24 Mar 2009 15:41:50 +0000 (15:41 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 24 Mar 2009 15:41:50 +0000 (15:41 +0000)
RFC 4646 & ISO 639-2 Language are not supposed to be mixed.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7940 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c
MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.inf

index 3fe9cb28fd7e62ab38973e013a84e3390754c7c4..aa110226f1f7bb96971f54330acb032a0b331e96 100644 (file)
@@ -39,8 +39,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/DevicePathToText.h>\r
 #include <Protocol/DevicePath.h>\r
 \r
-#include <Guid/GlobalVariable.h>\r
-\r
 #include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/UefiLib.h>\r
@@ -53,7 +51,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/ExtendedIfrSupportLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/DevicePathLib.h>\r
 #include "PlatOverMngr.h"\r
 \r
@@ -93,7 +90,6 @@ EFI_LOADED_IMAGE_PROTOCOL    *mDriverImageProtocol[MAX_CHOICE_NUM];
 EFI_DEVICE_PATH_PROTOCOL     *mControllerDevicePathProtocol[MAX_CHOICE_NUM];\r
 UINTN                        mSelectedDriverImageNum;\r
 UINTN                        mLastSavedDriverImageNum;\r
-CHAR8                        mLanguage[RFC_3066_ENTRY_SIZE];\r
 UINT16                       mCurrentPage;\r
 \r
 /**\r
@@ -113,55 +109,71 @@ DevicePathToStr (
   );\r
 \r
 /**\r
-  Do string convertion for the ComponentName supported language. It do\r
-  the convertion just for english language code from RFC 3066 to ISO 639-2.\r
-  Then it will check whether the converted language is in the supported language list.\r
-  If not supported, NULL is returned.\r
-  If Language is not english, NULL is returned.\r
+  Worker function to get the driver name by ComponentName or ComponentName2 protocol \r
+  according to the driver binding handle.\r
 \r
-  @param SupportedLanguages        Pointer to ComponentName supported language string list. ISO 639-2 language\r
-  @param Language                  The language string. RFC 3066 language\r
+  @param  DriverBindingHandle  The Handle of DriverBinding.\r
+  @param  ProtocolGuid         The pointer to Component Name (2) protocol GUID.\r
+  @param  VariableName         The name of the RFC 4646 or ISO 639-2 language variable.\r
 \r
-  @return  English language string (ISO 639-2)\r
-  @return  NULL if the conertion is not successful.\r
+  @retval !NULL               Pointer into the image name if the image name is found,\r
+  @retval NULL                Pointer to NULL if the image name is not found.\r
 \r
 **/\r
-CHAR8 *\r
-ConvertComponentNameSupportLanguage (\r
-  IN CHAR8                           *SupportedLanguages,\r
-  IN CHAR8                           *Language\r
+CHAR16 *\r
+GetComponentNameWorker (\r
+  IN EFI_HANDLE                      DriverBindingHandle,\r
+  IN EFI_GUID                        *ProtocolGuid,\r
+  IN CONST CHAR16                    *VariableName\r
   )\r
 {\r
-  CHAR8    *LangCode;\r
-  LangCode = NULL;\r
+  EFI_STATUS                         Status;\r
+  EFI_COMPONENT_NAME_PROTOCOL        *ComponentName;\r
+  CHAR16                             *DriverName;\r
+  CHAR8                              *Language;\r
+  CHAR8                              *BestLanguage;\r
 \r
-  //\r
-  // Check the input language is English\r
-  //\r
-  if (AsciiStrnCmp (Language, "en-", 3) != 0) {\r
+  Status = gBS->OpenProtocol (\r
+                  DriverBindingHandle,\r
+                  ProtocolGuid,\r
+                  (VOID *) &ComponentName,\r
+                  NULL,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
-  \r
+\r
   //\r
-  // Check SupportedLanguages format\r
+  // Find the best matching language.\r
   //\r
-  if (AsciiStrStr (SupportedLanguages, "en-") != NULL) {\r
-    //\r
-    // Create RFC 3066 language\r
-    //\r
-    LangCode = AllocateZeroPool(AsciiStrSize (Language));\r
-    AsciiStrCpy (LangCode, Language);\r
-  } else if (AsciiStrStr (SupportedLanguages, "en") != NULL) {\r
-    //\r
-    // Create ISO 639-2 Language\r
-    //\r
-    LangCode = AllocateZeroPool(4);\r
-    AsciiStrCpy (LangCode, "eng");    \r
+  Language = GetEfiGlobalVariable (VariableName);\r
+  BestLanguage = GetBestLanguage (\r
+                   ComponentName->SupportedLanguages,\r
+                   (BOOLEAN) (ProtocolGuid == &gEfiComponentNameProtocolGuid),\r
+                   Language,\r
+                   NULL\r
+                   );\r
+\r
+  DriverName = NULL;\r
+  if (BestLanguage != NULL) {\r
+    ComponentName->GetDriverName (\r
+                     ComponentName,\r
+                     BestLanguage,\r
+                     &DriverName\r
+                     );\r
+    FreePool (BestLanguage);\r
   }\r
-  \r
-  return LangCode;\r
+\r
+  if (Language != NULL) {\r
+    FreePool (Language);\r
+  }\r
+\r
+  return DriverName;\r
 }\r
 \r
+\r
 /**\r
   Get the driver name by ComponentName or ComponentName2 protocol \r
   according to the driver binding handle\r
@@ -177,59 +189,17 @@ GetComponentName (
   IN EFI_HANDLE                      DriverBindingHandle\r
   )\r
 {\r
-  EFI_STATUS                   Status;\r
-  EFI_COMPONENT_NAME_PROTOCOL  *ComponentName;\r
-  EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;\r
-  CHAR8                        *SupportedLanguage;\r
-  CHAR16                       *DriverName;\r
-\r
-  ComponentName  = NULL;\r
-  ComponentName2 = NULL;\r
-  Status = gBS->OpenProtocol (\r
-                 DriverBindingHandle,\r
-                 &gEfiComponentName2ProtocolGuid,\r
-                 (VOID **) &ComponentName2,\r
-                 NULL,\r
-                 NULL,\r
-                 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                 );\r
-  if (EFI_ERROR(Status)) {\r
-    Status = gBS->OpenProtocol (\r
-                   DriverBindingHandle,\r
-                   &gEfiComponentNameProtocolGuid,\r
-                   (VOID **) &ComponentName,\r
-                   NULL,\r
-                   NULL,\r
-                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                   );\r
-  }\r
-\r
-  Status     = EFI_SUCCESS;\r
-  DriverName = NULL;\r
-  if (ComponentName != NULL) {\r
-    if (ComponentName->GetDriverName != NULL) {\r
-      SupportedLanguage = ConvertComponentNameSupportLanguage (ComponentName->SupportedLanguages, mLanguage);\r
-      if (SupportedLanguage != NULL) {\r
-        Status = ComponentName->GetDriverName (\r
-                                  ComponentName,\r
-                                  SupportedLanguage,\r
-                                  &DriverName\r
-                                  );\r
-        FreePool (SupportedLanguage);\r
-      }\r
-    }\r
-  } else if (ComponentName2 != NULL) {\r
-    if (ComponentName2->GetDriverName != NULL) {\r
-      Status = ComponentName2->GetDriverName (\r
-                                 ComponentName2,\r
-                                 mLanguage,\r
-                                 &DriverName\r
-                                 );\r
-    }\r
-  }\r
+  CHAR16                    *DriverName;\r
 \r
-  if (EFI_ERROR (Status)) {\r
-    return NULL;\r
+  //\r
+  // Try RFC 4646 Component Name 2 protocol first.\r
+  //\r
+  DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentName2ProtocolGuid, L"PlatformLang");\r
+  if (DriverName == NULL) {\r
+    //\r
+    // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol. \r
+    //\r
+    DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentNameProtocolGuid, L"Lang");\r
   }\r
 \r
   return DriverName;\r
@@ -237,7 +207,7 @@ GetComponentName (
 \r
 /**\r
   Get the image name from EFI UI section.\r
-  Get FV protocol by its loaded image protoocl to abastract EFI UI section.\r
+  Get FV protocol by its loaded image protocol to abstract EFI UI section.\r
 \r
   @param Image            Pointer to the loaded image protocol\r
 \r
@@ -340,7 +310,6 @@ UpdateDeviceSelectPage (
 {\r
   EFI_HII_UPDATE_DATA                       UpdateData;\r
   EFI_STATUS                                Status;\r
-  UINTN                                     LangSize;\r
   UINTN                                     Index;\r
   UINTN                                     DevicePathHandleCount;\r
   CHAR16                                    *NewString;\r
@@ -356,19 +325,6 @@ UpdateDeviceSelectPage (
   //\r
   mCurrentPage = FORM_ID_DEVICE;  \r
   \r
-  //\r
-  // Get Platform supported Language (RFC_3066 format)\r
-  //\r
-  LangSize = RFC_3066_ENTRY_SIZE;\r
-  Status = gRT->GetVariable (\r
-              L"PlatformLang",\r
-              &gEfiGlobalVariableGuid,\r
-              NULL,\r
-              &LangSize,\r
-              mLanguage\r
-              );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   //\r
   // Initial the mapping database in memory\r
   //\r
index 8be683a0c3960423c0988f2bb5025157ebf07be8..8d22f62b4b90bdf11b816af96a990975602b585c 100644 (file)
   ExtendedIfrSupportLib\r
   BaseMemoryLib\r
   MemoryAllocationLib\r
-  UefiRuntimeServicesTableLib\r
   DevicePathLib\r
   \r
 [Guids]\r
-  gEfiGlobalVariableGuid                        ## CONSUMED ## Variable:L"PlatformLang" this variable specifies the platform supported language string (RFC 3066 format)\r
+##  This GUID C Name is not required for build since it is from UefiLib and not directly used by this module source.\r
+##  gEfiGlobalVariableGuid                      ## SOMETIMES_CONSUMED ## Variable:L"PlatformLang" this variable specifies the platform supported language string (RFC 4646 format)\r
+##  gEfiGlobalVariableGuid                      ## SOMETIMES_CONSUMED ## Variable:L"Lang" this variable specifies the platform supported language string (ISO 639-2 format)\r
 \r
 [Protocols]\r
   gEfiComponentName2ProtocolGuid                ## SOMETIMES_CONSUMED (Get Driver Name if ComponentName2Protocol exists)\r