소스 검색

Fix dmdirc.exe dialogs not showing on windows XP, tidy source code

tags/0.6.3m1rc1
Michael 15 년 전
부모
커밋
d527c64c50
3개의 변경된 파일808개의 추가작업 그리고 739개의 파일을 삭제
  1. 466
    462
      installer/windows/Setup.dpr
  2. 170
    152
      installer/windows/Vista.pas
  3. 172
    125
      launcher/windows/DMDirc.dpr

+ 466
- 462
installer/windows/Setup.dpr 파일 보기

@@ -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.

+ 170
- 152
installer/windows/Vista.pas 파일 보기

@@ -1,83 +1,101 @@
1 1
 {*
2 2
  * Vista image improvements from http://www.installationexcellence.com/articles/VistaWithDelphi/Original/Index.html
3 3
  * and http://www.installationexcellence.com/articles/VistaWithDelphi/Index.html
4
+ *
5
+ * This application launches DMDirc on windows and passes control to the
6
+ * update engine as necessary.
7
+ *
8
+ * DMDirc - Open Source IRC Client
9
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes,
10
+ * Michael Nixon
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in
20
+ * all copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
4 29
  *}
30
+{* NOTE: The version in the installer/ directory is the one to edit! *}
5 31
 unit Vista;
6 32
 
7
-//{$IFDEF LAZARUS}
8
-//	{$DEFINE MESSAGEDLG}
9
-// {$ENDIF}
10
-
11 33
 interface
12 34
 
13
-uses {$IFDEF LAZARUS}Forms, Graphics, Controls,{$IFDEF MESSAGEDLG} Dialogs,{$ENDIF}{$ENDIF} Windows, SysUtils;
35
+uses Windows, SysUtils;
14 36
 
15 37
 function IsWindowsVista: Boolean;
16 38
 function TaskDialog(const AHandle: THandle; const ATitle, ADescription, AContent: WideString; const Icon, Buttons: integer; includeDescInXP: boolean = false; stripLineFeed: boolean = true): Integer;
17
-{$IFDEF LAZARUS}
18
-procedure SetVistaFonts(const AForm: TCustomForm);
19
-{$ENDIF}
39
+//procedure SetVistaFonts(const AForm: TCustomForm);
20 40
 
21 41
 const
22
-	VistaFont = 'Segoe UI'; 
23
-	VistaContentFont = 'Calibri';
24
-	XPContentFont = 'Verdana';
25
-	XPFont = 'Tahoma';
26
-
27
-	TD_ICON_BLANK = 0;
28
-	TD_ICON_WARNING = 84;
29
-	TD_ICON_QUESTION = 99;
30
-	TD_ICON_ERROR = 98;
31
-	TD_ICON_INFORMATION = 81;
32
-	TD_ICON_SHIELD_QUESTION = 104;
33
-	TD_ICON_SHIELD_ERROR = 105;
34
-	TD_ICON_SHIELD_OK = 106;
35
-	TD_ICON_SHIELD_WARNING = 107;
36
-
37
-	TD_BUTTON_OK = 1;
38
-	TD_BUTTON_YES = 2;
39
-	TD_BUTTON_NO = 4;
40
-	TD_BUTTON_CANCEL = 8;
41
-	TD_BUTTON_RETRY = 16;
42
-	TD_BUTTON_CLOSE = 32;
43
-
44
-	TD_RESULT_OK = 1;
45
-	TD_RESULT_CANCEL = 2;
46
-	TD_RESULT_RETRY = 4;
47
-	TD_RESULT_YES = 6;
48
-	TD_RESULT_NO = 7;
49
-	TD_RESULT_CLOSE = 8;
50
-	
51
-	{$IFNDEF LAZARUS}
52
-		mrNone = 0;
53
-		mrOK = mrNone + 1;
54
-		mrCancel = mrNone + 2;
55
-		mrAbort = mrNone + 3;
56
-		mrRetry = mrNone + 4;
57
-		mrYes = mrNone + 6;
58
-		mrNo = mrNone + 7;
59
-	{$ENDIF}
42
+  VistaFont = 'Segoe UI'; 
43
+  VistaContentFont = 'Calibri';
44
+  XPContentFont = 'Verdana';
45
+  XPFont = 'Tahoma';
46
+
47
+  TD_ICON_BLANK = 0;
48
+  TD_ICON_WARNING = 84;
49
+  TD_ICON_QUESTION = 99;
50
+  TD_ICON_ERROR = 98;
51
+  TD_ICON_INFORMATION = 81;
52
+  TD_ICON_SHIELD_QUESTION = 104;
53
+  TD_ICON_SHIELD_ERROR = 105;
54
+  TD_ICON_SHIELD_OK = 106;
55
+  TD_ICON_SHIELD_WARNING = 107;
56
+
57
+  TD_BUTTON_OK = 1;
58
+  TD_BUTTON_YES = 2;
59
+  TD_BUTTON_NO = 4;
60
+  TD_BUTTON_CANCEL = 8;
61
+  TD_BUTTON_RETRY = 16;
62
+  TD_BUTTON_CLOSE = 32;
63
+
64
+  TD_RESULT_OK = 1;
65
+  TD_RESULT_CANCEL = 2;
66
+  TD_RESULT_RETRY = 4;
67
+  TD_RESULT_YES = 6;
68
+  TD_RESULT_NO = 7;
69
+  TD_RESULT_CLOSE = 8;
70
+  
71
+  mrNone = 0;
72
+  mrOK = mrNone + 1;
73
+  mrCancel = mrNone + 2;
74
+  mrAbort = mrNone + 3;
75
+  mrRetry = mrNone + 4;
76
+  mrYes = mrNone + 6;
77
+  mrNo = mrNone + 7;
60 78
 
