当用户确认卸载应用程序时,如何将特定文件夹的备份副本保存到用户桌面?
我尝试过但没有成功...也许有一种更简单的方法可以在不使用代码的情况下做到这一点...
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then
begin
CopyFile('{app}\Profile\*', '{userdesktop}\Backup\Profile\', False);
end;
end;
谢谢你们! :)
在
CurUninstallStepChanged(usUninstall)
上触发备份是最好的解决方案。
您遇到的问题是:
CopyFile
功能无法复制文件夹。
ExpandConstant
函数 来解析 {app}
和 {userdesktop}
常量。
您必须创建目标文件夹。
使用
DirectoryCopy
用户功能(来自上面引用的问题),您可以执行以下操作:
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;