Skip to content

Commit bf02f67

Browse files
committed
Merge branch 'master' into release
2 parents a3b63ab + 57731ea commit bf02f67

33 files changed

+771
-66
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/AppUpdater.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public void Update(CancellationToken cancellationToken)
3636
DebugLogger.Log("Updating.");
3737

3838
var strategy = _strategyResolver.Resolve(Context);
39+
40+
Context.StatusMonitor.Reset();
41+
3942
strategy.Update(cancellationToken);
4043
}
4144
}

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

Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/CheckDiskSpaceCommand.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ private static extern bool GetDiskFreeSpaceEx(string directoryName,
4444
out ulong totalFreeBytes);
4545
#endif
4646

47+
#if UNITY_STANDALONE_OSX
48+
49+
[DllImport("getdiskspaceosx", SetLastError = true, CharSet = CharSet.Auto)]
50+
[return: MarshalAs(UnmanagedType.Bool)]
51+
private static extern bool getAvailableDiskSpace(string t_path, out long freeBytes);
52+
53+
#endif
54+
4755
public void Execute(CancellationToken cancellationToken)
4856
{
4957
long availableDiskSpace = -1;
@@ -56,6 +64,14 @@ public void Execute(CancellationToken cancellationToken)
5664
GetDiskFreeSpaceEx(dir.Directory.Root.FullName, out freeBytes, out totalBytes, out totalFreeBytes);
5765

5866
availableDiskSpace = (long) freeBytes;
67+
68+
#elif UNITY_STANDALONE_OSX
69+
70+
long freeBytes = 0;
71+
getAvailableDiskSpace(dir.Directory.Root.FullName, out freeBytes);
72+
73+
availableDiskSpace = freeBytes;
74+
5975
#else
6076
var drive = new DriveInfo(dir.Directory.Root.FullName);
6177

Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/CheckVersionIntegrityCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override void Execute(CancellationToken cancellationToken)
6060
{
6161
files[i] = CheckFile(_versionSummary.Files[i]);
6262

63-
_statusReporter.OnProgressChanged((i + 1)/(double)_versionSummary.Files.Length);
63+
_statusReporter.OnProgressChanged((i + 1)/(double)_versionSummary.Files.Length, "Checking version integrity...");
6464
}
6565

6666
Results = new VersionIntegrity(files);

Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,31 @@ public override void Execute(CancellationToken cancellationToken)
102102

103103
IUnarchiver unarchiver = CreateUnrachiver(packageDirPath);
104104

105+
_unarchivePackageStatusReporter.OnProgressChanged(0.0, "Unarchiving package...");
106+
105107
unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount) =>
106108
{
107-
_unarchivePackageStatusReporter.OnProgressChanged(entry/(double) amount);
109+
_unarchivePackageStatusReporter.OnProgressChanged(entry/(double) amount, "Unarchiving package...");
108110
};
109111

110112
unarchiver.Unarchive(cancellationToken);
111113

112-
_unarchivePackageStatusReporter.OnProgressChanged(1.0);
114+
_unarchivePackageStatusReporter.OnProgressChanged(1.0, string.Empty);
113115

114116
DebugLogger.Log("Copying files.");
115117

118+
_copyFilesStatusReporter.OnProgressChanged(0.0, "Installing package...");
119+
116120
for (int i = 0; i < _versionContentSummary.Files.Length; i++)
117121
{
118122
cancellationToken.ThrowIfCancellationRequested();
119123

120124
InstallFile(_versionContentSummary.Files[i].Path, packageDirPath);
121125

122-
_copyFilesStatusReporter.OnProgressChanged((i + 1)/(double)_versionContentSummary.Files.Length);
126+
_copyFilesStatusReporter.OnProgressChanged((i + 1)/(double)_versionContentSummary.Files.Length, "Installing package...");
123127
}
124128

125-
_copyFilesStatusReporter.OnProgressChanged(1.0);
129+
_copyFilesStatusReporter.OnProgressChanged(1.0, string.Empty);
126130
}
127131
finally
128132
{

Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallDiffCommand.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ public override void Execute(CancellationToken cancellationToken)
101101
DebugLogger.Log("Unarchiving files.");
102102
IUnarchiver unarchiver = CreateUnrachiver(packageDirPath);
103103

104+
_unarchivePackageStatusReporter.OnProgressChanged(0.0, "Unarchiving package...");
105+
104106
unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount) =>
105107
{
106-
_unarchivePackageStatusReporter.OnProgressChanged(entry/(double) amount);
108+
_unarchivePackageStatusReporter.OnProgressChanged(entry/(double) amount, "Unarchiving package...");
107109
};
108110

109111
unarchiver.Unarchive(cancellationToken);
110112

111-
_unarchivePackageStatusReporter.OnProgressChanged(1.0);
113+
_unarchivePackageStatusReporter.OnProgressChanged(1.0, string.Empty);
112114

113115
ProcessAddedFiles(packageDirPath, cancellationToken);
114116
ProcessRemovedFiles(cancellationToken);
@@ -148,6 +150,8 @@ private void ProcessRemovedFiles(CancellationToken cancellationToken)
148150

149151
int counter = 0;
150152

