o
    ^iA                     @   s   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 d dl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)windll	Structurebyrefc_uintcreate_unicode_buffer	addressofGetLastErrorFormatError)HWNDUINTLPCWSTRBOOL)preprocess_pathsc                	   @   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   _fields_ r   r   P/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/send2trash/win/legacy.pyr      s    r                  @   i   c              
   C   s   i 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ddddddddddddddddd}| | | S )Nq   P   r   W   s   t   u   i  v   x      y   o   z   |      }   ~                        i        )            r6   i  i   it  )get)resultresultsr   r   r   convert_sh_file_opt_result7   sZ   	
rF   c                 C   sd   d| }}|  |s%|  drd}|| dd  }||fS ||  }||fS |  |d r.d}||fS )zGuess 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\\\\?\UNCr   NzUNC\)
startswith)pathprefix	long_pathr   r   r   prefix_and_pathZ   s   


rL   c                 C   s,   | dkrd|t | d  S |t | d S )zGuess 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.
    rG   \N)len)rJ   rI   r   r   r   get_awaited_path_from_prefixr   s   rO   c                 C   sR   t | \}}t|d d}|st }t|t||t|}t||| t||jS )Nr   )rL   GetShortPathNameWr	   WindowsErrorr
   r   rO   value)	long_namerJ   rK   buf_sizeerr_nooutputr   r   r   get_short_path_name~   s   rW   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|}|rlt|}td t|| |d S )	Nc                 S   s$   g | ]}t |tst|d n|qS )mbcs)
isinstancestr.0rI   r   r   r   
<listcomp>      $ zsend2trash.<locals>.<listcomp>c                 S   s$   g | ]}t |st |n|qS r   )opisabsabspathr[   r   r   r   r]      r^   c                 S   s   g | ]}t |qS r   )rW   r[   r   r   r   r]      s    r     r   )r   r   r   	FO_DELETEr   r   joinrN   r   r   r   r   FOF_ALLOWUNDOFOF_NOCONFIRMATIONFOF_NOERRORUI
FOF_SILENTr   r   r   r   SHFileOperationWr   rF   rQ   r
   )pathsfileopbufferpath_stringrD   errorr   r   r   
send2trash   s.   
rp   )(
__future__r   os.pathrI   r_   ctypesr   r   r   r   r   r   r	   r
   ctypes.wintypesr   r   r   r   send2trash.utilr   kernel32rP   shell32rj   r   FO_MOVEFO_COPYrd   	FO_RENAMEFOF_MULTIDESTFILESri   rg   rf   rh   rF   rL   rO   rW   rp   r   r   r   r   <module>   s0   (
#