Consider the following:
I have two files, for example XXX.txt
and YYY.txt
I want to install them to a folder (let's say files
), in which there are already XXX.txt
and YYY.txt
files
I want to "back up" the two original files, renaming them to XXX.txt.backup
and YYY.txt.backup
On uninstall I want to restore the two files to their original state
How can I achieve this with Inno Setup?
Add
[Files]
; Backup Function_Template
Source: "{app}\XXX.txt"; DestDir: "{app}"; DestName: "XXX.txt.bkup"; Flags: external skipifsourcedoesntexist uninsneveruninstall
That would move the existing file, and the flags will prevent from uninstalling it. 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With