spiegel-keyman/developer/src/tike/project/Keyman.Developer.System.Project.kmnProjectFileAction.pas
Marc Durdin a918cc182f fix(developer): keyboard that targets only web can cause crashes and other problems
Fixes #10655.
Fixes #10663.

If a .kmn file had only a .js target, then Keyman Developer would return
an empty string for the target (based on .kmx). This meant that the path
for the compiler was an empty string, the path for opening the build
folder was an empty string.

Refactored the relevant code to simplify the logic a little.
2024-02-07 13:15:51 +07:00

87 lines
2.1 KiB
ObjectPascal

unit Keyman.Developer.System.Project.kmnProjectFileAction;
interface
uses
System.SysUtils,
Keyman.Developer.System.Project.kmnProjectFile,
Keyman.Developer.System.Project.ProjectFile,
Keyman.Developer.System.Project.ProjectFiles,
Keyman.Developer.System.Project.ProjectFileType,
UKeymanTargets;
type
TkmnProjectFileAction = class(TkmnProjectFile)
private
procedure CheckFilenameConventions;
public
function CompileKeyboard: Boolean;
function Clean: Boolean;
end;
implementation
uses
System.Classes,
System.StrUtils,
System.Variants,
Winapi.Windows,
Keyman.Developer.System.Project.ProjectLog,
Keyman.System.KeyboardUtils,
Keyman.Developer.System.KmcWrapper,
utilfiletypes;
function TkmnProjectFileAction.Clean: Boolean;
begin
if Targets * KMXKeymanTargets <> [] then
begin
CleanFile(KmxTargetFileName);
CleanFile(ExtractFilePath(KmxTargetFileName) + ExtractFileName(ChangeFileExt(KVKFileName, Ext_VisualKeyboard)), True);
end;
if Targets * KMWKeymanTargets <> [] then
begin
CleanFile(JsTargetFileName);
end;
Result := True;
end;
procedure TkmnProjectFileAction.CheckFilenameConventions;
begin
if not OwnerProject.Options.CheckFilenameConventions then
Exit;
if not TKeyboardUtils.DoesKeyboardFilenameFollowConventions(FileName) then
begin
HasCompileWarning := True;
Log(plsWarning, Format(TKeyboardUtils.SKeyboardNameDoesNotFollowConventions_Message, [ExtractFileName(FileName)]), CERR_WARNING, 0);
end;
if KVKFileName <> '' then
begin
if not TKeyboardUtils.DoesKeyboardFilenameFollowConventions(KVKFileName) then
begin
HasCompileWarning := True;
Log(plsWarning, Format(TKeyboardUtils.SKeyboardNameDoesNotFollowConventions_Message, [ExtractFileName(KVKFileName)]), CERR_WARNING, 0);
end;
end;
end;
function TkmnProjectFileAction.CompileKeyboard: Boolean;
var
w: TKmcWrapper;
begin
w := TKmcWrapper.Create;
try
Result := w.Compile(Self, FileName, TargetFilename, Debug);
finally
w.Free;
end;
end;
initialization
RegisterProjectFileType('.kmn', TkmnProjectFileAction);
end.