2016-04-08 10 views
1

通常はsavegamesのバックアップに問題はありませんが、このゲームではFreeArcを使用しています。ゲームが非常に大きいので、Inno Setupではどのファイル削除する。 FreeArcを使用すると、Inno Setup - データサブディレクトリ以外のアプリケーションフォルダ全体を削除

[UninstallDelete] 
Type: files; Name: "{app}" 

を使用する必要がある。しかし、この特定のゲームは{app}\data\saveでセーブデータを格納します。私はそのフォルダをどこかに移動してゲームをアンインストールし、それを元に戻す機能が必要です。

ここに私のコードです:

procedure DirectoryCopy(SourcePath, DestPath: string); 
var 
    FindRec: TFindRec; 
    SourceFilePath: string; 
    DestFilePath: string; 
begin 
    if FindFirst(SourcePath + '\*', FindRec) then 
    begin 
    try 
     repeat 
     if (FindRec.Name <> '.') and (FindRec.Name <> '..') then 
     begin 
      SourceFilePath := SourcePath + '\' + FindRec.Name; 
      DestFilePath := DestPath + '\' + FindRec.Name; 
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then 
      begin 
      if FileCopy(SourceFilePath, DestFilePath, False) then 
      begin 
       Log(Format('Copied %s to %s', [SourceFilePath, DestFilePath])); 
      end 
       else 
      begin 
       Log(Format('Failed to copy %s to %s', [SourceFilePath, DestFilePath])); 
      end; 
      end 
      else 
      begin 
      if CreateDir(DestFilePath) then 
      begin 
       Log(Format('Created %s', [DestFilePath])); 
       DirectoryCopy(SourceFilePath, DestFilePath); 
      end 
       else 
      begin 
       Log(Format('Failed to create %s', [DestFilePath])); 
      end; 
      end; 
     end; 
     until not FindNext(FindRec); 
    finally 
     FindClose(FindRec); 
    end; 
    end 
    else 
    begin 
    Log(Format('Failed to list %s', [SourcePath])); 
    end; 
end; 

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); 
Begin 
    if (CurUninstallStep = usUninstall) and DirExists(ExpandConstant('{app}\data\SAVE')) then 
    begin 
    if MsgBox('Do you want to delete all save games?', mbConfirmation, MB_YESNO) = IDYES then 
     begin 
     DelTree(ExpandConstant('{app}'), True, True, True); 
     end 
    else 
     begin 
     DirectoryCopy(ExpandConstant('{app}\data\SAVE'), ExpandConstant('{app}\SAVE')); 
     Deltree(ExpandConstant('{app}\data'), True, True, True); 
     DirectoryCopy(ExpandConstant('{app}\SAVE'), ExpandConstant('{app}\data\SAVE')); 
     end 
    end; 
End; 

そして、ここでは、ログです:

2016-04-08 10:16:02.420 Log opened. (Time zone: UTC+04:00) 
2016-04-08 10:16:02.421 Setup version: Inno Setup version 5.5.6 (u) 
2016-04-08 10:16:02.421 Original Uninstall EXE: C:\Games\MyApp\unins001.exe 
2016-04-08 10:16:02.421 Uninstall DAT: C:\Games\MyApp\unins001.dat 
2016-04-08 10:16:02.421 Uninstall command line: /SECONDPHASE="C:\Games\MyApp\unins001.exe" /FIRSTPHASEWND=$B5111C /log=C:\setup.log 
2016-04-08 10:16:02.421 Windows version: 6.1.7601 SP1 (NT platform: Yes) 
2016-04-08 10:16:02.421 64-bit Windows: Yes 
2016-04-08 10:16:02.421 Processor architecture: x64 
2016-04-08 10:16:02.421 User privileges: Administrative 
2016-04-08 10:16:02.421 64-bit install mode: No 
2016-04-08 10:16:02.422 Created temporary directory: C:\Users\George\AppData\Local\Temp\is-GSI4R.tmp 
2016-04-08 10:16:02.440 Message box (Yes/No): 
          Are you sure you want to completely remove MyApp and all of its components? 
2016-04-08 10:16:04.014 User chose Yes. 
2016-04-08 10:16:04.031 Message box (Yes/No): 
          Do you want to delete all save games? 