61 79
 implementation
62 80
 
63
-{$IFDEF LAZARUS}
81
+{*
64 82
 procedure SetVistaFonts(const AForm: TCustomForm);
65 83
 begin
66
-	if IsWindowsVista and not SameText(AForm.Font.Name, VistaFont) and (Screen.Fonts.IndexOf(VistaFont) >= 0) then
67
-	begin
68
-		AForm.Font.Size := AForm.Font.Size + 1;
69
-		AForm.Font.Name := VistaFont;
70
-	end;
84
+  if IsWindowsVista and not SameText(AForm.Font.Name, VistaFont) and (Screen.Fonts.IndexOf(VistaFont) >= 0) then
85
+  begin
86
+    AForm.Font.Size := AForm.Font.Size + 1;
87
+    AForm.Font.Name := VistaFont;
88
+  end;
71 89
 end;
72
-{$ENDIF}
90
+*}
73 91
 
74 92
 function IsWindowsVista: Boolean;
75 93
 var
76
-	VerInfo: TOSVersioninfo;
94
+  VerInfo: TOSVersioninfo;
77 95
 begin
78
-	VerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
79
-	GetVersionEx(VerInfo);
80
-	Result := VerInfo.dwMajorVersion >= 6;
96
+  VerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
97
+  GetVersionEx(VerInfo);
98
+  Result := VerInfo.dwMajorVersion >= 6;
81 99
 end;
82 100
 
83 101
 // http://www.swissdelphicenter.ch/en/showcode.php?id=1692
@@ -90,16 +108,16 @@ function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
90 108
 var
91 109
   l: integer;
92 110
 begin
93
-	if ws = '' then begin
94
-		Result := ''
95
-	end
96
-	else begin
97
-		l := WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, nil, 0, nil, nil);
98
-		SetLength(Result, l - 1);
99
-		if l > 1 then begin
100
-			WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, @Result[1], l - 1, nil, nil);
101
-		end;
102
-	end;
111
+  if ws = '' then begin
112
+    Result := ''
113
+  end
114
+  else begin
115
+    l := WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, nil, 0, nil, nil);
116
+    SetLength(Result, l - 1);
117
+    if l > 1 then begin
118
+      WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, @Result[1], l - 1, nil, nil);
119
+    end;
120
+  end;
103 121
 end;
104 122
 
105 123
 
