123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- program Uninstaller;
- {$MODE Delphi}
- {$APPTYPE GUI}
-
- uses Windows, SysUtils, classes, registry;
-
- {$R uninstall.res}
-
- function GetTempDirectory(): String;
- var
- buf: array[0..MAX_PATH] of Char;
- wintemp, temp: String;
- begin
- GetTempPath(SizeOf(buf)-1, buf);
- wintemp := StrPas(buf);
- Randomize;
- temp := '\DMDirc-uninstaller-'+inttostr(1000 + Random(1000));
- while (DirectoryExists(wintemp+temp+'\')) do begin
- temp := temp+'-'+inttostr(1+Random(1000));
- end;
- MkDir(wintemp+temp+'\');
- result := wintemp+temp+'\';
- end;
-
-
- procedure Launch(sProgramToRun: String);
- var
- StartupInfo: TStartupInfo;
- ProcessInfo: TProcessInformation;
- begin
- FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
- with StartupInfo do begin
- cb := SizeOf(TStartupInfo);
- dwFlags := STARTF_USESHOWWINDOW;
- wShowWindow := SW_SHOWNORMAL;
- end;
-
- CreateProcess(nil, PChar(sProgramToRun), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
- end;
-
- function KillDir(Dir: string): Integer;
- var
- searchResult: TSearchRec;
- begin
- Result := 0;
- if FindFirst(Dir+'\*', faDirectory + faHidden + faReadOnly + faSysfile + faAnyFile, searchResult) = 0 then
- begin
- repeat
- if (searchResult.attr and faDirectory) <> faDirectory then begin
- Try
- DeleteFile(Dir+'\'+searchResult.name);
- Except
- MessageBox(0, PChar('Unable to delete "'+Dir+'\'+searchResult.name+'" - is DMDirc still running?.'), 'DMDirc Uninstaller', MB_OK);
- end;
- end
- else begin
- if (searchResult.name <> '.') and (searchResult.name <> '..') then begin
- KillDir(Dir+'\'+searchResult.name);
- end;
- end;
- until FindNext(searchResult) <> 0;
- FindClose(searchResult);
- end;
- Try
- RmDir(Dir);
- Except
- end;
- end;
-
- var
- TempDir: String;
- InstallDir: String = '';
- hK32: THandle;
- i: Integer;
- Reg: TRegistry;
- handlerInfo: String;
- profileDir: String;
- deleteProtocol: boolean;
- begin
- if (ParamCount > 0) then begin
- for i := 1 to ParamCount do begin
- InstallDir := InstallDir+' '+paramstr(i);
- end;
- InstallDir := trim(InstallDir);
- KillDir(InstallDir);
- hK32 := GetModuleHandle('kernel32');
- profileDir := GetEnvironmentVariable('USERPROFILE');
-
- if GetProcAddress(hK32, 'GetLocaleInfoEx') <> nil then begin
- // Vista
- KillDir(GetEnvironmentVariable('APPDATA')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
- DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
- DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
- profileDir := profileDir+'\AppData\Roaming\DMDirc';
- end
- else begin
- // Not Vista
- KillDir(GetEnvironmentVariable('USERPROFILE')+'\Microsoft\Windows\Start Menu\Programs\DMDirc');
- DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Application Data\Microsoft\Internet Explorer\Quick Launch\DMDirc.lnk');
- DeleteFile(GetEnvironmentVariable('USERPROFILE')+'\Desktop\DMDirc.lnk');
- profileDir := profileDir+'\Application Data\DMDirc';
- end;
- // Remove irc:// handler if it is us.
- deleteProtocol := false;
- Reg := TRegistry.Create;
- Reg.RootKey := HKEY_CLASSES_ROOT;
- if Reg.OpenKey('irc\Shell\open\command', false) then begin
- handlerInfo := Reg.ReadString('');
- if (handlerInfo = '"'+InstallDir+'DMDirc.exe" -c %1') then begin
- deleteProtocol := true;
- end
- end;
- Reg.CloseKey;
- Reg.Free;
-
- if deleteProtocol then begin
- Reg := TRegistry.Create;
- Reg.RootKey := HKEY_CLASSES_ROOT;
- Reg.DeleteKey('irc\Shell\open\command');
- Reg.DeleteKey('irc\Shell\open');
- Reg.DeleteKey('irc\Shell');
- Reg.DeleteKey('irc\DefaultIcon');
- Reg.DeleteKey('irc');
- Reg.CloseKey;
- Reg.Free;
- end;
-
- Reg := TRegistry.Create;
- Reg.RootKey := HKEY_LOCAL_MACHINE;
- Reg.DeleteKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DMDirc');
- Reg.CloseKey;
- Reg.Free;
-
- if (FileExists(profileDir+'\dmdirc.config')) then begin
- 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
- KillDir(profileDir);
- end;
- end;
-
- MessageBox(0, PChar('DMDirc has been uninstalled from "'+InstallDir+'".'), 'DMDirc Uninstaller', MB_OK);
- end
- else begin
- TempDir := GetTempDirectory;
- 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
- CopyFile(pchar(paramstr(0)), pchar(TempDir+'/uninstall.exe'), false);
- Launch(TempDir+'/uninstall.exe '+ExtractFileDir(paramstr(0))+'\');
- end;
- end;
- end.
|