forked from Memnarch/Delphinus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DN.Setup.pas
135 lines (119 loc) · 3.74 KB
/
DN.Setup.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
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
132
133
134
135
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.Setup;
interface
uses
DN.Types,
DN.Setup.Core,
DN.Installer.Intf,
DN.Uninstaller.Intf,
DN.Package.Intf,
DN.Package.Version.Intf,
DN.PackageProvider.Intf,
DN.Progress.Intf;
type
TDNSetup = class(TDNSetupCore)
private
FInstaller: IDNInstaller;
FUninstaller: IDNUninstaller;
protected
function GetHasPendingChanges: Boolean; override;
public
constructor Create(const AInstaller: IDNInstaller; const AUninstaller: IDNUninstaller; const APackageProvider: IDNPackageProvider);
destructor Destroy; override;
function Install(const APackage: IDNPackage; const AVersion: IDNPackageVersion): Boolean; override;
function Uninstall(const APackage: IDNPackage): Boolean; override;
function InstallDirectory(const ADirectory: string): Boolean; override;
function UninstallDirectory(const ADirectory: string): Boolean; override;
end;
implementation
uses
SysUtils,
IOUtils,
StrUtils,
DN.JSonFile.InstalledInfo;
{ TDNSetup }
constructor TDNSetup.Create(const AInstaller: IDNInstaller;
const AUninstaller: IDNUninstaller;
const APackageProvider: IDNPackageProvider);
begin
inherited Create(APackageProvider);
FInstaller := AInstaller;
if Assigned(FInstaller) then
FInstaller.OnMessage := DoMessage;
RegisterProgressHandler(FInstaller);
FUninstaller := AUninstaller;
if Assigned(FUninstaller) then
FUninstaller.OnMessage := DoMessage;
RegisterProgressHandler(FUninstaller);
end;
destructor TDNSetup.Destroy;
begin
UnregisterProgressHandler(FInstaller);
UnregisterProgressHandler(FUninstaller);
inherited;
end;
function TDNSetup.GetHasPendingChanges: Boolean;
begin
Result := FInstaller.HasPendingChanges or FUninstaller.HasPendingChanges;
end;
function TDNSetup.Install(const APackage: IDNPackage;
const AVersion: IDNPackageVersion): Boolean;
var
LContentDirectory: string;
LInstallDirectory: string;
begin
try
FProgress.SetTasks(['Downloading', 'Installing']);
Result := DownloadPackage(APackage, AVersion, LContentDirectory);
if Result then
begin
FProgress.NextTask();
LInstallDirectory := GetInstallDirectoryForPackage(APackage);
Result := FInstaller.Install(LContentDirectory, LInstallDirectory);
if Result then
Result := ExtendInfoFile(APackage, AVersion, LInstallDirectory);
FProgress.Completed();
end;
finally
CleanupTemp();
end;
if Result then
ReportInfo('Installation finished')
else
ReportError('Installation failed');
end;
function TDNSetup.InstallDirectory(const ADirectory: string): Boolean;
var
LInstallDirectory: string;
begin
FProgress.SetTasks(['Installing']);
LInstallDirectory := GetInstallDirectoryForDirectory(ADirectory);
Result := FInstaller.Install(ADirectory, LInstallDirectory);
FProgress.Completed();
if Result then
ReportInfo('Installation finished')
else
ReportError('Installation failed');
end;
function TDNSetup.Uninstall(const APackage: IDNPackage): Boolean;
begin
Result := UninstallDirectory(GetInstallDirectoryForPackage(APackage));
end;
function TDNSetup.UninstallDirectory(const ADirectory: string): Boolean;
begin
ReportInfo('Uninstalling...');
FProgress.SetTasks(['Uninstalling']);
Result := FUninstaller.Uninstall(ADirectory);
FProgress.Completed();
if Result then
ReportInfo('success')
else
ReportError('failed');
end;
end.