o
    tBhP                     @   s   d dl Z d dlZd dlmZ d dlmZmZ ddlmZ G dd deZ	de
d	e
fd
dZde
d	e
fddZde
d	e
fddZd	ee
ge
f fddZedde ZdgZdS )    N)	lru_cache)CallableOptional   )PlatformDirsABCc                   @   s   e Zd ZdZedefddZdddedee defd	d
ZedefddZ	edefddZ
edefddZedefddZedefddZedef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>`.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   k/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/platformdirs/windows.pyuser_data_dir   s   
zWindows.user_data_dirNopinion_valuer   r   c                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_dir1      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_dir6   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_dirD   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_dirI   s   zWindows.user_log_dir)__name__
__module____qualname____doc__propertystrr   r   r   r#   r'   r)   r+   r,   r.   r   r   r   r   r   	   s"    	 
r   
csidl_namer   c                 C   sN   dddd | }|du rtd|  tj |}|du r%td| |S )z&Get folder from environment variables.APPDATAALLUSERSPROFILELOCALAPPDATAr	   r    r
   NUnknown CSIDL name: zUnset environment variable: )get
ValueErrorr   environ)r5   env_var_nameresultr   r   r   get_win_folder_from_env_varsT   s   r@   c                 C   sV   dddd | }|du rtd|  ddl}||jd}|||\}}t|S )	zGet 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 AppDatar9   Nr:   r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)r;   r<   winregOpenKeyHKEY_CURRENT_USERQueryValueExr4   )r5   shell_folder_namerB   key	directory_r   r   r   get_win_folder_from_registryc   s   rJ   c                 C   s   dddd | }|du rtd|  td}ttd}|jd|dd	| d
}|D ]}t|dkr8d} nq,|rKtd}|j	|j
|drK|}|j
S )zGet folder with ctypes.   #      r9   Nr:   i   windllr   F   T)r;   r<   ctypescreate_unicode_buffergetattrshell32SHGetFolderPathWordkernel32GetShortPathNameWvalue)r5   csidl_constbufrN   has_high_charcbuf2r   r   r   get_win_folder_via_ctypesy   s,   


r^   c                  C   s4   t tdrtS zdd l} W tS  ty   t Y S w )NrN   r   )hasattrrP   r^   rB   ImportErrorr@   rJ   )rB   r   r   r   _pick_get_win_folder   s   

ra   )maxsize)rP   r   	functoolsr   typingr   r   apir   r   r4   r@   rJ   r^   ra   r   __all__r   r   r   r   <module>   s    K