1 | unit UChronisModule;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, SpecializedList, UPDClient;
|
---|
9 |
|
---|
10 | type
|
---|
11 |
|
---|
12 | { TChronisModule }
|
---|
13 |
|
---|
14 | TChronisModule = class
|
---|
15 | System: TObject; // TChronisBase;
|
---|
16 | SysName: string;
|
---|
17 | Name: string;
|
---|
18 | Version: string;
|
---|
19 | Creator: string;
|
---|
20 | License: string;
|
---|
21 | Website: string;
|
---|
22 | Description: TStringList;
|
---|
23 | Dependencies: TStringList;
|
---|
24 | function IsInstalled: Boolean;
|
---|
25 | procedure Install; virtual;
|
---|
26 | procedure Uninstall; virtual;
|
---|
27 | constructor Create; virtual;
|
---|
28 | destructor Destroy; override;
|
---|
29 | end;
|
---|
30 |
|
---|
31 | TChronisModuleClass = class of TChronisModule;
|
---|
32 |
|
---|
33 |
|
---|
34 | implementation
|
---|
35 |
|
---|
36 | uses
|
---|
37 | USystem;
|
---|
38 |
|
---|
39 |
|
---|
40 | { TChronisModule }
|
---|
41 |
|
---|
42 | function TChronisModule.IsInstalled: Boolean;
|
---|
43 | var
|
---|
44 | List: TListProxy;
|
---|
45 | begin
|
---|
46 | List := TListProxy.Create;
|
---|
47 | List.Client := TChronisBase(System).Client;
|
---|
48 | List.Path := TChronisBase(System).Client.Schema;
|
---|
49 | List.ObjectName := SystemModuleObject;
|
---|
50 | List.Condition := '(SysName="' + SysName + '") AND (Installed=1)';
|
---|
51 | List.Load;
|
---|
52 | Result := List.Objects.Count > 0;
|
---|
53 | List.Free;
|
---|
54 | end;
|
---|
55 |
|
---|
56 | procedure TChronisModule.Install;
|
---|
57 | var
|
---|
58 | NewObject: TObjectProxy;
|
---|
59 | List: TListProxy;
|
---|
60 | begin
|
---|
61 | List := TListProxy.Create;
|
---|
62 | List.Client := TChronisBase(System).Client;
|
---|
63 | List.Path := TChronisBase(System).Client.Schema;
|
---|
64 | List.ObjectName := SystemModuleObject;
|
---|
65 | List.Condition := 'SysName="' + SysName + '"';
|
---|
66 | List.Load;
|
---|
67 | if List.Objects.Count > 0 then begin
|
---|
68 | NewObject := TObjectProxy.Create;
|
---|
69 | NewObject.Id := StrToInt(TObjectProxy(List.Objects[0]).Properties.Values['Id']);
|
---|
70 | NewObject.Client := TChronisBase(System).Client;
|
---|
71 | NewObject.Path := TChronisBase(System).Client.Schema;
|
---|
72 | NewObject.ObjectName := SystemModuleObject;
|
---|
73 | NewObject.Properties.Add('Installed', '1');
|
---|
74 | NewObject.Save;
|
---|
75 | NewObject.Free;
|
---|
76 | end;
|
---|
77 | List.Free;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | procedure TChronisModule.Uninstall;
|
---|
81 | var
|
---|
82 | NewObject: TObjectProxy;
|
---|
83 | List: TListProxy;
|
---|
84 | begin
|
---|
85 | List := TListProxy.Create;
|
---|
86 | List.Client := TChronisBase(System).Client;
|
---|
87 | List.Path := TChronisBase(System).Client.Schema;
|
---|
88 | List.ObjectName := SystemModuleObject;
|
---|
89 | List.Condition := 'SysName="' + SysName + '"';
|
---|
90 | List.Load;
|
---|
91 | if List.Objects.Count > 0 then begin
|
---|
92 | NewObject := TObjectProxy.Create;
|
---|
93 | NewObject.Id := StrToInt(TObjectProxy(List.Objects[0]).Properties.Values['Id']);
|
---|
94 | NewObject.Client := TChronisBase(System).Client;
|
---|
95 | NewObject.Path := TChronisBase(System).Client.Schema;
|
---|
96 | NewObject.ObjectName := SystemModuleObject;
|
---|
97 | NewObject.Properties.Add('Installed', '0');
|
---|
98 | NewObject.Save;
|
---|
99 | NewObject.Free;
|
---|
100 | end;
|
---|
101 | List.Free;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | constructor TChronisModule.Create;
|
---|
105 | begin
|
---|
106 | Dependencies := TStringList.Create;
|
---|
107 | Description := TStringList.Create;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | destructor TChronisModule.Destroy;
|
---|
111 | begin
|
---|
112 | Description.Free;
|
---|
113 | Dependencies.Free;
|
---|
114 | inherited Destroy;
|
---|
115 | end;
|
---|
116 |
|
---|
117 | end.
|
---|
118 |
|
---|