|
@@ -63,22 +63,9 @@ program Setup;
|
63
|
63
|
//{$DEFINE FORCEJREDOWNLOAD}
|
64
|
64
|
|
65
|
65
|
uses
|
66
|
|
- {$IFDEF LAZARUS}Interfaces, Forms, ComCtrls, Buttons, Messages, Controls, StdCtrls, {$ENDIF}
|
|
66
|
+ {$IFDEF KOL}kol,{$ENDIF}
|
67
|
67
|
Vista, Windows, SysUtils, classes, registry, strutils {$IFNDEF FPC},masks{$ENDIF};
|
68
|
68
|
|
69
|
|
-{$IFDEF LAZARUS}
|
70
|
|
- type
|
71
|
|
- TProgressForm = class(TForm)
|
72
|
|
- ProgressBar: TProgressBar;
|
73
|
|
- CancelButton: TButton;
|
74
|
|
- CaptionLabel: TLabel;
|
75
|
|
- constructor Create(AOwner: TComponent); override;
|
76
|
|
- private
|
77
|
|
- procedure onButtonClick(Sender: TObject);
|
78
|
|
- public
|
79
|
|
- procedure setProgress(value: integer);
|
80
|
|
- end;
|
81
|
|
-{$ENDIF}
|
82
|
69
|
|
83
|
70
|
const
|
84
|
71
|
{$I SetupConsts.inc}
|
|
@@ -90,63 +77,88 @@ const
|
90
|
77
|
{$ENDIF}
|
91
|
78
|
|
92
|
79
|
var
|
93
|
|
-{$IFDEF LAZARUS} form: TProgressForm; {$ENDIF}
|
|
80
|
+ {$IFDEF KOL}
|
|
81
|
+ frmmain: pcontrol;
|
|
82
|
+ progressbar, btncancel: pcontrol;
|
|
83
|
+ label1, label2, label3, label4, label5, label6, label7: pcontrol;
|
|
84
|
+ {$ENDIF}
|
94
|
85
|
terminateDownload: boolean = false;
|
95
|
|
-
|
96
|
|
-{$IFDEF LAZARUS}
|
97
|
|
- constructor TProgressForm.Create(AOwner: TComponent);
|
98
|
|
- begin
|
99
|
|
- inherited;
|
100
|
|
- self.Width := 500;
|
101
|
|
- self.Height := 80;
|
102
|
|
- self.Position := poScreenCenter;
|
103
|
|
- self.BorderStyle := bsSingle;
|
104
|
|
- CaptionLabel := TLabel.create(self);
|
105
|
|
- CaptionLabel.Parent := self;
|
106
|
|
- CaptionLabel.Width := 490;
|
107
|
|
- CaptionLabel.Height := 15;
|
108
|
|
- CaptionLabel.Top := 5;
|
109
|
|
- CaptionLabel.Left := 5;
|
110
|
|
- CaptionLabel.Caption := 'Downloading JRE - 0%';
|
111
|
|
-
|
112
|
|
- ProgressBar := TProgressBar.create(self);
|
113
|
|
- ProgressBar.Parent := self;
|
114
|
|
- ProgressBar.Width := 490;
|
115
|
|
- ProgressBar.Height := 20;
|
116
|
|
- ProgressBar.Top := CaptionLabel.Top+CaptionLabel.Height+5;
|
117
|
|
- ProgressBar.Left := 5;
|
118
|
|
- ProgressBar.Visible := true;
|
119
|
|
- ProgressBar.Max := 100;
|
120
|
|
- ProgressBar.Position := 0;
|
121
|
|
-
|
122
|
|
- CancelButton := TButton.create(self);
|
123
|
|
- CancelButton.Parent := self;
|
124
|
|
- CancelButton.Width := 80;
|
125
|
|
- CancelButton.Height := 25;
|
126
|
|
- CancelButton.Top := ProgressBar.Top+ProgressBar.Height+5;
|
127
|
|
- CancelButton.Left := Round((self.Width/2) - (CancelButton.Width/2));
|
128
|
|
- CancelButton.Visible := true;
|
129
|
|
- CancelButton.Caption := 'Cancel';
|
130
|
|
- CancelButton.onClick := self.onButtonClick;
|
131
|
|
-
|
132
|
|
- self.Caption := pChar('DMDirc Setup');
|
133
|
|
- Application.Title := self.Caption;
|
134
|
|
-
|
135
|
|
- SetVistaFonts(self);
|
136
|
|
- end;
|
137
|
|
-
|
138
|
|
- procedure TProgressForm.onButtonClick(Sender: TObject);
|
139
|
|
- begin
|
140
|
|
- terminateDownload := true;
|
141
|
|
- end;
|
142
|
|
-
|
143
|
|
- procedure TProgressForm.setProgress(value: integer);
|
144
|
|
- begin
|
145
|
|
- ProgressBar.Position := value;
|
146
|
|
- CaptionLabel.Caption := pchar('Downloading JRE - '+inttostr(value)+'%');
|
147
|
|
- self.Caption := pChar('DMDirc Setup - '+CaptionLabel.Caption);
|
148
|
|
- Application.Title := self.Caption;
|
149
|
|
- end;
|
|
86
|
+
|
|
87
|
+{$IFDEF KOL}
|
|
88
|
+procedure btnCancel_Click(Dummy: Pointer; Sender: PControl);
|
|
89
|
+begin
|
|
90
|
+ { Button clicked }
|
|
91
|
+ terminateDownload := true;
|
|
92
|
+end;
|
|
93
|
+
|
|
94
|
+procedure setProgress(value: integer);
|
|
95
|
+begin
|
|
96
|
+ ProgressBar.progress := value;
|
|
97
|
+ //CaptionLabel.Caption := pchar('Downloading JRE - '+inttostr(value)+'%');
|
|
98
|
+ //self.Caption := pChar('DMDirc Setup - '+CaptionLabel.Caption);
|
|
99
|
+ //Application.Title := self.Caption;
|
|
100
|
+ applet.processmessages;
|
|
101
|
+end;
|
|
102
|
+
|
|
103
|
+procedure CreateMainWindow;
|
|
104
|
+var
|
|
105
|
+ screenw, screenh: longint;
|
|
106
|
+begin
|
|
107
|
+ InitCommonControls;
|
|
108
|
+
|
|
109
|
+ screenw := GetSystemMetrics(SM_CXSCREEN);
|
|
110
|
+ screenh := GetSystemMetrics(SM_CYSCREEN);
|
|
111
|
+
|
|
112
|
+ Applet := NewApplet('DMDirc Setup');
|
|
113
|
+ Applet.Visible := true;
|
|
114
|
+ Applet.Icon := THandle(-1);
|
|
115
|
+
|
|
116
|
+ frmmain := NewForm( Applet, 'DMDirc Setup').SetClientSize(400, 184);
|
|
117
|
+ frmmain.CreateVisible := True;
|
|
118
|
+ frmmain.CanResize := False;
|
|
119
|
+ frmmain.Style := frmmain.style and (not WS_MAXIMIZEBOX);
|
|
120
|
+ frmmain.Font.FontName := 'Ms Sans Serif';
|
|
121
|
+ frmmain.Font.FontHeight := 8;
|
|
122
|
+ frmmain.SetPosition((screenw div 2) - (frmmain.Width div 2), (screenh div 2) - (frmmain.height div 2));
|
|
123
|
+ frmmain.Icon := THandle(-1);
|
|
124
|
+
|
|
125
|
+ progressbar := NewProgressBar(frmmain).SetPosition(16, 114);
|
|
126
|
+ progressbar.SetSize(frmmain.clientWidth - (progressbar.Left * 2), 16);
|
|
127
|
+ progressbar.MaxProgress := 100;
|
|
128
|
+ progressbar.Progress := 0;
|
|
129
|
+ progressbar.Visible := true;
|
|
130
|
+
|
|
131
|
+ btncancel := NewButton(frmmain, 'Cancel').SetPosition(progressbar.Left +
|
|
132
|
+ progressbar.width - 60, progressbar.Top + progressbar.Height + 14);
|
|
133
|
+ btncancel.SetSize(60, 24);
|
|
134
|
+
|
|
135
|
+ label1 := NewLabel(frmmain, 'Downloading Java Runtime Environment').SetPosition(16, 16);
|
|
136
|
+ label1.SetSize(frmmain.ClientWidth - 32, 16);
|
|
137
|
+ label1.Font.FontStyle := [fsBold];
|
|
138
|
+
|
|
139
|
+ label2 := NewLabel(frmmain, 'Address:').SetPosition(16, label1.top + 28);
|
|
140
|
+ label2.SetSize(frmmain.ClientWidth - 32, 16);
|
|
141
|
+
|
|
142
|
+ label3 := NewLabel(frmmain, 'Speed:').SetPosition(16, label2.top + 20);
|
|
143
|
+ label3.SetSize(frmmain.ClientWidth - 32, 16);
|
|
144
|
+
|
|
145
|
+ label4 := NewLabel(frmmain, 'Progress:').SetPosition(16, label3.top + 20);
|
|
146
|
+ label4.SetSize(frmmain.ClientWidth - 32, 16);
|
|
147
|
+
|
|
148
|
+ label5 := NewLabel(frmmain, 'http://java.ftw.com/foo/').SetPosition(70, label1.top + 28);
|
|
149
|
+ label5.SetSize(frmmain.ClientWidth - 32, 16);
|
|
150
|
+ label5.BringToFront;
|
|
151
|
+
|
|
152
|
+ label6 := NewLabel(frmmain, '328KByte/sec').SetPosition(70, label2.top + 20);
|
|
153
|
+ label6.SetSize(frmmain.ClientWidth - 32, 16);
|
|
154
|
+ label6.BringToFront;
|
|
155
|
+
|
|
156
|
+ label7 := NewLabel(frmmain, '500KByte of 10.4MByte (50%)').SetPosition(70, label3.top + 20);
|
|
157
|
+ label7.SetSize(frmmain.ClientWidth - 32, 16);
|
|
158
|
+ label7.BringToFront;
|
|
159
|
+
|
|
160
|
+ btncancel.OnClick := TOnEvent(MakeMethod(nil, @btnCancel_Click ));
|
|
161
|
+end;
|
150
|
162
|
{$ENDIF}
|
151
|
163
|
|
152
|
164
|
function askQuestion(Question: String): boolean;
|
|
@@ -287,7 +299,7 @@ var
|
287
|
299
|
f: TextFile;
|
288
|
300
|
bits: TStringList;
|
289
|
301
|
match: boolean;
|
290
|
|
- {$IFDEF LAZARUS}
|
|
302
|
+ {$IFDEF KOL}
|
291
|
303
|
wantedsize: double;
|
292
|
304
|
currentsize: double;
|
293
|
305
|
{$ENDIF}
|
|
@@ -317,7 +329,7 @@ begin
|
317
|
329
|
bits.Clear;
|
318
|
330
|
bits.Delimiter := ' ';
|
319
|
331
|
bits.DelimitedText := line;
|
320
|
|
- {$IFDEF LAZARUS}
|
|
332
|
+ {$IFDEF KOL}
|
321
|
333
|
try
|
322
|
334
|
wantedsize := strtoint(StringReplace(bits[1], ',', '', [rfReplaceAll]))
|
323
|
335
|
except
|
|
@@ -325,33 +337,33 @@ begin
|
325
|
337
|
end;
|
326
|
338
|
{$ENDIF}
|
327
|
339
|
if askQuestion(message+' (Download Size: '+AnsiMidStr(bits[2], 2, length(bits[2])-2)+')') then begin
|
328
|
|
- {$IFDEF LAZARUS}
|
|
340
|
+ {$IFDEF KOL}
|
329
|
341
|
ProcessInfo := Launch('wget.exe '+url+' -O jre.exe', true);
|
330
|
|
- form.show();
|
|
342
|
+ CreateMainWindow;
|
331
|
343
|
if wantedsize <= 0 then begin
|
332
|
|
- form.setProgress(50);
|
|
344
|
+ progressbar.progress := 50;
|
333
|
345
|
end;
|
334
|
346
|
{$ELSE}
|
335
|
347
|
ProcessInfo := Launch('wget.exe '+url+' -O jre.exe');
|
336
|
348
|
{$ENDIF}
|
337
|
349
|
getExitCodeProcess(ProcessInfo.hProcess, processResult);
|
338
|
|
-
|
|
350
|
+
|
339
|
351
|
while (processResult=STILL_ACTIVE) and (not terminateDownload) do begin
|
340
|
352
|
// Update progress bar.
|
341
|
|
- {$IFDEF LAZARUS}
|
|
353
|
+ {$IFDEF KOL}
|
342
|
354
|
if wantedsize > 0 then begin
|
343
|
355
|
currentsize := GetFileSizeByName('jre.exe');
|
344
|
|
- if (currentsize > 0) then form.setProgress(Round((currentsize/wantedsize)*100));
|
|
356
|
+ if (currentsize > 0) then setProgress(Round((currentsize/wantedsize)*100));
|
345
|
357
|
end;
|
346
|
|
- Application.ProcessMessages;
|
|
358
|
+ applet.ProcessMessages;
|
347
|
359
|
{$ENDIF}
|
348
|
360
|
sleep(10);
|
349
|
361
|
GetExitCodeProcess(ProcessInfo.hProcess, processResult);
|
350
|
362
|
end;
|
351
|
|
- {$IFDEF LAZARUS}form.hide();{$ENDIF}
|
|
363
|
+ {$IFDEF KOL}frmmain.visible := false;{$ENDIF}
|
352
|
364
|
if (terminateDownload) then begin
|
353
|
365
|
Result := false;
|
354
|
|
- {$IFDEF LAZARUS}
|
|
366
|
+ {$IFDEF KOL}
|
355
|
367
|
TerminateProcess(ProcessInfo.hProcess, 0);
|
356
|
368
|
showError('JRE Download was aborted', false);
|
357
|
369
|
{$ENDIF}
|
|
@@ -364,7 +376,7 @@ begin
|
364
|
376
|
else begin
|
365
|
377
|
// If the download was cancelled by the form, this error will already
|
366
|
378
|
// have been given.
|
367
|
|
- {$IFNDEF LAZARUS}
|
|
379
|
+ {$IFNDEF KOL}
|
368
|
380
|
showError('JRE Download was aborted', false);
|
369
|
381
|
{$ENDIF}
|
370
|
382
|
end;
|
|
@@ -415,11 +427,7 @@ var
|
415
|
427
|
Reg: TRegistry;
|
416
|
428
|
result: Integer;
|
417
|
429
|
begin
|
418
|
|
- {$IFDEF LAZARUS}
|
419
|
|
- Application.Initialize;
|
420
|
|
- Application.CreateForm(TProgressForm, form);
|
421
|
|
- {$ENDIF}
|
422
|
|
-
|
|
430
|
+
|
423
|
431
|
if IsConsole then begin
|
424
|
432
|
writeln('-----------------------------------------------------------------------');
|
425
|
433
|
writeln('Welcome to the DMDirc installer.');
|