Guest User

Untitled

a guest
Jun 20th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. // DARIA P. DLA MOJEGO INSTALATORA
  2.  
  3. // OBSŁUGA KROKÓW DEINSTALACJI - POPRAWIONA WERSJA
  4. procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
  5. var
  6. SettingsPath: String;
  7. ConfigFiles: TStringList;
  8. i: Integer;
  9. DeleteCount: Cardinal;
  10. FilePath: String;
  11. begin
  12. // PRZED ROZPOCZĘCIEM DEINSTALACJI - lepszy moment na pytanie
  13. if CurUninstallStep = usUninstall then
  14. begin
  15. SettingsPath := ExpandConstant('{app}');
  16. ConfigFiles := TStringList.Create;
  17. try
  18. // Znajdź wszystkie pliki konfiguracyjne
  19. if FileExists(SettingsPath + '\settings.ini') then
  20. ConfigFiles.Add('settings.ini');
  21. if FileExists(SettingsPath + '\config.ini') then
  22. ConfigFiles.Add('config.ini');
  23. if FileExists(SettingsPath + '\tasks.dat') then
  24. ConfigFiles.Add('tasks.dat');
  25. if FileExists(SettingsPath + '\statistics.log') then
  26. ConfigFiles.Add('statistics.log');
  27.  
  28. // Jeśli znaleziono pliki konfiguracyjne
  29. if ConfigFiles.Count > 0 then
  30. begin
  31. if MsgBox('Znaleziono pliki ustawień i danych użytkownika:' + #13#13 +
  32. ConfigFiles.Text + #13 +
  33. 'Czy chcesz zachować te pliki?' + #13#13 +
  34. 'TAK - zachowaj moje ustawienia' + #13 +
  35. 'NIE - usuń wszystko',
  36. mbConfirmation, MB_YESNO or MB_DEFBUTTON1) = IDNO then
  37. begin
  38. // Użytkownik chce usunąć - oznacz pliki do usunięcia
  39. Log('Użytkownik wybrał usunięcie plików konfiguracyjnych');
  40. for i := 0 to ConfigFiles.Count - 1 do
  41. begin
  42. RegWriteStringValue(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall',
  43. 'DeleteFile' + IntToStr(i), SettingsPath + '\' + ConfigFiles[i]);
  44. end;
  45. RegWriteDWordValue(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall',
  46. 'DeleteCount', ConfigFiles.Count);
  47. end
  48. else
  49. begin
  50. Log('Użytkownik wybrał zachowanie plików konfiguracyjnych');
  51. end;
  52. end;
  53. finally
  54. ConfigFiles.Free;
  55. end;
  56. end;
  57.  
  58. // PO ZAKOŃCZENIU DEINSTALACJI - usuń oznaczone pliki
  59. if CurUninstallStep = usPostUninstall then
  60. begin
  61. // Sprawdź czy są pliki do usunięcia
  62. if RegQueryDWordValue(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall', 'DeleteCount', DeleteCount) then
  63. begin
  64. Log('Usuwam ' + IntToStr(DeleteCount) + ' plików konfiguracyjnych...');
  65. for i := 0 to DeleteCount - 1 do
  66. begin
  67. if RegQueryStringValue(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall',
  68. 'DeleteFile' + IntToStr(i), FilePath) then
  69. begin
  70. if FileExists(FilePath) then
  71. begin
  72. if DeleteFile(FilePath) then
  73. Log('Usunięto: ' + FilePath)
  74. else
  75. Log('Nie udało się usunąć: ' + FilePath);
  76. end;
  77. end;
  78. end;
  79.  
  80. // Wyczyść klucze rejestru
  81. RegDeleteKeyIncludingSubkeys(HKCU, 'SOFTWARE\{#MyAppPublisher}\{#MyAppName}\Uninstall');
  82. end;
  83. end;
  84. end;
Advertisement
Add Comment
Please, Sign In to add comment