@@ -108,94 +126,94 @@ function TaskDialog(const AHandle: THandle; const ATitle, ADescription, AContent
108 126
 type
109 127
         tTaskDialogProc = function(HWND: THandle; hInstance: THandle; cTitle, cDescription, cContent: pwidechar; Buttons: Integer; Icon: integer; ResButton: pinteger): integer; stdcall;
110 128
 var
111
-	DLLHandle: THandle;
112
-	res: integer;
113
-	wS: WideString;
114
-	S: String;
115
-	{$IFDEF MESSAGEDLG}
116
-	Btns: TMsgDlgButtons;
117
-	DlgType: TMsgDlgType;
118
-	{$ELSE}
119
-	Btns: Integer;
120
-	myIcon: Integer;
121
-	{$ENDIF}
122
-	TaskDialogFound: boolean;
123
-	TaskDialogProc: tTaskDialogProc;
129
+  DLLHandle: THandle;
130
+  res: integer;
131
+  wS: WideString;
132
+  S: String;
133
+  {$IFDEF MESSAGEDLG}
134
+  Btns: TMsgDlgButtons;
135
+  DlgType: TMsgDlgType;
136
+  {$ELSE}
137
+  Btns: Integer;
138
+  myIcon: Integer;
139
+  {$ENDIF}
140
+  TaskDialogFound: boolean;
141
+  TaskDialogProc: tTaskDialogProc;
124 142
 begin
125
-	TaskDialogFound := false;
126
-	Result := 0;
127
-	if IsWindowsVista then begin
128
-		DLLHandle := LoadLibrary('comctl32.dll');
129
-		if DLLHandle >= 32 then begin
130
-			TaskDialogProc := tTaskDialogProc(GetProcAddress(DLLHandle,'TaskDialog'));
131
-			
132
-			if Assigned(TaskDialogProc) then begin
133
-				
134
-				if stripLineFeed then begin
135
-					wS := StringReplace(AContent, #10, '', [rfReplaceAll]);
136
-					wS := StringReplace(wS, #13, '', [rfReplaceAll]);
137
-				end
138
-				else begin
139
-					wS := AContent;
140
-				end;
141
-
142
-				TaskDialogProc(AHandle, 0, PWideChar(ATitle), PWideChar(ADescription), PWideChar(wS), Buttons, Icon, @res);
143
-				TaskDialogFound := true;
144
-				Result := mrOK;
145
-				case res of
146
-					TD_RESULT_CANCEL : Result := mrCancel;
147
-					TD_RESULT_RETRY : Result := mrRetry;
148
-					TD_RESULT_YES : Result := mrYes;
149
-					TD_RESULT_NO : Result := mrNo;
150
-					TD_RESULT_CLOSE : Result := mrAbort;
151
-				end;
152
-			end;
153
-			FreeLibrary(DLLHandle);
154
-		end;
155
-	end;
156
-	
157
-	if not TaskDialogFound then begin
158
-		S := '';
159
-		if includeDescInXP then S := ADescription + #10#13 + #10#13 + AContent else S := AContent;
160
-		
161
-		{$IFDEF MESSAGEDLG}
162
-			Btns := [];
163
-			if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := Btns + [MBOK];
164
-			if Buttons and TD_BUTTON_YES = TD_BUTTON_YES then Btns := Btns + [MBYES];
165
-			if Buttons and TD_BUTTON_NO = TD_BUTTON_NO then Btns := Btns + [MBNO];
166
-			if Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL then Btns := Btns + [MBCANCEL];
167
-			if Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY then Btns := Btns + [MBRETRY];
168
-	
169
-			if Buttons and TD_BUTTON_CLOSE = TD_BUTTON_CLOSE then Btns := Btns + [MBABORT];
170
-	
171
-			DlgType := mtCustom;
172
-	
173
-			case Icon of
174
-				TD_ICON_WARNING : DlgType := mtWarning;
175
-				TD_ICON_QUESTION : DlgType := mtConfirmation;
176
-				TD_ICON_ERROR : DlgType := mtError;
177
-				TD_ICON_INFORMATION: DlgType := mtInformation;
178
-			end;
179
-	
180
-			Result := MessageDlg(S, DlgType, Btns, 0);
181
-		{$ELSE}
182
-			Btns := 0;
183
-			if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := MB_OK;
184
-			if (Buttons and TD_BUTTON_YES = TD_BUTTON_YES) and (Buttons and TD_BUTTON_NO = TD_BUTTON_NO) then Btns := MB_YESNO;
185
-			if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_YES = TD_BUTTON_YES) and (Buttons and TD_BUTTON_NO = TD_BUTTON_NO) then Btns := MB_YESNOCANCEL;
186
-			if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_OK = TD_BUTTON_OK) then Btns := MB_OKCANCEL;
187
-			if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY) then Btns := MB_RETRYCANCEL;
188
-			
189
-			myIcon := 0;
190
-			case Icon of
191
-				TD_ICON_QUESTION : myIcon := MB_ICONQUESTION;
192
-				TD_ICON_ERROR : myIcon := MB_ICONSTOP;
193
-				TD_ICON_INFORMATION: myIcon := MB_ICONINFORMATION;
194
-			end;
143
+  TaskDialogFound := false;
144
+  Result := 0;
145
+  if IsWindowsVista then begin
146
+    DLLHandle := LoadLibrary('comctl32.dll');
147
+    if DLLHandle >= 32 then begin
148
+      TaskDialogProc := tTaskDialogProc(GetProcAddress(DLLHandle,'TaskDialog'));
149
+      
150
+      if Assigned(TaskDialogProc) then begin
151
+        
152
+        if stripLineFeed then begin
153
+          wS := StringReplace(AContent, #10, '', [rfReplaceAll]);
154
+          wS := StringReplace(wS, #13, '', [rfReplaceAll]);
155
+        end
156
+        else begin
157
+          wS := AContent;
158
+        end;
159
+
160
+        TaskDialogProc(AHandle, 0, PWideChar(ATitle), PWideChar(ADescription), PWideChar(wS), Buttons, Icon, @res);
161
+        TaskDialogFound := true;
162
+        Result := mrOK;
163
+        case res of
164
+          TD_RESULT_CANCEL : Result := mrCancel;
165
+          TD_RESULT_RETRY : Result := mrRetry;
166
+          TD_RESULT_YES : Result := mrYes;
167
+          TD_RESULT_NO : Result := mrNo;
168
+          TD_RESULT_CLOSE : Result := mrAbort;
169
+        end;
170
+      end;
171
+      FreeLibrary(DLLHandle);
172
+    end;
173
+  end;
174
+  
175
+  if not TaskDialogFound then begin
176
+    S := '';
177
+    if includeDescInXP then S := ADescription + #10#13 + #10#13 + AContent else S := AContent;
178
+    
179
+    {$IFDEF MESSAGEDLG}
180
+      Btns := [];
181
+      if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := Btns + [MBOK];
182
+      if Buttons and TD_BUTTON_YES = TD_BUTTON_YES then Btns := Btns + [MBYES];
183
+      if Buttons and TD_BUTTON_NO = TD_BUTTON_NO then Btns := Btns + [MBNO];
184
+      if Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL then Btns := Btns + [MBCANCEL];
185
+      if Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY then Btns := Btns + [MBRETRY];
186
+  
187
+      if Buttons and TD_BUTTON_CLOSE = TD_BUTTON_CLOSE then Btns := Btns + [MBABORT];
188
+  
189
+      DlgType := mtCustom;
190
+  
191
+      case Icon of
192
+        TD_ICON_WARNING : DlgType := mtWarning;
193
+        TD_ICON_QUESTION : DlgType := mtConfirmation;
194
+        TD_ICON_ERROR : DlgType := mtError;
195
+        TD_ICON_INFORMATION: DlgType := mtInformation;
196
+      end;
197
+  
198
+      Result := MessageDlg(S, DlgType, Btns, 0);
199
+    {$ELSE}
200
+      Btns := 0;
201
+      if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := MB_OK;
202
+      if (Buttons and TD_BUTTON_YES = TD_BUTTON_YES) and (Buttons and TD_BUTTON_NO = TD_BUTTON_NO) then Btns := MB_YESNO;
203
+      if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_YES = TD_BUTTON_YES) and (Buttons and TD_BUTTON_NO = TD_BUTTON_NO) then Btns := MB_YESNOCANCEL;
204
+      if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_OK = TD_BUTTON_OK) then Btns := MB_OKCANCEL;
205
+      if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY) then Btns := MB_RETRYCANCEL;
206
+      
207
+      myIcon := 0;
208
+      case Icon of
209
+        TD_ICON_QUESTION : myIcon := MB_ICONQUESTION;
210
+        TD_ICON_ERROR : myIcon := MB_ICONSTOP;
211
+        TD_ICON_INFORMATION: myIcon := MB_ICONINFORMATION;
212
+      end;
195 213
 
