|
@@ -1,138 +1,138 @@
|
1
|
|
-{*
|
2
|
|
- * This application launches the dmdirc java-based installer.
|
3
|
|
- *
|
4
|
|
- * DMDirc - Open Source IRC Client
|
5
|
|
- * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes,
|
6
|
|
- * Michael Nixon
|
7
|
|
- *
|
8
|
|
- * Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
|
- * of this software and associated documentation files (the "Software"), to deal
|
10
|
|
- * in the Software without restriction, including without limitation the rights
|
11
|
|
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
|
- * copies of the Software, and to permit persons to whom the Software is
|
13
|
|
- * furnished to do so, subject to the following conditions:
|
14
|
|
- *
|
15
|
|
- * The above copyright notice and this permission notice shall be included in
|
16
|
|
- * all copies or substantial portions of the Software.
|
17
|
|
- *
|
18
|
|
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
|
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
|
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
|
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
|
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
|
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
24
|
|
- * SOFTWARE.
|
25
|
|
- *}
|
26
|
|
-
|
27
|
|
-(* Current DMDirc windows setup flow:
|
28
|
|
- *
|
29
|
|
- * 1) Outer wrapper EXE that extracts a 7zip SFX to windows temp dir
|
30
|
|
- * 2) 7zip SFX unpacks
|
31
|
|
- * 3) Wrapper EXE starts Setup.exe (this program)
|
32
|
|
- * 4) Setup checks for existence of the JRE and offers to download/install it
|
33
|
|
- * 5) Setup starts the java portion of the DMDirc installer
|
34
|
|
- *)
|
35
|
|
-program Setup;
|
36
|
|
-
|
37
|
|
-// Resource file - icon, versioninfo, manifest
|
38
|
|
-{$R most.res}
|
39
|
|
-
|
40
|
|
-{ ---------------------------------------------------------------------------- }
|
41
|
|
-{$IFDEF FPC}
|
42
|
|
- {$MODE Delphi}
|
43
|
|
-{$ENDIF}
|
44
|
|
-
|
45
|
|
-// Use this instead of {$APPTYPE XXX}
|
46
|
|
-// APP_XXX is the same as {$APPTYPE XXX}
|
47
|
|
-// Defaults to console
|
48
|
|
-// This is a work-around for a bug in FPC Cross Compiling to windows in delphi
|
49
|
|
-// mode (IsConsole is always true)
|
50
|
|
-{$DEFINE APP_GUI}
|
51
|
|
-
|
52
|
|
-// This block actually does the work for the above work-around
|
53
|
|
-{$IFDEF APP_GUI}
|
54
|
|
- {$APPTYPE GUI}
|
55
|
|
-{$ELSE}
|
56
|
|
- {$IFDEF APP_FS}
|
57
|
|
- {$APPTYPE FS}
|
58
|
|
- {$ELSE}
|
59
|
|
- {$IFDEF APP_TOOL}
|
60
|
|
- {$DEFINE APP_CONSOLE}
|
61
|
|
- {$APPTYPE TOOL}
|
62
|
|
- {$ELSE}
|
63
|
|
- {$DEFINE APP_CONSOLE}
|
64
|
|
- {$APPTYPE CONSOLE}
|
65
|
|
- {$ENDIF}
|
66
|
|
- {$ENDIF}
|
67
|
|
-{$ENDIF}
|
68
|
|
-
|
69
|
|
-{ ----------------------------------------------------------------------------
|
70
|
|
- Debugging specific compiler directives
|
71
|
|
- ---------------------------------------------------------------------------- }
|
72
|
|
-
|
73
|
|
-// If defined the JRE will always be downloaded as if it didn't exist. Used for
|
74
|
|
-// testing the JRE download dialog.
|
75
|
|
-//{$DEFINE FORCEJREDOWNLOAD}
|
76
|
|
-
|
77
|
|
-uses
|
78
|
|
- kol, Vista, Windows, SysUtils, classes, registry;
|
79
|
|
-
|
80
|
|
-const
|
81
|
|
- // SetupConsts holds build information for this release
|
82
|
|
- {$I SetupConsts.inc}
|
83
|
|
- // This is also part of the above IsConsole workaround.
|
84
|
|
- {$IFDEF APP_CONSOLE}
|
85
|
|
- IsConsole: boolean = true;
|
86
|
|
- {$ELSE}
|
87
|
|
- IsConsole: boolean = false;
|
88
|
|
- {$ENDIF}
|
89
|
|
-
|
90
|
|
-var
|
91
|
|
- { --------------------------------------------------------------------------
|
92
|
|
- KOL form objects
|
93
|
|
- -------------------------------------------------------------------------- }
|
94
|
|
- frmmain: pcontrol;
|
95
|
|
- progressbar, btncancel: pcontrol;
|
96
|
|
- label1, label2, label3, label4, labelurl, labelspeed, labelprogress: pcontrol;
|
97
|
|
-
|
98
|
|
- { --------------------------------------------------------------------------
|
99
|
|
- Other globals
|
100
|
|
- -------------------------------------------------------------------------- }
|
101
|
|
- terminateDownload: boolean = false;
|
102
|
|
-
|
103
|
|
-{ ----------------------------------------------------------------------------
|
104
|
|
- Main form: Cancel button clicked event
|
105
|
|
- ---------------------------------------------------------------------------- }
|
106
|
|
-procedure btnCancel_Click(Dummy: Pointer; Sender: PControl);
|
|
1
|
+{*
|
|
2
|
+ * This application launches the dmdirc java-based installer.
|
|
3
|
+ *
|
|
4
|
+ * DMDirc - Open Source IRC Client
|
|
5
|
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes,
|
|
6
|
+ * Michael Nixon
|
|
7
|
+ *
|
|
8
|
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+ * of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+ * in the Software without restriction, including without limitation the rights
|
|
11
|
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+ * copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+ * furnished to do so, subject to the following conditions:
|
|
14
|
+ *
|
|
15
|
+ * The above copyright notice and this permission notice shall be included in
|
|
16
|
+ * all copies or substantial portions of the Software.
|
|
17
|
+ *
|
|
18
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+ * SOFTWARE.
|
|
25
|
+ *}
|
|
26
|
+
|
|
27
|
+(* Current DMDirc windows setup flow:
|
|
28
|
+ *
|
|
29
|
+ * 1) Outer wrapper EXE that extracts a 7zip SFX to windows temp dir
|
|
30
|
+ * 2) 7zip SFX unpacks
|
|
31
|
+ * 3) Wrapper EXE starts Setup.exe (this program)
|
|
32
|
+ * 4) Setup checks for existence of the JRE and offers to download/install it
|
|
33
|
+ * 5) Setup starts the java portion of the DMDirc installer
|
|
34
|
+ *)
|
|
35
|
+program Setup;
|
|
36
|
+
|
|
37
|
+// Resource file - icon, versioninfo, manifest
|
|
38
|
+{$R most.res}
|
|
39
|
+
|
|
40
|
+{ ---------------------------------------------------------------------------- }
|
|
41
|
+{$IFDEF FPC}
|
|
42
|
+ {$MODE Delphi}
|
|
43
|
+{$ENDIF}
|
|
44
|
+
|
|
45
|
+// Use this instead of {$APPTYPE XXX}
|
|
46
|
+// APP_XXX is the same as {$APPTYPE XXX}
|
|
47
|
+// Defaults to console
|
|
48
|
+// This is a work-around for a bug in FPC Cross Compiling to windows in delphi
|
|
49
|
+// mode (IsConsole is always true)
|
|
50
|
+{$DEFINE APP_GUI}
|
|
51
|
+
|
|
52
|
+// This block actually does the work for the above work-around
|
|
53
|
+{$IFDEF APP_GUI}
|
|
54
|
+ {$APPTYPE GUI}
|
|
55
|
+{$ELSE}
|
|
56
|
+ {$IFDEF APP_FS}
|
|
57
|
+ {$APPTYPE FS}
|
|
58
|
+ {$ELSE}
|
|
59
|
+ {$IFDEF APP_TOOL}
|
|
60
|
+ {$DEFINE APP_CONSOLE}
|
|
61
|
+ {$APPTYPE TOOL}
|
|
62
|
+ {$ELSE}
|
|
63
|
+ {$DEFINE APP_CONSOLE}
|
|
64
|
+ {$APPTYPE CONSOLE}
|
|
65
|
+ {$ENDIF}
|
|
66
|
+ {$ENDIF}
|
|
67
|
+{$ENDIF}
|
|
68
|
+
|
|
69
|
+{ ----------------------------------------------------------------------------
|
|
70
|
+ Debugging specific compiler directives
|
|
71
|
+ ---------------------------------------------------------------------------- }
|
|
72
|
+
|
|
73
|
+// If defined the JRE will always be downloaded as if it didn't exist. Used for
|
|
74
|
+// testing the JRE download dialog.
|
|
75
|
+//{$DEFINE FORCEJREDOWNLOAD}
|
|
76
|
+
|
|
77
|
+uses
|
|
78
|
+ kol, Vista, Windows, SysUtils, classes, registry;
|
|
79
|
+
|
|
80
|
+const
|
|
81
|
+ // SetupConsts holds build information for this release
|
|
82
|
+ {$I SetupConsts.inc}
|
|
83
|
+ // This is also part of the above IsConsole workaround.
|
|
84
|
+ {$IFDEF APP_CONSOLE}
|
|
85
|
+ IsConsole: boolean = true;
|
|
86
|
+ {$ELSE}
|
|
87
|
+ IsConsole: boolean = false;
|
|
88
|
+ {$ENDIF}
|
|
89
|
+
|
|
90
|
+var
|
|
91
|
+ { --------------------------------------------------------------------------
|
|
92
|
+ KOL form objects
|
|
93
|
+ -------------------------------------------------------------------------- }
|
|
94
|
+ frmmain: pcontrol;
|
|
95
|
+ progressbar, btncancel: pcontrol;
|
|
96
|
+ label1, label2, label3, label4, labelurl, labelspeed, labelprogress: pcontrol;
|
|
97
|
+
|
|
98
|
+ { --------------------------------------------------------------------------
|
|
99
|
+ Other globals
|
|
100
|
+ -------------------------------------------------------------------------- }
|
|
101
|
+ terminateDownload: boolean = false;
|
|
102
|
+
|
|
103
|
+{ ----------------------------------------------------------------------------
|
|
104
|
+ Main form: Cancel button clicked event
|
|
105
|
+ ---------------------------------------------------------------------------- }
|
|
106
|
+procedure btnCancel_Click(Dummy: Pointer; Sender: PControl);
|
107
|
107
|
begin
|
108
|
108
|
terminateDownload := true;
|
109
|
109
|
end;
|
110
|
|
-
|
111
|
|
-{ ----------------------------------------------------------------------------
|
112
|
|
- Main form: Set progress percentage to <value> and display in label <msg>
|
113
|
|
- ---------------------------------------------------------------------------- }
|
114
|
|
-procedure setProgress(value: integer; msg: string);
|
115
|
|
-begin
|
116
|
|
- ProgressBar.progress := value;
|
117
|
|
- labelprogress.Caption := msg;
|
118
|
|
- //self.Caption := pChar('DMDirc Setup - '+CaptionLabel.Caption);
|
119
|
|
- //Application.Title := self.Caption;
|
120
|
|
- applet.processmessages;
|
121
|
|
-end;
|
122
|
|
-
|
123
|
|
-{ ----------------------------------------------------------------------------
|
124
|
|
- Initialise KOL and create the main window
|
125
|
|
- ---------------------------------------------------------------------------- }
|
126
|
|
-procedure CreateMainWindow;
|
127
|
|
-var
|
|
110
|
+
|
|
111
|
+{ ----------------------------------------------------------------------------
|
|
112
|
+ Main form: Set progress percentage to <value> and display in label <msg>
|
|
113
|
+ ---------------------------------------------------------------------------- }
|
|
114
|
+procedure setProgress(value: integer; msg: string);
|
|
115
|
+begin
|
|
116
|
+ ProgressBar.progress := value;
|
|
117
|
+ labelprogress.Caption := msg;
|
|
118
|
+ //self.Caption := pChar('DMDirc Setup - '+CaptionLabel.Caption);
|
|
119
|
+ //Application.Title := self.Caption;
|
|
120
|
+ applet.processmessages;
|
|
121
|
+end;
|
|
122
|
+
|
|
123
|
+{ ----------------------------------------------------------------------------
|
|
124
|
+ Initialise KOL and create the main window
|
|
125
|
+ ---------------------------------------------------------------------------- }
|
|
126
|
+procedure CreateMainWindow;
|
|
127
|
+var
|
128
|
128
|
screenw, screenh: longint;
|
129
|
|
-begin
|
130
|
|
- { This call is required for common control 6 DLL to be correctly imported.
|
131
|
|
- Without it strange things happen on windows XP }
|
132
|
|
- InitCommonControls;
|
133
|
|
-
|
134
|
|
- { We need the screen size to centre the window later }
|
135
|
|
- screenw := GetSystemMetrics(SM_CXSCREEN);
|
|
129
|
+begin
|
|
130
|
+ { This call is required for common control 6 DLL to be correctly imported.
|
|
131
|
+ Without it strange things happen on windows XP }
|
|
132
|
+ InitCommonControls;
|
|
133
|
+
|
|
134
|
+ { We need the screen size to centre the window later }
|
|
135
|
+ screenw := GetSystemMetrics(SM_CXSCREEN);
|
136
|
136
|
screenh := GetSystemMetrics(SM_CYSCREEN);
|
137
|
137
|
|
138
|
138
|
{ KOL programs ideally need an Applet created }
|
|
@@ -195,27 +195,27 @@ begin
|
195
|
195
|
labelprogress := NewLabel(frmmain, '').SetPosition(70, label3.top + 20);
|
196
|
196
|
labelprogress.SetSize(frmmain.ClientWidth - 32, 16);
|
197
|
197
|
labelprogress.BringToFront;
|
198
|
|
-
|
199
|
|
- { Assign UI methods }
|
200
|
|
- btncancel.OnClick := TOnEvent(MakeMethod(nil, @btnCancel_Click ));
|
201
|
|
-
|
202
|
|
- { The window will not appear until the messageloop is started with Run() but
|
203
|
|
- this means we must yield this thread to the UI. This is unacceptable for
|
204
|
|
- such a simple program. Calling CreateWindow here will cause the window to
|
205
|
|
- appear but the message loop does not run; consequently the app must service
|
206
|
|
- messages by hand at a timely interval to avoid windows from marking the
|
207
|
|
- program as unresponsive. This is a hack but acceptable here. }
|
208
|
|
-
|
209
|
|
- { /!\ WARNING /!\ Run() can no longer be used to enter the message loop after
|
210
|
|
- this call or a nasty crash will occur. }
|
211
|
|
- applet.createwindow;
|
212
|
|
-end;
|
213
|
|
-
|
214
|
|
-{ ----------------------------------------------------------------------------
|
215
|
|
- Takes a size, <dsize> in bytes, and converts it a human readable string with
|
|
198
|
+
|
|
199
|
+ { Assign UI methods }
|
|
200
|
+ btncancel.OnClick := TOnEvent(MakeMethod(nil, @btnCancel_Click ));
|
|
201
|
+
|
|
202
|
+ { The window will not appear until the messageloop is started with Run() but
|
|
203
|
+ this means we must yield this thread to the UI. This is unacceptable for
|
|
204
|
+ such a simple program. Calling CreateWindow here will cause the window to
|
|
205
|
+ appear but the message loop does not run; consequently the app must service
|
|
206
|
+ messages by hand at a timely interval to avoid windows from marking the
|
|
207
|
+ program as unresponsive. This is a hack but acceptable here. }
|
|
208
|
+
|
|
209
|
+ { /!\ WARNING /!\ Run() can no longer be used to enter the message loop after
|
|
210
|
+ this call or a nasty crash will occur. }
|
|
211
|
+ applet.createwindow;
|
|
212
|
+end;
|
|
213
|
+
|
|
214
|
+{ ----------------------------------------------------------------------------
|
|
215
|
+ Takes a size, <dsize> in bytes, and converts it a human readable string with
|
216
|
216
|
a suffix (MB or GB).
|
217
|
|
- ---------------------------------------------------------------------------- }
|
218
|
|
-function nicesize(dsize: extended): string;
|
|
217
|
+ ---------------------------------------------------------------------------- }
|
|
218
|
+function nicesize(dsize: extended): string;
|
219
|
219
|
var
|
220
|
220
|
kbytes: single;
|
221
|
221
|
mbytes: single;
|
|
@@ -238,322 +238,326 @@ begin
|
238
|
238
|
result := FloatToStrF(gbytes, ffFixed, 10, 2) + ' GB';
|
239
|
239
|
exit;
|
240
|
240
|
end;
|
241
|
|
-
|
242
|
|
-{ ----------------------------------------------------------------------------
|
243
|
|
- Ask a question and return True for YES and False for NO
|
244
|
|
- Uses nifty vista task dialog if available
|
245
|
|
- ---------------------------------------------------------------------------- }
|
246
|
|
-function askQuestion(Question: String): boolean;
|
247
|
|
-begin
|
248
|
|
- Result := TaskDialog(0, 'DMDirc Setup', 'Question', Question, TD_ICON_QUESTION, TD_BUTTON_YES + TD_BUTTON_NO) = mrYes;
|
249
|
|
-end;
|
250
|
|
-
|
251
|
|
-{ ----------------------------------------------------------------------------
|
252
|
|
- Show an error message
|
253
|
|
- Uses nifty vista task dialog if available
|
254
|
|
- ---------------------------------------------------------------------------- }
|
255
|
|
-procedure showError(ErrorMessage: String; addFooter: boolean = true; includeDescInXP: boolean = true);
|
256
|
|
-begin
|
257
|
|
- if addFooter then begin
|
258
|
|
- ErrorMessage := ErrorMessage+#13#10;
|
259
|
|
- ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
|
260
|
|
- if not IsWindowsVista then ErrorMessage := ErrorMessage+#13#10;
|
261
|
|
- ErrorMessage := ErrorMessage+'please feel free to contact us.';
|
262
|
|
- end;
|
263
|
|
- TaskDialog(0, 'DMDirc Setup', 'Sorry, setup is unable to continue.', ErrorMessage, TD_ICON_ERROR, TD_BUTTON_OK, includeDescInXP, false);
|
264
|
|
-end;
|
265
|
|
-
|
266
|
|
-{ ----------------------------------------------------------------------------
|
267
|
|
- Show a message box (information)
|
268
|
|
- Uses nifty vista task dialog if available
|
269
|
|
- ---------------------------------------------------------------------------- }
|
270
|
|
-procedure showmessage(message: String; context:String = 'Information');
|
271
|
|
-begin
|
272
|
|
- TaskDialog(0, 'DMDirc Setup', context, message, TD_ICON_INFORMATION, TD_BUTTON_OK);
|
273
|
|
-end;
|
274
|
|
-
|
275
|
|
-{ ----------------------------------------------------------------------------
|
276
|
|
- Launch a process (hidden if requested) and immediately return control to
|
277
|
|
- the current thread
|
278
|
|
- ---------------------------------------------------------------------------- }
|
279
|
|
-function Launch(sProgramToRun: String; hide: boolean = false): TProcessInformation;
|
280
|
|
-var
|
281
|
|
- StartupInfo: TStartupInfo;
|
282
|
|
-begin
|
283
|
|
- FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
|
284
|
|
- with StartupInfo do begin
|
285
|
|
- cb := SizeOf(TStartupInfo);
|
286
|
|
- dwFlags := STARTF_USESHOWWINDOW;
|
287
|
|
- if hide then wShowWindow := SW_HIDE
|
288
|
|
- else wShowWindow := SW_SHOWNORMAL;
|
289
|
|
- end;
|
290
|
|
-
|
291
|
|
- CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, Result);
|
292
|
|
-end;
|
293
|
|
-
|
294
|
|
-{ ----------------------------------------------------------------------------
|
295
|
|
- Launch a process (hidden if requested) and wait for it to finish
|
296
|
|
- ---------------------------------------------------------------------------- }
|
297
|
|
-function ExecAndWait(sProgramToRun: String; hide: boolean = false): Longword;
|
298
|
|
-var
|
299
|
|
- ProcessInfo: TProcessInformation;
|
300
|
|
-begin
|
301
|
|
- ProcessInfo := Launch(sProgramToRun, hide);
|
302
|
|
- getExitCodeProcess(ProcessInfo.hProcess, Result);
|
303
|
|
-
|
304
|
|
- while Result = STILL_ACTIVE do begin
|
305
|
|
- sleep(1000);
|
306
|
|
- GetExitCodeProcess(ProcessInfo.hProcess, Result);
|
307
|
|
- end;
|
308
|
|
-end;
|
309
|
|
-
|
310
|
|
-{ ----------------------------------------------------------------------------
|
311
|
|
- Return the size in bytes of the file specified by <name>
|
312
|
|
- Returns -1 on error
|
313
|
|
- ---------------------------------------------------------------------------- }
|
314
|
|
-function GetFileSizeByName(name: String): Integer;
|
315
|
|
-var
|
316
|
|
- hand: THandle;
|
317
|
|
-begin
|
318
|
|
- hand := 0;
|
319
|
|
- Result := 0;
|
320
|
|
- if FileExists(name) then begin
|
321
|
|
- try
|
322
|
|
- hand := CreateFile(PChar(name), GENERIC_READ, FILE_SHARE_WRITE or FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
323
|
|
- Result := GetFileSize(hand, nil);
|
324
|
|
- finally
|
325
|
|
- try
|
326
|
|
- if (hand <> 0) then CloseHandle(hand);
|
327
|
|
- except
|
328
|
|
- Result := -1;
|
329
|
|
- end;
|
330
|
|
- end;
|
331
|
|
- end;
|
332
|
|
-end;
|
333
|
|
-
|
334
|
|
-{$IFNDEF VER150}
|
335
|
|
-{ ----------------------------------------------------------------------------
|
336
|
|
- Return part of a string
|
337
|
|
- ---------------------------------------------------------------------------- }
|
338
|
|
-function AnsiMidStr(Source: String; Start: Integer; Count: Integer): String;
|
339
|
|
-begin
|
340
|
|
- // Not perfectly accurate, but does the job
|
341
|
|
- { ^ What does that mean? // Zipplet }
|
342
|
|
- Result := Copy(Source, Start, Count);
|
343
|
|
-end;
|
344
|
|
-{$ENDIF}
|
345
|
|
-
|
346
|
|
-{ ----------------------------------------------------------------------------
|
347
|
|
- Downloads the JRE. Returns TRUE if the user installed it. False otherwise
|
348
|
|
- ---------------------------------------------------------------------------- }
|
349
|
|
-function downloadJRE(message: String = 'Would you like to download the java JRE?'): boolean;
|
350
|
|
-var
|
351
|
|
- ProcessInfo: TProcessInformation;
|
352
|
|
- processResult: Longword;
|
353
|
|
- url: String;
|
354
|
|
- dir: String;
|
355
|
|
- line: String;
|
356
|
|
- f: TextFile;
|
357
|
|
- bits: TStringList;
|
358
|
|
- match: boolean;
|
359
|
|
- wantedsize: double;
|
360
|
|
- currentsize: double;
|
361
|
|
- lastsize: double;
|
362
|
|
- i: double;
|
363
|
|
- c: longint;
|
364
|
|
-begin
|
365
|
|
- dir := IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)));
|
366
|
|
- url := 'http://www.dmdirc.com/getjava/windows/all';
|
367
|
|
- Result := false;
|
368
|
|
-
|
369
|
|
- { First we will determine the approximate size of the download.
|
370
|
|
- In my opinion we should not do this until we have asked the user if they
|
371
|
|
- would like to download the JRE. Might change this later.
|
372
|
|
- We obtain the size by asking wget to find out. }
|
373
|
|
- ExecAndWait('wget.exe -o "'+dir+'wgetoutput" --spider '+url, true);
|
374
|
|
-
|
375
|
|
- { Just incase wget fails ... }
|
376
|
|
- if not fileexists(dir+'wgetoutput') then begin
|
|
241
|
+
|
|
242
|
+{ ----------------------------------------------------------------------------
|
|
243
|
+ Ask a question and return True for YES and False for NO
|
|
244
|
+ Uses nifty vista task dialog if available
|
|
245
|
+ ---------------------------------------------------------------------------- }
|
|
246
|
+function askQuestion(Question: String): boolean;
|
|
247
|
+begin
|
|
248
|
+ Result := TaskDialog(0, 'DMDirc Setup', 'Question', Question, TD_ICON_QUESTION, TD_BUTTON_YES + TD_BUTTON_NO) = mrYes;
|
|
249
|
+end;
|
|
250
|
+
|
|
251
|
+{ ----------------------------------------------------------------------------
|
|
252
|
+ Show an error message
|
|
253
|
+ Uses nifty vista task dialog if available
|
|
254
|
+ ---------------------------------------------------------------------------- }
|
|
255
|
+procedure showError(ErrorMessage: String; addFooter: boolean = true; includeDescInXP: boolean = true);
|
|
256
|
+begin
|
|
257
|
+ if addFooter then begin
|
|
258
|
+ ErrorMessage := ErrorMessage+#13#10;
|
|
259
|
+ ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
|
|
260
|
+ if not IsWindowsVista then ErrorMessage := ErrorMessage+#13#10;
|
|
261
|
+ ErrorMessage := ErrorMessage+'please feel free to contact us.';
|
|
262
|
+ end;
|
|
263
|
+ TaskDialog(0, 'DMDirc Setup', 'Sorry, setup is unable to continue.', ErrorMessage, TD_ICON_ERROR, TD_BUTTON_OK, includeDescInXP, false);
|
|
264
|
+end;
|
|
265
|
+
|
|
266
|
+{ ----------------------------------------------------------------------------
|
|
267
|
+ Show a message box (information)
|
|
268
|
+ Uses nifty vista task dialog if available
|
|
269
|
+ ---------------------------------------------------------------------------- }
|
|
270
|
+procedure showmessage(message: String; context:String = 'Information');
|
|
271
|
+begin
|
|
272
|
+ TaskDialog(0, 'DMDirc Setup', context, message, TD_ICON_INFORMATION, TD_BUTTON_OK);
|
|
273
|
+end;
|
|
274
|
+
|
|
275
|
+{ ----------------------------------------------------------------------------
|
|
276
|
+ Launch a process (hidden if requested) and immediately return control to
|
|
277
|
+ the current thread
|
|
278
|
+ ---------------------------------------------------------------------------- }
|
|
279
|
+function Launch(sProgramToRun: String; hide: boolean = false): TProcessInformation;
|
|
280
|
+var
|
|
281
|
+ StartupInfo: TStartupInfo;
|
|
282
|
+begin
|
|
283
|
+ FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
|
|
284
|
+ with StartupInfo do begin
|
|
285
|
+ cb := SizeOf(TStartupInfo);
|
|
286
|
+ dwFlags := STARTF_USESHOWWINDOW;
|
|
287
|
+ if hide then wShowWindow := SW_HIDE
|
|
288
|
+ else wShowWindow := SW_SHOWNORMAL;
|
|
289
|
+ end;
|
|
290
|
+
|
|
291
|
+ CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, Result);
|
|
292
|
+end;
|
|
293
|
+
|
|
294
|
+{ ----------------------------------------------------------------------------
|
|
295
|
+ Launch a process (hidden if requested) and wait for it to finish
|
|
296
|
+ ---------------------------------------------------------------------------- }
|
|
297
|
+function ExecAndWait(sProgramToRun: String; hide: boolean = false): Longword;
|
|
298
|
+var
|
|
299
|
+ ProcessInfo: TProcessInformation;
|
|
300
|
+begin
|
|
301
|
+ ProcessInfo := Launch(sProgramToRun, hide);
|
|
302
|
+ getExitCodeProcess(ProcessInfo.hProcess, Result);
|
|
303
|
+
|
|
304
|
+ while Result = STILL_ACTIVE do begin
|
|
305
|
+ sleep(1000);
|
|
306
|
+ GetExitCodeProcess(ProcessInfo.hProcess, Result);
|
|
307
|
+ end;
|
|
308
|
+end;
|
|
309
|
+
|
|
310
|
+{ ----------------------------------------------------------------------------
|
|
311
|
+ Return the size in bytes of the file specified by <name>
|
|
312
|
+ Returns -1 on error
|
|
313
|
+ ---------------------------------------------------------------------------- }
|
|
314
|
+function GetFileSizeByName(name: String): Integer;
|
|
315
|
+var
|
|
316
|
+ hand: THandle;
|
|
317
|
+begin
|
|
318
|
+ hand := 0;
|
|
319
|
+ Result := 0;
|
|
320
|
+ if FileExists(name) then begin
|
|
321
|
+ try
|
|
322
|
+ hand := CreateFile(PChar(name), GENERIC_READ, FILE_SHARE_WRITE or FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
|
323
|
+ Result := GetFileSize(hand, nil);
|
|
324
|
+ finally
|
|
325
|
+ try
|
|
326
|
+ if (hand <> 0) then CloseHandle(hand);
|
|
327
|
+ except
|
|
328
|
+ Result := -1;
|
|
329
|
+ end;
|
|
330
|
+ end;
|
|
331
|
+ end;
|
|
332
|
+end;
|
|
333
|
+
|
|
334
|
+{$IFNDEF VER150}
|
|
335
|
+{ ----------------------------------------------------------------------------
|
|
336
|
+ Return part of a string
|
|
337
|
+ ---------------------------------------------------------------------------- }
|
|
338
|
+function AnsiMidStr(Source: String; Start: Integer; Count: Integer): String;
|
|
339
|
+begin
|
|
340
|
+ // Not perfectly accurate, but does the job
|
|
341
|
+ { ^ What does that mean? // Zipplet }
|
|
342
|
+ Result := Copy(Source, Start, Count);
|
|
343
|
+end;
|
|
344
|
+{$ENDIF}
|
|
345
|
+
|
|
346
|
+{ ----------------------------------------------------------------------------
|
|
347
|
+ Downloads the JRE. Returns TRUE if the user installed it. False otherwise
|
|
348
|
+ ---------------------------------------------------------------------------- }
|
|
349
|
+function downloadJRE(message: String = 'Would you like to download the java JRE?'): boolean;
|
|
350
|
+var
|
|
351
|
+ ProcessInfo: TProcessInformation;
|
|
352
|
+ processResult: Longword;
|
|
353
|
+ url: String;
|
|
354
|
+ dir: String;
|
|
355
|
+ line: String;
|
|
356
|
+ f: TextFile;
|
|
357
|
+ bits: TStringList;
|
|
358
|
+ match: boolean;
|
|
359
|
+ wantedsize: double;
|
|
360
|
+ currentsize: double;
|
|
361
|
+ lastsize: double;
|
|
362
|
+ i: double;
|
|
363
|
+ c: longint;
|
|
364
|
+begin
|
|
365
|
+ dir := IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)));
|
|
366
|
+ url := 'http://www.dmdirc.com/getjava/windows/all';
|
|
367
|
+ Result := false;
|
|
368
|
+
|
|
369
|
+ { First we will determine the approximate size of the download.
|
|
370
|
+ In my opinion we should not do this until we have asked the user if they
|
|
371
|
+ would like to download the JRE. Might change this later.
|
|
372
|
+ We obtain the size by asking wget to find out. }
|
|
373
|
+ ExecAndWait('wget.exe -o "'+dir+'wgetoutput" --spider '+url, true);
|
|
374
|
+
|
|
375
|
+ { Just incase wget fails ... }
|
|
376
|
+ if not fileexists(dir+'wgetoutput') then begin
|
377
|
377
|
showerror('Internal error: wget returned no output.');
|
378
|
378
|
result := false;
|
379
|
379
|
exit;
|
380
|
|
- end;
|
381
|
|
-
|
382
|
|
- { Parse the output and grab the approximate size }
|
383
|
|
- AssignFile(f, dir+'wgetoutput');
|
384
|
|
- Reset(f);
|
385
|
|
- line := '';
|
386
|
|
- match := false;
|
387
|
|
- while not Eof(f) do begin
|
388
|
|
- ReadLn(f, line);
|
389
|
|
- if length(line) > 8 then begin
|
|
380
|
+ end;
|
|
381
|
+
|
|
382
|
+ { Parse the output and grab the approximate size }
|
|
383
|
+ AssignFile(f, dir+'wgetoutput');
|
|
384
|
+ Reset(f);
|
|
385
|
+ line := '';
|
|
386
|
+ match := false;
|
|
387
|
+ while not Eof(f) do begin
|
|
388
|
+ ReadLn(f, line);
|
|
389
|
+ if length(line) > 8 then begin
|
390
|
390
|
if copy(line, 1, 7) = 'Length:' then begin
|
391
|
391
|
match := true;
|
392
|
392
|
break;
|
393
|
393
|
end;
|
394
|
|
- end;
|
395
|
|
- end;
|
396
|
|
- if match then begin
|
397
|
|
- bits := TStringList.create;
|
398
|
|
- try
|
399
|
|
- bits.Clear;
|
400
|
|
- bits.Delimiter := ' ';
|
401
|
|
- bits.DelimitedText := line;
|
402
|
|
- try
|
403
|
|
- wantedsize := strtoint(StringReplace(bits[1], ',', '', [rfReplaceAll]))
|
404
|
|
- except
|
405
|
|
- wantedsize := 0;
|
406
|
|
- end;
|
407
|
|
-
|
408
|
|
- { We ask the user if they wish to download the JRE }
|
409
|
|
- if askQuestion(message+' (Download Size: '+AnsiMidStr(bits[2], 2, length(bits[2])-2)+')') then begin
|
410
|
|
- { Create progress window and show it }
|
411
|
|
- CreateMainWindow;
|
412
|
|
- { Get wget to start the download }
|
413
|
|
- ProcessInfo := Launch('wget.exe '+url+' -O jre.exe', true);
|
414
|
|
- labelurl.caption := url;
|
415
|
|
- labelspeed.caption := 'Connecting to site...';
|
416
|
|
-
|
417
|
|
- { Why is this case needed ?! }
|
418
|
|
- if wantedsize <= 0 then begin
|
419
|
|
- progressbar.progress := 50;
|
420
|
|
- end;
|
421
|
|
- getExitCodeProcess(ProcessInfo.hProcess, processResult);
|
422
|
|
-
|
423
|
|
- lastsize := 0;
|
424
|
|
- c := 0;
|
425
|
|
- i := 0;
|
426
|
|
- while (processResult = STILL_ACTIVE) and (not terminateDownload) do begin
|
427
|
|
- if wantedsize > 0 then begin
|
428
|
|
- currentsize := GetFileSizeByName(dir + 'jre.exe');
|
429
|
|
- inc(c);
|
430
|
|
- if (c >= 5) then begin
|
431
|
|
- i := (i + currentsize - lastsize) / 2;
|
432
|
|
- labelspeed.caption := nicesize(round(i * 2)) + '/sec';
|
433
|
|
- lastsize := currentsize;
|
434
|
|
- c := 0;
|
435
|
|
- end;
|
436
|
|
- if (currentsize > 0) then setProgress(Round((currentsize/wantedsize)*100),
|
437
|
|
- nicesize(currentsize) + ' of ' + nicesize(wantedsize) +
|
438
|
|
- ' (' + inttostr(Round((currentsize/wantedsize)*100)) + '%)');
|
439
|
|
- end;
|
440
|
|
- { We must process the message loop or the window wont respond to the user }
|
441
|
|
- applet.ProcessMessages;
|
442
|
|
- { Sleep to prevent 100% CPU usage }
|
443
|
|
- sleep(100);
|
444
|
|
- GetExitCodeProcess(ProcessInfo.hProcess, processResult);
|
445
|
|
- end;
|
446
|
|
- frmmain.visible := false;
|
447
|
|
- applet.visible := false;
|
448
|
|
- if (terminateDownload) then begin
|
449
|
|
- Result := false;
|
450
|
|
- TerminateProcess(ProcessInfo.hProcess, 0);
|
451
|
|
- showError('JRE Download was aborted', false);
|
452
|
|
- end
|
453
|
|
- else Result := processResult = 0;
|
454
|
|
- if not Result then begin
|
455
|
|
- if not terminateDownload then begin
|
456
|
|
- showError('JRE Download Failed', false);
|
457
|
|
- end
|
458
|
|
- else begin
|
459
|
|
- // If the download was cancelled by the form, this error will already
|
460
|
|
- // have been given.
|
461
|
|
- { No action needed here anymore }
|
462
|
|
- end;
|
463
|
|
- end;
|
464
|
|
- end;
|
465
|
|
- finally
|
466
|
|
- bits.free;
|
467
|
|
- end;
|
468
|
|
- end;
|
469
|
|
-end;
|
470
|
|
-
|
|
394
|
+ end;
|
|
395
|
+ end;
|
|
396
|
+ if match then begin
|
|
397
|
+ bits := TStringList.create;
|
|
398
|
+ try
|
|
399
|
+ bits.Clear;
|
|
400
|
+ bits.Delimiter := ' ';
|
|
401
|
+ bits.DelimitedText := line;
|
|
402
|
+ try
|
|
403
|
+ wantedsize := strtoint(StringReplace(bits[1], ',', '', [rfReplaceAll]))
|
|
404
|
+ except
|
|
405
|
+ wantedsize := 0;
|
|
406
|
+ end;
|
|
407
|
+
|
|
408
|
+ { We ask the user if they wish to download the JRE }
|
|
409
|
+ if askQuestion(message+' (Download Size: '+AnsiMidStr(bits[2], 2, length(bits[2])-2)+')') then begin
|
|
410
|
+ { Create progress window and show it }
|
|
411
|
+ CreateMainWindow;
|
|
412
|
+ { Get wget to start the download }
|
|
413
|
+ ProcessInfo := Launch('wget.exe '+url+' -O jre.exe', true);
|
|
414
|
+ labelurl.caption := url;
|
|
415
|
+ labelspeed.caption := 'Connecting to site...';
|
|
416
|
+
|
|
417
|
+ { Why is this case needed ?! }
|
|
418
|
+ if wantedsize <= 0 then begin
|
|
419
|
+ progressbar.progress := 50;
|
|
420
|
+ end;
|
|
421
|
+ getExitCodeProcess(ProcessInfo.hProcess, processResult);
|
|
422
|
+
|
|
423
|
+ lastsize := 0;
|
|
424
|
+ c := 0;
|
|
425
|
+ i := 0;
|
|
426
|
+ while (processResult = STILL_ACTIVE) and (not terminateDownload) do begin
|
|
427
|
+ if wantedsize > 0 then begin
|
|
428
|
+ currentsize := GetFileSizeByName(dir + 'jre.exe');
|
|
429
|
+ inc(c);
|
|
430
|
+ if (c >= 5) then begin
|
|
431
|
+ i := (i + currentsize - lastsize) / 2;
|
|
432
|
+ labelspeed.caption := nicesize(round(i * 2)) + '/sec';
|
|
433
|
+ lastsize := currentsize;
|
|
434
|
+ c := 0;
|
|
435
|
+ end;
|
|
436
|
+ if (currentsize > 0) then setProgress(Round((currentsize/wantedsize)*100),
|
|
437
|
+ nicesize(currentsize) + ' of ' + nicesize(wantedsize) +
|
|
438
|
+ ' (' + inttostr(Round((currentsize/wantedsize)*100)) + '%)');
|
|
439
|
+ end;
|
|
440
|
+ { We must process the message loop or the window wont respond to the user }
|
|
441
|
+ applet.ProcessMessages;
|
|
442
|
+ { Sleep to prevent 100% CPU usage }
|
|
443
|
+ sleep(100);
|
|
444
|
+ GetExitCodeProcess(ProcessInfo.hProcess, processResult);
|
|
445
|
+ end;
|
|
446
|
+ frmmain.visible := false;
|
|
447
|
+ applet.visible := false;
|
|
448
|
+ if (terminateDownload) then begin
|
|
449
|
+ Result := false;
|
|
450
|
+ TerminateProcess(ProcessInfo.hProcess, 0);
|
|
451
|
+ showError('JRE Download was aborted', false);
|
|
452
|
+ end
|
|
453
|
+ else Result := processResult = 0;
|
|
454
|
+ if not Result then begin
|
|
455
|
+ if not terminateDownload then begin
|
|
456
|
+ showError('JRE Download Failed', false);
|
|
457
|
+ end
|
|
458
|
+ else begin
|
|
459
|
+ // If the download was cancelled by the form, this error will already
|
|
460
|
+ // have been given.
|
|
461
|
+ { No action needed here anymore }
|
|
462
|
+ end;
|
|
463
|
+ end;
|
|
464
|
+ end;
|
|
465
|
+ finally
|
|
466
|
+ bits.free;
|
|
467
|
+ end;
|
|
468
|
+ end;
|
|
469
|
+end;
|
|
470
|
+
|
|
471
|
+{ ----------------------------------------------------------------------------
|
|
472
|
+ Begin the JRE download/install.
|
|
473
|
+ ---------------------------------------------------------------------------- }
|
|
474
|
+function installJRE(isUpgrade: boolean): boolean;
|
|
475
|
+var
|
|
476
|
+ question: String;
|
|
477
|
+ needDownload: boolean;
|
|
478
|
+ canContinue: boolean;
|
|
479
|
+begin
|
|
480
|
+ Result := false;
|
|
481
|
+ needDownload := not FileExists(IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)))+'jre.exe');
|
|
482
|
+ if needDownload then begin
|
|
483
|
+ if not isUpgrade then question := 'Java was not detected on your machine. Would you like to download and install it now?'
|
|
484
|
+ else question := 'The version of java detected on your machine is not compatible with DMDirc. Would you like to download and install a compatible version now?';
|
|
485
|
+ end
|
|
486
|
+ else begin
|
|
487
|
+ if not isUpgrade then question := 'Java was not detected on your machine. Would you like to install it now?'
|
|
488
|
+ else question := 'The version of java detected on your machine is not compatible with DMDirc. Would you like to install a compatible version now?';
|
|
489
|
+ end;
|
|
490
|
+
|
|
491
|
+ canContinue := true;
|
|
492
|
+ if (needDownload) then begin
|
|
493
|
+ canContinue := downloadJRE(question);
|
|
494
|
+ end;
|
|
495
|
+
|
|
496
|
+ if canContinue then begin
|
|
497
|
+ // Final result of this function is the return value of installing java.
|
|
498
|
+ if needDownload or askQuestion(question) then begin
|
|
499
|
+ showmessage('The Java installer will now run. Please follow the instructions given. '+#13#10+'The DMDirc installation will continue afterwards.');
|
|
500
|
+ Result := (ExecAndWait('jre.exe') = 0);
|
|
501
|
+ end;
|
|
502
|
+ end
|
|
503
|
+end;
|
|
504
|
+
|
471
|
505
|
{ ----------------------------------------------------------------------------
|
472
|
|
- Begin the JRE download/install.
|
473
|
|
- ---------------------------------------------------------------------------- }
|
474
|
|
-function installJRE(isUpgrade: boolean): boolean;
|
475
|
|
-var
|
476
|
|
- question: String;
|
477
|
|
- needDownload: boolean;
|
478
|
|
- canContinue: boolean;
|
479
|
|
-begin
|
480
|
|
- Result := false;
|
481
|
|
- needDownload := not FileExists(IncludeTrailingPathDelimiter(ExtractFileDir(paramstr(0)))+'jre.exe');
|
482
|
|
- if needDownload then begin
|
483
|
|
- if not isUpgrade then question := 'Java was not detected on your machine. Would you like to download and install it now?'
|
484
|
|
- else question := 'The version of java detected on your machine is not compatible with DMDirc. Would you like to download and install a compatible version now?';
|
485
|
|
- end
|
486
|
|
- else begin
|
487
|
|
- if not isUpgrade then question := 'Java was not detected on your machine. Would you like to install it now?'
|
488
|
|
- else question := 'The version of java detected on your machine is not compatible with DMDirc. Would you like to install a compatible version now?';
|
489
|
|
- end;
|
490
|
|
-
|
491
|
|
- canContinue := true;
|
492
|
|
- if (needDownload) then begin
|
493
|
|
- canContinue := downloadJRE(question);
|
494
|
|
- end;
|
495
|
|
-
|
496
|
|
- if canContinue then begin
|
497
|
|
- // Final result of this function is the return value of installing java.
|
498
|
|
- if needDownload or askQuestion(question) then begin
|
499
|
|
- showmessage('The Java installer will now run. Please follow the instructions given. '+#13#10+'The DMDirc installation will continue afterwards.');
|
500
|
|
- Result := (ExecAndWait('jre.exe') = 0);
|
501
|
|
- end;
|
502
|
|
- end
|
503
|
|
-end;
|
504
|
|
-
|
505
|
|
-var
|
506
|
|
- errorMessage: String;
|
507
|
|
- javaCommand: String = 'javaw.exe';
|
508
|
|
- params: String = '';
|
509
|
|
- dir: String = '';
|
510
|
|
- Reg: TRegistry;
|
511
|
|
- result: Integer;
|
512
|
|
-begin
|
513
|
|
-
|
514
|
|
- errorMessage := '';
|
515
|
|
- if FileExists('DMDirc.jar') then begin
|
516
|
|
- {$IFDEF FORCEJREDOWNLOAD}if (1 <> 0) then begin{$ELSE}if (ExecAndWait(javaCommand+' -version') <> 0) then begin{$ENDIF}
|
517
|
|
- if not installJRE(false) then begin
|
518
|
|
- showError('DMDirc setup can not continue without Java. Please install Java and try again.', false, false);
|
519
|
|
- exit;
|
520
|
|
- end;
|
521
|
|
- end;
|
522
|
|
-
|
523
|
|
- Reg := TRegistry.Create;
|
524
|
|
- Reg.RootKey := HKEY_LOCAL_MACHINE;
|
525
|
|
- if Reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc', false) then begin
|
526
|
|
- dir := Reg.ReadString('InstallDir');
|
527
|
|
- if (dir <> '') then begin
|
528
|
|
- params := params+' --directory "'+dir+'"';
|
529
|
|
- end;
|
530
|
|
- end;
|
531
|
|
- Reg.CloseKey;
|
532
|
|
- Reg.Free;
|
533
|
|
- if (ReleaseNumber <> '') then begin
|
534
|
|
- params := params+' --release '+ReleaseNumber;
|
535
|
|
- end;
|
536
|
|
- // Check if the installer runs
|
537
|
|
- if (ExecAndWait(javaCommand+' -cp DMDirc.jar com.dmdirc.installer.Main --help') <> 0) then begin
|
538
|
|
- if not installJRE(true) then begin
|
539
|
|
- showError('Sorry, DMDirc setup can not continue without an updated version of java.', false, false);
|
540
|
|
- exit;
|
541
|
|
- end
|
542
|
|
- else begin
|
543
|
|
- // Try again now that java is installed.
|
544
|
|
- result := ExecAndWait(javaCommand+' -cp DMDirc.jar com.dmdirc.installer.Main '+params);
|
545
|
|
- end;
|
546
|
|
- end
|
547
|
|
- else begin
|
548
|
|
- // Java is the right version, run the installer
|
549
|
|
- result := ExecAndWait(javaCommand+' -cp DMDirc.jar com.dmdirc.installer.Main '+params);
|
550
|
|
- end;
|
551
|
|
- end
|
552
|
|
- else begin
|
553
|
|
- errorMessage := errorMessage+'DMDirc.jar was not found.';
|
554
|
|
- errorMessage := errorMessage+#13#10;
|
555
|
|
- errorMessage := errorMessage+#13#10+'This is likely because of a corrupt installer build.';
|
556
|
|
- errorMessage := errorMessage+#13#10+'Please check http://www.dmdirc.com/ for an updated build.';
|
557
|
|
- showError(errorMessage);
|
558
|
|
- end;
|
559
|
|
-end.
|
|
506
|
+
|
|
507
|
+ MAIN PROGRAM
|
|
508
|
+ ---------------------------------------------------------------------------- }
|
|
509
|
+var
|
|
510
|
+ errorMessage: String;
|
|
511
|
+ javaCommand: String = 'javaw.exe';
|
|
512
|
+ params: String = '';
|
|
513
|
+ dir: String = '';
|
|
514
|
+ Reg: TRegistry;
|
|
515
|
+ result: Integer;
|
|
516
|
+begin
|
|
517
|
+
|
|
518
|
+ errorMessage := '';
|
|
519
|
+ if FileExists('DMDirc.jar') then begin
|
|
520
|
+ {$IFDEF FORCEJREDOWNLOAD}if (1 <> 0) then begin{$ELSE}if (ExecAndWait(javaCommand+' -version') <> 0) then begin{$ENDIF}
|
|
521
|
+ if not installJRE(false) then begin
|
|
522
|
+ showError('DMDirc setup can not continue without Java. Please install Java and try again.', false, false);
|
|
523
|
+ exit;
|
|
524
|
+ end;
|
|
525
|
+ end;
|
|
526
|
+
|
|
527
|
+ Reg := TRegistry.Create;
|
|
528
|
+ Reg.RootKey := HKEY_LOCAL_MACHINE;
|
|
529
|
+ if Reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc', false) then begin
|
|
530
|
+ dir := Reg.ReadString('InstallDir');
|
|
531
|
+ if (dir <> '') then begin
|
|
532
|
+ params := params+' --directory "'+dir+'"';
|
|
533
|
+ end;
|
|
534
|
+ end;
|
|
535
|
+ Reg.CloseKey;
|
|
536
|
+ Reg.Free;
|
|
537
|
+ if (ReleaseNumber <> '') then begin
|
|
538
|
+ params := params+' --release '+ReleaseNumber;
|
|
539
|
+ end;
|
|
540
|
+ // Check if the installer runs
|
|
541
|
+ if (ExecAndWait(javaCommand+' -cp DMDirc.jar com.dmdirc.installer.Main --help') <> 0) then begin
|
|
542
|
+ if not installJRE(true) then begin
|
|
543
|
+ showError('Sorry, DMDirc setup can not continue without an updated version of java.', false, false);
|
|
544
|
+ exit;
|
|
545
|
+ end
|
|
546
|
+ else begin
|
|
547
|
+ // Try again now that java is installed.
|
|
548
|
+ result := ExecAndWait(javaCommand+' -cp DMDirc.jar com.dmdirc.installer.Main '+params);
|
|
549
|
+ end;
|
|
550
|
+ end
|
|
551
|
+ else begin
|
|
552
|
+ // Java is the right version, run the installer
|
|
553
|
+ result := ExecAndWait(javaCommand+' -cp DMDirc.jar com.dmdirc.installer.Main '+params);
|
|
554
|
+ end;
|
|
555
|
+ end
|
|
556
|
+ else begin
|
|
557
|
+ errorMessage := errorMessage+'DMDirc.jar was not found.';
|
|
558
|
+ errorMessage := errorMessage+#13#10;
|
|
559
|
+ errorMessage := errorMessage+#13#10+'This is likely because of a corrupt installer build.';
|
|
560
|
+ errorMessage := errorMessage+#13#10+'Please check http://www.dmdirc.com/ for an updated build.';
|
|
561
|
+ showError(errorMessage);
|
|
562
|
+ end;
|
|
563
|
+end.
|