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