Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DARIA P. DLA MOJEGO INSTALATORA
- // OBSŁUGA KROKÓW DEINSTALACJI - POPRAWIONA WERSJA
- procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
- var
- SettingsPath: String;
- ConfigFiles: TStringList;
- i: Integer;
- DeleteCount: Cardinal;
- FilePath: String;
- begin
- // PRZED ROZPOCZĘCIEM DEINSTALACJI - lepszy moment na pytanie
- if CurUninstallStep = usUninstall then
- begin
- SettingsPath := ExpandConstant('{app}');
- ConfigFiles := TStringList.Create;
- try
- // Znajdź wszystkie pliki konfiguracyjne
- if FileExists(SettingsPath + '\settings.ini') then
- ConfigFiles.Add('settings.ini');
- if FileExists(SettingsPath + '\config.ini') then
- ConfigFiles.Add('config.ini');
- if FileExists(SettingsPath + '\tasks.dat') then
- ConfigFiles.Add('tasks.dat');
- if FileExists(SettingsPath + '\statistics.log') then
- ConfigFiles.Add('statistics.log');
- // Jeśli znaleziono pliki konfiguracyjne
- if ConfigFiles.Count > 0 then
- begin
- if MsgBox('Znaleziono pliki ustawień i danych użytkownika:' + #13#13 +
- ConfigFiles.Text + #13 +
- 'Czy chcesz zachować te pliki?' + #13#13 +
- 'TAK - zachowaj moje ustawienia' + #13 +
- 'NIE - usuń wszystko',
- mbConfirmation, MB_YESNO or MB_DEFBUTTON1) = IDNO then
- begin
- // Użytkownik chce usunąć - oznacz pliki do usunięcia
- Log('Użytkownik wybrał usunięcie plików konfiguracyjnych');
- for i := 0 to ConfigFiles.Count - 1 do
- begin
- RegWriteStringValue(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall',
- 'DeleteFile' + IntToStr(i), SettingsPath + '\' + ConfigFiles[i]);
- end;
- RegWriteDWordValue(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall',
- 'DeleteCount', ConfigFiles.Count);
- end
- else
- begin
- Log('Użytkownik wybrał zachowanie plików konfiguracyjnych');
- end;
- end;
- finally
- ConfigFiles.Free;
- end;
- end;
- // PO ZAKOŃCZENIU DEINSTALACJI - usuń oznaczone pliki
- if CurUninstallStep = usPostUninstall then
- begin
- // Sprawdź czy są pliki do usunięcia
- if RegQueryDWordValue(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall', 'DeleteCount', DeleteCount) then
- begin
- Log('Usuwam ' + IntToStr(DeleteCount) + ' plików konfiguracyjnych...');
- for i := 0 to DeleteCount - 1 do
- begin
- if RegQueryStringValue(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall',
- 'DeleteFile' + IntToStr(i), FilePath) then
- begin
- if FileExists(FilePath) then
- begin
- if DeleteFile(FilePath) then
- Log('Usunięto: ' + FilePath)
- else
- Log('Nie udało się usunąć: ' + FilePath);
- end;
- end;
- end;
- // Wyczyść klucze rejestru
- RegDeleteKeyIncludingSubkeys(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall');
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment