Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(windows): keyboard load blob 🎼 #12684

Draft
wants to merge 1 commit into
base: epic/web-core
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions windows/src/engine/keyman32/K32_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

#include "pch.h"
#include <stdio.h>

BOOL GetKeyboardFileName(LPSTR kbname, LPSTR buf, int nbuf)
{
Expand Down Expand Up @@ -78,13 +79,41 @@ BOOL LoadlpKeyboard(int i)
_td->lpKeyboards[i].lpCoreKeyboardState = NULL;
}

char buf[256];
if (!GetKeyboardFileName(_td->lpKeyboards[i].Name, buf, 255)) {
char kmx_filename[256];
if (!GetKeyboardFileName(_td->lpKeyboards[i].Name, kmx_filename, 255)) {
return_SendDebugExit(FALSE);
}

PWCHAR keyboardPath = strtowstr(buf);
km_core_status err_status = km_core_keyboard_load(keyboardPath, &_td->lpKeyboards[i].lpCoreKeyboard);
FILE* kmx_file;
errno_t status = fopen_s(&kmx_file, kmx_filename, "rb");
if (!status) {
SendDebugMessageFormat("Problem reading opening kmx_file %s status [%d].", kmx_filename, status);
return_SendDebugExit(FALSE);
}

fseek(kmx_file, 0, SEEK_END);
size_t length = ftell(kmx_file);
fseek(kmx_file, 0, SEEK_SET);
void* buffer = malloc(length);

if (!buffer) {
fclose(kmx_file);
return_SendDebugExit(FALSE);
}

if (fread(buffer, 1, length, kmx_file) != length) {
SendDebugMessageFormat("Problem reading entire kmx_file %s.", kmx_filename);
fclose(kmx_file);
free(buffer);
return_SendDebugExit(FALSE);
}

fclose(kmx_file);
PWCHAR keyboardPath = strtowstr(kmx_filename);
km_core_status err_status = km_core_keyboard_load_from_blob(keyboardPath, buffer, length, &_td->lpKeyboards[i].lpCoreKeyboard);

free(buffer);

if (err_status != KM_CORE_STATUS_OK) {
SendDebugMessageFormat("km_core_keyboard_load failed for %ls with error status [%d]", keyboardPath, err_status);
delete[] keyboardPath;
Expand Down
Loading