o
    Ëý°j'  ã                   @  s’   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	 G dd„ de	ƒ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 )é    )ÚannotationsN)Ú	lru_cache)ÚCallableé   )ÚPlatformDirsABCc                   @  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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>`.Ú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   ú“/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/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  st   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)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_dir-   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_dir3   ó   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_dir8   r*   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_dir=   s   zWindows.user_cache_dirc                 C  r&   )zB:return: state directory tied to the user, same as `user_data_dir`r'   r(   r   r   r   Úuser_state_dirF   r*   zWindows.user_state_dirc                 C  s   | j }| jrtj |d¡}|S )zy
        :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   Úuser_log_dirK   s   zWindows.user_log_dirc                 C  s   t j tdƒ¡S )z`
        :return: documents directory tied to the user e.g. ``%USERPROFILE%\Documents``
        ÚCSIDL_PERSONAL)r   r   r   r   r(   r   r   r   Úuser_documents_dirU   s   zWindows.user_documents_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+   r-   r.   r0   r2   r4   r   r   r   r   r      s*    	
	r   Ú
csidl_namer	   r   c                 C  sr   | dkrt j t j t jd ¡d¡S ddddœ | ¡}|du r&td	| › �ƒ‚t j |¡}|du r7td
|› �ƒ‚|S )z&Get folder from environment variables.r1   ÚUSERPROFILEÚ	DocumentsÚAPPDATAÚALLUSERSPROFILEÚLOCALAPPDATA)r
   r"   r   NúUnknown CSIDL name: zUnset environment variable: )r   r   r   r   ÚenvironÚgetÚ
ValueError)r:   Úenv_var_nameÚresultr   r   r   Úget_win_folder_from_env_varsf   s   ýürF   c                 C  sX   dddddœ  | ¡}|du rtd| › �ƒ‚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 this guarantees us the correct answer for all CSIDL_*
    names.
    ÚAppDatazCommon AppDatazLocal AppDataÚPersonal©r
   r"   r   r1   Nr@   r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)rB   rC   ÚwinregÚOpenKeyÚHKEY_CURRENT_USERÚQueryValueExr	   )r:   Úshell_folder_namerJ   ÚkeyÚ	directoryÚ_r   r   r   Úget_win_folder_from_registryx   s   üûrR   c                 C  sŠ   dddddœ  | ¡}|du rtd| › �ƒ‚t d¡}ttd	ƒ}|j d|dd
|¡ tdd„ |D ƒƒrBt d¡}|j 	|j
|d¡rB|}|j
S )zGet folder with ctypes.é   é#   é   é   rI   Nr@   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>)rB   rC   ÚctypesÚcreate_unicode_bufferÚgetattrÚshell32ÚSHGetFolderPathWÚanyÚkernel32ÚGetShortPathNameWÚvalue)r:   Úcsidl_constÚbufrW   Úbuf2r   r   r   Úget_win_folder_via_ctypes�   s"   üû


ri   ú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 )NrW   r   )Úhasattrr]   ri   rJ   ÚImportErrorrF   rR   )rJ   r   r   r   Ú_pick_get_win_folder§   s   

ýÿrm   )Úmaxsize)r:   r	   r   r	   )r   rj   )Ú
__future__r   r]   r   Ú	functoolsr   Útypingr   Úapir   r   rF   rR   ri   rm   r   Ú__all__r   r   r   r   Ú<module>   s    
[


ÿ