@@ -67,9 +67,17 @@ static Theme()
6767
6868 public bool HaveAsset ( string key )
6969 {
70+ if ( Mode == ThemeMode . Modern )
71+ {
72+ if ( ! _archiveLoaded )
73+ {
74+ ReloadAssets ( ) ;
75+ }
76+ return _archive ? . Entries . Any ( x => x . FullName == "Assets/" + key ) ?? false ;
77+ }
78+
7079 //We can't load in assets from the older theming
71- return Mode == ThemeMode . Modern
72- && ( _archive ? . Entries . Any ( x => x . FullName == "Assets/" + key ) ?? false ) ;
80+ return false ;
7381 }
7482
7583 public Stream GetAssetStream ( string key )
@@ -78,12 +86,17 @@ public Stream GetAssetStream(string key)
7886 {
7987 return Stream . Null ;
8088 }
81-
89+ if ( ! _archiveLoaded )
90+ {
91+ ReloadAssets ( ) ;
92+ }
93+
8294 return _archive ? . Entries
8395 . FirstOrDefault ( x => x . FullName == "Assets/" + key ) ?
8496 . Open ( ) ?? Stream . Null ;
8597 }
86-
98+
99+ private string _filepath = null ! ;
87100 private ZipArchive ? _archive ;
88101 /// <summary>
89102 /// Load's in the theme for being used
@@ -114,10 +127,12 @@ public Stream GetAssetStream(string key)
114127 return null ;
115128 }
116129
117- var theme = new Theme ( )
130+ var theme = new Theme
118131 {
119132 Location = filepath ,
120- _archive = archive
133+ _archive = archive ,
134+ _filepath = filepath ,
135+ _archiveLoaded = true
121136 } ;
122137 try
123138 {
@@ -154,10 +169,27 @@ public Stream GetAssetStream(string key)
154169 if ( theme . Mode == ThemeMode . Legacy )
155170 {
156171 archive . Dispose ( ) ;
172+ theme . _archiveLoaded = false ;
157173 }
158174 return theme ;
159175 }
160176
177+ private bool _archiveLoaded = false ;
178+ public void ReloadAssets ( )
179+ {
180+ UnloadAssets ( ) ;
181+
182+ var fileStream = StreamUtil . SafeOpenRead ( _filepath ) ;
183+ _archive = new ZipArchive ( fileStream , ZipArchiveMode . Read ) ;
184+ _archiveLoaded = true ;
185+ }
186+
187+ public void UnloadAssets ( )
188+ {
189+ _archive ? . Dispose ( ) ;
190+ _archiveLoaded = false ;
191+ }
192+
161193 /// <summary>
162194 /// Applies the theming to a IResourceDictionary (or App.Current.Resources if nothing is applied)
163195 /// </summary>
@@ -167,7 +199,7 @@ public void Apply(IResourceDictionary? resourceDictionary = null)
167199 if ( resourceDictionary == null )
168200 {
169201 resourceDictionary = Application . Current . Resources ;
170- ActiveTheme ? . Dispose ( ) ;
202+ ActiveTheme ? . UnloadAssets ( ) ;
171203 ActiveTheme = this ;
172204 }
173205 resourceDictionary [ "ThemeAccentColor" ] = Colours . ThemeAccentColor ;
@@ -188,7 +220,6 @@ public void Apply(IResourceDictionary? resourceDictionary = null)
188220
189221 public void Dispose ( )
190222 {
191- _archive ? . Dispose ( ) ;
192223 GC . SuppressFinalize ( this ) ;
193224 }
194225}
0 commit comments