refactor(developer): km_core_keyboard_load_from_blob in debugger

Replaces `km_core_keyboard_load` with `km_core_keyboard_load_from_blob`.

Fixes: #12690
Cherry-pick: #12711
This commit is contained in:
Marc Durdin 2024-11-27 08:56:50 +07:00 committed by Eberhard Beilharz
parent 8492b12fdb
commit 249428db7b
No known key found for this signature in database
GPG key ID: E9140597606020D3
2 changed files with 26 additions and 3 deletions

View file

@ -37,6 +37,8 @@ type
implementation
uses
System.Classes,
KeymanPaths;
{ TDebugCore }
@ -44,6 +46,9 @@ uses
constructor TDebugCore.Create(const Filename: string; EnableDebug: Boolean);
var
status: km_core_status;
fs: TFileStream;
Buffer: Pointer;
BufferSize: NativeInt;
begin
inherited Create;
@ -52,7 +57,23 @@ begin
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)]);

View file

@ -245,8 +245,10 @@ type
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;