forked from corneliusdavid/AutoGetIt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathufrmInstallLog.pas
126 lines (103 loc) · 2.99 KB
/
ufrmInstallLog.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
unit ufrmInstallLog;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls, DosCommand,
Vcl.Buttons, Vcl.ExtCtrls;
type
TfrmInstallLog = class(TForm)
lbInstallLog: TListBox;
DosCmdGetItInstall: TDosCommand;
pnlLogBottom: TPanel;
btnCancel: TBitBtn;
lblCount: TLabel;
pbInstalls: TProgressBar;
btnClose: TBitBtn;
procedure DosCmdGetItInstallNewLine(ASender: TObject;
const ANewLine: string; AOutputType: TOutputType);
procedure DosCmdGetItInstallTerminated(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
private
FAbort: Boolean;
FFinished: Boolean;
procedure AddLog(const LogMsg: string);
public
procedure Initialize;
procedure NotifyFinished;
procedure ProcessGetItPackage(const StartDir, GetItCmdArgs: string;
const Count, Total: Integer;
var Aborted: Boolean);
end;
var
frmInstallLog: TfrmInstallLog;
implementation
{$R *.dfm}
uses
System.IOUtils, System.Diagnostics;
{ TfrmInstallLog }
procedure TfrmInstallLog.AddLog(const LogMsg: string);
begin
lbInstallLog.Items.Add(LogMsg);
lbInstallLog.ItemIndex := lbInstallLog.Items.Count - 1;
lbInstallLog.Update;
end;
procedure TfrmInstallLog.btnCancelClick(Sender: TObject);
begin
FAbort := True;
DosCmdGetItInstall.Stop;
end;
procedure TfrmInstallLog.btnCloseClick(Sender: TObject);
begin
Hide;
end;
procedure TfrmInstallLog.Initialize;
begin
lbInstallLog.Items.Clear;
btnCancel.BringToFront;
Show;
end;
procedure TfrmInstallLog.DosCmdGetItInstallNewLine(ASender: TObject;
const ANewLine: string; AOutputType: TOutputType);
begin
AddLog(ANewLine);
end;
procedure TfrmInstallLog.DosCmdGetItInstallTerminated(Sender: TObject);
begin
FFinished := True;
end;
procedure TfrmInstallLog.ProcessGetItPackage(const StartDir, GetItCmdArgs: string;
const Count, Total: Integer;
var Aborted: Boolean);
begin
lblCount.Caption := Format('%d of %d packages', [Count, Total]);
lblCount.Update;
pbInstalls.Max := Total;
pbInstalls.Position := Count;
pbInstalls.Update;
DosCmdGetItInstall.CurrentDir := StartDir;
DosCmdGetItInstall.CommandLine := TPath.Combine(StartDir, 'GetItCmd.exe ') + GetItCmdArgs;
AddLog('Command Line: ' + DosCmdGetItInstall.CommandLine);
FAbort := False;
FFinished := False;
btnCancel.Enabled := True;
Screen.Cursor := crHourGlass;
try
DosCmdGetItInstall.Execute;
repeat
Application.ProcessMessages;
until FFinished or FAbort;
AddLog('========================');
finally
Screen.Cursor := crDefault;
end;
Aborted := FAbort;
if FAbort then
AddLog('Aborted!');
end;
procedure TfrmInstallLog.NotifyFinished;
begin
AddLog('Finished');
btnClose.BringToFront;
end;
end.