1- using System . Collections ;
1+ using System ;
2+ using System . Collections ;
23using System . Linq ;
4+ using Newtonsoft . Json ;
35using PatchKit . Api . Models . Main ;
6+ using PatchKit . Unity . Patcher . AppData . Local ;
47using PatchKit . Unity . Patcher . Cancellation ;
58using PatchKit . Unity . UI ;
69using 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 )
0 commit comments