
    i|$                     x   S r SSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
Jr  SSKJr  \R                  " \5      rSrSrSr " S	 S
5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S5      rSS jrS r\S:X  a,  SSKr\R:                  S   r\R:                  SS r\" \\5        gg)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                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
	Structure$   c                    [         R                  " U R                  5      =ol        [	        [         R
                  " U R                  SU-  5      5      U l        0 =o l        [        U R                  5       H	  u  p4X2U'   M     g )N    )
structcalcsize_format__sizeInByteslistunpack_fields_	_indexes_	enumerate_names_)selfsizeindexesinms        IC:\des-py\RoboSAPF\venv\Lib\site-packages\PyInstaller\utils\win32\icon.py__init__Structure.__init__%   s_    #)??4==#AA V]]4=='D.IJ#%%.t||,EABK -    c           	          [         R                  SU 5        U R                   H;  nUR                  S5      (       a  M  [         R                  SU[	        X5      5        M=     [         R                  S5        g )Nz
DUMP of %s_z	%20s = %s )loggerinfor   
startswithgetattr)r   names     r   dumpStructure.dump,   sO    L$'LLD??3''Kwt/BC ! 	Br!   c                     XR                   ;   a  U R                  U   nU R                  U   $  U R                  U   $ ! [         a  n[        U5      UeS nAff = fN)r   r   r   __dict__KeyErrorAttributeError)r   r)   indexes       r   __getattr__Structure.__getattr__3   sZ    <<NN4(E==''	.==&& 	. &A-	.s   > 
AAAc                 z    XR                   ;   a  U R                  U   nX R                  U'   g X R                  U'   g r-   )r   r   r   r.   )r   r)   valuer1   s       r   __setattr__Structure.__setattr__<   s2    <<NN4(E#(MM% "'MM$r!   c                 X    [         R                  " U R                  /U R                  Q76 $ r-   )r   packr   r   r   s    r   tostringStructure.tostringC   s    {{4==94==99r!   c                     UR                  U R                  5      n[        [        R                  " U R
                  U5      5      U l        g r-   )readr   r   r   r   r   r   )r   filedatas      r   fromfileStructure.fromfileF   s1    yy**+V]]4==$?@r!   )r   r   r   N)__name__
