How to save a folder when user confirms uninstallation? (Inno Setup)

后端 未结 1 1913
囚心锁ツ
囚心锁ツ 2021-01-06 23:56

How can I save a backup copy of an specific folder to user desktop, when user confirms application uninstall?

I tried this without success... Maybe there is an easie

相关标签:
1条回答
  • 2021-01-07 00:14

    Triggering the backup on CurUninstallStepChanged(usUninstall) is the best solution.

    The problems you have are:

    • The FileCopy function cannot copy folders.

      For that see Inno Setup: copy folder, subfolders and files recursively in Code section.

    • You have to use the ExpandConstant function to resolve the {app} and the {userdesktop} constants.

    • You have to create the target folder.

    With use of the DirectoryCopy user function (from the question referenced above), you can do:

    procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
    var
      SourcePath: string;
      DestPath: string;
    begin
      if CurUninstallStep = usUninstall then
      begin
        SourcePath := ExpandConstant('{app}\Profile');
        DestPath := ExpandConstant('{userdesktop}\Backup\Profile');
        Log(Format('Backing up %s to %s before uninstallation', [SourcePath, DestPath]));
        if not ForceDirectories(DestPath) then
        begin
          Log(Format('Failed to create %s', [DestPath]));
        end
          else
        begin
          DirectoryCopy(SourcePath, DestPath);
        end;
      end;
    end;
    
    0 讨论(0)
提交回复
热议问题