33using System . Linq ;
44using System . Linq . Expressions ;
55using System . Threading ;
6+ using System . Collections . Generic ;
67using PatchKit . Unity . Patcher . Cancellation ;
78using PatchKit . Unity . Patcher . Debug ;
89using PatchKit . Unity . Patcher . AppUpdater . Commands ;
@@ -72,12 +73,12 @@ AppContentSummary latestVersionContentSummary
7273 checkIntegrity . Execute ( cancellationToken ) ;
7374
7475 var missingFiles = checkIntegrity . Results . Files
75- . Select ( f => f . Status == FileIntegrityStatus . MissingData ) ;
76+ . Where ( f => f . Status == FileIntegrityStatus . MissingData ) ;
7677
7778 int missingFilesCount = missingFiles . Count ( ) ;
7879
7980 var invalidSizeFiles = checkIntegrity . Results . Files
80- . Select ( f => f . Status == FileIntegrityStatus . InvalidSize ) ;
81+ . Where ( f => f . Status == FileIntegrityStatus . InvalidSize ) ;
8182
8283 int invalidSizeFilesCount = invalidSizeFiles . Count ( ) ;
8384
@@ -87,15 +88,7 @@ AppContentSummary latestVersionContentSummary
8788 return ;
8889 }
8990
90- double repairCost = ( missingFilesCount + invalidSizeFilesCount ) * 2 ;
91- if ( isNewVersionAvailable )
92- {
93- repairCost *= latestVersionContentSummary . Chunks . Size ;
94- }
95- else
96- {
97- repairCost *= installedVersionContentSummary . Chunks . Size ;
98- }
91+ double repairCost = CalculateRepairCost ( installedVersionContentSummary , missingFiles . Concat ( invalidSizeFiles ) ) ;
9992
10093 if ( repairCost < contentSize )
10194 {
@@ -112,6 +105,13 @@ AppContentSummary latestVersionContentSummary
112105 }
113106 }
114107
108+ private long CalculateRepairCost ( AppContentSummary contentSummary , IEnumerable < FileIntegrity > filesToRepair )
109+ {
110+ return filesToRepair
111+ . Select ( f => contentSummary . Files . FirstOrDefault ( e => e . Path == f . FileName ) )
112+ . Sum ( f => f . Size ) ;
113+ }
114+
115115 public void Update ( CancellationToken cancellationToken )
116116 {
117117 Assert . MethodCalledOnlyOnce ( ref _updateHasBeenCalled , "Update" ) ;
0 commit comments