__module____qualname____firstlineno__r   r*   r3   r7   r<   rB   __static_attributes__ r!   r   r   r   $   s!    .(:Ar!   r   c                       \ rS rSrSrSrSrg)ICONDIRHEADERK   
idReservedidTypeidCounthhhrI   NrD   rE   rF   rG   r   r   rH   rI   r!   r   rK   rK   K       /GHr!   rK   c                       \ rS rSrSrSrSrg)ICONDIRENTRYP   )bWidthbHeightbColorCount	bReservedwPlanes	wBitCountdwBytesInResdwImageOffsetbbbbhhiirI   NrR   rI   r!   r   rU   rU   P   s    xGHr!   rU   c                       \ rS rSrSrSrSrg)
GRPICONDIRU   rM   rQ   rI   NrR   rI   r!   r   ra   ra   U   rS   r!   ra   c                       \ rS rSrSrSrSrg)GRPICONDIRENTRYZ   )rW   rX   rY   rZ   r[   r\   r]   nIDbbbbhhihrI   NrR   rI   r!   r   rd   rd   Z   s    nGHr!   rd   c                   *    \ rS rSrS rS rSS jrSrg)IconFile`   c                    Xl          [        U R                   S5      nU   / U l        / U l        [        5       =o0l        UR                  U5        [        UR                  5       H9  n[        5       nUR                  U5        U R                  R                  U5        M;     U R                   HS  nUR                  UR                  S5        U R
                  R                  UR                  UR                   5      5        MU     S S S 5        g ! [         a    [        SU R                    S35      ef = f! , (       d  f       g = f)Nrbz ERROR: Unable to open icon file !r   )pathopenOSError
SystemExitentriesimagesrK   headerrB   rangerP   rU   appendseekr^   r?   r]   )r   rn   r@   rt   r   entryr2   s          r   r   IconFile.__init__a   s    		N		4(D
 DLDK#0?2F[OOD!6>>*$t$##E* + \\		!//1-""499Q^^#<= " T	  	N ?		{!LMM	N Ts   D C%D5$D25
Ec                 6    U R                   R                  5       $ r-   )rt   r<   r;   s    r   grp_icon_dirIconFile.grp_icon_dirw   s    {{##%%r!   c           
          SnU R                    HU  n[        5       nUR                  S S  H  n[        XE[	        X55      5        M     Xl        US-   nX$R                  5       -   nMW     U$ )Nr!      )rr   rd   r   setattrr(   rf   r<   )r   idrA   rx   r2   ns         r   grp_icondir_entriesIconFile.grp_icondir_entriesz   sc    \\E!AYYs^ge/0 $EaB**,&D " r!   )rr   rt   rs   rn   Nr   )rD   rE   rF   rG   r   r{   r   rH   rI   r!   r   ri   ri   `   s    >,&	r!   ri   r   c           	      L   [        [        U5      n[        R                  SU5        [        R
                  " U S5      nSn[        U5       H  u  pgUR                  5       nXR                  U5      -   n[        R                  " U[        US-   U5        [        R                  SUS-   [        U5      5        UR                   HD  n[        R                  " U[        XX5        [        R                  SU[        U5      5        US-   nMF     M     [        R                  " US5        g)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   r   z/Writing RT_GROUP_ICON %d resource with %d bytesz)Writing RT_ICON %d resource with %d bytesN)mapri   r%   debugr   BeginUpdateResourcer   r{   r   UpdateResourceRT_GROUP_ICONlenrs   RT_ICONEndUpdateResource)	dstpathsrcpathr   iconshdsticonidr   frA   s	            r   CopyIcons_FromIcor      s     '"E
LL('2''3DF % ~~++F33mQUDAFAsSWyYHHD##D'6@LLDfcRViXaZF  ! tQ'r!   c           
         [        U[        [        R                  45      (       a  U/nU Vs/ s H  n[        U5      PM     nnS n[	        [        X15      5      n[        U5      S:  aG  / nU H4  nUR                  [        US   SS[        R                  S   5      5        M6     [        X5      $ US   u  p[        USS[        R                  S   5      n[        R                  R                  U5      S   nUR                  5       S:X  a  [        X/5      $ Ub  [        R!                  S
X5        O[        R!                  SU5         ["        R$                  " US[&        5      n["        R4                  " U S5      n
Uc  ["        R6                  " U[8        5      S   nO(US:  a  ["        R6                  " U[8        5      U   nOU* n["        R:                  " U[8        U5      n["        R<                  " U
[8        X5        ["        R6                  " U[>        5       H;  n["        R:                  " U[>        U5      n["        R<                  " U
[>        X5        M=     ["        R@                  " U5        ["        RB                  " U
S5        g	s  snf ! [(        R*                   a4  n	[-        SR/                  XR0                  U	R2                  5      5      eS	n	A	ff = f)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                      U R                  S5      u  pUR                  5       [        U5      4$ ! [         a    U S4s $ f = f)z^
Convert "pathname" to tuple ("pathname", None)
Convert "pathname,n" to tuple ("pathname", n)
,N)splitstripint
ValueError)sr   r1   s      r   splitterCopyIcons.<locals>.splitter   sC    
	WWS\NG==?CJ.. 	d7N	s   -0 A Ar   r   )icor   workpath)exer   z.icoNzCopying icon from %s, %dr   z9ERROR: Unable to load icon file {}
    {} (Error code {}))"
isinstancestrosPathLiker   r   r   rv   r   r   CONFr   rn   splitextlowerr%   r   r   LoadLibraryExLOAD_LIBRARY_AS_DATAFILEr   errorrq   formatstrerrorwinerrorr   EnumResourceNamesr   LoadResourcer   r   FreeLibraryr   )r   r   rn   r   srcsr   r1   srcexthsrcW32Er   grpnamerA   iconnames                 r   	CopyIconsr      s^    'C-..)%,-WTs4yWG-	 3x)*G
7|a
 AKK+AaD(E6;;zCZ[\  // QZNG "'>5&++jBYZGWWg&q)F ||~ )44 /@,g6	
 %%gq2JK ''3D},,T=A!D	!,,T=A%H&  }g>DD-?..tW=$$T7H=gx> > tQ'G .b  
HOOPWYfYfhlhuhuv
 	

s   J
J K /KK__main__r   ) __doc__r   os.pathr   PyInstaller.loglogloggingPyInstallerr   PyInstaller.compatr   r   PyInstaller.building.iconr   	getLoggerrD   r%   r   r   r   r   rK   rU   ra   rd   ri   r   r   sysargvr   r   rI   r!   r   <module>r      s    
   !  3 9			8	$
 $A $ANI 
9 
 
i # #L(8Q(h zhhqkGhhqrlGgw r!   