196 214
                         Result := MessageBox(0, pchar(S), pchar(String(ATitle)), Btns + myIcon);
197
-		{$ENDIF}
198
-	end;
215
+    {$ENDIF}
216
+  end;
199 217
 end;
200 218
 
201 219
 end.

+ 172
- 125
launcher/windows/DMDirc.dpr 파일 보기

@@ -1,3 +1,29 @@
1
+{*
2
+ * This application launches DMDirc on windows and passes control to the
3
+ * update engine as necessary.
4
+ *
5
+ * DMDirc - Open Source IRC Client
6
+ * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes,
7
+ * Michael Nixon
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in
17
+ * all copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ *}
1 27
 program DMDirc;
2 28
 {$MODE Delphi}
3 29
 {$APPTYPE GUI}
@@ -7,160 +33,181 @@ program DMDirc;
7 33
 {$R version.rc}
8 34
 
9 35
 uses Windows, SysUtils, classes, StrUtils, Vista;
36
+procedure InitCommonControls; stdcall; External 'comctl32.dll' name 'InitCommonControls';
37
+{ ---------------------------------------------------------------------------- }
10 38
 
39
+{ ----------------------------------------------------------------------------
40
+  Ask a question and return True for YES and False for NO
41
+  Uses nifty vista task dialog if available
42
+  ---------------------------------------------------------------------------- }
11 43
 function askQuestion(Question: String): boolean;
