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 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. program Uninstaller;
  2. {$MODE Delphi}
  3. {$APPTYPE GUI}
  4. uses Windows, SysUtils, classes, registry;
  5. {$R uninstall.res}
  6. function GetTempDirectory(): String;
  7. var
  8. buf: array[0..MAX_PATH] of Char;
  9. wintemp, temp: String;
  10. begin
  11. GetTempPath(SizeOf(buf)-1, buf);
  12. wintemp := StrPas(buf);
  13. Randomize;
  14. temp := '\DMDirc-uninstaller-'+inttostr(1000 + Random(1000));
  15. while (DirectoryExists(wintemp+temp+'\')) do begin
  16. temp := temp+'-'+inttostr(1+Random(1000));
  17. end;
  18. MkDir(wintemp+temp+'\');
  19. result := wintemp+temp+'\';
  20. end;
  21. procedure Launch(sProgramToRun: String);
  22. var
  23. StartupInfo: TStartupInfo;
  24. ProcessInfo: TProcessInformation;
  25. begin
  26. FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  27. with StartupInfo do begin
  28. cb := SizeOf(TStartupInfo);
  29. dwFlags := STARTF_USESHOWWINDOW;
  30. wShowWindow := SW_SHOWNORMAL;
  31. end;
  32. CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
  33. end;
  34. function KillDir(Dir: string): Integer;
  35. var
  36. searchResult: TSearchRec;
  37. begin
  38. Result := 0;
  39. if FindFirst(Dir+'\*', faDirectory + faHidden + faReadOnly + faSysfile + faAnyFile, searchResult) = 0 then
  40. begin
  41. repeat
  42. if (searchResult.attr and faDirectory) <> faDirectory then begin
  43. Try
  44. DeleteFile(Dir+'\'+searchResult.name);
  45. Except
  46. MessageBox(0, PChar('Unable to delete "'+Dir+'\'+searchResult.name+'" - is DMDirc still running?.'), 'DMDirc Uninstaller', MB_OK);
  47. end;
  48. end
  49. else begin
  50. if (searchResult.name <> '.') and (searchResult.name <> '..') then begin
  51. KillDir(Dir+'\'+searchResult.name);
  52. end;
  53. end;
  54. until FindNext(searchResult) <> 0;
  55. FindClose(searchResult);
  56. end;
  57. Try
  58. RmDir(Dir);
  59. Except
  60. end;
  61. end;
  62. var
  63. TempDir: String;
  64. InstallDir: String = '';
  65. hK32: THandle;
  66. i: Integer;
  67. Reg: TRegistry;
  68. handlerInfo: String;
  69. profileDir: String;
  70. deleteProtocol: boolean;
  71. begin
  72. if (ParamCount > 0) then begin
  73. for i := 1 to ParamCount do begin
  74. InstallDir := InstallDir+' '+paramstr(i);
  75. end;
  76. InstallDir := trim(InstallDir);
  77. KillDir(InstallDir);
  78. hK32 := GetModuleHandle('kernel32');
  79. profileDir := GetEnvironmentVariable('USERPROFILE');
  80. if GetProcAddress(hK32, 'GetLocaleInfoEx') <> nil then begin
  81. // Vista
  82. KillDir(GetEnvironmentVariable('APPDATA')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
  83. DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
  84. DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
  85. profileDir := profileDir+'\AppData\Roaming\DMDirc';
  86. end
  87. else begin
  88. // Not Vista
  89. KillDir(GetEnvironmentVariable('USERPROFILE')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
  90. DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Application Data\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
  91. DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
  92. profileDir := profileDir+'\Application Data\DMDirc';
  93. end;
  94. // Remove irc:// handler if it is us.
  95. deleteProtocol := false;
  96. Reg := TRegistry.Create;
  97. Reg.RootKey := HKEY_CLASSES_ROOT;
  98. if Reg.OpenKey('irc\Shell\open\command', false) then begin
  99. handlerInfo := Reg.ReadString('');
  100. if (handlerInfo = '"'+InstallDir+'DMDirc.exe" -c %1') then begin
  101. deleteProtocol := true;
  102. end
  103. end;
  104. Reg.CloseKey;
  105. Reg.Free;
  106. if deleteProtocol then begin
  107. Reg := TRegistry.Create;
  108. Reg.RootKey := HKEY_CLASSES_ROOT;
  109. Reg.DeleteKey('irc\Shell\open\command');
  110. Reg.DeleteKey('irc\Shell\open');
  111. Reg.DeleteKey('irc\Shell');
  112. Reg.DeleteKey('irc\DefaultIcon');
  113. Reg.DeleteKey('irc');
  114. Reg.CloseKey;
  115. Reg.Free;
  116. end;
  117. Reg := TRegistry.Create;
  118. Reg.RootKey := HKEY_LOCAL_MACHINE;
  119. Reg.DeleteKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc');
  120. Reg.CloseKey;
  121. Reg.Free;
  122. if (FileExists(profileDir+'\dmdirc.config')) then begin
  123. 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
  124. KillDir(profileDir);
  125. end;
  126. end;
  127. MessageBox(0, PChar('DMDirc has been uninstalled from "'+InstallDir+'".'), 'DMDirc Uninstaller', MB_OK);
  128. end
  129. else begin
  130. TempDir := GetTempDirectory;
  131. if MessageBox(0, PChar('This will uninstall DMDirc.'+#13#10+#13#10+'Please make sure DMDirc is not running before continuing, or some files might not get correctly removed.'+#13#10+#13#10+'Do you want to continue?'), 'DMDirc Uninstaller', MB_YESNO) = IDYES then begin
  132. CopyFile(pchar(paramstr(0)), pchar(TempDir+'/uninstall.exe'), false);
  133. Launch(TempDir+'/uninstall.exe '+ExtractFileDir(paramstr(0))+'\');
  134. end;
  135. end;
  136. end.