This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
PageProgress.pas
196 lines (173 loc) · 5.05 KB
/
PageProgress.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
{**
DelphiPI (Delphi Package Installer)
Author : ibrahim dursun (ibrahimdursun gmail)
License : GNU General Public License 2.0
**}
unit PageProgress;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Vcl.Controls, Forms,
Dialogs, PageBase, StdCtrls, ComCtrls, WizardIntfs, CompileThread, ProgressMonitor, PackageInfo;
type
TProgressPage = class(TWizardPage, IProgressMonitor)
GroupBox1: TGroupBox;
ProgressBar: TProgressBar;
Label1: TLabel;
lblPackage: TLabel;
lblCurrentPackageNo: TLabel;
memo: TRichEdit;
btnCancel: TButton;
chkShowFullLog: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnCancelClick(Sender: TObject);
procedure chkShowFullLogClick(Sender: TObject);
private
compileThreadWorking: Boolean;
compileThread: TCompileThread;
fFullLog : TStringList;
protected
procedure WriteInfo(const color: TColor; const info: string);
public
procedure Compile;
procedure UpdateWizardState; override;
procedure Finished;
procedure Started;
procedure CompilerOutput(const line: string);
procedure PackageProcessed(const packageInfo: TPackageInfo;
status: TPackageStatus);
procedure Log(const text: string);
end;
var
ProgressPage: TProgressPage;
implementation
uses gnugettext, StrUtils, JclStrings;
var
savedRtf: string;
{$R *.dfm}
{ TProgressPage }
procedure TProgressPage.FormCreate(Sender: TObject);
begin
inherited;
TranslateComponent(self);
lblPackage.Caption := '';
compileThreadWorking := false;
fFullLog := TStringList.Create;
chkShowFullLog.Enabled := false;
Compile;
end;
procedure TProgressPage.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
if compileThreadWorking then begin
compileThread.Cancel := true;
compileThread.WaitFor;
compileThread.Terminate;
end;
fFullLog.Free;
end;
procedure TProgressPage.UpdateWizardState;
begin
inherited;
wizard.SetHeader(_('Compile and Install Packages'));
wizard.SetDescription(_('Compiling packages that you have selected. Design time packages are going to be installed.'));
with wizard.GetAction(wbtNext) do
Enabled := not compileThreadWorking;
with wizard.GetAction(wbtBack) do
Enabled := not compileThreadWorking;
btnCancel.Enabled := compileThreadWorking;
chkShowFullLog.Enabled := not compileThreadWorking;
end;
procedure TProgressPage.WriteInfo(const color: TColor; const info: string);
var
oldColor: TColor;
begin
oldColor := memo.SelAttributes.Color;
memo.SelAttributes.Color := color;
memo.Lines.Add(info);
memo.SelAttributes.Color := oldColor;
memo.SelStart := Length(memo.Text);
end;
procedure TProgressPage.btnCancelClick(Sender: TObject);
begin
inherited;
CompileThread.Cancel := true;
end;
procedure TProgressPage.chkShowFullLogClick(Sender: TObject);
var
line: string;
begin
inherited;
if chkShowFullLog.Checked then
begin
savedRtf := memo.Text;
memo.Clear;
for line in fFullLog do
begin
if StartsStr('-=',line) then
begin
memo.SelAttributes.Size := 12;
memo.SelAttributes.Style := [fsBold];
memo.Lines.Add(Copy(line,3,length(line)-2));
end else begin
memo.SelAttributes.Size := 8;
memo.SelAttributes.Style := [];
memo.Lines.Add(line);
end;
end;
end else begin
memo.Text := savedRtf;
end;
end;
procedure TProgressPage.Compile;
begin
ProgressBar.Max := fCompilationData.PackageList.Count;
compileThread := TCompileThread.Create(fCompilationData);
compileThread.Monitor := Self as IProgressMonitor;
with compileThread do begin
FreeOnTerminate := true;
compileThreadWorking := true;
Resume;
end;
end;
procedure TProgressPage.Log(const text: string);
begin
fFullLog.Add(text);
end;
procedure TProgressPage.PackageProcessed(const packageInfo: TPackageInfo;
status: TPackageStatus);
begin
case status of
psNone: ;
psCompiling: begin
WriteInfo(clBlack, _('Compiling:') + packageInfo.PackageName);
ProgressBar.StepBy(1);
lblCurrentPackageNo.Caption := Format('%d/%d',[ProgressBar.Position,ProgressBar.Max]);
end;
psInstalling: WriteInfo(clBlue, _('Installing'));
psSuccess: WriteInfo(clGreen, _('Successful'));
psError: WriteInfo(clRed,_('Failed'));
end;
end;
procedure TProgressPage.Started;
begin
ProgressBar.Position := 0;
ProgressBar.Max := fCompilationData.PackageList.Count;
end;
procedure TProgressPage.CompilerOutput(const line: string);
var
S : String;
begin
S := Trim(line);
if (Pos('Fatal:', S) > 0) or (Pos('Error', S) > 0) then
WriteInfo(clRed, line);
end;
procedure TProgressPage.Finished;
begin
lblPackage.Caption :='';
ProgressBar.Position := 0;
compileThreadWorking := false;
WriteInfo(clBlack, _('*** Completed'));
Wizard.UpdateInterface;
end;
end.