-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathDN.PackageProvider.Installed.pas
81 lines (72 loc) · 2.03 KB
/
DN.PackageProvider.Installed.pas
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
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.PackageProvider.Installed;
interface
uses
Classes,
Types,
SysUtils,
DN.PackageProvider,
DN.Package.Intf,
DN.Package.DirectoryLoader.Intf;
type
TDNInstalledPackageProvider = class(TDNPackageProvider)
private
FComponentDirectory: string;
FLoader: IDNPackageDirectoryLoader;
public
constructor Create(const AComponentDirectory: string);
function Reload: Boolean; override;
end;
implementation
uses
IOUtils,
Graphics,
DN.Types,
DN.Package,
DN.Uninstaller.Intf,
DN.JSonFile.InstalledInfo,
DN.Package.Version,
DN.Package.Version.Intf,
DN.Graphics.Loader,
DN.Package.DirectoryLoader;
{ TDNInstalledPackageProvider }
constructor TDNInstalledPackageProvider.Create(
const AComponentDirectory: string);
begin
inherited Create();
FComponentDirectory := AComponentDirectory;
FLoader := TDNPackageDirectoryLoader.Create();
end;
function TDNInstalledPackageProvider.Reload: Boolean;
var
LDirectories: TStringDynArray;
LDirectory: string;
LPackage: IDNPackage;
begin
Result := False;
if TDirectory.Exists(FComponentDirectory) then
begin
Packages.Clear();
LDirectories := TDirectory.GetDirectories(FComponentDirectory);
for LDirectory in LDirectories do
begin
if TFile.Exists(TPath.Combine(LDirectory, CUninstallFile))
//when uninstalling we rename directories for delete on reboot with a ~
//exclude them here!
and (Pos('~', ExtractFileName(ExcludeTrailingPathDelimiter(LDirectory))) < 1) then
begin
LPackage := TDNPackage.Create();
FLoader.Load(LDirectory, LPackage);
Packages.Add(LPackage);
end;
end;
Result := True;
end;
end;
end.