12 44
 begin
13
-	Result := TaskDialog(0, 'DMDirc', 'Question', Question, TD_ICON_QUESTION, TD_BUTTON_YES + TD_BUTTON_NO) = mrYes;
45
+  Result := TaskDialog(0, 'DMDirc', 'Question', Question, TD_ICON_QUESTION, TD_BUTTON_YES + TD_BUTTON_NO) = mrYes;
14 46
 end;
15 47
 
48
+{ ----------------------------------------------------------------------------
49
+  Show an error message
50
+  Uses nifty vista task dialog if available
51
+  ---------------------------------------------------------------------------- }
16 52
 procedure showError(ErrorMessage: String; addFooter: boolean = true);
17 53
 begin
18
-	if addFooter then begin
19
-		ErrorMessage := ErrorMessage+#13#10;
20
-		ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
21
-		ErrorMessage := ErrorMessage+#13#10+'please feel free to contact us.';
22
-	end;
23
-	
24
-	TaskDialog(0, 'DMDirc', 'There was an error starting DMDirc', ErrorMessage, TD_ICON_ERROR, TD_BUTTON_OK, false, false);
54
+  if addFooter then begin
55
+    ErrorMessage := ErrorMessage+#13#10;
56
+    ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
57
+    ErrorMessage := ErrorMessage+#13#10+'please feel free to contact us.';
58
+  end;
59
+
60
+  TaskDialog(0, 'DMDirc', 'There was an error starting DMDirc', ErrorMessage, TD_ICON_ERROR, TD_BUTTON_OK, false, false);
25 61
 end;
26 62
 
63
+{ ----------------------------------------------------------------------------
64
+  Show a message box (information)
65
+  Uses nifty vista task dialog if available
66
+  ---------------------------------------------------------------------------- }
27 67
 procedure showmessage(message: String; context:String = 'Information');
28 68
 begin
29
-	TaskDialog(0, 'DMDirc', context, message, TD_ICON_INFORMATION, TD_BUTTON_OK);
69
+  TaskDialog(0, 'DMDirc', context, message, TD_ICON_INFORMATION, TD_BUTTON_OK);
30 70
 end;
