Inno Setup: Backup external file before install delete section

后端 未结 1 752
终归单人心
终归单人心 2020-12-06 15:34

I would make a backup of files and folders before the [InstallDelete] section deletes them

[Files]
Source: \"{app}\\res_mods\\configs\\wotstat\\         


        
相关标签:
1条回答
  • 2020-12-06 15:54

    The [InstallDelete] section is processed (as one would expect) before the [Files] section. See the installation order.

    You can code the backup in the CurStepChanged(ssInstall) event, that happens before the installation starts:

    [Code]
    
    procedure CurStepChanged(CurStep: TSetupStep);
    var
      SourcePath: string;
      DestPath: string;
    begin
      if CurStep = ssInstall then
      begin
        SourcePath := ExpandConstant('{app}\res_mods\0.9.17.1\vehicles');
        DestPath := ExpandConstant('{app}\_backup\res_mods_{#DateTime}\0.9.17.1\vehicles');
        Log(Format('Backing up %s to %s before installation', [SourcePath, DestPath]));
        if not ForceDirectories(DestPath) then
        begin
          Log(Format('Failed to create %s', [DestPath]));
        end
          else
        begin
          DirectoryCopy(SourcePath, DestPath);
        end;
    
        SourcePath := ExpandConstant('{app}\res_mods\configs\wotstat\cache.json');
        DestPath := ExpandConstant('{app}\_backup\res_mods_{#DateTime}\configs\wotstat');
        if not ForceDirectories(DestPath) then
        begin
          Log(Format('Failed to create %s', [DestPath]));
        end
          else
        begin
          if not FileCopy(SourcePath, DestPath + '\cache.json', False) then
          begin
            Log(Format('Failed to copy %s', [SourcePath]));
          end
            else 
          begin
            Log(Format('Backed up %s', [SourcePath]));
          end;
        end;
      end;
    end;
    

    The code uses the DirectoryCopy function from the Inno Setup: copy folder, subfolders and files recursively in Code section.

    0 讨论(0)
提交回复
热议问题