o
    5ee%                     @  s   d Z ddlm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 e	r.ddlmZ G d	d
 d
eZdddZdddZdddZdddZdddZedde Zd
gZdS )zWindows.    )annotationsN)	lru_cache)TYPE_CHECKING   )PlatformDirsABC)Callablec                   @  s   e Zd ZdZed'ddZddd(ddZed'ddZed'ddZed'ddZ	ed'ddZ
ed'ddZed'ddZed'ddZed'ddZed'ddZed'dd Zed'd!d"Zed'd#d$Zed'd%d&ZdS ))Windowsa  
    `MSDN on where to store app data files
    <http://support.microsoft.com/default.aspx?scid=kb;en-us;310294#XSLTH3194121123120121120120>`_.
    Makes use of the
    `appname <platformdirs.api.PlatformDirsABC.appname>`,
    `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`,
    `version <platformdirs.api.PlatformDirsABC.version>`,
    `roaming <platformdirs.api.PlatformDirsABC.roaming>`,
    `opinion <platformdirs.api.PlatformDirsABC.opinion>`,
    `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
    returnstrc                 C  s(   | j rdnd}tjt|}| |S )z
        :return: data directory tied to the user, e.g.
         ``%USERPROFILE%\AppData\Local\$appauthor\$appname`` (not roaming) or
         ``%USERPROFILE%\AppData\Roaming\$appauthor\$appname`` (roaming)
        CSIDL_APPDATACSIDL_LOCAL_APPDATA)roamingospathnormpathget_win_folder_append_parts)selfconstr    r   S/var/www/html/venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/windows.pyuser_data_dir   s   
zWindows.user_data_dirNopinion_valuer   r   
str | Nonec                C  s   g }| j r0| jdur| jp| j }|| || j  |d ur'| jr'|| | jr0|| j tjj|g|R  }| | |S )NF)	appname	appauthorappendopinionversionr   r   join_optionally_create_directory)r   r   r   paramsauthorr   r   r   r   (   s   



zWindows._append_partsc                 C  s   t jtd}| |S )zT:return: data directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname``CSIDL_COMMON_APPDATAr   r   r   r   r   r   r   r   r   r   site_data_dir7   s   
zWindows.site_data_dirc                 C     | j S )zC:return: config directory tied to the user, same as `user_data_dir`r   r   r   r   r   user_config_dir=      zWindows.user_config_dirc                 C  r(   )zF:return: config directory shared by the users, same as `site_data_dir`)r'   r*   r   r   r   site_config_dirB   r,   zWindows.site_config_dirc                 C     t jtd}| j|ddS )z
        :return: cache directory tied to the user (if opinionated with ``Cache`` folder within ``$appname``) e.g.
         ``%USERPROFILE%\AppData\Local\$appauthor\$appname\Cache\$version``
        r   Cacher   r%   r&   r   r   r   user_cache_dirG   s   zWindows.user_cache_dirc                 C  r.   )zd:return: cache directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname\Cache\$version``r$   r/   r   r%   r&   r   r   r   site_cache_dirP   s   zWindows.site_cache_dirc                 C  r(   )zB:return: state directory tied to the user, same as `user_data_dir`r)   r*   r   r   r   user_state_dirV   r,   zWindows.user_state_dirc                 C  s(   | j }| jrtj|d}| | |S )zg:return: log directory tied to the user, same as `user_data_dir` if not opinionated else ``Logs`` in itLogs)r   r   r   r   r    r!   r&   r   r   r   user_log_dir[   s
   
zWindows.user_log_dirc                 C     t jtdS )zN:return: documents directory tied to the user e.g. ``%USERPROFILE%\Documents``CSIDL_PERSONALr   r   r   r   r*   r   r   r   user_documents_dird      zWindows.user_documents_dirc                 C  r5   )zN:return: downloads directory tied to the user e.g. ``%USERPROFILE%\Downloads``CSIDL_DOWNLOADSr7   r*   r   r   r   user_downloads_diri   r9   zWindows.user_downloads_dirc                 C  r5   )zL:return: pictures directory tied to the user e.g. ``%USERPROFILE%\Pictures``CSIDL_MYPICTURESr7   r*   r   r   r   user_pictures_dirn   r9   zWindows.user_pictures_dirc                 C  r5   )zH:return: videos directory tied to the user e.g. ``%USERPROFILE%\Videos``CSIDL_MYVIDEOr7   r*   r   r   r   user_videos_dirs   r9   zWindows.user_videos_dirc                 C  r5   )zF:return: music directory tied to the user e.g. ``%USERPROFILE%\Music``CSIDL_MYMUSICr7   r*   r   r   r   user_music_dirx   r9   zWindows.user_music_dirc                 C  s$   t jt jtdd}| |S )z
        :return: runtime directory tied to the user, e.g.
         ``%USERPROFILE%\AppData\Local\Temp\$appauthor\$appname``
        r   Temp)r   r   r   r    r   r   r&   r   r   r   user_runtime_dir}   s   
zWindows.user_runtime_dir)r	   r
   )r   r
   r   r   r	   r
   )__name__
__module____qualname____doc__propertyr   r   r'   r+   r-   r0   r1   r2   r4   r8   r;   r=   r?   rA   rC   r   r   r   r   r      s>    
r   
csidl_namer
   r	   c                 C  sj   t | }|dur
|S dddd| }|du r d|  }t|tj|}|du r3d| }t||S )z&Get folder from environment variables.NAPPDATAALLUSERSPROFILELOCALAPPDATA)r   r$   r   Unknown CSIDL name: zUnset environment variable: )(get_win_folder_if_csidl_name_not_env_varget
ValueErrorr   environ)rI   resultenv_var_namemsgr   r   r   get_win_folder_from_env_vars   s"   

rU   r   c                 C  s   | dkrt jt jt jd dS | dkr$t jt jt jd dS | dkr6t jt jt jd dS | dkrHt jt jt jd d	S | d
krZt jt jt jd dS dS )zKGet folder for a CSIDL name that does not exist as an environment variable.r6   USERPROFILE	Documentsr:   	Downloadsr<   Picturesr>   Videosr@   MusicN)r   r   r    r   rQ   )rI   r   r   r   rN      s   rN   c              	   C  sr   ddddddddd	 | }|d
u rd|  }t|tjdkr"tdd
l}||jd}|||\}}t	|S )z
    Get folder from the registry.

    This is a fallback technique at best. I'm not sure if using the registry for these guarantees us the correct answer
    for all CSIDL_* names.
    AppDatazCommon AppDatazLocal AppDataPersonalz&{374DE290-123F-4565-9164-39C4925E467B}zMy PictureszMy VideozMy Music)r   r$   r   r6   r:   r<   r>   r@   NrM   win32r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)
rO   rP   sysplatformNotImplementedErrorwinregOpenKeyHKEY_CURRENT_USERQueryValueExr
   )rI   shell_folder_namerT   rb   key	directory_r   r   r   get_win_folder_from_registry   s(   	


rj   c              	   C  s   ddddddddd	 | }|d
u rd|  }t|td}ttd}|jd
|d
d| tdd |D rHtd}|j	|j
|drH|}| dkrTtj|j
dS |j
S )zGet folder with ctypes.   #         '         (   )r   r$   r   r6   r<   r>   r@   r:   NrM   i   windllr   c                 s  s    | ]	}t |d kV  qdS )   N)ord).0cr   r   r   	<genexpr>   s    z,get_win_folder_via_ctypes.<locals>.<genexpr>r:   rX   )rO   rP   ctypescreate_unicode_buffergetattrshell32SHGetFolderPathWanykernel32GetShortPathNameWvaluer   r   r    )rI   csidl_constrT   bufrs   buf2r   r   r   get_win_folder_via_ctypes   s0   	




r   Callable[[str], str]c                  C  s4   t tdrtS zdd l} W tS  ty   t Y S w )Nrs   r   )hasattrry   r   rb   ImportErrorrU   rj   )rb   r   r   r   _pick_get_win_folder   s   

r   )maxsize)rI   r
   r	   r
   )rI   r
   r	   r   )r	   r   )rG   
__future__r   ry   r   r_   	functoolsr   typingr   apir   collections.abcr   r   rU   rN   rj   r   r   r   __all__r   r   r   r   <module>   s&    
w



$