2017-03-09 50 views
1

我想使文件和文件夾的備份[InstallDelete]部分之前將它們刪除Inno Setup的:備份外部文件之前,安裝刪除部分

[Files] 
Source: "{app}\res_mods\configs\wotstat\cache.json"; \ 
    DestDir: "{app}\_backup\res_mods_{#DateTime}\configs\wotstat\"; \ 
    Flags: external skipifsourcedoesntexist uninsneveruninstall 
Source: "{app}\res_mods\0.9.17.1\vehicles\*"; \ 
    DestDir:"{app}\_backup\res_mods_{#DateTime}\0.9.17.1\vehicles\"; \ 
    Flags: external skipifsourcedoesntexist createallsubdirs recursesubdirs uninsneveruninstall 

這工作得很好。但是,如果我檢查

[InstallDelete] 
Type: filesandordirs; Name: "{app}\mods\*.*"; Tasks: cleanres 
Type: filesandordirs; Name: "{app}\res_mods\*.*"; Tasks: cleanres 

沒有文件被保存

我怎樣才能使它工作。 Thx

+0

什麼是「{#DateTime}」? –

+0

將日期和/或時間放到名稱文件夾中。使用#define DateTime GetDateTimeString('dd/mm/yy',' - ',''); 。 [鏈接](http://www.jrsoftware.org/ispphelp/index.php?topic=getdatetimestring) –

+0

但是什麼日期/時間? - 你如何設置它? –

回答

1

[Files]部分之前對[InstallDelete]部分進行處理(如人們所期望的)。請參閱installation order

您可以編寫在CurStepChanged(ssInstall) event備份,這種情況發生在安裝開始前:

[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; 

的代碼使用從Inno Setup: copy folder, subfolders and files recursively in Code sectionDirectoryCopy功能。

+0

隨着代碼,有一個未知的標識符源路徑 –

+0

你從另一個問題複製'DirectoryCopy'嗎? –

+0

不,但它是一樣的 –

相關問題