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

refactor(developer): km_core_keyboard_load_from_blob in debugger 🎼 #12711

Merged
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ TDebugCore = class
implementation

uses
System.Classes,

KeymanPaths;

{ TDebugCore }

constructor TDebugCore.Create(const Filename: string; EnableDebug: Boolean);
var
status: km_core_status;
fs: TFileStream;
Buffer: Pointer;
BufferSize: NativeInt;
begin
inherited Create;

Expand All @@ -52,7 +57,23 @@ constructor TDebugCore.Create(const Filename: string; EnableDebug: Boolean);
FKeyboard := nil;
FState := nil;

status := km_core_keyboard_load(PChar(FileName), FKeyboard);
Buffer := nil;
try
fs := TFileStream.Create(Filename, fmOpenRead or fmShareDenyWrite);
try
BufferSize := fs.Size;
Buffer := AllocMem(BufferSize);
if fs.Read(Buffer^, BufferSize) <> BufferSize then
raise EDebugCore.Create('Unable to start debugger -- failed to read file from disk');
finally
fs.Free;
end;

status := km_core_keyboard_load_from_blob(PChar(FileName), Buffer, BufferSize, FKeyboard);
finally
FreeMem(Buffer);
end;

if status <> KM_CORE_STATUS_OK then
raise EDebugCore.CreateFmt('Unable to start debugger -- keyboard load failed with error %x', [Ord(status)]);

Expand Down
6 changes: 4 additions & 2 deletions developer/src/tike/main/Keyman.System.KeymanCore.pas
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ km_core_keyboard_attrs = record

pkm_core_keyboard_attrs = ^km_core_keyboard_attrs;

function km_core_keyboard_load(
kb_path: km_core_path_name;
function km_core_keyboard_load_from_blob(
kb_name: km_core_path_name;
blob: Pointer;
blob_size: NativeUint;
var keyboard: pkm_core_keyboard
): km_core_status; cdecl; external keymancore delayed;

Expand Down