From 905ebbbf91f2923612ae4d85b9f440e1955c8837 Mon Sep 17 00:00:00 2001 From: Konstantin Aladyshev Date: Tue, 9 Nov 2021 18:25:39 +0300 Subject: Add lesson 55 Signed-off-by: Konstantin Aladyshev --- UefiLessonsPkg/AddNewLanguage/AddNewLanguage.c | 71 ++++++++++++++++++++++++ UefiLessonsPkg/AddNewLanguage/AddNewLanguage.inf | 27 +++++++++ 2 files changed, 98 insertions(+) create mode 100644 UefiLessonsPkg/AddNewLanguage/AddNewLanguage.c create mode 100644 UefiLessonsPkg/AddNewLanguage/AddNewLanguage.inf (limited to 'UefiLessonsPkg/AddNewLanguage') 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 + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include +#include +#include +#include + + +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 +# +# 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 -- cgit v1.2.3-18-g5258