[USETUP] Move loading of requested font from blue.sys to usetup

This commit is contained in:
Hervé Poussineau 2020-04-26 00:23:13 +02:00
parent 04ec14e23e
commit 2391e31cf0

View file

@ -44,6 +44,31 @@ static UINT LastLoadedCodepage;
/* FUNCTIONS *****************************************************************/
typedef struct _CONSOLE_CABINET_CONTEXT
{
CABINET_CONTEXT CabinetContext;
PVOID Data;
ULONG Size;
} CONSOLE_CABINET_CONTEXT, *PCONSOLE_CABINET_CONTEXT;
static PVOID
ConsoleCreateFileHandler(
IN PCABINET_CONTEXT CabinetContext,
IN ULONG FileSize)
{
PCONSOLE_CABINET_CONTEXT ConsoleCabinetContext;
ConsoleCabinetContext = (PCONSOLE_CABINET_CONTEXT)CabinetContext;
ConsoleCabinetContext->Data = RtlAllocateHeap(ProcessHeap, 0, FileSize);
if (!ConsoleCabinetContext->Data)
{
DPRINT("Failed to allocate %d bytes\n", FileSize);
return NULL;
}
ConsoleCabinetContext->Size = FileSize;
return ConsoleCabinetContext->Data;
}
BOOL
WINAPI
AllocConsole(VOID)
@ -667,6 +692,12 @@ WINAPI
SetConsoleOutputCP(
IN UINT wCodepage)
{
WCHAR FontName[100];
WCHAR FontFile[] = L"\\SystemRoot\\vgafonts.cab";
CONSOLE_CABINET_CONTEXT ConsoleCabinetContext;
PCABINET_CONTEXT CabinetContext = &ConsoleCabinetContext.CabinetContext;
CAB_SEARCH Search;
ULONG CabStatus;
HANDLE hConsoleOutput;
IO_STATUS_BLOCK IoStatusBlock;
NTSTATUS Status;
@ -676,14 +707,43 @@ SetConsoleOutputCP(
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
CabinetInitialize(CabinetContext);
CabinetSetEventHandlers(CabinetContext,
NULL, NULL, NULL, ConsoleCreateFileHandler);
CabinetSetCabinetName(CabinetContext, FontFile);
CabStatus = CabinetOpen(CabinetContext);
if (CabStatus != CAB_STATUS_SUCCESS)
{
DPRINT("CabinetOpen('%S') returned 0x%08x\n", FontFile, CabStatus);
return FALSE;
}
swprintf(FontName, L"%u-8x8.bin", wCodepage);
CabStatus = CabinetFindFirst(CabinetContext, FontName, &Search);
if (CabStatus != CAB_STATUS_SUCCESS)
{
DPRINT("CabinetFindFirst('%S', '%S') returned 0x%08x\n", FontFile, FontName, CabStatus);
CabinetClose(CabinetContext);
return FALSE;
}
CabStatus = CabinetExtractFile(CabinetContext, &Search);
CabinetClose(CabinetContext);
if (CabStatus != CAB_STATUS_SUCCESS)
{
DPRINT("CabinetLoadFile('%S', '%S') returned 0x%08x\n", FontFile, FontName, CabStatus);
return FALSE;
}
Status = NtDeviceIoControlFile(hConsoleOutput,
NULL,
NULL,
NULL,
&IoStatusBlock,
IOCTL_CONSOLE_LOADFONT,
&wCodepage,
sizeof(ULONG),
IOCTL_CONSOLE_SETFONT,
ConsoleCabinetContext.Data,
ConsoleCabinetContext.Size,
NULL,
0);
if (!NT_SUCCESS(Status))