diff options
author | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2009-03-27 03:21:37 +0000 |
---|---|---|
committer | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2009-03-27 03:21:37 +0000 |
commit | a3a795afdb9d8efd8e6603cce92103d610346b78 (patch) | |
tree | 63da744bf7df2922e6fa782248daecb9931b5448 /IntelFrameworkModulePkg/Universal | |
parent | bda1bdbbf0a4d2a8c139563794dc7e451dfe3b8a (diff) | |
download | edk2-platforms-a3a795afdb9d8efd8e6603cce92103d610346b78.tar.xz |
Apply GetBestLanguage() API in UEFI
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7963 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'IntelFrameworkModulePkg/Universal')
-rw-r--r-- | IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c | 116 |
1 files changed, 85 insertions, 31 deletions
diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c index fb605d57d9..29974769bb 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c @@ -129,10 +129,12 @@ FrontPageCallback ( {
CHAR8 *LanguageString;
CHAR8 *LangCode;
- CHAR8 Lang[RFC_3066_ENTRY_SIZE];
+ CHAR8 *Lang;
CHAR8 OldLang[ISO_639_2_ENTRY_SIZE];
UINTN Index;
EFI_STATUS Status;
+ CHAR8 *PlatformSupportedLanguages;
+ CHAR8 *BestLanguage;
if ((Value == NULL) || (ActionRequest == NULL)) {
return EFI_INVALID_PARAMETER;
@@ -158,7 +160,12 @@ FrontPageCallback ( //
LanguageString = HiiLibGetSupportedLanguages (gFrontPagePrivate.HiiHandle);
ASSERT (LanguageString != NULL);
-
+ //
+ // Allocate working buffer for RFC 4646 language in supported LanguageString.
+ //
+ Lang = AllocatePool (AsciiStrSize (LanguageString));
+ ASSERT (Lang != NULL);
+
Index = 0;
LangCode = LanguageString;
while (*LangCode != 0) {
@@ -171,30 +178,53 @@ FrontPageCallback ( Index++;
}
- Status = gRT->SetVariable (
- L"PlatformLang",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- AsciiStrSize (Lang),
- Lang
- );
-
- if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
- //
- // Set UEFI deprecated variable "Lang" for backwards compatibility
- //
- Status = ConvertRfc3066LanguageToIso639Language (Lang, OldLang);
- if (!EFI_ERROR (Status)) {
- Status = gRT->SetVariable (
- L"Lang",
- &gEfiGlobalVariableGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- ISO_639_2_ENTRY_SIZE,
- OldLang
- );
+ PlatformSupportedLanguages = GetEfiGlobalVariable (L"PlatformLangCodes");
+ if (PlatformSupportedLanguages == NULL) {
+ PlatformSupportedLanguages = AllocateCopyPool (
+ AsciiStrSize ((CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)),
+ (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)
+ );
+ ASSERT (PlatformSupportedLanguages != NULL);
+ }
+
+ //
+ // Select the best language in platform supported Language.
+ //
+ BestLanguage = GetBestLanguage (
+ PlatformSupportedLanguages,
+ FALSE,
+ Lang,
+ NULL
+ );
+ if (BestLanguage != NULL) {
+ Status = gRT->SetVariable (
+ L"PlatformLang",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ AsciiStrSize (BestLanguage),
+ Lang
+ );
+
+ if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
+ //
+ // Set UEFI deprecated variable "Lang" for backwards compatibility
+ //
+ Status = ConvertRfc3066LanguageToIso639Language (BestLanguage, OldLang);
+ if (!EFI_ERROR (Status)) {
+ Status = gRT->SetVariable (
+ L"Lang",
+ &gEfiGlobalVariableGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ ISO_639_2_ENTRY_SIZE,
+ OldLang
+ );
+ }
}
+ FreePool (BestLanguage);
}
-
+
+ FreePool (PlatformSupportedLanguages);
+ FreePool (Lang);
FreePool (LanguageString);
break;
@@ -247,8 +277,9 @@ InitializeFrontPage ( IFR_OPTION *OptionList;
CHAR8 *LanguageString;
CHAR8 *LangCode;
- CHAR8 Lang[RFC_3066_ENTRY_SIZE];
- CHAR8 CurrentLang[RFC_3066_ENTRY_SIZE];
+ CHAR8 *Lang;
+ CHAR8 *CurrentLang;
+ CHAR8 *BestLanguage;
UINTN OptionCount;
EFI_STRING_ID Token;
CHAR16 *StringBuffer;
@@ -329,10 +360,6 @@ InitializeFrontPage ( }
}
- //
- // Get current language setting
- //
- GetCurrentLanguage (CurrentLang);
//
// Allocate space for creation of UpdateData Buffer
@@ -350,6 +377,28 @@ InitializeFrontPage ( HiiHandle = gFrontPagePrivate.HiiHandle;
LanguageString = HiiLibGetSupportedLanguages (HiiHandle);
ASSERT (LanguageString != NULL);
+ //
+ // Allocate working buffer for RFC 4646 language in supported LanguageString.
+ //
+ Lang = AllocatePool (AsciiStrSize (LanguageString));
+ ASSERT (Lang != NULL);
+
+ CurrentLang = GetEfiGlobalVariable (L"PlatformLang");
+ //
+ // Select the best language in LanguageString as the default one.
+ //
+ BestLanguage = GetBestLanguage (
+ LanguageString,
+ FALSE,
+ (CurrentLang != NULL) ? CurrentLang : "",
+ (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),
+ LanguageString,
+ NULL
+ );
+ //
+ // BestLanguage must be selected as it is the first language in LanguageString by default
+ //
+ ASSERT (BestLanguage != NULL);
OptionCount = 0;
LangCode = LanguageString;
@@ -394,7 +443,7 @@ InitializeFrontPage ( Token = gFrontPagePrivate.LanguageToken[OptionCount];
}
- if (AsciiStrCmp (Lang, CurrentLang) == 0) {
+ if (AsciiStrCmp (Lang, BestLanguage) == 0) {
OptionList[OptionCount].Flags = EFI_IFR_OPTION_DEFAULT;
} else {
OptionList[OptionCount].Flags = 0;
@@ -405,6 +454,11 @@ InitializeFrontPage ( OptionCount++;
}
+ if (CurrentLang != NULL) {
+ FreePool (CurrentLang);
+ }
+ FreePool (BestLanguage);
+ FreePool (Lang);
FreePool (LanguageString);
UpdateData.Offset = 0;
|