How to save a folder when user confirms uninstalla

2019-02-20 17:13发布

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 easier way to do it without using code...

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usUninstall then
  begin
    FileCopy('{app}\Profile\*', '{userdesktop}\Backup\Profile\', False);
  end;
end;

Thank you guys! :)

1条回答
做个烂人
2楼-- · 2019-02-20 17:40

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

The problems you have are:

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;
查看更多
登录 后发表回答