|
@@ -1,136 +1,129 @@
|
|
1
|
+{*
|
|
2
|
+ * Updates DMDirc windows components
|
|
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
|
+ *}
|
1
|
26
|
program DMDircUpdater;
|
2
|
27
|
{$MODE Delphi}
|
3
|
28
|
{$APPTYPE GUI}
|
4
|
29
|
|
5
|
30
|
{$R UAC.rc}
|
6
|
31
|
|
7
|
|
-uses Windows, SysUtils, classes, StrUtils, Vista;
|
|
32
|
+uses Vista, shared, Windows, SysUtils, classes, StrUtils;
|
|
33
|
+procedure InitCommonControls; stdcall; External 'comctl32.dll' name 'InitCommonControls';
|
|
34
|
+{ ---------------------------------------------------------------------------- }
|
8
|
35
|
|
9
|
|
-function askQuestion(Question: String): boolean;
|
10
|
|
-begin
|
11
|
|
- Result := TaskDialog(0, 'DMDirc Updater', 'Question', Question, TD_ICON_QUESTION, TD_BUTTON_YES + TD_BUTTON_NO) = mrYes;
|
12
|
|
-end;
|
13
|
|
-
|
14
|
|
-procedure showError(ErrorMessage: String; addFooter: boolean = true);
|
|
36
|
+{ ----------------------------------------------------------------------------
|
|
37
|
+ MAIN PROGRAM
|
|
38
|
+ ---------------------------------------------------------------------------- }
|
|
39
|
+var
|
|
40
|
+ sourceDir: String = '';
|
|
41
|
+ thisDir: String;
|
|
42
|
+ cliParams: String = '';
|
|
43
|
+ i: integer;
|
|
44
|
+ jarName: String;
|
|
45
|
+ launcherUpdate: boolean = false;
|
|
46
|
+ myName: String;
|
|
47
|
+ canDoMore: boolean = true;
|
15
|
48
|
begin
|
16
|
|
- if addFooter then begin
|
17
|
|
- ErrorMessage := ErrorMessage+#13#10;
|
18
|
|
- ErrorMessage := ErrorMessage+#13#10+'If you feel this is incorrect, or you require some further assistance,';
|
19
|
|
- ErrorMessage := ErrorMessage+#13#10+'please feel free to contact us.';
|
20
|
|
- end;
|
21
|
|
-
|
22
|
|
- TaskDialog(0, 'DMDirc Updater', 'There was an error starting DMDirc', ErrorMessage, TD_ICON_ERROR, TD_BUTTON_OK, false, false);
|
23
|
|
-end;
|
|
49
|
+ myName := ExtractFileName(paramstr(0));
|
|
50
|
+ thisDir := ExtractFileDir(paramstr(0));
|
|
51
|
+ jarName := thisDir+'\DMDirc.jar';
|
24
|
52
|
|
25
|
|
-procedure showmessage(message: String; context:String = 'Information');
|
26
|
|
-begin
|
27
|
|
- TaskDialog(0, 'DMDirc Updater', context, message, TD_ICON_INFORMATION, TD_BUTTON_OK);
|
28
|
|
-end;
|
|
53
|
+ if ParamCount > 0 then begin
|
|
54
|
+ for i := 1 to ParamCount do begin
|
|
55
|
+ if AnsiContainsStr(cliParams, ' ') then cliParams := cliParams+' "'+paramstr(i)+'"'
|
|
56
|
+ else cliParams := cliParams+' '+paramstr(i);
|
|
57
|
+ if (paramstr(i) = '--UpdateSourceDir') then begin // Source Directory
|
|
58
|
+ if ParamCount > i then begin
|
|
59
|
+ sourceDir := paramstr(i+1);
|
|
60
|
+ end;
|
|
61
|
+ end
|
|
62
|
+ end;
|
29
|
63
|
|
30
|
|
-// Run an application and don't wait for it to finish.
|
31
|
|
-procedure Launch(sProgramToRun: String);
|
32
|
|
-var
|
33
|
|
- StartupInfo: TStartupInfo;
|
34
|
|
- ProcessInfo: TProcessInformation;
|
35
|
|
-begin
|
36
|
|
- FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
|
37
|
|
- with StartupInfo do begin
|
38
|
|
- cb := SizeOf(TStartupInfo);
|
39
|
|
- dwFlags := STARTF_USESHOWWINDOW;
|
40
|
|
- wShowWindow := SW_SHOWNORMAL;
|
41
|
|
- end;
|
42
|
|
- // MessageBox(0, pchar('Foo: '+sProgramToRun), 'Update Failed', MB_ICONSTOP);
|
43
|
|
- CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
|
44
|
|
-end;
|
|
64
|
+ // Look for a launcher update.
|
|
65
|
+ if FileExists(pchar(sourceDir+'\.DMDirc.exe')) and FileExists(pchar(sourceDir+'\.DMDircUpdater.exe')) then begin
|
|
66
|
+ if myName = 'DMDircUpdater.exe' then begin
|
|
67
|
+ // Windows won't let us overwrite ourself, so we need to copy ourself
|
|
68
|
+ // to another name, and run the new us.
|
|
69
|
+ if CopyFile(pchar(thisDir+'\DMDircUpdater.exe'), pchar(thisDir+'\DMDircLauncherUpdater.exe'), False) then begin
|
|
70
|
+ canDoMore := false;
|
|
71
|
+ Launch('"'+thisDir+'\DMDircLauncherUpdater.exe" '+cliParams);
|
|
72
|
+ end
|
|
73
|
+ else begin
|
|
74
|
+ showmessage('Unable to overwrite launcher', 'DMDirc', 'Update Failed');
|
|
75
|
+ end;
|
|
76
|
+ end
|
|
77
|
+ else begin
|
|
78
|
+ launcherUpdate := true;
|
|
79
|
+ if FileExists(pchar(thisDir+'\DMDirc.exe')) then begin
|
|
80
|
+ if not DeleteFile(pchar(thisDir+'\DMDirc.exe')) then begin
|
|
81
|
+ showmessage('Unable to delete DMDirc.exe', 'DMDirc', 'Launcher Update Failed');
|
|
82
|
+ end;
|
|
83
|
+ end;
|
|
84
|
+
|
|
85
|
+ if not FileExists(pchar(thisDir+'\DMDirc.exe')) and MoveFile(pchar(sourceDir+'\.DMDirc.exe'), pchar(thisDir+'\DMDirc.exe')) then begin
|
|
86
|
+ if FileExists(pchar(thisDir+'\DMDircUpdater.exe')) then begin
|
|
87
|
+ if not DeleteFile(pchar(thisDir+'\DMDircUpdater.exe')) then begin
|
|
88
|
+ showmessage('Unable to delete DMDircUpdater.exe', 'DMDirc', 'Launcher Update Failed');
|
|
89
|
+ end;
|
|
90
|
+ end;
|
|
91
|
+ if not FileExists(pchar(thisDir+'\DMDircUpdater.exe')) and MoveFile(pchar(sourceDir+'\.DMDircUpdater.exe'), pchar(thisDir+'\DMDircUpdater.exe')) then begin
|
|
92
|
+ showmessage('Launcher update was successful', 'DMDirc');
|
|
93
|
+ end
|
|
94
|
+ else begin
|
|
95
|
+ showmessage('Unable to update DMDircUpdater.exe', 'DMDirc', 'Launcher Update Failed');
|
|
96
|
+ end;
|
|
97
|
+ end
|
|
98
|
+ else begin
|
|
99
|
+ showmessage('Unable to update DMDirc.exe', 'DMDirc', 'Launcher Update Failed');
|
|
100
|
+ end;
|
|
101
|
+ end;
|
|
102
|
+ end;
|
45
|
103
|
|
46
|
|
-var
|
47
|
|
- sourceDir: String = '';
|
48
|
|
- thisDir: String;
|
49
|
|
- cliParams: String = '';
|
50
|
|
- i: integer;
|
51
|
|
- jarName: String;
|
52
|
|
- launcherUpdate: boolean = false;
|
53
|
|
- myName: String;
|
54
|
|
- canDoMore: boolean = true;
|
55
|
|
-begin
|
56
|
|
- myName := ExtractFileName(paramstr(0));
|
57
|
|
- thisDir := ExtractFileDir(paramstr(0));
|
58
|
|
- jarName := thisDir+'\DMDirc.jar';
|
59
|
|
-
|
60
|
|
- if ParamCount > 0 then begin
|
61
|
|
- for i := 1 to ParamCount do begin
|
62
|
|
- if AnsiContainsStr(cliParams, ' ') then cliParams := cliParams+' "'+paramstr(i)+'"'
|
63
|
|
- else cliParams := cliParams+' '+paramstr(i);
|
64
|
|
- if (paramstr(i) = '--UpdateSourceDir') then begin // Source Directory
|
65
|
|
- if ParamCount > i then begin
|
66
|
|
- sourceDir := paramstr(i+1);
|
67
|
|
- end;
|
68
|
|
- end
|
69
|
|
- end;
|
|
104
|
+ // Look for client update
|
|
105
|
+ if canDoMore then begin
|
|
106
|
+ if FileExists(pchar(sourceDir+'\.DMDirc.jar')) then begin
|
|
107
|
+ if FileExists(pchar(jarName)) then begin
|
|
108
|
+ if not DeleteFile(pchar(jarName)) then begin
|
|
109
|
+ showmessage('Unable to update DMDirc.jar', 'DMDirc', 'Launcher Update Failed');
|
|
110
|
+ end;
|
|
111
|
+ end;
|
70
|
112
|
|
71
|
|
- // Look for a launcher update.
|
72
|
|
- if FileExists(pchar(sourceDir+'\.DMDirc.exe')) and FileExists(pchar(sourceDir+'\.DMDircUpdater.exe')) then begin
|
73
|
|
- if myName = 'DMDircUpdater.exe' then begin
|
74
|
|
- // Windows won't let us overwrite ourself, so we need to copy ourself
|
75
|
|
- // to another name, and run the new us.
|
76
|
|
- if CopyFile(pchar(thisDir+'\DMDircUpdater.exe'), pchar(thisDir+'\DMDircLauncherUpdater.exe'), False) then begin
|
77
|
|
- canDoMore := false;
|
78
|
|
- Launch('"'+thisDir+'\DMDircLauncherUpdater.exe" '+cliParams);
|
79
|
|
- end
|
80
|
|
- else begin
|
81
|
|
- showmessage('Unable to overwrite launcher', 'Update Failed');
|
82
|
|
- end;
|
83
|
|
- end
|
84
|
|
- else begin
|
85
|
|
- launcherUpdate := true;
|
86
|
|
- if FileExists(pchar(thisDir+'\DMDirc.exe')) then begin
|
87
|
|
- if not DeleteFile(pchar(thisDir+'\DMDirc.exe')) then begin
|
88
|
|
- showmessage('Unable to delete DMDirc.exe', 'Launcher Update Failed');
|
89
|
|
- end;
|
90
|
|
- end;
|
91
|
|
-
|
92
|
|
- if not FileExists(pchar(thisDir+'\DMDirc.exe')) and MoveFile(pchar(sourceDir+'\.DMDirc.exe'), pchar(thisDir+'\DMDirc.exe')) then begin
|
93
|
|
- if FileExists(pchar(thisDir+'\DMDircUpdater.exe')) then begin
|
94
|
|
- if not DeleteFile(pchar(thisDir+'\DMDircUpdater.exe')) then begin
|
95
|
|
- showmessage('Unable to delete DMDircUpdater.exe', 'Launcher Update Failed');
|
96
|
|
- end;
|
97
|
|
- end;
|
98
|
|
- if not FileExists(pchar(thisDir+'\DMDircUpdater.exe')) and MoveFile(pchar(sourceDir+'\.DMDircUpdater.exe'), pchar(thisDir+'\DMDircUpdater.exe')) then begin
|
99
|
|
- showmessage('Launcher update was successful');
|
100
|
|
- end
|
101
|
|
- else begin
|
102
|
|
- showmessage('Unable to update DMDircUpdater.exe', 'Launcher Update Failed');
|
103
|
|
- end;
|
104
|
|
- end
|
105
|
|
- else begin
|
106
|
|
- showmessage('Unable to update DMDirc.exe', 'Launcher Update Failed');
|
107
|
|
- end;
|
108
|
|
- end;
|
109
|
|
- end;
|
110
|
|
-
|
111
|
|
- // Look for client update
|
112
|
|
- if canDoMore then begin
|
113
|
|
- if FileExists(pchar(sourceDir+'\.DMDirc.jar')) then begin
|
114
|
|
- if FileExists(pchar(jarName)) then begin
|
115
|
|
- if not DeleteFile(pchar(jarName)) then begin
|
116
|
|
- showmessage('Unable to update DMDirc.jar', 'Launcher Update Failed');
|
117
|
|
- end;
|
118
|
|
- end;
|
119
|
|
-
|
120
|
|
- if MoveFile(pchar(sourceDir+'\.DMDirc.jar'), pchar(jarName)) then begin
|
121
|
|
- showmessage('Client update was successful');
|
122
|
|
- end
|
123
|
|
- else begin
|
124
|
|
- showmessage('Unable to move '''+sourceDir+'\.DMDirc.jar'' to '+jarName, 'Update Failed');
|
125
|
|
- end;
|
126
|
|
- end;
|
127
|
|
-
|
128
|
|
- if launcherUpdate then begin
|
129
|
|
- showmessage('The DMDirc launcher has been updated, to complete the update please relaunch DMDirc.', 'Restart Required');
|
130
|
|
- end;
|
131
|
|
- end;
|
132
|
|
- end
|
133
|
|
- else begin
|
134
|
|
- showError('This program can not be run on its own.');
|
135
|
|
- end;
|
|
113
|
+ if MoveFile(pchar(sourceDir+'\.DMDirc.jar'), pchar(jarName)) then begin
|
|
114
|
+ showmessage('Client update was successful', 'DMDirc');
|
|
115
|
+ end
|
|
116
|
+ else begin
|
|
117
|
+ showmessage('Unable to move '''+sourceDir+'\.DMDirc.jar'' to '+jarName, 'DMDirc', 'Update Failed');
|
|
118
|
+ end;
|
|
119
|
+ end;
|
|
120
|
+
|
|
121
|
+ if launcherUpdate then begin
|
|
122
|
+ showmessage('The DMDirc launcher has been updated, to complete the update please relaunch DMDirc.', 'DMDirc', 'Restart Required');
|
|
123
|
+ end;
|
|
124
|
+ end;
|
|
125
|
+ end
|
|
126
|
+ else begin
|
|
127
|
+ showError('This program can not be run on its own.', 'DMDirc');
|
|
128
|
+ end;
|
136
|
129
|
end.
|