
    !hi|$                     t   d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ  ej                  e      ZdZdZdZ G d	 d
      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d      ZddZd Zedk(  r,ddlZej:                  d   Zej:                  dd Z eee       yy)ao  
The code in this module supports the --icon parameter on Windows.
(For --icon support under macOS, see building/osx.py.)

The only entry point, called from api.py, is CopyIcons(), below. All the elaborate structure of classes that follows
is used to support the operation of CopyIcons_FromIco(). None of these classes and globals are referenced outside
this module.
    N)config)
pywintypeswin32api)normalize_icon_type         c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)	Structurec                    t        j                  | j                        x}| _        t	        t        j
                  | j                  d|z              | _        i x}| _        t        | j                        D ]
  \  }}|||<    y )N    )
structcalcsize_format__sizeInByteslistunpack_fields_	_indexes_	enumerate_names_)selfsizeindexesinms        HC:\des-py\Monitor\venv\Lib\site-packages\PyInstaller/utils/win32/icon.py__init__zStructure.__init__%   sl    #)??4==#AAt V]]4=='D.IJ#%%$.t||, 	EArGBK	    c           	          t         j                  d|        | j                  D ]5  }|j                  d      rt         j                  d|t	        | |             7 t         j                  d       y )Nz
DUMP of %s_z	%20s = %s )loggerinfor   
startswithgetattr)r   names     r   dumpzStructure.dump,   sU    L$'LL 	DD??3'KwtT/BC	D 	Br   c                     || j                   v r| j                  |   }| j                  |   S 	 | j                  |   S # t        $ r}t        |      |d }~ww xY wN)r   r   r   __dict__KeyErrorAttributeError)r   r'   indexes       r   __getattr__zStructure.__getattr__3   s\    4<<NN4(E==''	.==&& 	. &A-	.s   = 	AAAc                 |    || j                   v r| j                  |   }|| j                  |<   y || j                  |<   y r*   )r   r   r   r+   )r   r'   valuer.   s       r   __setattr__zStructure.__setattr__<   s8    4<<NN4(E#(DMM% "'DMM$r   c                 V    t        j                  | j                  g| j                   S r*   )r   packr   r   r   s    r   tostringzStructure.tostringC   s    {{4==94==99r   c                     |j                  | j                        }t        t        j                  | j
                  |            | _        y r*   )readr   r   r   r   r   r   )r   filedatas      r   fromfilezStructure.fromfileF   s1    yy**+V]]4==$?@r   N)	__name__
__module____qualname__r   r(   r0   r3   r7   r<    r   r   r   r   $   s!    .(:Ar   r   c                       e Zd ZdZdZy)ICONDIRHEADER
idReservedidTypeidCounthhhNr=   r>   r?   r   r   r@   r   r   rB   rB   K       /GHr   rB   c                       e Zd ZdZdZy)ICONDIRENTRY)bWidthbHeightbColorCount	bReservedwPlanes	wBitCountdwBytesInResdwImageOffsetbbbbhhiiNrH   r@   r   r   rK   rK   P   s    xGHr   rK   c                       e Zd ZdZdZy)
GRPICONDIRrC   rG   NrH   r@   r   r   rV   rV   U   rI   r   rV   c                       e Zd ZdZdZy)GRPICONDIRENTRY)rL   rM   rN   rO   rP   rQ   rR   nIDbbbbhhihNrH   r@   r   r   rX   rX   Z   s    nGHr   rX   c                        e Zd Zd Zd ZddZy)IconFilec                 ~   || _         	 t        | j                   d      }|5  g | _        g | _        t               x}| _        |j                  |       t        |j                        D ]8  }t               }|j                  |       | j                  j                  |       : | j                  D ]R  }|j                  |j                  d       | j
                  j                  |j                  |j                                T 	 d d d        y # t        $ r t        d| j                    d      w xY w# 1 sw Y   y xY w)Nrbz ERROR: Unable to open icon file !r   )pathopenOSError
