Skip to content

Commit 3377038

Browse files
authored
Merge branch 'dev/v3.x.x.x' into feature/v3.x.x.x/1350-cache-app-display-name
2 parents ef861c3 + cb02623 commit 3377038

File tree

7 files changed

+107
-27
lines changed

7 files changed

+107
-27
lines changed

Assets/PatchKit Patcher/Scripts/Api/Models/Main/AppDiffSummary.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public struct AppDiffSummary
5151
/// </summary>
5252
[JsonProperty("removed_files")]
5353
public string[] RemovedFiles;
54+
55+
[JsonProperty("unchanged_files")]
56+
public string[] UnchangedFiles;
5457

5558
[JsonProperty("hash_code")]
5659
public string HashCode;

Assets/PatchKit Patcher/Scripts/AppData/Local/BaseWritableDirectory.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ public virtual void PrepareForWriting()
5151
{
5252
DebugLogger.Log("Preparing directory for writing.");
5353

54-
if (!_hasWriteAccess)
55-
{
56-
DebugLogger.Log("Creating directory.");
54+
DirectoryOperations.CreateDirectory(_path, CancellationToken.Empty);
5755

58-
DirectoryOperations.CreateDirectory(_path, CancellationToken.Empty);
56+
_hasWriteAccess = true;
5957

60-
_hasWriteAccess = true;
61-
}
58+
DebugLogger.Log("Directory prepared for writing.");
6259
}
6360

6461
~BaseWritableDirectory()

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,6 @@ private void PatchFile(
486486
string.Format("Couldn't patch file {0} because it doesn't exists in local data.", fileName));
487487
}
488488

489-
var sourceDeltaFilePath = Path.Combine(packageDirPath, fileName + suffix);
490-
_logger.LogTrace("sourceDeltaFilePath = " + sourceDeltaFilePath);
491-
492-
if (!File.Exists(sourceDeltaFilePath))
493-
{
494-
throw new MissingFileFromPackageException(string.Format("Cannot find delta file {0} in diff package.",
495-
fileName));
496-
}
497-
498489
var fileVersion = _localMetaData.GetEntryVersionId(fileName);
499490
_logger.LogTrace("fileVersion = " + fileVersion);
500491

