Skip to content

Commit cb02623

Browse files
authored
Merge pull request #137 from patchkit-net/feature/v3.x.x.x/1361-cache-app-changelog
Cache app changelog (#1361)
2 parents 21e8c49 + 34f02a5 commit cb02623

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [3.x.x.x]
8-
### Added
8+
### Added
9+
- Caching application changelog so it can be displayed in offline mode (#1361)
910
- Skip unchanged files while patching (#994)
1011

1112
### Changed

0 commit comments

Comments
 (0)