-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignedPluginsApp.dpr
More file actions
131 lines (111 loc) · 2.91 KB
/
Copy pathSignedPluginsApp.dpr
File metadata and controls
131 lines (111 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
program SignedPluginsApp;
uses
System.SysUtils, System.IOUtils, System.Classes,
FMX.Forms, FMX.Dialogs,
Plugin.Interfaces,
Plugin.ServiceRegistry,
Plugin.Loader,
Plugin.Logger,
Plugin.EventBroker,
Plugin.Security,
Plugin.UI.Splash in '..\..\Helpers\Plugin.UI.Splash.pas' {PluginSplash},
uMain in 'Source\uMain.pas' {frmSecurityMain};
{$R *.res}
type
TSignedPluginsApp = class
private
FLoader: TBPLLoader;
function ValidateModule(const AFilePath: string): Boolean;
public
procedure Run;
procedure Shutdown;
end;
{ TSignedPluginsApp }
function TSignedPluginsApp.ValidateModule(const AFilePath: string): Boolean;
begin
Result := TSecurityValidator.VerifyAuthenticode(AFilePath);
end;
procedure TSignedPluginsApp.Run;
var
Splash: TPluginSplash;
Svc: IInterface;
BinPath, JsonFile: string;
Plugins: TArray<IPlugin>;
P: IPlugin;
begin
BinPath := ExtractFilePath(ParamStr(0));
JsonFile := TPath.Combine(BinPath, 'plugins.json');
Splash := TPluginSplash.Create(nil);
try
Splash.SetAppInfo('SignedPlugins', '1.0.0');
Splash.Show;
Application.ProcessMessages;
// Core-Services registrieren
if not TServiceRegistry.Instance.GetService(ILogger, Svc) then
TServiceRegistry.Instance.RegisterService(ILogger,
TFileLogger.Create(TPath.Combine(BinPath, 'Logs')));
if not TServiceRegistry.Instance.GetService(IEventBroker, Svc) then
TServiceRegistry.Instance.RegisterService(IEventBroker,
TEventBroker.Create);
// Loader mit Validierungs-Hook
FLoader := TBPLLoader.Create(BinPath);
FLoader.OnValidateModule := ValidateModule;
FLoader.OnProgress := Splash.UpdateProgress;
// Plugins laden — Exception bei required + ungültig
FLoader.LoadAll(JsonFile);
// Alle geladenen Plugins initialisieren
Plugins := TServiceRegistry.Instance.GetPlugins;
for P in Plugins do
P.Initialize;
finally
Splash.Free;
end;
// MainForm erstellen + Application.Run
Application.CreateForm(TfrmSecurityMain, frmSecurityMain);
Application.Run;
end;
procedure TSignedPluginsApp.Shutdown;
var
Plugins: TArray<IPlugin>;
P: IPlugin;
begin
Plugins := TServiceRegistry.Instance.GetPlugins;
for P in Plugins do
begin
try
P.Finalize;
except
end;
end;
if Assigned(Application) and Assigned(Application.MainForm) then
Application.MainForm.Free;
P := nil;
Plugins := nil;
TServiceRegistry.Instance.ClearAll;
if Assigned(FLoader) then
begin
FLoader.UnloadAll;
FreeAndNil(FLoader);
end;
TServiceRegistry.ReleaseInstance;
end;
var
App: TSignedPluginsApp;
begin
Application.Initialize;
App := TSignedPluginsApp.Create;
try
try
App.Run;
except
on E: Exception do
begin
ShowMessage('Plugin-Validierung fehlgeschlagen:' + sLineBreak +
sLineBreak + E.Message);
end;
end;
finally
App.Shutdown;
App.Free;
end;
end.