-
Notifications
You must be signed in to change notification settings - Fork 0
/
PackageDependencyVerifier.pas
81 lines (65 loc) · 2.32 KB
/
PackageDependencyVerifier.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
{ **
DelphiPI (Delphi Package Installer)
Author : ibrahim dursun (ibrahimdursun gmail)
License : GNU General Public License 2.0
** }
unit PackageDependencyVerifier;
interface
uses Classes, PackageList, PackageInfo, CompilationData, InstalledPackageResolver, Generics.Collections;
type
TPackageDependencyVerifier = class
private
fMissingPackages: TStringList;
function GetMissingPackage(key: string): String;
public
constructor Create;
destructor Destroy; override;
procedure Verify(const selectedPackages: TList<TPackageInfo>; const installedPackageResolver: TInstalledPackageResolver); virtual;
property MissingPackages[key: string]: String read GetMissingPackage;
end;
implementation
uses SysUtils, JclFileUtils, gnugettext;
{ TPackageDependencyVerifier }
constructor TPackageDependencyVerifier.Create;
begin
fMissingPackages := TStringList.Create;
end;
destructor TPackageDependencyVerifier.Destroy;
begin
fMissingPackages.Free;
inherited;
end;
function TPackageDependencyVerifier.GetMissingPackage(key: string): String;
begin
Result := fMissingPackages.Values[key];
end;
procedure TPackageDependencyVerifier.Verify(const selectedPackages: TList<TPackageInfo>; const installedPackageResolver: TInstalledPackageResolver);
var
requiredPackage: string;
i: Integer;
package: TPackageInfo;
allPackages: TStringList;
begin
fMissingPackages.Clear;
allPackages := TStringList.Create;
try
allPackages.AddStrings(installedPackageResolver.InstalledPackages);
for I := 0 to selectedPackages.Count - 1 do
allPackages.Add(UpperCase(selectedPackages[i].PackageName));
for i := 0 to selectedPackages.Count - 1 do
begin
package := selectedPackages[i];
fMissingPackages.Values[package.packageName] := '';
for requiredPackage in package.RequiredPackageList do
begin
if fMissingPackages.Values[requiredPackage] <> '' then
fMissingPackages.Values[package.packageName] := Format(_('%s requires %s'), [requiredPackage, fMissingPackages.Values[requiredPackage]]);
if allPackages.IndexOf(UpperCase(requiredPackage)) = -1 then
fMissingPackages.Values[package.packageName] := requiredPackage;
end;
end;
finally
allPackages.Free;
end;
end;
end.