a
    <Bìjz(  ã                   @  sÌ   d Z ddlm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rTddlmZ G d	d
„ d
e
ƒZdddœdd„Zdddœdd„Zdddœdd„Zdddœdd„Zddœdd„Zedd�eƒ ƒZd
gZdS )zWindows.é    )ÚannotationsN)Ú	lru_cache)ÚTYPE_CHECKINGé   )ÚPlatformDirsABC)ÚCallablec                   @  sH  e Zd ZdZeddœdd„ƒZddœdddd	œd
d„Zeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZ	eddœdd„ƒZ
eddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœdd„ƒZeddœd d!„ƒZeddœd"d#„ƒZeddœd$d%„ƒZeddœd&d'„ƒZeddœd(d)„ƒZdS )*ÚWindowsað  
    `MSDN on where to store app data files <https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid>`_.

    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>`.

    Ústr©Úreturnc                 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   ú_/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pip/_vendor/platformdirs/windows.pyÚuser_data_dir   s    zWindows.user_data_dirN©Úopinion_valueú
str | None)r   r   r   c                C  s‚   g }| j r`| jdur*| jp| j }| |¡ | | j ¡ |d urN| jrN| |¡ | jr`| | 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_dir5   s    zWindows.site_data_dirc                 C  s   | j S )zC:return: config directory tied to the user, same as `user_data_dir`©r   ©r   r   r   r   Úuser_config_dir;   s    zWindows.user_config_dirc                 C  s   | j S )zF:return: config directory shared by the users, same as `site_data_dir`)r(   r*   r   r   r   Úsite_config_dir@   s    zWindows.site_config_dirc                 C  s   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_dirE   s    zWindows.user_cache_dirc                 C  s   t j tdƒ¡}| j|dd�S )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_dirN   s    zWindows.site_cache_dirc                 C  s   | j S )zB:return: state directory tied to the user, same as `user_data_dir`r)   r*   r   r   r   Úuser_state_dirT   s    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_dirY   s
    
zWindows.user_log_dirc                 C  s   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_dirb   s    zWindows.user_documents_dirc                 C  s   t j tdƒ¡S )zN:return: downloads directory tied to the user e.g. ``%USERPROFILE%\Downloads``ÚCSIDL_DOWNLOADSr4   r*   r   r   r   Úuser_downloads_dirg   s    zWindows.user_downloads_dirc                 C  s   t j tdƒ¡S )zL:return: pictures directory tied to the user e.g. ``%USERPROFILE%\Pictures``ÚCSIDL_MYPICTURESr4   r*   r   r   r   Úuser_pictures_dirl   s    zWindows.user_pictures_dirc                 C  s   t j tdƒ¡S )zH:return: videos directory tied to the user e.g. ``%USERPROFILE%\Videos``ÚCSIDL_MYVIDEOr4   r*   r   r   r   Úuser_videos_dirq   s    zWindows.user_videos_dirc                 C  s   t j tdƒ¡S )zF:return: music directory tied to the user e.g. ``%USERPROFILE%\Music``ÚCSIDL_MYMUSICr4   r*   r   r   r   Úuser_music_dirv   s    zWindows.user_music_dirc                 C  s   t j tdƒ¡S )zK:return: desktop directory tied to the user, e.g. ``%USERPROFILE%\Desktop``ÚCSIDL_DESKTOPDIRECTORYr4   r*   r   r   r   Úuser_desktop_dir{   s    zWindows.user_desktop_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   ZTemp)r   r   r   r!   r   r   r'   r   r   r   Úuser_runtime_dir€   s    zWindows.user_runtime_dirc                 C  s   | j S )zF:return: runtime directory shared by users, same as `user_runtime_dir`)r@   r*   r   r   r   Úsite_runtime_dir‰   s    zWindows.site_runtime_dir)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r(   r+   r,   r.   r/   r0   r2   r5   r7   r9   r;   r=   r?   r@   rA   r   r   r   r   r      sD   

r   r	   )Ú
csidl_namer   c                 C  sj   t | ƒ}|dur|S ddddœ | ¡}|du r@d| › �}t|ƒ‚tj |¡}|du rfd|› �}t|ƒ‚|S )z&Get folder from environment variables.NÚAPPDATAZALLUSERSPROFILEÚLOCALAPPDATA)r   r%   r   úUnknown CSIDL name: zUnset environment variable: )Ú(get_win_folder_if_csidl_name_not_env_varÚgetÚ
ValueErrorr   Úenviron)rG   ÚresultZenv_var_nameÚmsgr   r   r   Úget_win_folder_from_env_vars�   s"    ýü

rQ   r   c                 C  s¸   | dkr$t j t j t jd ¡d¡S | dkrHt j t j t jd ¡d¡S | dkrlt j t j t jd ¡d¡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S )zMGet a folder for a CSIDL name that does not exist as an environment variable.r3   ÚUSERPROFILEZ	Documentsr6   Ú	Downloadsr8   ZPicturesr:   ZVideosr<   ZMusicN)r   r   r!   r   rN   )rG   r   r   r   rK   ¤   s    rK   c           	   	   C  sŠ   dh}dddddddd	d
œ  | ¡}|du r<d| › �}t|ƒ‚tjdkrJt‚ddl}| |v r`|jn|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.

    r%   ÚAppDatazCommon AppDatazLocal AppDataZPersonalz&{374DE290-123F-4565-9164-39C4925E467B}zMy PictureszMy VideozMy Music)r   r%   r   r3   r6   r8   r:   r<   NrJ   Úwin32r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)rL   rM   ÚsysÚplatformÚNotImplementedErrorÚwinregÚHKEY_LOCAL_MACHINEÚHKEY_CURRENT_USERÚOpenKeyÚQueryValueExr	   )	rG   Zmachine_namesÚshell_folder_namerP   rY   ÚhkeyÚkeyÚ	directoryÚ_r   r   r   Úget_win_folder_from_registry·   s.    	ÿø	÷