31 71
 
32 72
 
33
-// Run an application and wait for it to finish.
73
+{ ----------------------------------------------------------------------------
74
+  Launch a process (hidden if requested) and wait for it to finish
75
+  ---------------------------------------------------------------------------- }
34 76
 function ExecAndWait(sProgramToRun: String): Longword;
35 77
 var
36
-	StartupInfo: TStartupInfo;
37
-	ProcessInfo: TProcessInformation;
78
+  StartupInfo: TStartupInfo;
79
+  ProcessInfo: TProcessInformation;
38 80
 begin
39
-	FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
40
-	with StartupInfo do begin
41
-		cb := SizeOf(TStartupInfo);
42
-		dwFlags := STARTF_USESHOWWINDOW;
43
-		wShowWindow := SW_SHOWNORMAL;
44
-	end;
45
-
46
-	CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
47
-	getExitCodeProcess(ProcessInfo.hProcess, Result);
48
-
49
-	while Result=STILL_ACTIVE do begin
50
-		sleep(1000);
51
-		GetExitCodeProcess(ProcessInfo.hProcess, Result);
52
-	end;
81
+  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
82
+  with StartupInfo do begin
83
+    cb := SizeOf(TStartupInfo);
84
+    dwFlags := STARTF_USESHOWWINDOW;
85
+    wShowWindow := SW_SHOWNORMAL;
86
+  end;
87
+
88
+  CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
89
+  getExitCodeProcess(ProcessInfo.hProcess, Result);
90
+
91
+  while Result=STILL_ACTIVE do begin
92
+    sleep(1000);
93
+    GetExitCodeProcess(ProcessInfo.hProcess, Result);
94
+  end;
53 95
 end;
54 96
 
55
-// Run an application and don't wait for it to finish.
97
+{ ----------------------------------------------------------------------------
98
+  Launch a process (hidden if requested) and immediately return control to
99
+  the current thread
100
+  ---------------------------------------------------------------------------- }
56 101
 procedure Launch(sProgramToRun: String);
57 102
 var
58
-	StartupInfo: TStartupInfo;
59
-	ProcessInfo: TProcessInformation;
103
+  StartupInfo: TStartupInfo;
104
+  ProcessInfo: TProcessInformation;
60 105
 begin
61
-	FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
62
-	with StartupInfo do begin
63
-		cb := SizeOf(TStartupInfo);
64
-		dwFlags := STARTF_USESHOWWINDOW;
65
-		wShowWindow := SW_SHOWNORMAL;
66
-	end;
67
-	
68
-	CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
106
+  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
107
+  with StartupInfo do begin
108
+    cb := SizeOf(TStartupInfo);
109
+    dwFlags := STARTF_USESHOWWINDOW;
110
+    wShowWindow := SW_SHOWNORMAL;
111
+  end;
112
+
113
+  CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
69 114
 end;
70 115
 
116
+{ ----------------------------------------------------------------------------
117
+  Launch a process and either waits for it or returns control immediately
118
+  ---------------------------------------------------------------------------- }
71 119
 procedure RunProgram(sProgramToRun: String; wait: boolean);
72 120
 begin
73
-	if wait then ExecAndWait(sProgramToRun)
74
-	else Launch(sProgramToRun);
121
+  if wait then ExecAndWait(sProgramToRun)
122
+  else Launch(sProgramToRun);
75 123
 end;
76 124
 
125
+{ ----------------------------------------------------------------------------
126
+  MAIN PROGRAM
127
+  ---------------------------------------------------------------------------- }
77 128
 const
78
-	launcherVersion: String = '2';
129
+  launcherVersion: String = '2';
79 130
 var
80
-	errorMessage: String;
81
-	javaCommand: String = 'javaw.exe';
82
-	cliParams: String = '';
83
-	directory: String = '';
84
-	i: integer;
85
-	jarName: String;
86
-	launcherUpdate: boolean = false;
131
+  errorMessage: String;
132
+  javaCommand: String = 'javaw.exe';
133
+  cliParams: String = '';
134
+  directory: String = '';
135
+  i: integer;
136
+  jarName: String;
137
+  launcherUpdate: boolean = false;
87 138
 begin
