You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Uninstaller.dpr 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. {*
  2. * DMDirc Uninstaller
  3. *
  4. * This application launches DMDirc on windows and passes control to the
  5. * update engine as necessary.
  6. *
  7. * DMDirc - Open Source IRC Client
  8. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes,
  9. * Michael Nixon
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a copy
  12. * of this software and associated documentation files (the "Software"), to deal
  13. * in the Software without restriction, including without limitation the rights
  14. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. * copies of the Software, and to permit persons to whom the Software is
  16. * furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in
  19. * all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27. * SOFTWARE.
  28. *}
  29. program Uninstaller;
  30. {$IFDEF FPC}
  31. {$MODE Delphi}
  32. {$ENDIF}
  33. // Use this instead of {$APPTYPE XXX}
  34. // APP_XXX is the same as {$APPTYPE XXX}
  35. // Defaults to console
  36. // This is a work-around for a bug in FPC Cross Compiling to windows in delphi
  37. // mode (IsConsole is always true)
  38. {$DEFINE APP_GUI}
  39. // This block actually does the work for the above work-around
  40. {$IFDEF APP_GUI}
  41. {$APPTYPE GUI}
  42. {$ELSE}
  43. {$IFDEF APP_FS}
  44. {$APPTYPE FS}
  45. {$ELSE}
  46. {$IFDEF APP_TOOL}
  47. {$DEFINE APP_CONSOLE}
  48. {$APPTYPE TOOL}
  49. {$ELSE}
  50. {$DEFINE APP_CONSOLE}
  51. {$APPTYPE CONSOLE}
  52. {$ENDIF}
  53. {$ENDIF}
  54. {$ENDIF}
  55. uses shared, Windows, SysUtils, registry, Vista;
  56. procedure InitCommonControls; stdcall; External 'comctl32.dll' name 'InitCommonControls';
  57. {$R uninstall.res}
  58. { ---------------------------------------------------------------------------- }
  59. { ----------------------------------------------------------------------------
  60. Create a temp directory and return the path to it
  61. ---------------------------------------------------------------------------- }
  62. function GetTempDirectory(): String;
  63. var
  64. buf: array[0..MAX_PATH] of Char;
  65. wintemp, temp: String;
  66. begin
  67. GetTempPath(SizeOf(buf)-1, buf);
  68. wintemp := StrPas(buf);
  69. Randomize;
  70. temp := '\DMDirc-uninstaller-'+inttostr(1000 + Random(1000));
  71. while (DirectoryExists(wintemp+temp+'\')) do begin
  72. temp := temp+'-'+inttostr(1+Random(1000));
  73. end;
  74. MkDir(wintemp+temp+'\');
  75. result := wintemp+temp+'\';
  76. end;
  77. { ----------------------------------------------------------------------------
  78. Delete a directory and all files it contains
  79. ---------------------------------------------------------------------------- }
  80. function KillDir(Dir: string): Integer;
  81. var
  82. searchResult: TSearchRec;
  83. begin
  84. Result := 0;
  85. if FindFirst(Dir+'\*', faDirectory + faHidden + faReadOnly + faSysfile + faAnyFile, searchResult) = 0 then
  86. begin
  87. repeat
  88. if (searchResult.attr and faDirectory) <> faDirectory then begin
  89. Try
  90. DeleteFile(Dir+'\'+searchResult.name);
  91. Except
  92. MessageBox(0, PChar('Unable to delete "'+Dir+'\'+searchResult.name+'" - is DMDirc still running?.'), 'DMDirc Uninstaller', MB_OK);
  93. end;
  94. end
  95. else begin
  96. if (searchResult.name <> '.') and (searchResult.name <> '..') then begin
  97. KillDir(Dir+'\'+searchResult.name);
  98. end;
  99. end;
  100. until FindNext(searchResult) <> 0;
  101. FindClose(searchResult);
  102. end;
  103. Try
  104. RmDir(Dir);
  105. Except
  106. end;
  107. end;
  108. { ----------------------------------------------------------------------------
  109. MAIN PROGRAM
  110. ---------------------------------------------------------------------------- }
  111. var
  112. TempDir: String;
  113. InstallDir: String = '';
  114. i: Integer;
  115. Reg: TRegistry;
  116. handlerInfo: String;
  117. profileDir: String;
  118. deleteProtocol: boolean;
  119. begin
  120. InitCommonControls;
  121. if (ParamCount > 0) then begin
  122. for i := 1 to ParamCount do begin
  123. InstallDir := InstallDir+' '+paramstr(i);
  124. end;
  125. InstallDir := trim(InstallDir);
  126. KillDir(InstallDir);
  127. profileDir := GetEnvironmentVariable('USERPROFILE');
  128. if IsWindowsVista then begin
  129. // Vista
  130. KillDir(GetEnvironmentVariable('APPDATA')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
  131. DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
  132. DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
  133. profileDir := profileDir+'\AppData\Roaming\DMDirc';
  134. end
  135. else begin
  136. // Not Vista
  137. KillDir(GetEnvironmentVariable('USERPROFILE')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
  138. DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Application Data\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
  139. DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
  140. profileDir := profileDir+'\Application Data\DMDirc';
  141. end;
  142. // Remove irc:// handler if it is us.
  143. deleteProtocol := false;
  144. Reg := TRegistry.Create;
  145. Reg.RootKey := HKEY_CLASSES_ROOT;
  146. if Reg.OpenKey('irc\Shell\open\command', false) then begin
  147. handlerInfo := Reg.ReadString('');
  148. if (handlerInfo = '"'+InstallDir+'DMDirc.exe" -c %1') then begin
  149. deleteProtocol := true;
  150. end
  151. end;
  152. Reg.CloseKey;
  153. Reg.Free;
  154. if deleteProtocol then begin
  155. Reg := TRegistry.Create;
  156. Reg.RootKey := HKEY_CLASSES_ROOT;
  157. Reg.DeleteKey('irc\Shell\open\command');
  158. Reg.DeleteKey('irc\Shell\open');
  159. Reg.DeleteKey('irc\Shell');
  160. Reg.DeleteKey('irc\DefaultIcon');
  161. Reg.DeleteKey('irc');
  162. Reg.CloseKey;
  163. Reg.Free;
  164. end;
  165. Reg := TRegistry.Create;
  166. Reg.RootKey := HKEY_LOCAL_MACHINE;
  167. Reg.DeleteKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc');
  168. Reg.CloseKey;
  169. Reg.Free;
  170. if (FileExists(profileDir+'\dmdirc.config')) then begin
  171. if MessageBox(0, PChar('A dmdirc profile has been detected ('+profileDir+') '+#13#10+'Do you want to delete it as well?'), 'DMDirc Uninstaller', MB_YESNO) = IDYES then begin
  172. KillDir(profileDir);
  173. end;
  174. end;
  175. showmessage('DMDirc has been uninstalled from "'+InstallDir+'".', 'DMDirc Uninstaller', 'Uninstall Successful');
  176. end
  177. else if askQuestion('This will uninstall DMDirc. '+#13#10+#13#10+'Do you want to continue?', 'DMDirc Uninstaller') then begin
  178. if (ExecAndWait('java -jar "' + ExtractFileDir(paramstr(0)) + '\DMDirc.jar" -k', true) <> 0) then begin
  179. TempDir := GetTempDirectory;
  180. CopyFile(pchar(paramstr(0)), pchar(TempDir+'/uninstall.exe'), false);
  181. Launch('"'+TempDir+'/uninstall.exe" '+ExtractFileDir(paramstr(0))+'\');
  182. end else begin
  183. showError('Uninstall Aborted - DMDirc is still running.' +
  184. #13#10 + 'Please close DMDirc before continuing',
  185. 'DMDirc Uninstaller', False, False);
  186. end;
  187. end;
  188. end.