1 USING: accessors alien alien.c-types arrays classes.struct combinators
2 io.backend kernel locals math sequences specialized-arrays
3 tools.deploy.windows windows.kernel32 windows.types alien.data ;
4 IN: tools.deploy.windows.ico
13 STRUCT: ico-directory-entry
21 { ImageOffset DWORD } ;
22 SPECIALIZED-ARRAY: ico-directory-entry
24 STRUCT: group-directory-entry
32 { ImageResourceID WORD } ;
34 : ico>group-directory-entry ( ico i -- group )
36 [ Width>> ] [ Height>> ] [ Colors>> ] [ Reserved>> ]
37 [ Planes>> ] [ BitsPerPixel>> ] [ ImageSize>> ]
38 } cleave ] [ 1 + ] bi* group-directory-entry <struct-boa> >c-ptr ; inline
40 : ico-icon ( directory-entry bytes -- subbytes )
41 [ [ ImageOffset>> dup ] [ ImageSize>> + ] bi ] dip subseq ; inline
43 :: ico-group-and-icons ( bytes -- group-bytes icon-bytes )
44 bytes ico-header memory>struct :> header
46 ico-header heap-size bytes <displaced-alien>
47 header ImageCount>> ico-directory-entry <c-direct-array> :> directory
49 directory dup length iota [ ico>group-directory-entry ] { } 2map-as
51 directory [ bytes ico-icon ] { } map-as :> icon-bytes
53 header clone >c-ptr group-directory concat append
56 ERROR: unsupported-ico-format bytes format ;
58 : check-ico-type ( bytes -- bytes )
60 "PNG" unsupported-ico-format
63 "UNKNOWN" unsupported-ico-format
68 :: embed-icon-resource ( exe ico-bytes id -- )
69 exe normalize-path 1 BeginUpdateResource :> hUpdate
71 ico-bytes check-ico-type ico-group-and-icons :> ( group icons )
72 hUpdate RT_GROUP_ICON id 0 group dup byte-length
76 hUpdate RT_ICON i 1 + MAKEINTRESOURCE 0 icon dup byte-length
80 hUpdate 0 EndUpdateResource drop