Backing up files and restoring them when deleted using InnoSetup?

Consider the following:

  • I have two files, for example XXX.txt and YYY.txt

  • I want to install them in a folder (say files ), in which there are already XXX.txt and YYY.txt

  • I want to โ€œbackupโ€ the two source files by renaming them to XXX.txt.backup and YYY.txt.backup

  • When deleting, I want to restore two files to their original state

How can I achieve this using Inno Setup?

+4
source share
3 answers

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; 
+12
source
 Source: "{app}\XXX.txt"; DestDir: "{app}"; DestName: "XXX.txt.bkup"; Flags: external skipifsourcedoesntexist uninsneveruninstall 

It does not work, because "the compiler will add the path to the installation source directory if you do not specify the full path name."

However, I just discovered that this works great! I left the "external" flag.

0
source

Well, maybe the pop-up message "Already have XXX.txt.backup. Do you really want to overwrite it?"

-1
source

All Articles