Skip to content

Commit 722f72b

Browse files
authored
Merge pull request #9470 from keymanapp/feat/developer/package-license
feat(developer): add LicenseFile as property of package 🎺
2 parents 920a435 + 3af9f6d commit 722f72b

File tree

9 files changed

+142
-43
lines changed

9 files changed

+142
-43
lines changed

common/schemas/kps/kps.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<xs:element minOccurs="0" maxOccurs="1" name="ExecuteProgram" type="xs:string" />
3232
<xs:element minOccurs="0" maxOccurs="1" name="ReadMeFile" type="xs:string" />
3333
<xs:element minOccurs="0" maxOccurs="1" name="GraphicFile" type="xs:string" />
34+
<xs:element minOccurs="0" maxOccurs="1" name="LicenseFile" type="xs:string" />
3435
<xs:element minOccurs="0" maxOccurs="1" name="MSIFileName" type="xs:string" />
3536
<xs:element minOccurs="0" maxOccurs="1" name="MSIOptions" type="xs:string" />
3637
<xs:element minOccurs="0" maxOccurs="1" name="FollowKeyboardVersion" type="km-empty" />

common/web/types/src/package/kmp-json-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface KmpJsonFileSystem {
1717
export interface KmpJsonFileOptions {
1818
readmeFile?: string;
1919
graphicFile?: string;
20+
licenseFile?: string;
2021
executeProgram?: string;
2122
msiFilename?: string;
2223
msiOptions?: string;

common/web/types/src/package/kps-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface KpsFileOptions {
4141
followKeyboardVersion?: string;
4242
readMeFile?: string;
4343
graphicFile?: string;
44+
licenseFile?: string;
4445
executeProgram?: string;
4546
msiFileName?: string;
4647
msiOptions?: string;

common/windows/delphi/packages/PackageInfo.pas

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ TPackageOptions = class(TPackageBaseObject)
149149
FExecuteProgram: WideString;
150150
FReadmeFile: TPackageContentFile;
151151
FGraphicFile: TPackageContentFile;
152+
FLicenseFile: TPackageContentFile;
152153
FLoadLegacy: Boolean;
153154
procedure SetReadmeFile(const Value: TPackageContentFile);
154155
procedure SetExecuteProgram(Value: WideString);
@@ -158,6 +159,9 @@ TPackageOptions = class(TPackageBaseObject)
158159
EventType: TPackageNotifyEventType; var FAllow: Boolean);
159160
procedure ReadmeRemoved(Sender: TObject;
160161
EventType: TPackageNotifyEventType; var FAllow: Boolean);
162+
procedure SetLicenseFile(const Value: TPackageContentFile);
163+
procedure LicenseRemoved(Sender: TObject;
164+
EventType: TPackageNotifyEventType; var FAllow: Boolean);
161165
public
162166
constructor Create(APackage: TPackage); override;
163167
destructor Destroy; override;
@@ -173,6 +177,7 @@ TPackageOptions = class(TPackageBaseObject)
173177
property ExecuteProgram: WideString read FExecuteProgram write SetExecuteProgram;
174178
property ReadmeFile: TPackageContentFile read FReadmeFile write SetReadmeFile;
175179
property GraphicFile: TPackageContentFile read FGraphicFile write SetGraphicFile;
180+
property LicenseFile: TPackageContentFile read FLicenseFile write SetLicenseFile;
176181
end;
177182

178183
{ Package Information }
@@ -509,6 +514,7 @@ implementation
509514
SPackageInfoTooNew = 'The package file is version %s. This version can only read version '+SKeymanVersion+' and older files.';
510515
SReadmeNotOwnedCorrectly = 'The readme file ''%s'' referred to is not part of the package.';
511516
SGraphicNotOwnedCorrectly = 'The graphic file ''%s'' referred to is not part of the package.';
517+
SLicenseNotOwnedCorrectly = 'The license file ''%s'' referred to is not part of the package.';
512518
SFileNotOwnedCorrectly = 'The file ''%s'' referred to is not part of the package.';
513519
SDisplayFontNotOwnedCorrectly = 'The display font file ''%s'' referred to is not part of the package.';
514520
SOSKFontNotOwnedCorrectly = 'The OSK font file ''%s'' referred to is not part of the package.';
@@ -561,6 +567,7 @@ implementation
561567
SJSON_Options_ExecuteProgram = 'executeProgram';
562568
SJSON_Options_ReadMeFile = 'readmeFile';
563569
SJSON_Options_GraphicFile = 'graphicFile';
570+
SJSON_Options_LicenseFile = 'licenseFile';
564571

565572
SJSON_Registry = 'registry';
566573
SJSON_Registry_Root = 'root';
@@ -655,6 +662,9 @@ procedure TPackageOptions.Assign(Source: TPackageOptions);
655662
if Assigned(Source.GraphicFile)
656663
then GraphicFile := Package.Files.FromFileName(Source.GraphicFile.FileName)
657664
else GraphicFile := nil;
665+
if Assigned(Source.LicenseFile)
666+
then LicenseFile := Package.Files.FromFileName(Source.LicenseFile.FileName)
667+
else LicenseFile := nil;
658668
end;
659669

660670
constructor TPackageOptions.Create(APackage: TPackage);
@@ -668,6 +678,7 @@ destructor TPackageOptions.Destroy;
668678
begin
669679
ReadmeFile := nil;
670680
GraphicFile := nil;
681+
LicenseFile := nil;
671682
inherited Destroy;
672683
end;
673684

@@ -681,14 +692,21 @@ procedure TPackageOptions.GraphicRemoved(Sender: TObject; EventType: TPackageNot
681692
FGraphicFile := nil;
682693
end;
683694

695+
procedure TPackageOptions.LicenseRemoved(Sender: TObject; EventType: TPackageNotifyEventType; var FAllow: Boolean);
696+
begin
697+
FLicenseFile := nil;
698+
end;
699+
684700
procedure TPackageOptions.LoadXML(ARoot: IXMLNode);
685701
begin
686702
FileVersion := XmlVarToStr(ARoot.ChildNodes['System'].ChildNodes['FileVersion'].NodeValue);
687703
ExecuteProgram := XmlVarToStr(ARoot.ChildNodes['Options'].ChildNodes['ExecuteProgram'].NodeValue);
688704
ReadmeFile := Package.Files.FromFileName(XmlVarToStr(ARoot.ChildNodes['Options'].ChildNodes['ReadMeFile'].NodeValue));
689705
GraphicFile := Package.Files.FromFileName(XmlVarToStr(ARoot.ChildNodes['Options'].ChildNodes['GraphicFile'].NodeValue));
706+
LicenseFile := Package.Files.FromFileName(XmlVarToStr(ARoot.ChildNodes['Options'].ChildNodes['LicenseFile'].NodeValue));
690707
if Assigned(ReadmeFile) then ReadmeFile.AddNotifyObject(ReadmeRemoved);
691708
if Assigned(GraphicFile) then GraphicFile.AddNotifyObject(GraphicRemoved);
709+
if Assigned(LicenseFile) then LicenseFile.AddNotifyObject(LicenseRemoved);
692710
end;
693711

694712
procedure TPackageOptions.SaveXML(ARoot: IXMLNode);
@@ -699,6 +717,8 @@ procedure TPackageOptions.SaveXML(ARoot: IXMLNode);
699717
ARoot.ChildNodes['Options'].ChildNodes['ReadMeFile'].NodeValue := ReadmeFile.RelativeFileName;
700718
if Assigned(GraphicFile) then
701719
ARoot.ChildNodes['Options'].ChildNodes['GraphicFile'].NodeValue := GraphicFile.RelativeFileName;
720+
if Assigned(LicenseFile) then
721+
ARoot.ChildNodes['Options'].ChildNodes['LicenseFile'].NodeValue := LicenseFile.RelativeFileName;
702722
end;
703723

704724
procedure TPackageOptions.LoadIni(AIni: TIniFile);
@@ -709,6 +729,7 @@ procedure TPackageOptions.LoadIni(AIni: TIniFile);
709729
GraphicFile := Package.Files.FromFileName(AIni.ReadString('Package', 'GraphicFile', ''));
710730
if Assigned(ReadmeFile) then ReadmeFile.AddNotifyObject(ReadmeRemoved);
711731
if Assigned(GraphicFile) then GraphicFile.AddNotifyObject(GraphicRemoved);
732+
// LicenseFile not supported in ini
712733
end;
713734

714735
procedure TPackageOptions.LoadJSON(ARoot: TJSONObject);
@@ -722,8 +743,10 @@ procedure TPackageOptions.LoadJSON(ARoot: TJSONObject);
722743
ExecuteProgram := GetJsonValueString(FOptions, SJSON_Options_ExecuteProgram);
723744
ReadmeFile := Package.Files.FromFileName(GetJsonValueString(FOptions, SJSON_Options_ReadMeFile));
724745
GraphicFile := Package.Files.FromFileName(GetJsonValueString(FOptions, SJSON_Options_GraphicFile));
746+
LicenseFile := Package.Files.FromFileName(GetJsonValueString(FOptions, SJSON_Options_LicenseFile));
725747
if Assigned(ReadmeFile) then ReadmeFile.AddNotifyObject(ReadmeRemoved);
726748
if Assigned(GraphicFile) then GraphicFile.AddNotifyObject(GraphicRemoved);
749+
if Assigned(LicenseFile) then LicenseFile.AddNotifyObject(LicenseRemoved);
727750
end;
728751

729752
procedure TPackageOptions.SaveIni(AIni: TIniFile);
@@ -734,6 +757,7 @@ procedure TPackageOptions.SaveIni(AIni: TIniFile);
734757
AIni.WriteString('Package', 'ReadMeFile', ReadmeFile.RelativeFileName);
735758
if Assigned(GraphicFile) then
736759
AIni.WriteString('Package', 'GraphicFile', GraphicFile.RelativeFileName);
760+
// licenseFile not supported in ini
737761
end;
738762

739763
procedure TPackageOptions.SaveJSON(ARoot: TJSONObject);
@@ -753,6 +777,8 @@ procedure TPackageOptions.SaveJSON(ARoot: TJSONObject);
753777
FOptions.AddPair(SJSON_Options_ReadMeFile, ReadmeFile.RelativeFileName);
754778
if Assigned(GraphicFile) then
755779
FOptions.AddPair(SJSON_Options_GraphicFile, GraphicFile.RelativeFileName);
780+
if Assigned(LicenseFile) then
781+
FOptions.AddPair(SJSON_Options_LicenseFile, LicenseFile.RelativeFileName);
756782
end;
757783

758784
procedure TPackageOptions.SetExecuteProgram(Value: WideString);
@@ -780,6 +806,19 @@ procedure TPackageOptions.SetGraphicFile(const Value: TPackageContentFile);
780806
end;
781807
end;
782808

809+
procedure TPackageOptions.SetLicenseFile(const Value: TPackageContentFile);
810+
begin
811+
if Assigned(FLicenseFile) then FLicenseFile.RemoveNotifyObject(LicenseRemoved);
812+
if not Assigned(Value) then
813+
FLicenseFile := nil
814+
else
815+
begin
816+
if Value.Package <> Package then raise EPackageInfo.CreateFmt(SLicenseNotOwnedCorrectly, [Value]);
817+
FLicenseFile := Value;
818+
FLicenseFile.AddNotifyObject(LicenseRemoved);
819+
end;
820+
end;
821+
783822
procedure TPackageOptions.SetReadmeFile(const Value: TPackageContentFile);
784823
begin
785824
if Assigned(FReadmeFile) then FReadmeFile.RemoveNotifyObject(ReadmeRemoved);

developer/src/kmc-package/src/compiler/kmp-compiler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export class KmpCompiler {
7777
if(kps.options.readMeFile) {
7878
kmp.options.readmeFile = /[/\\]?([^/\\]*)$/.exec(kps.options.readMeFile)[1];
7979
}
80+
if(kps.options.licenseFile) {
81+
kmp.options.licenseFile = /[/\\]?([^/\\]*)$/.exec(kps.options.licenseFile)[1];
82+
}
8083
}
8184

8285
//

developer/src/kmconvert/Keyman.Developer.System.KeyboardProjectTemplate.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ procedure TKeyboardProjectTemplate.WriteKPS;
285285
kps.Files.Add(f);
286286
kps.Options.ReadmeFile := f;
287287

288+
// Add license
289+
f := TPackageContentFile.Create(kps);
290+
f.FileName := BasePath + ID + '\' + SFile_LicenseMD;
291+
kps.Files.Add(f);
292+
kps.Options.LicenseFile := f;
293+
288294
// Add metadata about the keyboard
289295
pk := TPackageKeyboard.Create(kps);
290296
pk.Name := Name;

developer/src/kmconvert/Keyman.Developer.System.ModelProjectTemplate.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ procedure TModelProjectTemplate.WriteKPS;
179179
kps.Files.Add(f);
180180
kps.Options.ReadmeFile := f;
181181

182+
// Add license
183+
f := TPackageContentFile.Create(kps);
184+
f.FileName := BasePath + ID + '\' + SFile_LicenseMD;
185+
kps.Files.Add(f);
186+
kps.Options.LicenseFile := f;
187+
182188
// Add metadata about the lexical model
183189
plm := TPackageLexicalModel.Create(kps);
184190
plm.Name := Name;

0 commit comments

Comments
 (0)