diff options
author | Konstantin Aladyshev <aladyshev22@gmail.com> | 2021-11-09 18:25:39 +0300 |
---|---|---|
committer | Konstantin Aladyshev <aladyshev22@gmail.com> | 2021-11-09 18:25:39 +0300 |
commit | 905ebbbf91f2923612ae4d85b9f440e1955c8837 (patch) | |
tree | 8721e253ad4e428116a77a3b647dd0fa65719884 /UefiLessonsPkg/AddNewLanguage | |
parent | 316faf0520a407572138e31875a9276293613601 (diff) | |
download | UEFI-Lessons-905ebbbf91f2923612ae4d85b9f440e1955c8837.tar.gz UEFI-Lessons-905ebbbf91f2923612ae4d85b9f440e1955c8837.tar.bz2 UEFI-Lessons-905ebbbf91f2923612ae4d85b9f440e1955c8837.zip |
Add lesson 55
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'UefiLessonsPkg/AddNewLanguage')
-rw-r--r-- | UefiLessonsPkg/AddNewLanguage/AddNewLanguage.c | 71 | ||||
-rw-r--r-- | UefiLessonsPkg/AddNewLanguage/AddNewLanguage.inf | 27 |
2 files changed, 98 insertions, 0 deletions
diff --git a/UefiLessonsPkg/AddNewLanguage/AddNewLanguage.c b/UefiLessonsPkg/AddNewLanguage/AddNewLanguage.c new file mode 100644 index 0000000..cd4920d --- /dev/null +++ b/UefiLessonsPkg/AddNewLanguage/AddNewLanguage.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com> + * + * SPDX-License-Identifier: MIT + */ + +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> + +#include <Library/MemoryAllocationLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Protocol/VariablePolicy.h> + + +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + CHAR8* LanguageString; + Status = GetEfiGlobalVariable2(L"PlatformLangCodes", (VOID**)&LanguageString, NULL); + if (EFI_ERROR(Status)) { + Print(L"Error! Can't perform GetEfiGlobalVariable2, status=%r\n", Status); + return Status; + } + Print(L"Current value of the 'PlatformLangCodes' variable is '%a'\n", LanguageString); + + CHAR8* NewLanguageString = AllocatePool(AsciiStrLen(LanguageString) + AsciiStrSize(";ru-RU")); + if (NewLanguageString == NULL) { + Print(L"Error! Can't allocate size for new PlatformLangCodes variable\n"); + FreePool(LanguageString); + return EFI_OUT_OF_RESOURCES; + } + + CopyMem(NewLanguageString, LanguageString, AsciiStrLen(LanguageString)); + CopyMem(&NewLanguageString[AsciiStrLen(LanguageString)], ";ru-RU", AsciiStrSize(";ru-RU")); + + Print(L"Set 'PlatformLangCodes' variable to '%a'\n", NewLanguageString); + + Status = gRT->SetVariable ( + L"PlatformLangCodes", + &gEfiGlobalVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + AsciiStrSize(NewLanguageString), + NewLanguageString + ); + if (EFI_ERROR(Status)) { + Print(L"Error! Can't set PlatformLangCodes variable, status=%r\n", Status); + } + + EDKII_VARIABLE_POLICY_PROTOCOL* VariablePolicyProtocol; + Status = gBS->LocateProtocol(&gEdkiiVariablePolicyProtocolGuid, + NULL, + (VOID**)&VariablePolicyProtocol); + if (EFI_ERROR(Status)) { + Print(L"Error! Could not find Variable Policy protocol: %r\n", Status); + return Status; + } + Status = VariablePolicyProtocol->DisableVariablePolicy(); + if (EFI_ERROR(Status)) { + Print(L"Error! Can't disable VariablePolicy: %r\n", Status); + return Status; + } + + return EFI_SUCCESS; +} diff --git a/UefiLessonsPkg/AddNewLanguage/AddNewLanguage.inf b/UefiLessonsPkg/AddNewLanguage/AddNewLanguage.inf new file mode 100644 index 0000000..1a34438 --- /dev/null +++ b/UefiLessonsPkg/AddNewLanguage/AddNewLanguage.inf @@ -0,0 +1,27 @@ +## +# Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com> +# +# SPDX-License-Identifier: MIT +## + +[Defines] + INF_VERSION = 1.25 + BASE_NAME = AddNewLanguage + FILE_GUID = 6790e268-0762-4ce8-8999-2ff2131e6512 + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = UefiMain + +[Sources] + AddNewLanguage.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiApplicationEntryPoint + UefiLib + +[Protocols] + gEdkiiVariablePolicyProtocolGuid |