|
@@ -23,44 +23,36 @@ begin
|
23
|
23
|
end;
|
24
|
24
|
|
25
|
25
|
|
26
|
|
-procedure Launch(sProgramToRun: String);
|
|
26
|
+// Run an application and don't wait for it to finish.
|
|
27
|
+function Launch(sProgramToRun: String; hide: boolean = false): TProcessInformation;
|
27
|
28
|
var
|
28
|
29
|
StartupInfo: TStartupInfo;
|
29
|
|
- ProcessInfo: TProcessInformation;
|
30
|
30
|
begin
|
31
|
31
|
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
|
32
|
32
|
with StartupInfo do begin
|
33
|
33
|
cb := SizeOf(TStartupInfo);
|
34
|
34
|
dwFlags := STARTF_USESHOWWINDOW;
|
35
|
|
- wShowWindow := SW_SHOWNORMAL;
|
|
35
|
+ if hide then wShowWindow := SW_HIDE
|
|
36
|
+ else wShowWindow := SW_SHOWNORMAL;
|
36
|
37
|
end;
|
37
|
38
|
|
38
|
|
- CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
|
|
39
|
+ CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, Result);
|
39
|
40
|
end;
|
40
|
41
|
|
41
|
|
-function CheckStdErr(sProgramToRun: String): Boolean;
|
|
42
|
+// Run an application and wait for it to finish.
|
|
43
|
+function ExecAndWait(sProgramToRun: String; hide: boolean = false): Longword;
|
42
|
44
|
var
|
43
|
|
- StartupInfo: TStartupInfo;
|
44
|
|
- Pipe, Pipe2: THandle;
|
45
|
|
- ProcessInfo: TProcessInformation;
|
46
|
|
- BytesRead: Cardinal;
|
47
|
|
- Buffer: array[0..255] of Char;
|
|
45
|
+ ProcessInfo: TProcessInformation;
|
48
|
46
|
begin
|
49
|
|
- CreatePipe(Pipe2, Pipe, nil, 0);
|
50
|
|
-
|
51
|
|
- FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
|
52
|
|
- with StartupInfo do begin
|
53
|
|
- cb := SizeOf(TStartupInfo);
|
54
|
|
- dwFlags := STARTF_USESHOWWINDOW;
|
55
|
|
- wShowWindow := SW_SHOWNORMAL;
|
56
|
|
- hStdError := Pipe;
|
57
|
|
- end;
|
58
|
|
-
|
59
|
|
- CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
|
|
47
|
+ ProcessInfo := Launch(sProgramToRun, hide);
|
|
48
|
+ getExitCodeProcess(ProcessInfo.hProcess, Result);
|
60
|
49
|
|
61
|
|
- ReadFile(Pipe2, Buffer, 255, BytesRead, nil);
|
62
|
|
-
|
63
|
|
- Result := BytesRead > 0;
|
|
50
|
+ while Result=STILL_ACTIVE do begin
|
|
51
|
+ sleep(1000);
|
|
52
|
+ GetExitCodeProcess(ProcessInfo.hProcess, Result);
|
|
53
|
+ end;
|
|
54
|
+
|
|
55
|
+ MessageBox(0, PChar('Exec: '+sProgramToRun+#13#10+'Res: '+inttostr(Result)), 'DMDirc Uninstaller', MB_OK + MB_ICONEXCLAMATION);
|
64
|
56
|
end;
|
65
|
57
|
|
66
|
58
|
function KillDir(Dir: string): Integer;
|
|
@@ -102,77 +94,77 @@ var
|
102
|
94
|
profileDir: String;
|
103
|
95
|
deleteProtocol: boolean;
|
104
|
96
|
begin
|
105
|
|
- if (ParamCount > 0) then begin
|
106
|
|
- for i := 1 to ParamCount do begin
|
107
|
|
- InstallDir := InstallDir+' '+paramstr(i);
|
108
|
|
- end;
|
109
|
|
- InstallDir := trim(InstallDir);
|
110
|
|
- KillDir(InstallDir);
|
111
|
|
- hK32 := GetModuleHandle('kernel32');
|
112
|
|
- profileDir := GetEnvironmentVariable('USERPROFILE');
|
113
|
|
-
|
114
|
|
- if GetProcAddress(hK32, 'GetLocaleInfoEx') <> nil then begin
|
115
|
|
- // Vista
|
116
|
|
- KillDir(GetEnvironmentVariable('APPDATA')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
|
117
|
|
- DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
|
118
|
|
- DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
|
119
|
|
- profileDir := profileDir+'\AppData\Roaming\DMDirc';
|
120
|
|
- end
|
121
|
|
- else begin
|
122
|
|
- // Not Vista
|
123
|
|
- KillDir(GetEnvironmentVariable('USERPROFILE')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
|
124
|
|
- DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Application Data\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
|
125
|
|
- DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
|
126
|
|
- profileDir := profileDir+'\Application Data\DMDirc';
|
127
|
|
- end;
|
128
|
|
- // Remove irc:// handler if it is us.
|
129
|
|
- deleteProtocol := false;
|
130
|
|
- Reg := TRegistry.Create;
|
131
|
|
- Reg.RootKey := HKEY_CLASSES_ROOT;
|
132
|
|
- if Reg.OpenKey('irc\Shell\open\command', false) then begin
|
133
|
|
- handlerInfo := Reg.ReadString('');
|
134
|
|
- if (handlerInfo = '"'+InstallDir+'DMDirc.exe" -c %1') then begin
|
135
|
|
- deleteProtocol := true;
|
|
97
|
+ if MessageBox(0, PChar('This will uninstall DMDirc.'+#13#10+#13#10+'Do you want to continue?'), 'DMDirc Uninstaller', MB_YESNO) = IDYES then begin
|
|
98
|
+ if (ParamCount > 0) then begin
|
|
99
|
+ for i := 1 to ParamCount do begin
|
|
100
|
+ InstallDir := InstallDir+' '+paramstr(i);
|
|
101
|
+ end;
|
|
102
|
+ InstallDir := trim(InstallDir);
|
|
103
|
+ KillDir(InstallDir);
|
|
104
|
+ hK32 := GetModuleHandle('kernel32');
|
|
105
|
+ profileDir := GetEnvironmentVariable('USERPROFILE');
|
|
106
|
+
|
|
107
|
+ if GetProcAddress(hK32, 'GetLocaleInfoEx') <> nil then begin
|
|
108
|
+ // Vista
|
|
109
|
+ KillDir(GetEnvironmentVariable('APPDATA')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
|
|
110
|
+ DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
|
|
111
|
+ DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
|
|
112
|
+ profileDir := profileDir+'\AppData\Roaming\DMDirc';
|
136
|
113
|
end
|
137
|
|
- end;
|
138
|
|
- Reg.CloseKey;
|
139
|
|
- Reg.Free;
|
140
|
|
-
|
141
|
|
- if deleteProtocol then begin
|
|
114
|
+ else begin
|
|
115
|
+ // Not Vista
|
|
116
|
+ KillDir(GetEnvironmentVariable('USERPROFILE')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
|
|
117
|
+ DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Application Data\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
|
|
118
|
+ DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
|
|
119
|
+ profileDir := profileDir+'\Application Data\DMDirc';
|
|
120
|
+ end;
|
|
121
|
+ // Remove irc:// handler if it is us.
|
|
122
|
+ deleteProtocol := false;
|
142
|
123
|
Reg := TRegistry.Create;
|
143
|
124
|
Reg.RootKey := HKEY_CLASSES_ROOT;
|
144
|
|
- Reg.DeleteKey('irc\Shell\open\command');
|
145
|
|
- Reg.DeleteKey('irc\Shell\open');
|
146
|
|
- Reg.DeleteKey('irc\Shell');
|
147
|
|
- Reg.DeleteKey('irc\DefaultIcon');
|
148
|
|
- Reg.DeleteKey('irc');
|
|
125
|
+ if Reg.OpenKey('irc\Shell\open\command', false) then begin
|
|
126
|
+ handlerInfo := Reg.ReadString('');
|
|
127
|
+ if (handlerInfo = '"'+InstallDir+'DMDirc.exe" -c %1') then begin
|
|
128
|
+ deleteProtocol := true;
|
|
129
|
+ end
|
|
130
|
+ end;
|
149
|
131
|
Reg.CloseKey;
|
150
|
132
|
Reg.Free;
|
151
|
|
- end;
|
152
|
133
|
|
153
|
|
- Reg := TRegistry.Create;
|
154
|
|
- Reg.RootKey := HKEY_LOCAL_MACHINE;
|
155
|
|
- Reg.DeleteKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc');
|
156
|
|
- Reg.CloseKey;
|
157
|
|
- Reg.Free;
|
158
|
|
-
|
159
|
|
- if (FileExists(profileDir+'\dmdirc.config')) then begin
|
160
|
|
- if MessageBox(0, PChar('A dmdirc profile has been detected ('+profileDir+')'+#13#10+' Do you want to delete it aswell?'), 'DMDirc Uninstaller', MB_YESNO) = IDYES then begin
|
161
|
|
- KillDir(profileDir);
|
|
134
|
+ if deleteProtocol then begin
|
|
135
|
+ Reg := TRegistry.Create;
|
|
136
|
+ Reg.RootKey := HKEY_CLASSES_ROOT;
|
|
137
|
+ Reg.DeleteKey('irc\Shell\open\command');
|
|
138
|
+ Reg.DeleteKey('irc\Shell\open');
|
|
139
|
+ Reg.DeleteKey('irc\Shell');
|
|
140
|
+ Reg.DeleteKey('irc\DefaultIcon');
|
|
141
|
+ Reg.DeleteKey('irc');
|
|
142
|
+ Reg.CloseKey;
|
|
143
|
+ Reg.Free;
|
|
144
|
+ end;
|
|
145
|
+
|
|
146
|
+ Reg := TRegistry.Create;
|
|
147
|
+ Reg.RootKey := HKEY_LOCAL_MACHINE;
|
|
148
|
+ Reg.DeleteKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc');
|
|
149
|
+ Reg.CloseKey;
|
|
150
|
+ Reg.Free;
|
|
151
|
+
|
|
152
|
+ if (FileExists(profileDir+'\dmdirc.config')) then begin
|
|
153
|
+ if MessageBox(0, PChar('A dmdirc profile has been detected ('+profileDir+')'+#13#10+' Do you want to delete it aswell?'), 'DMDirc Uninstaller', MB_YESNO) = IDYES then begin
|
|
154
|
+ KillDir(profileDir);
|
|
155
|
+ end;
|
|
156
|
+ end;
|
|
157
|
+
|
|
158
|
+ MessageBox(0, PChar('DMDirc has been uninstalled from "'+InstallDir+'".'), 'DMDirc Uninstaller', MB_OK);
|
|
159
|
+ end
|
|
160
|
+ else begin
|
|
161
|
+ if (ExecAndWait('java -jar ' + ExtractFileDir(paramstr(0)) + '\DMDirc.jar -k', true) <> 0) then begin
|
|
162
|
+ TempDir := GetTempDirectory;
|
|
163
|
+ CopyFile(pchar(paramstr(0)), pchar(TempDir+'/uninstall.exe'), false);
|
|
164
|
+ Launch(TempDir+'/uninstall.exe '+ExtractFileDir(paramstr(0))+'\');
|
|
165
|
+ end else begin
|
|
166
|
+ MessageBox(0, PChar('Uninstall Aborted - DMDirc is still running.'+#13#10+'Please close DMDirc before continuing'), 'DMDirc Uninstaller', MB_OK + MB_ICONEXCLAMATION);
|
162
|
167
|
end;
|
163
|
|
- end;
|
164
|
|
-
|
165
|
|
- MessageBox(0, PChar('DMDirc has been uninstalled from "'+InstallDir+'".'), 'DMDirc Uninstaller', MB_OK);
|
166
|
|
- end
|
167
|
|
- else begin
|
168
|
|
-MessageBox(0, PChar('java -jar ' + ExtractFileDir(paramstr(0)) + '/DMDirc.jar -e -v'), 'DMDirc Uninstaller', MB_OK + MB_ICONEXCLAMATION);
|
169
|
|
-
|
170
|
|
- if checkStdErr('java -jar ' + ExtractFileDir(paramstr(0)) + 'DMDirc.jar -e -v') then begin
|
171
|
|
- TempDir := GetTempDirectory;
|
172
|
|
- CopyFile(pchar(paramstr(0)), pchar(TempDir+'/uninstall.exe'), false);
|
173
|
|
- Launch(TempDir+'/uninstall.exe '+ExtractFileDir(paramstr(0))+'\');
|
174
|
|
- end else begin
|
175
|
|
- MessageBox(0, PChar('Uninstall Aborted - DMDirc is still running.'+#13#10+'Please close DMDirc before continuing'), 'DMDirc Uninstaller', MB_OK + MB_ICONEXCLAMATION);
|
176
|
168
|
end;
|
177
|
169
|
end;
|
178
|
170
|
end.
|