ó
Ý²k^c           @` sü  d  d l  m Z m Z m Z m Z d  d l m Z d  d l m Z d d l	 m
 Z
 m Z m Z e e ƒ Z e r¥d  d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z m Z m  Z  m! Z! m" Z" m# Z# e e ƒ Z$ e e  ƒ Z% d Z& d	 Z' e j( j) Z) e e  f e) _* e  e) _+ e j( j, Z, e f e, _* e e, _+ d
 e f d „  ƒ  YZ- e e- ƒ Z. e j/ j0 Z1 e. f e1 _* e e1 _+ n  d e f d „  ƒ  YZ2 d e f d „  ƒ  YZ3 d „  Z4 d „  Z5 d „  Z6 e7 d „ Z8 d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   IntEnum(   t	   getLoggeri   (   t   ensure_binaryt   on_wint   string_types(   t   POINTERt	   Structuret   WinErrort   byreft   c_ulongt   c_char_pt   c_intt   c_ulonglongt   c_void_pt	   c_wchar_pt   pointert   sizeoft   windll(   t   HANDLEt   BOOLt   DWORDt   HWNDt	   HINSTANCEt   HKEYi@   iÿÿÿÿt   ShellExecuteInfoc           B` s¤   e  Z d  Z d e f d e f d e f d e f d e f d e f d e f d e f d	 e f d
 e	 f d e f d e
 f d e f d e f d e f g Z d „  Z RS(   uÀ   
https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-shellexecuteexa
https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/ns-shellapi-_shellexecuteinfoa
        u   cbSizeu   fMasku   hwndu   lpVerbu   lpFileu   lpParametersu   lpDirectoryu   nShowu   hInstAppu   lpIDListu   lpClassu	   hKeyClassu   dwHotKeyu   hIconu   hProcessc         K` sk   t  j |  ƒ t |  ƒ |  _ xH | j ƒ  D]: \ } } t | t ƒ rS t | ƒ } n  t |  | | ƒ q) Wd  S(   N(	   R
   t   __init__R   t   cbSizet   itemst
   isinstanceR   R   t   setattr(   t   selft   kwargst
   field_namet   field_value(    (    s7   lib/python2.7/site-packages/conda/common/_os/windows.pyR   6   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R   t   _fields_R   (    (    (    s7   lib/python2.7/site-packages/conda/common/_os/windows.pyR      s"   														t   SWc           B` sP   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 d Z d	 Z d
 Z RS(   i    i   i   i	   i   i
   i   i   i   i   i   (   R&   R'   t   HIDEt   MAXIMIZEt   MINIMIZEt   RESTOREt   SHOWt   SHOWDEFAULTt   SHOWMAXIMIZEDt   SHOWMINIMIZEDt   SHOWMINNOACTIVEt   SHOWNAt   SHOWNOACTIVATEt
   SHOWNORMAL(    (    (    s7   lib/python2.7/site-packages/conda/common/_os/windows.pyR*   D   s   t   ERRORc           B` sV   e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 d	 Z d
 Z d Z d Z RS(   i    i   i   i   i   i   i   i   i   i    i   i   i   (   R&   R'   t   ZEROt   FILE_NOT_FOUNDt   PATH_NOT_FOUNDt
   BAD_FORMATt   ACCESS_DENIEDt   ASSOC_INCOMPLETEt   DDE_BUSYt   DDE_FAILt   DDE_TIMEOUTt   DLL_NOT_FOUNDt   NO_ASSOCt   OOMt   SHARE(    (    (    s7   lib/python2.7/site-packages/conda/common/_os/windows.pyR7   S   s   c         C` sn   d  } t d ƒ } y2 t j j t |  ƒ d  d  t | ƒ ƒ | j } Wn# t k
 ri } t	 j
 d | ƒ n X| S(   Ni    u   %r(   t   NoneR   R   t   kernel32t   GetDiskFreeSpaceExWR   R   t   valuet	   Exceptiont   logt   info(   t   dir_namet   resultt
   free_bytest   e(    (    s7   lib/python2.7/site-packages/conda/common/_os/windows.pyt   get_free_space_on_windowsc   s    		c          C` sI   t  }  y t j j ƒ  d k }  Wn# t k
 rD } t j d | ƒ n X|  S(   Ni    u   %r(   t   FalseR   t   shell32t   IsUserAnAdminRI   RJ   RK   (   RM   RO   (    (    s7   lib/python2.7/site-packages/conda/common/_os/windows.pyt   is_admin_on_windowss   s    c         C` sE   y t  |  t ƒ t |  ƒ Wn# t k
 r@ } t j d | ƒ n Xd S(   uB   Waits until spawned process finishes and closes the handle for it.u   %rN(   t   WaitForSingleObjectt   INFINITEt   CloseHandleRI   RJ   RK   (   t   process_handleRO   (    (    s7   lib/python2.7/site-packages/conda/common/_os/windows.pyt   _wait_and_close_handle~   s
    c   	      C` sú   |  d } d j  t |  ƒ d k r, |  d n d ƒ } d } d } yU t d t d d d d d | d	 | d
 d d t j ƒ } t t | ƒ ƒ } | j	 } Wn/ t
 k
 rÇ } t } | } t j d | ƒ n X| sÚ t ƒ  } n | rð t | j	 ƒ n  | | f S(   uÍ  
    Run command line argument list (`args`) with elevated privileges.

    If `wait` is True, the process will block until completion.

    NOTES:
        - no stdin / stdout / stderr pipe support
        - does not automatically quote arguments (i.e. for paths that may contain spaces)
    See:
    - http://stackoverflow.com/a/19719292/1170370 on 20160407 MCS.
    - msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx
    - https://github.com/ContinuumIO/menuinst/blob/master/menuinst/windows/win_elevate.py
    - https://github.com/saltstack/salt-windows-install/blob/master/deps/salt/python/App/Lib/site-packages/win32/Demos/pipes/runproc.py  # NOQA
    - https://github.com/twonds/twisted/blob/master/twisted/internet/_dumbwin32proc.py
    - https://stackoverflow.com/a/19982092/2127762
    - https://www.codeproject.com/Articles/19165/Vista-UAC-The-Definitive-Guide
    - https://github.com/JustAMan/pyWinClobber/blob/master/win32elevate.py
    i    u    i   t   fMaskt   hwndt   lpVerbu   runast   lpFilet   lpParameterst   lpDirectoryt   nShowu   %r(    N(   t   joint   lenRE   R   t   SEE_MASK_NOCLOSEPROCESSR*   R+   t   ShellExecuteExR   t   hProcessRI   RQ   RJ   RK   R   RY   (	   t   argst   waitt   arg0t	   param_strt   hprocesst
   error_codet   execute_infot
   successfulRO   (    (    s7   lib/python2.7/site-packages/conda/common/_os/windows.pyt   run_as_admin‡   s0    
+N(9   t
   __future__R    R   R   R   t   enumR   t   loggingR   t   compatR   R   R   R&   RJ   t   ctypesR	   R
   R   R   R   R   R   R   R   R   R   R   R   t   ctypes.wintypesR   R   R   R   R   R   t   PHANDLEt   PDWORDRc   RV   RF   RU   t   argtypest   restypeRW   R   t   PShellExecuteInfot   Shell32t   ShellExecuteExARd   R*   R7   RP   RT   RY   t   TrueRn   (    (    (    s7   lib/python2.7/site-packages/conda/common/_os/windows.pyt   <module>   s8   "X.		 				