Skip to content

Commit 41169dd

Browse files
committed
Add configuration option to switch whether to use diffs or not
Enabled by default.
1 parent 50dc0d6 commit 41169dd

File tree

4 files changed

+61
-47
lines changed

4 files changed

+61
-47
lines changed

Assets/PatchKit Patcher/Patcher.unity

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ MonoBehaviour:
854854
AppUpdaterConfiguration:
855855
UseTorrents: 1
856856
CheckConsistencyBeforeDiffUpdate: 1
857+
UseDiffUpdates: 1
857858
AutomaticallyStartApp: 0
858859
AutomaticallyCheckForAppUpdates: 1
859860
AutomaticallyInstallApp: 1

Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ public struct AppUpdaterConfiguration
88
public bool UseTorrents;
99

1010
public bool CheckConsistencyBeforeDiffUpdate;
11+
12+
public bool UseDiffUpdates;
1113
}
1214
}

Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterStrategyResolver.cs

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
### Added
99
- getdiskspaceosx a native library for determining the amount of free space available on Mac OSX.
1010
- Status descriptions for updating app patcher state
11+
- Add configuration option to switch whether to use diffs or not
1112

1213
### Changed
1314
- Separate version integrity check progress from update progress

0 commit comments

Comments
 (0)