rc   c              
   C  s¸   ddl }ddddddd	d
ddœ	 | ¡}|du r@d| › �}t|ƒ‚| d¡}t|dƒ}|j d|dd|¡ tdd„ |D ƒƒrš| d¡}|j 	|j
|d¡rš|}| dkr²tj |j
d¡S |j
S )zGet folder with ctypes.r   Né   é#   é   é   é'   é   é   é(   é   )	r   r%   r   r3   r8   r:   r<   r6   r>   rJ   i   Úwindllc                 s  s   | ]}t |ƒd kV  qdS )éÿ   N)Úord)Ú.0Úcr   r   r   Ú	<genexpr>÷   ó    z,get_win_folder_via_ctypes.<locals>.<genexpr>r6   rS   )ÚctypesrL   rM   Úcreate_unicode_bufferÚgetattrÚshell32ÚSHGetFolderPathWÚanyÚkernel32ÚGetShortPathNameWÚvaluer   r   r!   )rG   rt   Úcsidl_constrP   Úbufrm   Úbuf2r   r   r   Úget_win_folder_via_ctypesÛ   s4    ÷
ö



r€   zCallable[[str], str]r
   c                  C  sZ   zdd l } W n ty   Y n0 t| dƒr.tS zdd l}W n tyP   t Y S 0 tS d S )Nr   rm   )rt   ÚImportErrorÚhasattrr€   rY   rQ   rc   )rt   rY   r   r   r   Ú_pick_get_win_folder  s    

rƒ   )Úmaxsize)rE   Ú
__future__r   r   rV   Ú	functoolsr   Útypingr   Úapir   Úcollections.abcr   r   rQ   rK   rc   r€   rƒ   r   Ú__all__r   r   r   r   Ú<module>   s"   $'ÿ