88
-	jarName := ExtractFileDir(paramstr(0))+'\DMDirc.jar';
89
-	
90
-	directory := GetEnvironmentVariable('APPDATA')+'\DMDirc';
91
-	if ParamCount > 0 then begin
92
-		for i := 1 to ParamCount do begin
93
-			if AnsiContainsStr(cliParams, ' ') then cliParams := cliParams+' "'+paramstr(i)+'"'
94
-			else cliParams := cliParams+' '+paramstr(i);
95
-			if (paramstr(i) = '-d') or (paramstr(i) = '--directory') then begin
96
-				if ParamCount > i then begin
97
-					directory := paramstr(i+1);
98
-				end;
99
-			end
100
-		end;
101
-	end;
102
-
103
-	// Update if needed.
104
-	launcherUpdate := FileExists(directory+'\.DMDirc.exe') and FileExists(directory+'\.DMDircUpdater.exe');
105
-	if FileExists(directory+'\.DMDirc.jar') or launcherUpdate then begin
106
-		// Vista Sucks.
107
-		if IsWindowsVista then begin
108
-			// Vista >.<
109
-			// Try and delete the old file, if it fails then the user needs to give
110
-			// us permission to delete the file (UAC), otherwise we can just go ahead
111
-			// and run the updater.
112
-			if not DeleteFile(pchar(jarName)) then begin
113
-				errorMessage := 'An update to DMDirc has been previously downloaded. ';
114
-				errorMessage := errorMessage+#13#10;
115
-				errorMessage := errorMessage+#13#10+'As you are running Windows Vista, DMDirc requires administrator access to ';
116
-				errorMessage := errorMessage+#13#10+'complete the update. ';
117
-				errorMessage := errorMessage+#13#10;
118
-				errorMessage := errorMessage+#13#10+'Please click ''Allow'' on the UAC prompt to complete the update, or click no ';
119
-				errorMessage := errorMessage+#13#10+'here to continue without updating. ';
120
-				if askQuestion(errorMessage) then begin
121
-					RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
122
-				end;
123
-			end
124
-			else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
125
-		end
126
-		else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
127
-	end;
128
-	
129
-	if not launcherUpdate then begin
130
-		// Check JVM
131
-		if (ExecAndWait(javaCommand+' -version') <> 0) then begin
132
-			errorMessage := 'No JVM is currently installed.';
133
-			errorMessage := errorMessage+#13#10;
134
-			errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from: ';
135
-			errorMessage := errorMessage+#13#10+'http://java.com/ ';
136
-			errorMessage := errorMessage+#13#10;
137
-			errorMessage := errorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance, ';
138
-			errorMessage := errorMessage+#13#10+'please feel free to contact us.';
139
-			
140
-			showError(errorMessage);
141
-		end
142
-		// Else try and run client. (This only asks for help output to check that client
143
-		// runs on this OS, otherwise later segfaults or so would cause the error to
144
-		// appear
145
-		else if FileExists(jarName) then begin
146
-			if (ExecAndWait(javaCommand+' -jar "'+jarName+'" --help') <> 0) then begin
147
-				errorMessage := 'The currently installed version of java is not compatible with DMDirc.';
148
-				errorMessage := errorMessage+#13#10;
149
-				errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from: ';
150
-				errorMessage := errorMessage+#13#10+'http://java.com/ ';
151
-				errorMessage := errorMessage+#13#10;
152
-				errorMessage := errorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance, ';
153
-				errorMessage := errorMessage+#13#10+'please feel free to contact us. ';
154
-				
155
-				showError(errorMessage);
156
-			end
157
-			else begin
158
-				Launch(javaCommand+' -ea -jar "'+jarName+'"'+' -l windows-'+launcherVersion+' '+cliParams)
159
-			end;
160
-		end
161
-		else begin
162
-			errorMessage := 'Your DMDirc installation has been broken. DMDirc.jar no longer exists.';
163
-			showError(errorMessage);
164
-		end;
165
-	end;
139
+  InitCommonControls;
140
+
141
+  jarName := ExtractFileDir(paramstr(0))+'\DMDirc.jar';
142
+
143
+  directory := GetEnvironmentVariable('APPDATA')+'\DMDirc';
144
+  if ParamCount > 0 then begin
145
+    for i := 1 to ParamCount do begin
146
+      if AnsiContainsStr(cliParams, ' ') then cliParams := cliParams+' "'+paramstr(i)+'"'
147
+      else cliParams := cliParams+' '+paramstr(i);
148
+      if (paramstr(i) = '-d') or (paramstr(i) = '--directory') then begin
149
+        if ParamCount > i then begin
150
+          directory := paramstr(i+1);
151
+        end;
152
+      end
153
+    end;
154
+  end;
155
+
156
+  // Update if needed.
157
+  launcherUpdate := FileExists(directory+'\.DMDirc.exe') and FileExists(directory+'\.DMDircUpdater.exe');
158
+  if FileExists(directory+'\.DMDirc.jar') or launcherUpdate then begin
159
+    // Vista Sucks.
160
+    if IsWindowsVista then begin
161
+      // Vista >.<
162
+      // Try and delete the old file, if it fails then the user needs to give
163
+      // us permission to delete the file (UAC), otherwise we can just go ahead
164
+      // and run the updater.
165
+      if not DeleteFile(pchar(jarName)) then begin
166
+        errorMessage := 'An update to DMDirc has been previously downloaded. ';
167
+        errorMessage := errorMessage+#13#10;
168
+        errorMessage := errorMessage+#13#10+'As you are running Windows Vista, DMDirc requires administrator access to ';
169
+        errorMessage := errorMessage+#13#10+'complete the update. ';
170
+        errorMessage := errorMessage+#13#10;
171
+        errorMessage := errorMessage+#13#10+'Please click ''Allow'' on the UAC prompt to complete the update, or click no ';
172
+        errorMessage := errorMessage+#13#10+'here to continue without updating. ';
173
+        if askQuestion(errorMessage) then begin
174
+          RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
175
+        end;
176
+      end
177
+      else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
178
+    end
179
+    else RunProgram('"'+ExtractFileDir(paramstr(0))+'\DMDircUpdater.exe" --UpdateSourceDir "'+directory+'"', not launcherUpdate);
180
+  end;
181
+  
182
+  if not launcherUpdate then begin
183
+    // Check JVM
184
+    if (ExecAndWait(javaCommand+' -version') <> 0) then begin
185
+      errorMessage := 'No JVM is currently installed.';
186
+      errorMessage := errorMessage+#13#10;
187
+      errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
188
+      errorMessage := errorMessage+#13#10+'http://java.com/';
189
+      showError(errorMessage, true);
190
+    end
191
+    // Else try and run client. (This only asks for help output to check that client
192
+    // runs on this OS, otherwise later segfaults or so would cause the error to
193
+    // appear
194
+    else if FileExists(jarName) then begin
195
+      if (ExecAndWait(javaCommand+' -jar "'+jarName+'" --help') <> 0) then begin
196
+        errorMessage := 'The currently installed version of java is not compatible with DMDirc.';
197
+        errorMessage := errorMessage+#13#10;
198
+        errorMessage := errorMessage+#13#10+'DMDirc requires a 1.6.0 compatible JVM, you can get one from:';
199
+        errorMessage := errorMessage+#13#10+'http://java.com/';
200
+        showError(errorMessage, True);
201
+      end
202
+      else begin
203
+        Launch(javaCommand+' -ea -jar "'+jarName+'"'+' -l windows-'+launcherVersion+' '+cliParams)
204
+      end;
205
+    end
206
+    else begin
207
+      errorMessage := 'A file required to start DMDirc is missing. Please re-install DMDirc to rectify the problem.';
208
+      errorMessage := errorMessage+#13#10;
209
+      errorMessage := errorMessage+#13#10 + 'File: DMDirc.jar';
210
+      showError(errorMessage);
211
+    end;
212
+  end;
166 213
 end.

Loading…
취소
저장