SystemExitentriesimagesrB   headerr<   rangerF   rK   appendseekrS   r9   rR   )r   r`   r:   rf   r   entryr/   s          r   r   zIconFile.__init__a   s   		N		4(D
  	>DLDK#0?2FT[OOD!6>>* +$t$##E*+ \\ >		!//1-""499Q^^#<=>	> 	>	  	N ?		{!LMM	N	> 	>s   D C"D3#D03D<c                 6    | j                   j                         S r*   )rf   r7   r6   s    r   grp_icon_dirzIconFile.grp_icon_dirw   s    {{##%%r   c           
          d}| j                   D ]V  }t               }|j                  d d D ]  }t        ||t	        ||              ||_        |dz   }||j                         z   }X |S )Nr      )rd   rX   r   setattrr&   rY   r7   )r   idr;   rj   r/   ns         r   grp_icondir_entrieszIconFile.grp_icondir_entriesz   su    \\ 	'E!AYYs^ 11geQ/01AEaB!**,&D	' r   Nro   )r=   r>   r?   r   rl   rs   r@   r   r   r\   r\   `   s    >,&	r   r\   ro   c           	      B   t        t        |      }t        j                  d|       t	        j
                  | d      }d}t        |      D ]  \  }}|j                         }||j                  |      z   }t	        j                  |t        |dz   |       t        j                  d|dz   t        |             |j                  D ]C  }t	        j                  |t        ||       t        j                  d|t        |             |dz   }E  t	        j                  |d       y)z
    Use the Win API UpdateResource facility to apply the icon resource(s) to the .exe file.

    :param str dstpath: absolute path of the .exe file being built.
    :param str srcpath: list of 1 or more .ico file paths
    Copying icons from %sr   ro   z/Writing RT_GROUP_ICON %d resource with %d bytesz)Writing RT_ICON %d resource with %d bytesN)mapr\   r#   debugr   BeginUpdateResourcer   rl   rs   UpdateResourceRT_GROUP_ICONlenre   RT_ICONEndUpdateResource)	dstpathsrcpathrq   iconshdsticonidr   fr;   s	            r   CopyIcons_FromIcor      s     '"E
LL('2''3DF %   1~~a++F33mQUDAFAsSWyYHH 	 D##D'64@LLDfcRViXaZF	   tQ'r   c           
         t        |t        t        j                  f      r|g}|D cg c]  }t        |       }}d }t	        t        ||            }t        |      dkD  rFg }|D ]3  }|j                  t        |d   ddt        j                  d                5 t        | |      S |d   \  }}t        |ddt        j                  d         }t        j                  j                  |      d   }|j                         dk(  rt        | |g      S |t        j!                  d
||       nt        j!                  d|       	 t#        j$                  |dt&              }t#        j4                  | d      }
|t#        j6                  |t8              d   }n&|dk\  rt#        j6                  |t8              |   }n| }t#        j:                  |t8        |      }t#        j<                  |
t8        ||       t#        j6                  |t>              D ]9  }t#        j:                  |t>        |      }t#        j<                  |
t>        ||       ; t#        j@                  |       t#        jB                  |
d       y	c c}w # t(        j*                  $ r5}	t-        dj/                  ||	j0                  |	j2                              d	}	~	ww xY w)a  
    Called from building/api.py to handle icons. If the input was by --icon on the command line, srcpath is a single
    string. However, it is possible to modify the spec file adding icon=['foo.ico','bar.ico'] to the EXE() statement.
    In that case, srcpath is a list of strings.

    The string format is either path-to-.ico or path-to-.exe,n for n an integer resource index in the .exe. In either
    case, the path can be relative or absolute.
    c                     	 | j                  d      \  }}|j                         t        |      fS # t        $ r | dfcY S w xY w)zv
        Convert "pathname" to tuple ("pathname", None)
        Convert "pathname,n" to tuple ("pathname", n)
        ,N)splitstripint
ValueError)sr   r.   s      r   splitterzCopyIcons.<locals>.splitter   sE    
	WWS\NGU==?CJ.. 	d7N	s   .1 A Aro   r   )icor   workpath)exer   z.icoNzCopying icon from %s, %drv   z9ERROR: Unable to load icon file {}
    {} (Error code {}))"
isinstancestrosPathLiker   rw   r|   rh   r   r   CONFr   r`   splitextlowerr#   rx   r   LoadLibraryExLOAD_LIBRARY_AS_DATAFILEr   errorrc   formatstrerrorwinerrorry   EnumResourceNamesr{   LoadResourcerz   r}   FreeLibraryr~   )r   r   r`   r   srcsr   r.   srcexthsrcW32Er   grpnamer;   iconnames                 r   	CopyIconsr      sw    'C-.)%,-Ts4y-G-	 3x)*G
7|a
  	]AKK+AaD(E6;;zCZ[\	] $// QZNGU "'>5&++jBYZGWWg&q)F ||~ 7)44 /%@,g6	
 %%gq2JK ''3D},,T=A!D	!,,T=A%H&  }g>DD-$?..tW= ?$$T7H=gx>? tQ'G .b  
HOOPWY]YfYfhlhuhuv
 	

s   I2I7 7J?
0J::J?__main__rt   ) __doc__r   os.pathr   PyInstaller.loglogloggingPyInstallerr   PyInstaller.compatr   r   PyInstaller.building.iconr   	getLoggerr=   r#   r}   r{   r   r   rB   rK   rV   rX   r\   r   r   sysargvr   r   r@   r   r   <module>r      s    
   !  3 9			8	$
 $A $ANI 
9 
 
i # #L(8Q(h zhhqkGhhqrlGgw r   