Add
[Files] ; Backup Function_Template Source: "{app}\XXX.txt"; DestDir: "{app}"; DestName: "XXX.txt.bkup"; Flags: external skipifsourcedoesntexist uninsneveruninstall
This will move the existing file, and the flags will prevent it from being deleted. Now in the code you can put
[Code] procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); var OldFile: string; begin case CurUninstallStep of usPostUninstall: begin OldFile := ExpandConstant('{app}\XXX.txt.bkup'); if FileExists(OldFile) then RenameFile(OldFile, ExpandConstant('{app}\XXX.txt')); end; end; end;
source share