@@ -26,7 +26,7 @@ use super::super::common;
2626use crate :: Settings ;
2727use anyhow:: Context ;
2828use heck:: ToKebabCase ;
29- use image:: { self , codecs:: png:: PngDecoder , GenericImageView , ImageDecoder } ;
29+ use image:: { self , codecs:: png:: PngDecoder , ImageDecoder } ;
3030use libflate:: gzip;
3131use log:: info;
3232use walkdir:: WalkDir ;
@@ -281,71 +281,28 @@ fn generate_icon_files(settings: &Settings, data_dir: &Path) -> crate::Result<BT
281281 ) )
282282 } ;
283283 let mut icons = BTreeSet :: new ( ) ;
284- // Prefer PNG files.
285284 for icon_path in settings. icon_files ( ) {
286285 let icon_path = icon_path?;
287286 if icon_path. extension ( ) != Some ( OsStr :: new ( "png" ) ) {
288287 continue ;
289288 }
290- let decoder = PngDecoder :: new ( File :: open ( & icon_path) ?) ?;
291- let width = decoder. dimensions ( ) . 0 ;
292- let height = decoder. dimensions ( ) . 1 ;
293- let is_high_density = common:: is_retina ( & icon_path) ;
294- let dest_path = get_dest_path ( width, height, is_high_density) ;
295- let deb_icon = DebIcon {
296- width,
297- height,
298- is_high_density,
299- path : dest_path,
300- } ;
301- if !icons. contains ( & deb_icon) {
302- common:: copy_file ( & icon_path, & deb_icon. path ) ?;
303- icons. insert ( deb_icon) ;
304- }
305- }
306- // Fall back to non-PNG files for any missing sizes.
307- for icon_path in settings. icon_files ( ) {
308- let icon_path = icon_path?;
309- if icon_path. extension ( ) == Some ( OsStr :: new ( "png" ) ) {
310- continue ;
311- } else if icon_path. extension ( ) == Some ( OsStr :: new ( "icns" ) ) {
312- let icon_family = icns:: IconFamily :: read ( File :: open ( & icon_path) ?) ?;
313- for icon_type in icon_family. available_icons ( ) {
314- let width = icon_type. screen_width ( ) ;
315- let height = icon_type. screen_height ( ) ;
316- let is_high_density = icon_type. pixel_density ( ) > 1 ;
317- let dest_path = get_dest_path ( width, height, is_high_density) ;
318- let deb_icon = DebIcon {
319- width,
320- height,
321- is_high_density,
322- path : dest_path,
323- } ;
324- if !icons. contains ( & deb_icon) {
325- if let Ok ( icon) = icon_family. get_icon_with_type ( icon_type) {
326- icon. write_png ( common:: create_file ( & deb_icon. path ) ?) ?;
327- icons. insert ( deb_icon) ;
328- }
329- }
330- }
331- } else {
332- let icon = image:: open ( & icon_path) ?;
333- let ( width, height) = icon. dimensions ( ) ;
289+ // Put file in scope so that it's closed when copying it
290+ let deb_icon = {
291+ let decoder = PngDecoder :: new ( File :: open ( & icon_path) ?) ?;
292+ let width = decoder. dimensions ( ) . 0 ;
293+ let height = decoder. dimensions ( ) . 1 ;
334294 let is_high_density = common:: is_retina ( & icon_path) ;
335295 let dest_path = get_dest_path ( width, height, is_high_density) ;
336- let deb_icon = DebIcon {
296+ DebIcon {
337297 width,
338298 height,
339299 is_high_density,
340300 path : dest_path,
341- } ;
342- if !icons. contains ( & deb_icon) {
343- icon. write_to (
344- & mut common:: create_file ( & deb_icon. path ) ?,
345- image:: ImageOutputFormat :: Png ,
346- ) ?;
347- icons. insert ( deb_icon) ;
348301 }
302+ } ;
303+ if !icons. contains ( & deb_icon) {
304+ common:: copy_file ( & icon_path, & deb_icon. path ) ?;
305+ icons. insert ( deb_icon) ;
349306 }
350307 }
351308 Ok ( icons)
0 commit comments