@@ -198,33 +198,28 @@ fn initialize_spritesheet_bundle(
198
198
) ;
199
199
}
200
200
201
- fn extract_from_cache (
201
+ fn try_extract_from_cache (
202
202
path : & Path ,
203
203
working_dir : & Path ,
204
204
cache_bundle : & mut CacheBundle ,
205
205
shut_up : bool ,
206
- ) {
206
+ ) -> bool {
207
207
let path_name = path. to_str ( ) . unwrap ( ) ;
208
208
if !shut_up {
209
209
info ! ( "Extracting '{}' from cache" , path_name) ;
210
210
}
211
- cache_bundle. extract_cached_into (
211
+ cache_bundle. try_extract_cached_into (
212
212
path_name,
213
213
& working_dir. join ( path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ) ,
214
- ) ;
214
+ )
215
215
}
216
216
217
- pub fn get_spritesheet_bundles (
217
+ fn try_extract_bundles_from_cache (
218
218
sheet : & SpriteSheet ,
219
219
working_dir : & Path ,
220
220
cache : & mut Option < CacheBundle > ,
221
- mod_info : & ModFileInfo ,
222
221
shut_up : bool ,
223
- ) -> SheetBundles {
224
- if !shut_up {
225
- info ! ( "Fetching spritesheet {}" , sheet. name. bright_yellow( ) ) ;
226
- }
227
-
222
+ ) -> Option < SheetBundles > {
228
223
if let Some ( cache_bundle) = cache {
229
224
// Cache found
230
225
if let Some ( p) = cache_bundle. cache . fetch_spritesheet_bundles ( sheet) {
@@ -234,18 +229,37 @@ pub fn get_spritesheet_bundles(
234
229
let bundles = SheetBundles :: new ( p. to_path_buf ( ) ) ;
235
230
236
231
// Extract all files
237
- extract_from_cache ( & bundles. sd . png , working_dir, cache_bundle, shut_up) ;
238
- extract_from_cache ( & bundles. sd . plist , working_dir, cache_bundle, shut_up) ;
239
- extract_from_cache ( & bundles. hd . png , working_dir, cache_bundle, shut_up) ;
240
- extract_from_cache ( & bundles. hd . plist , working_dir, cache_bundle, shut_up) ;
241
- extract_from_cache ( & bundles. uhd . png , working_dir, cache_bundle, shut_up) ;
242
- extract_from_cache ( & bundles. uhd . plist , working_dir, cache_bundle, shut_up) ;
232
+ try_extract_from_cache ( & bundles. sd . png , working_dir, cache_bundle, shut_up) . then_some ( ( ) ) ? ;
233
+ try_extract_from_cache ( & bundles. sd . plist , working_dir, cache_bundle, shut_up) . then_some ( ( ) ) ? ;
234
+ try_extract_from_cache ( & bundles. hd . png , working_dir, cache_bundle, shut_up) . then_some ( ( ) ) ? ;
235
+ try_extract_from_cache ( & bundles. hd . plist , working_dir, cache_bundle, shut_up) . then_some ( ( ) ) ? ;
236
+ try_extract_from_cache ( & bundles. uhd . png , working_dir, cache_bundle, shut_up) . then_some ( ( ) ) ? ;
237
+ try_extract_from_cache ( & bundles. uhd . plist , working_dir, cache_bundle, shut_up) . then_some ( ( ) ) ? ;
243
238
244
239
done ! ( "Fetched {} from cache" , sheet. name. bright_yellow( ) ) ;
245
- return bundles;
240
+ return Some ( bundles) ;
246
241
}
247
242
}
243
+ None
244
+ }
245
+
246
+ pub fn get_spritesheet_bundles (
247
+ sheet : & SpriteSheet ,
248
+ working_dir : & Path ,
249
+ cache : & mut Option < CacheBundle > ,
250
+ mod_info : & ModFileInfo ,
251
+ shut_up : bool ,
252
+ ) -> SheetBundles {
253
+ if !shut_up {
254
+ info ! ( "Fetching spritesheet {}" , sheet. name. bright_yellow( ) ) ;
255
+ }
248
256
257
+ if let Some ( cached) = try_extract_bundles_from_cache (
258
+ sheet, working_dir, cache, shut_up
259
+ ) {
260
+ return cached;
261
+ }
262
+
249
263
if !shut_up {
250
264
info ! ( "Sheet is not cached, building from scratch" ) ;
251
265
}
0 commit comments