2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "InternalHiiLib.h"
19 This function create a new string in String Package or updates an existing
20 string in a String Package. If StringId is 0, then a new string is added to
21 a String Package. If StringId is not zero, then a string in String Package is
22 updated. If SupportedLanguages is NULL, then the string is added or updated
23 for all the languages that the String Package supports. If SupportedLanguages
24 is not NULL, then the string is added or updated for the set of languages
25 specified by SupportedLanguages.
27 If HiiHandle is NULL, then ASSERT().
28 If String is NULL, then ASSERT().
30 @param[in] HiiHandle A handle that was previously registered in the
32 @param[in] StringId If zero, then a new string is created in the
33 String Package associated with HiiHandle. If
34 non-zero, then the string specified by StringId
35 is updated in the String Package associated
37 @param[in] String A pointer to the Null-terminated Unicode string
38 to add or update in the String Package associated
40 @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string of
41 language codes. If this parameter is NULL, then
42 String is added or updated in the String Package
43 associated with HiiHandle for all the languages
44 that the String Package supports. If this
45 parameter is not NULL, then then String is added
46 or updated in the String Package associated with
47 HiiHandle for the set oflanguages specified by
48 SupportedLanguages. The format of
49 SupportedLanguages must follow the language
50 format assumed the HII Database.
52 @retval 0 The string could not be added or updated in the String Package.
53 @retval Other The EFI_STRING_ID of the newly added or updated string.
59 IN EFI_HII_HANDLE HiiHandle
,
60 IN EFI_STRING_ID StringId
, OPTIONAL
61 IN CONST EFI_STRING String
,
62 IN CONST CHAR8
*SupportedLanguages OPTIONAL
66 CHAR8
*AllocatedLanguages
;
70 ASSERT (HiiHandle
!= NULL
);
71 ASSERT (String
!= NULL
);
73 if (SupportedLanguages
== NULL
) {
75 // Retrieve the languages that the package specified by HiiHandle supports
77 AllocatedLanguages
= HiiGetSupportedLanguages (HiiHandle
);
80 // Allocate a copy of the SupportLanguages string that passed in
82 AllocatedLanguages
= AllocateCopyPool (AsciiStrSize (SupportedLanguages
), SupportedLanguages
);
86 // If there are not enough resources for the supported languages string, then return a StringId of 0
88 if (AllocatedLanguages
== NULL
) {
89 return (EFI_STRING_ID
)(0);
92 Status
= EFI_INVALID_PARAMETER
;
94 // Loop through each language that the string supports
96 for (Supported
= AllocatedLanguages
; *Supported
!= '\0'; ) {
98 // Cache a pointer to the beginning of the current language in the list of languages
100 Language
= Supported
;
103 // Search for the next language seperator and replace it with a Null-terminator
105 for (; *Supported
!= 0 && *Supported
!= ';'; Supported
++);
106 if (*Supported
!= 0) {
107 *(Supported
++) = '\0';
111 // If StringId is 0, then call NewString(). Otherwise, call SetString()
113 if (StringId
== (EFI_STRING_ID
)(0)) {
114 Status
= gHiiString
->NewString (gHiiString
, HiiHandle
, &StringId
, Language
, NULL
, String
, NULL
);
116 Status
= gHiiString
->SetString (gHiiString
, HiiHandle
, StringId
, Language
, String
, NULL
);
120 // If there was an error, then break out of the loop and return a StringId of 0
122 if (EFI_ERROR (Status
)) {
128 // Free the buffer of supported languages
130 FreePool (AllocatedLanguages
);
132 if (EFI_ERROR (Status
)) {
133 return (EFI_STRING_ID
)(0);
141 Retrieves a string from a string package names by GUID in a specific language.
142 If the language is not specified, then a string from a string package in the
143 current platform language is retrieved. If the string can not be retrieved
144 using the specified language or the current platform language, then the string
145 is retrieved from the string package in the first language the string package
146 supports. The returned string is allocated using AllocatePool(). The caller
147 is responsible for freeing the allocated buffer using FreePool().
149 If PackageListGuid is NULL, then ASSERT().
150 If StringId is 0, then ASSERT.
152 @param[in] PackageListGuid The GUID of a package list that was previously
153 registered in the HII Database.
154 @param[in] StringId The identifier of the string to retrieved from the
155 string package associated with PackageListGuid.
156 @param[in] Language The language of the string to retrieve. If this
157 parameter is NULL, then the current platform
158 language is used. The format of Language must
159 follow the language format assumed the HII Database.
161 @retval NULL The package list specified by PackageListGuid is not present in the
163 @retval NULL The string specified by StringId is not present in the string package.
164 @retval Other The string was returned.
169 HiiGetPackageString (
170 IN CONST EFI_GUID
*PackageListGuid
,
171 IN EFI_STRING_ID StringId
,
172 IN CONST CHAR8
*Language OPTIONAL
175 EFI_HANDLE
*HiiHandleBuffer
;
176 EFI_HANDLE HiiHandle
;
178 ASSERT (PackageListGuid
!= NULL
);
180 HiiHandleBuffer
= HiiGetHiiHandles (PackageListGuid
);
181 if (HiiHandleBuffer
== NULL
) {
185 HiiHandle
= HiiHandleBuffer
[0];
186 FreePool (HiiHandleBuffer
);
188 return HiiGetString (HiiHandle
, StringId
, Language
);
192 Retrieves a string from a string package in a specific language. If the language
193 is not specified, then a string from a string package in the current platform
194 language is retrieved. If the string can not be retrieved using the specified
195 language or the current platform language, then the string is retrieved from
196 the string package in the first language the string package supports. The
197 returned string is allocated using AllocatePool(). The caller is responsible
198 for freeing the allocated buffer using FreePool().
200 If HiiHandle is NULL, then ASSERT().
201 If StringId is 0, then ASSET.
203 @param[in] HiiHandle A handle that was previously registered in the HII Database.
204 @param[in] StringId The identifier of the string to retrieved from the string
205 package associated with HiiHandle.
206 @param[in] Language The language of the string to retrieve. If this parameter
207 is NULL, then the current platform language is used. The
208 format of Language must follow the language format assumed
211 @retval NULL The string specified by StringId is not present in the string package.
212 @retval Other The string was returned.
218 IN EFI_HII_HANDLE HiiHandle
,
219 IN EFI_STRING_ID StringId
,
220 IN CONST CHAR8
*Language OPTIONAL
227 CHAR8
*SupportedLanguages
;
228 CHAR8
*PlatformLanguage
;
231 ASSERT (HiiHandle
!= NULL
);
232 ASSERT (StringId
!= 0);
235 // Initialize all allocated buffers to NULL
237 SupportedLanguages
= NULL
;
238 PlatformLanguage
= NULL
;
243 // Get the languages that the package specified by HiiHandle supports
245 SupportedLanguages
= HiiGetSupportedLanguages (HiiHandle
);
246 if (SupportedLanguages
== NULL
) {
251 // Get the current platform language setting
253 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&PlatformLanguage
, NULL
);
256 // If Languag is NULL, then set it to an empty string, so it will be
257 // skipped by GetBestLanguage()
259 if (Language
== NULL
) {
264 // Get the best matching language from SupportedLanguages
266 BestLanguage
= GetBestLanguage (
268 FALSE
, // RFC 4646 mode
269 Language
, // Highest priority
270 PlatformLanguage
!= NULL
? PlatformLanguage
: "", // Next highest priority
271 SupportedLanguages
, // Lowest priority
274 if (BestLanguage
== NULL
) {
279 // Retrieve the size of the string in the string package for the BestLanguage
282 Status
= gHiiString
->GetString (
292 // If GetString() returns EFI_SUCCESS for a zero size,
293 // then there are no supported languages registered for HiiHandle. If GetString()
294 // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present
295 // in the HII Database
297 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
302 // Allocate a buffer for the return string
304 String
= AllocateZeroPool (StringSize
);
305 if (String
== NULL
) {
310 // Retrieve the string from the string package
312 Status
= gHiiString
->GetString (
321 if (EFI_ERROR (Status
)) {
323 // Free the buffer and return NULL if the supported languages can not be retrieved.
331 // Free allocated buffers
333 if (SupportedLanguages
!= NULL
) {
334 FreePool (SupportedLanguages
);
336 if (PlatformLanguage
!= NULL
) {
337 FreePool (PlatformLanguage
);
339 if (BestLanguage
!= NULL
) {
340 FreePool (BestLanguage
);
344 // Return the Null-terminated Unicode string