B
    '‹dx  ã               @   sè   d dl mZ d dlmZ d dlmZ d dlmZ d dl	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 e
jZejZe
jZejZG dd„ deƒZd	Zd
ZdZdZd	Z dZ!dZ"dZ#dZ$dd„ Z%dd„ Z&dd„ Z'dd„ Z(dd„ Z)dS )é    )Úunicode_literalsN)Ú	text_type)Úpreprocess_paths)ÚwindllÚ	StructureÚbyrefÚc_uintÚcreate_unicode_bufferÚ	addressofÚGetLastErrorÚFormatError)ÚHWNDÚUINTÚLPCWSTRÚBOOLc            	   @   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gZd	S )
ÚSHFILEOPSTRUCTWÚhwndÚwFuncÚpFromÚpToÚfFlagsÚfAnyOperationsAbortedÚhNameMappingsÚlpszProgressTitleN)	Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   Z_fields_© r   r   úb/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/send2trash/win/legacy.pyr       s   r   é   é   é   é   é   é@   i   c             C   sD   ddddddddddddddddd	d
ddd	dddddœ}|  | | ¡S )NéP   éW   iÇ  é   éo   é¡   é·   é   iù  éß   é   )éq   ér   és   ét   éu   év   éx   éy   éz   é|   é}   é~   é€   é   é‚   éƒ   é„   é…   é†   é‡   éˆ   r*   i  i   it  )Úget)ÚresultÚresultsr   r   r   Úconvert_sh_file_opt_result9   s4    rF   c             C   sX   d|  }}|   |¡s>|   d¡r4d}|| dd…  }qP||  }n|   |d ¡rPd}||fS )zÞGuess the long-path prefix based on the kind of *path*.
    Local paths (C:\folder\file.ext) and UNC names (\\server\folder\file.ext)
    are handled.

    Return a tuple of the long-path prefix and the prefixed path.
    z\\?\z\\z\\?\UNCr   NzUNC\)Ú
startswith)ÚpathÚprefixÚ	long_pathr   r   r   Úprefix_and_path\   s    



rK   c             C   s,   | dkrd|t | ƒd…  S |t | ƒd… S )z©Guess the correct path to pass to the SHFileOperationW() call.
    The long-path prefix must be removed, so we should take care of
    different long-path prefixes.
    z\\?\UNCú\N)Úlen)rI   rH   r   r   r   Úget_awaited_path_from_prefixt   s    rN   c             C   sR   t | ƒ\}}t|d dƒ}|s2tƒ }t|t|ƒ|ƒ‚t|ƒ}t|||ƒ t||jƒS )Nr   )rK   ÚGetShortPathNameWr   ÚWindowsErrorr   r	   rN   Úvalue)Z	long_namerI   rJ   Zbuf_sizeZerr_noÚoutputr   r   r   Úget_short_path_name€   s    rS   c             C   sÜ   t | ƒ} | sd S dd„ | D ƒ} dd„ | D ƒ} dd„ | D ƒ} tƒ }d|_t|_td | ¡ƒ}d | ¡}t|t|ƒd ƒ}tt	|ƒƒ|_
d |_ttB tB tB |_d|_d|_d |_tt|ƒƒ}|rØt|ƒ}td t|ƒ| |ƒ‚d S )	Nc             S   s$   g | ]}t |tƒst|d ƒn|‘qS )Úmbcs)Ú
isinstancer   )Ú.0rH   r   r   r   ú
<listcomp>’   s    zsend2trash.<locals>.<listcomp>c             S   s$   g | ]}t  |¡st  |¡n|‘qS r   )ÚopÚisabsÚabspath)rV   rH   r   r   r   rW   ”   s    c             S   s   g | ]}t |ƒ‘qS r   )rS   )rV   rH   r   r   r   rW   –   s    r   ú ú r   )r   r   r   Ú	FO_DELETEr   r	   ÚjoinrM   r   r
   r   r   ÚFOF_ALLOWUNDOÚFOF_NOCONFIRMATIONÚFOF_NOERRORUIÚ
FOF_SILENTr   r   r   r   ÚSHFileOperationWr   rF   rP   r   )ÚpathsÚfileopÚbufferZpath_stringrD   Úerrorr   r   r   Ú
send2trash   s,    
rh   )*Ú
__future__r   Úos.pathrH   rX   Zsend2trash.compatr   Zsend2trash.utilr   Úctypesr   r   r   r   r	   r
   r   r   Zctypes.wintypesr   r   r   r   Úkernel32rO   Zshell32rc   r   ZFO_MOVEZFO_COPYr]   Z	FO_RENAMEZFOF_MULTIDESTFILESrb   r`   r_   ra   rF   rK   rN   rS   rh   r   r   r   r   Ú<module>   s0   (
#