2016-04-08 10:16:04.790 User chose No. 
2016-04-08 10:16:04.791 Failed to create C:\Games\MyApp\SAVE\scores 
2016-04-08 10:16:04.805 Failed to list C:\Games\MyApp\SAVE 
2016-04-08 10:16:04.805 Starting the uninstallation process. 
2016-04-08 10:16:04.806 Deleting Uninstall data files. 
2016-04-08 10:16:05.326 Uninstallation process succeeded. 
2016-04-08 10:16:05.326 Removed all? Yes 
2016-04-08 10:16:05.326 Need to restart Windows? No 
2016-04-08 10:16:05.814 Message box (OK): 
          MyApp was successfully removed from your computer. 
2016-04-08 10:16:06.678 User chose OK. 
2016-04-08 10:16:06.679 Log closed. 
+0

「期待通りに機能しませんでした」* - 意味するものは何ですか?あなたのコードを私たちに教えてください。私たちにログファイルを表示してください。何が悪くなったのか説明してください。 –

+0

'{app}'フォルダはまだ削除されていました。ここで私の騒ぎに行く:どのように私はログですか? –

+0

'setup.exe/log = setup.log' +あなたのコードを表示してください。 –

答えて

1

は、戻って離れ、その後、節約コピーするやり過ぎではないですか?

ディレクトリツリーを繰り返し処理するコードを作成したら、「保存」フォルダ以外のファイルを削除するように繰り返します。

次のコードは(どちらのモードでも)すべての削除作業を行いますので、[UninstallDelete]セクションを削除する必要があります。

procedure DelTreeExceptSavesDir(Path: string); 
var 
    FindRec: TFindRec; 
    FilePath: string; 
begin 
    if FindFirst(Path + '\*', FindRec) then 
    begin 
    try 
     repeat 
     if (FindRec.Name <> '.') and (FindRec.Name <> '..') then 
     begin 
      FilePath := Path + '\' + FindRec.Name; 
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then 
      begin 
      if DeleteFile(FilePath) then 
      begin 
       Log(Format('Deleted file %s', [FilePath])); 
      end 
       else 
      begin 
       Log(Format('Failed to delete file %s', [FilePath])); 
      end; 
      end 
      else 
      begin 
      if CompareText(FindRec.Name, 'save') = 0 then 
      begin 
       Log(Format('Keeping directory %s', [FilePath])); 
      end 
       else 
      begin 
       DelTreeExceptSavesDir(FilePath); 

       if RemoveDir(FilePath) then 
       begin 
       Log(Format('Deleted directory %s', [FilePath])); 
       end 
       else 
       begin 
       Log(Format('Failed to delete directory %s', [FilePath])); 
       end; 
      end; 
      end; 
     end; 
     until not FindNext(FindRec); 
    finally 
     FindClose(FindRec); 
    end; 
    end 
    else 
    begin 
    Log(Format('Failed to list %s', [Path])); 
    end; 
end; 

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); 
var 
    SavePath: string; 
    AppPath: string; 
begin 
    SavePath := ExpandConstant('{app}\data\SAVE'); 

    if CurUninstallStep = usUninstall then 
    begin 
    AppPath := ExpandConstant('{app}') 

    if (not DirExists(SavePath)) or 
     (MsgBox('Do you want to delete all save games?', mbConfirmation, MB_YESNO) = IDYES) then 
    begin 
     Log(Format('Deleting application folder %s', [AppPath])); 
     DelTree(AppPath, True, True, True); 
    end 
     else 
    begin 
     Log(Format('Deleting application folder %s except saves', [AppPath])); 
     DelTreeExceptSavesDir(AppPath); 
    end; 
    Log('Delete done'); 
    end 
end; 

けれども、[UninstallDelete]セクションで、削除するディレクトリの一覧を表示する方が簡単ではないでしょうか?たくさんのフォルダはありません。

[UninstallDelete] 
Type: files; Name: "{app}\*" 
Type: filesandordirs; Name: "{app}\data\data1" 
Type: filesandordirs; Name: "{app}\data\data2" 
Type: filesandordirs; Name: "{app}\anotherfolder" 
+0

はい、最初は、1つを除くすべてのサブフォルダを削除するコードを探しましたが、見つからなかったため、回避策を探す必要がありました。また、いいえ、再び動作しませんでした、ログを更新しました。 –

+0

私の更新された回答を参照してください(CompareText関数は、 "保存"フォルダ+ 'UninstallDelete'を使った代替実装をスキップします) –

+0

実際には多くのフォルダがあります。いくつかはゲーム中に生成されています。新しいコードが動作します。どうもありがとう。 –

関連する問題