153+
_removeFilesStatusReporter.OnProgressChanged(0.0, "Installing package...");
154+
151155
foreach (var fileName in files)
152156
{
153157
cancellationToken.ThrowIfCancellationRequested();
@@ -162,7 +166,7 @@ private void ProcessRemovedFiles(CancellationToken cancellationToken)
162166
_localMetaData.UnregisterEntry(fileName);
163167

164168
counter++;
165-
_removeFilesStatusReporter.OnProgressChanged(counter/(double)_versionDiffSummary.RemovedFiles.Length);
169+
_removeFilesStatusReporter.OnProgressChanged(counter/(double)_versionDiffSummary.RemovedFiles.Length, "Installing package...");
166170
}
167171

168172
foreach (var dirName in directories)
@@ -180,17 +184,19 @@ private void ProcessRemovedFiles(CancellationToken cancellationToken)
180184
//_localMetaData.UnregisterEntry(dirName);
181185

182186
counter++;
183-
_removeFilesStatusReporter.OnProgressChanged(counter/(double)_versionDiffSummary.RemovedFiles.Length);
187+
_removeFilesStatusReporter.OnProgressChanged(counter/(double)_versionDiffSummary.RemovedFiles.Length, "Installing package...");
184188
}
185189

186-
_removeFilesStatusReporter.OnProgressChanged(1.0);
190+
_removeFilesStatusReporter.OnProgressChanged(1.0, string.Empty);
187191
}
188192

189193
private void ProcessAddedFiles(string packageDirPath,
190194
CancellationToken cancellationToken)
191195
{
192196
DebugLogger.Log("Processing added files.");
193-
197+
198+
_addFilesStatusReporter.OnProgressChanged(0.0, "Installing package...");
199+
194200
for (int i = 0; i < _versionDiffSummary.AddedFiles.Length; i++)
195201
{
196202
cancellationToken.ThrowIfCancellationRequested();
@@ -221,17 +227,19 @@ private void ProcessAddedFiles(string packageDirPath,
221227
_localMetaData.RegisterEntry(entryName, _versionId);
222228
}
223229

224-
_addFilesStatusReporter.OnProgressChanged((i + 1)/(double)_versionDiffSummary.AddedFiles.Length);
230+
_addFilesStatusReporter.OnProgressChanged((i + 1)/(double)_versionDiffSummary.AddedFiles.Length, "Installing package...");
225231
}
226232

227-
_addFilesStatusReporter.OnProgressChanged(1.0);
233+
_addFilesStatusReporter.OnProgressChanged(1.0, "Installing package...");
228234
}
229235

230236
private void ProcessModifiedFiles(string packageDirPath,
231237
CancellationToken cancellationToken)
232238
{
233239
DebugLogger.Log("Processing modified files.");
234240

241+
_modifiedFilesStatusReporter.OnProgressChanged(0.0, "Installing package...");
242+
235243
for (int i = 0; i < _versionDiffSummary.ModifiedFiles.Length; i++)
236244
{
237245
cancellationToken.ThrowIfCancellationRequested();
@@ -250,10 +258,10 @@ private void ProcessModifiedFiles(string packageDirPath,
250258
//_localMetaData.RegisterEntry(entryName, _versionId);
251259
}
252260

253-
_modifiedFilesStatusReporter.OnProgressChanged((i + 1)/(double)_versionDiffSummary.ModifiedFiles.Length);
261+
_modifiedFilesStatusReporter.OnProgressChanged((i + 1)/(double)_versionDiffSummary.ModifiedFiles.Length, "Installing package...");
254262
}
255263

256-
_modifiedFilesStatusReporter.OnProgressChanged(1.0);
264+
_modifiedFilesStatusReporter.OnProgressChanged(1.0, "Installing package...");
257265
}
258266

259267
// TODO: Temporary solution for situation when .app directory is not deleted

Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/UninstallCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public override void Execute(CancellationToken cancellationToken)
5656

5757
int counter = 0;
5858

59+
_statusReporter.OnProgressChanged(0.0, "Uninstalling...");
60+
5961
foreach (var fileName in files)
6062
{
6163
cancellationToken.ThrowIfCancellationRequested();
@@ -70,7 +72,7 @@ public override void Execute(CancellationToken cancellationToken)
7072
_localMetaData.UnregisterEntry(fileName);
7173

7274
counter++;
73-
_statusReporter.OnProgressChanged(counter / (double)entries.Length);
75+
_statusReporter.OnProgressChanged(counter / (double)entries.Length, "Uninstalling...");
7476
}
7577

7678
// TODO: Delete this after fixing directory registration in install content command
@@ -119,6 +121,8 @@ public override void Execute(CancellationToken cancellationToken)
119121
counter++;
120122
_statusReporter.OnProgressChanged(counter / (double)entries.Length);
121123
}*/
124+
125+
_statusReporter.OnProgressChanged(1.0, "Uninstalling...");
122126
}
123127
}
124128
}

Assets/PatchKit Patcher/Scripts/Status/GeneralStatusHolder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public class GeneralStatusHolder : IStatusHolder
55
public double Weight { get; private set; }
66

77
public double Progress { get; set; }
8+
9+
public string Description { get; set; }
810

911
public GeneralStatusHolder(double weight)
1012
{

0 commit comments

Comments
 (0)