@@ -20,84 +20,94 @@ public IAppUpdaterStrategy Resolve(AppUpdaterContext context)
2020
2121 DebugLogger . Log ( "Resolving best strategy for updating..." ) ;
2222
23- if ( context . App . IsInstalled ( ) )
23+ if ( context . Configuration . UseDiffUpdates )
2424 {
25- int installedVersionId = context . App . GetInstalledVersionId ( ) ;
26- int latestVersionId = context . App . GetLatestVersionId ( ) ;
27-
28- if ( installedVersionId == latestVersionId )
25+ if ( context . App . IsInstalled ( ) )
2926 {
30- DebugLogger . Log ( "Installed version is the same as the latest version. Using empty strategy." ) ;
27+ int installedVersionId = context . App . GetInstalledVersionId ( ) ;
28+ int latestVersionId = context . App . GetLatestVersionId ( ) ;
3129
32- return new AppUpdaterEmptyStrategy ( ) ;
33- }
30+ if ( installedVersionId == latestVersionId )
31+ {
32+ DebugLogger . Log ( "Installed version is the same as the latest version. Using empty strategy." ) ;
3433
35- if ( installedVersionId < latestVersionId )
36- {
37- DebugLogger . Log ( "Installed version is older than the latest version. Checking whether cost of updating with diff is lower than cost of updating with content..." ) ;
34+ return new AppUpdaterEmptyStrategy ( ) ;
35+ }
3836
39- if ( context . Configuration . CheckConsistencyBeforeDiffUpdate )
37+ if ( installedVersionId < latestVersionId )
4038 {
41- DebugLogger . Log ( "Checking consitency before allowing diff update..." ) ;
39+ DebugLogger . Log (
40+ "Installed version is older than the latest version. Checking whether cost of updating with diff is lower than cost of updating with content..." ) ;
41+
42+ if ( context . Configuration . CheckConsistencyBeforeDiffUpdate )
43+ {
44+ DebugLogger . Log ( "Checking consitency before allowing diff update..." ) ;
4245
43- var commandFactory = new AppUpdaterCommandFactory ( ) ;
46+ var commandFactory = new AppUpdaterCommandFactory ( ) ;
4447
45- var checkVersionIntegrity = commandFactory . CreateCheckVersionIntegrityCommand (
46- installedVersionId , context ) ;
48+ var checkVersionIntegrity = commandFactory . CreateCheckVersionIntegrityCommand (
49+ installedVersionId , context ) ;
4750
48- checkVersionIntegrity . Prepare ( context . StatusMonitor ) ;
49- checkVersionIntegrity . Execute ( CancellationToken . Empty ) ;
51+ checkVersionIntegrity . Prepare ( context . StatusMonitor ) ;
52+ checkVersionIntegrity . Execute ( CancellationToken . Empty ) ;
5053
51- if ( checkVersionIntegrity . Results . Files . All (
54+ if ( checkVersionIntegrity . Results . Files . All (
5255 fileIntegrity => fileIntegrity . Status == FileIntegrityStatus . Ok ) )
53- {
54- DebugLogger . Log ( "Version is consistent. Diff update is allowed." ) ;
55- }
56- else
57- {
58- foreach ( var fileIntegrity in checkVersionIntegrity . Results . Files )
5956 {
60- if ( fileIntegrity . Status != FileIntegrityStatus . Ok )
57+ DebugLogger . Log ( "Version is consistent. Diff update is allowed." ) ;
58+ }
59+ else
60+ {
61+ foreach ( var fileIntegrity in checkVersionIntegrity . Results . Files )
6162 {
62- DebugLogger . Log ( string . Format ( "File {0} is not consistent - {1}" ,
63- fileIntegrity . FileName , fileIntegrity . Status ) ) ;
63+ if ( fileIntegrity . Status != FileIntegrityStatus . Ok )
64+ {
65+ DebugLogger . Log ( string . Format ( "File {0} is not consistent - {1}" ,
66+ fileIntegrity . FileName , fileIntegrity . Status ) ) ;
67+ }
6468 }
65- }
6669
67- DebugLogger . Log (
68- "Version is not consistent. Diff update is forbidden - using content strategy." ) ;
70+ DebugLogger . Log (
71+ "Version is not consistent. Diff update is forbidden - using content strategy." ) ;
6972
70- return new AppUpdaterContentStrategy ( context ) ;
73+ return new AppUpdaterContentStrategy ( context ) ;
74+ }
7175 }
72- }
7376
74- var diffCost = GetDiffCost ( context ) ;
75- DebugLogger . LogVariable ( diffCost , "diffCost" ) ;
77+ var diffCost = GetDiffCost ( context ) ;
78+ DebugLogger . LogVariable ( diffCost , "diffCost" ) ;
7679
77- DebugLogger . Log ( string . Format ( "Cost of updating with diff equals {0}." , diffCost ) ) ;
80+ DebugLogger . Log ( string . Format ( "Cost of updating with diff equals {0}." , diffCost ) ) ;
7881
79- var contentCost = GetContentCost ( context ) ;
80- DebugLogger . LogVariable ( contentCost , "contentCost" ) ;
82+ var contentCost = GetContentCost ( context ) ;
83+ DebugLogger . LogVariable ( contentCost , "contentCost" ) ;
8184
82- DebugLogger . Log ( string . Format ( "Cost of updating with content equals {0}." , contentCost ) ) ;
85+ DebugLogger . Log ( string . Format ( "Cost of updating with content equals {0}." , contentCost ) ) ;
8386
84- if ( diffCost < contentCost )
85- {
86- DebugLogger . Log ( "Cost of updating with diff is lower than cost of updating with content. Using diff strategy." ) ;
87+ if ( diffCost < contentCost )
88+ {
89+ DebugLogger . Log (
90+ "Cost of updating with diff is lower than cost of updating with content. Using diff strategy." ) ;
8791
88- return new AppUpdaterDiffStrategy ( context ) ;
89- }
92+ return new AppUpdaterDiffStrategy ( context ) ;
93+ }
9094
91- DebugLogger . Log ( "Cost of updating with content is lower than cost of updating with diff. Using content strategy." ) ;
95+ DebugLogger . Log (
96+ "Cost of updating with content is lower than cost of updating with diff. Using content strategy." ) ;
97+ }
98+ else
99+ {
100+ DebugLogger . Log ( "Installed version is newer than the latest version. Using content strategy." ) ;
101+ }
92102 }
93103 else
94104 {
95- DebugLogger . Log ( "Installed version is newer than the latest version . Using content strategy." ) ;
105+ DebugLogger . Log ( "Application is not installed . Using content strategy." ) ;
96106 }
97107 }
98108 else
99109 {
100- DebugLogger . Log ( "Application is not installed . Using content strategy." ) ;
110+ DebugLogger . Log ( "Not using diffs because of configuration . Using content strategy." ) ;
101111 }
102112
103113 return new AppUpdaterContentStrategy ( context ) ;
0 commit comments