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

你说的曾经没有我的故事 提交于 2019-12-01 11:07:46

问题


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:


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;


来源:https://stackoverflow.com/questions/42684469/how-to-save-a-folder-when-user-confirms-uninstallation-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!