4

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?

mghie
  • 32,028
  • 6
  • 87
  • 129
lostprophet
  • 41
  • 1
  • 2
  • What do you want to happen if the installer finds `XXX.txt.backup` in the folder already - skip the backup? Overwrite the old backup? – mghie Aug 21 '10 at 16:26

3 Answers3

13

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;
adn
  • 897
  • 3
  • 22
  • 49
0
Source: "{app}\XXX.txt"; DestDir: "{app}"; DestName: "XXX.txt.bkup"; Flags: external skipifsourcedoesntexist uninsneveruninstall

Did not appear to work, since "The compiler will prepend the path of your installation's source directory if you do not specify a fully qualified pathname."

However, I just discovered this works fine! I had left off the "external" flag.

TLama
  • 75,147
  • 17
  • 214
  • 392
Bill
  • 1
  • 1
  • 3
    Welcome to StackOverflow. As this isn't an answer but a follow up to another answer, can you post it as a comment instead? If the answer is wrong, you can edit it with a suitable description and it'll be approved by a more experianced user. Thanks – Deanna Sep 21 '12 at 09:01
-1

Well, maybe a popup saying "There is already an XXX.txt.backup. Do you really want to overwrite it?"