@@ -510,6 +501,15 @@ private void PatchFile(
510501
{
511502
_logger.LogDebug("Patching is necessary. Generating new file with patched content...");
512503

504+
var sourceDeltaFilePath = Path.Combine(packageDirPath, fileName + suffix);
505+
_logger.LogTrace("sourceDeltaFilePath = " + sourceDeltaFilePath);
506+
507+
if (!File.Exists(sourceDeltaFilePath))
508+
{
509+
throw new MissingFileFromPackageException(string.Format("Cannot find delta file {0} in diff package.",
510+
fileName));
511+
}
512+
513513
var newFilePath = tempDiffDir.GetUniquePath();
514514
_logger.LogTrace("newFilePath = " + newFilePath);
515515

@@ -536,6 +536,11 @@ private void PatchFile(
536536

537537
private bool IsPatchingFileContentNecessary(string fileName)
538538
{
539+
if (_diffSummary.UnchangedFiles.Contains(fileName))
540+
{
541+
return false;
542+
}
543+
539544
//TODO: Throw exceptions if file is not present in any of both content summaries
540545
var fileHash = _contentSummary.Files.First(x => x.Path == fileName).Hash;
541546
var previousFileHash = _previousContentSummary.Files.First(x => x.Path == fileName).Hash;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ public override void Execute(CancellationToken cancellationToken)
6868

6969
foreach (var entry in _entries)
7070
{
71-
var tempDirName = _packagePath + string.Format("{0}_{1}_{2}", entry.Name, entry.Offset, entry.Size);
71+
var tempDirName = _packagePath + "_repair";
7272
TemporaryDirectory.ExecuteIn(tempDirName, (tempDir) =>
7373
{
7474
_logger.LogDebug(string.Format("Repairing the file {0}", entry.Name));
75-
string packagePath = Path.Combine(tempDir.Path, ".pack" + Path.GetRandomFileName());
76-
string unarchivePath = Path.Combine(tempDir.Path, Path.GetRandomFileName());
75+
string packagePath = Path.Combine(tempDir.Path, "p_" + Path.GetRandomFileName());
76+
string unarchivePath = Path.Combine(tempDir.Path, "u_" + Path.GetRandomFileName());
7777

7878
if (!Directory.Exists(unarchivePath))
7979
{

Assets/PatchKit Patcher/Scripts/Patcher.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ private void Awake()
249249
DebugLogger.LogFormat("System version: {0}", EnvironmentInfo.GetSystemVersion());
250250
DebugLogger.LogFormat("Runtime version: {0}", EnvironmentInfo.GetSystemVersion());
251251

252+
// In .NET API ProcessPriorityClass.Idle is really 'Low' process priority
253+
Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle;
254+
255+
DebugLogger.LogFormat("Process priority has been set to Low");
256+
252257
CheckEditorAppSecretSecure();
253258

254259
if (_canStartThread)

Assets/PatchKit Patcher/Scripts/UI/Changelog/ChangelogList.cs

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using System.Collections;
1+
using System;
2+
using System.Collections;
23
using System.Linq;
4+
using Newtonsoft.Json;
35
using PatchKit.Api.Models.Main;
6+
using PatchKit.Unity.Patcher.AppData.Local;
47
using PatchKit.Unity.Patcher.Cancellation;
58
using PatchKit.Unity.UI;
69
using PatchKit.Unity.Utilities;
@@ -20,15 +23,73 @@ protected override IEnumerator LoadCoroutine()
2023
yield return null;
2124
}
2225

26+
var appSecret = Patcher.Instance.Data.Value.AppSecret;
27+
28+
LoadChangelogFromCache(appSecret);
29+
2330
yield return
24-
Threading.StartThreadCoroutine(() => MainApiConnection.GetAppVersionList(Patcher.Instance.Data.Value.AppSecret, null, CancellationToken.Empty),
25-
response =>
26-
{
27-
foreach (var version in response.OrderByDescending(version => version.Id))
28-
{
29-
CreateVersionChangelog(version);
30-
}
31-
});
31+
Threading.StartThreadCoroutine(() =>
32+
MainApiConnection.GetAppVersionList(
33+
Patcher.Instance.Data.Value.AppSecret,
34+
null,
35+
CancellationToken.Empty),
36+
versions => CreateAndCacheChangelog(appSecret, versions));
37+
}
38+
39+
private void LoadChangelogFromCache(string appSecret)
40+
{
41+
try
42+
{
43+
var cacheValue = new UnityCache(appSecret).GetValue("app-changelog", null);
44+
45+
if (cacheValue == null)
46+
{
47+
return;
48+
}
49+
50+
var versions = JsonConvert.DeserializeObject<AppVersion[]>(cacheValue);
51+
52+
CreateChangelog(versions);
53+
}
54+
catch (Exception)
55+
{
56+
// ignore
57+
}
58+
}
59+
60+
private void CreateAndCacheChangelog(string appSecret, AppVersion[] versions)
61+
{
62+
try
63+
{
64+
var cacheValue = JsonConvert.SerializeObject(versions);
65+
66+
new UnityCache(appSecret).SetValue("app-changelog", cacheValue);
67+
}
68+
catch (Exception e)
69+
{
70+
UnityEngine.Debug.Log(e.ToString());
71+
}
72+
73+
CreateChangelog(versions);
74+
}
75+
76+
private void DestroyOldChangelog()
77+
{
78+
while(transform.childCount > 0)
79+
{
80+
DestroyImmediate(transform.GetChild(0).gameObject);
81+
}
82+
83+
}
84+
85+
private void CreateChangelog(AppVersion[] versions)
86+
{
87+
DestroyOldChangelog();
88+
89+
foreach (AppVersion version in versions.OrderByDescending(version => version.Id))
90+
{
91+
CreateVersionChangelog(version);
92+
}
3293
}
3394

3495
private void CreateVersionChangelog(AppVersion version)

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
## [3.x.x.x]
88
### Added
99
- Caching application display name so it can be displayed in offline mode (#1350)
10+
- Caching application changelog so it can be displayed in offline mode (#1361)
11+
- Skip unchanged files while patching (#994)
12+
13+
### Changed
14+
- Set process priority to Low (#1375)
15+
16+
### Fixed
17+
- Repairing files placed at long path (#1369)
18+
- Fix download directory recreation after removing it during patcher execution (#1360)
1019

1120
## [3.14.0.0]
1221
### Added

0 commit comments

Comments
 (0)