
    
_d                        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
  G d de
      Zdd	Zdd
ZddZddZ  ed       e             ZdgZy)    )annotationsN)	lru_cache)Callable   )PlatformDirsABCc                      e Zd ZdZedd       ZddddZedd       Zedd       Zedd       Z	edd	       Z
edd
       Zedd       Zedd       Zedd       Zy)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>`.c                    | j                   rdnd}t        j                  j                  t	        |            }| j                  |      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   s      L/usr/lib/python3/dist-packages/pkg_resources/_vendor/platformdirs/windows.pyuser_data_dirzWindows.user_data_dir   s<     $(<<5Jwwu 56!!$''    Nopinion_valuec                  g }| j                   r| j                  dur+| j                  xs | j                   }|j                  |       |j                  | j                          || j                  r|j                  |       | j                  r|j                  | j                         t        j                  j                  |g| S )NF)appname	appauthorappendopinionversionr   r   join)r   r   r   paramsauthors        r   r   zWindows._append_parts!   s    <<~~U*74<<f%MM$,,'(T\\m,||dll+ww||D*6**r   c                t    t         j                  j                  t        d            }| j	                  |      S )zT:return: data directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname``CSIDL_COMMON_APPDATAr   r   r   r   r   r   r   s     r   site_data_dirzWindows.site_data_dir.   s/     ww/E FG!!$''r   c                    | j                   S )zC:return: config directory tied to the user, same as `user_data_dir`r   r   s    r   user_config_dirzWindows.user_config_dir4        !!!r   c                    | j                   S )zF:return: config directory shared by the users, same as `site_data_dir`)r'   r*   s    r   site_config_dirzWindows.site_config_dir9   r,   r   c                x    t         j                  j                  t        d            }| j	                  |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&   s     r   user_cache_dirzWindows.user_cache_dir>   s4     ww/D EF!!$g!>>r   c                    | j                   S )zB:return: state directory tied to the user, same as `user_data_dir`r)   r*   s    r   user_state_dirzWindows.user_state_dirG   r,   r   c                v    | j                   }| j                  r t        j                  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&   s     r   user_log_dirzWindows.user_log_dirL   s/    
 !!<<77<<f-Dr   c                R    t         j                  j                  t        d            S )z`
        :return: documents directory tied to the user e.g. ``%USERPROFILE%\Documents``
        CSIDL_PERSONAL)r   r   r   r   r*   s    r   user_documents_dirzWindows.user_documents_dirV   s    
 ww/? @AAr   c                    t         j                  j                  t         j                  j                  t	        d      d            }| j                  |      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&   s     r   user_runtime_dirzWindows.user_runtime_dir]   s?     ww^<Q-RTZ [\!!$''r   )returnstr)r   r>   r   z
str | Noner=   r>   )__name__
__module____qualname____doc__propertyr   r   r'   r+   r.   r1   r3   r6   r9   r<    r   r   r	   r	      s    = ( ( GK + ( (
 " " " " ? ? " "   B B ( (r   r	   c                T   | dk(  rNt         j                  j                  t         j                  j                  t         j                  d         d      S ddddj                  |       }|t        d|        t         j                  j                  |      }|t        d	|       |S )
z&Get folder from environment variables.r8   USERPROFILE	DocumentsAPPDATAALLUSERSPROFILELOCALAPPDATA)r   r$   r   Unknown CSIDL name: zUnset environment variable: )r   r   r    r   environget
ValueError)
csidl_nameenv_var_nameresults      r   get_win_folder_from_env_varsrR   g   s    %%ww||BGG,,RZZ-FGUU # 1- 
c*o	 
 /
|<==ZZ^^L)F~7~FGGMr   c                    dddddj                  |       }|t        d|        t        j                  dk7  rt        d	dl}|j                  |j                  d
      }|j                  ||      \  }}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 AppDataPersonalr   r$   r   r8   NrK   win32r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)
rM   rN   sysplatformNotImplementedErrorwinregOpenKeyHKEY_CURRENT_USERQueryValueExr>   )rO   shell_folder_namer[   key	directory_s         r   get_win_folder_from_registryrc   y   s     # 0.$	
 
c*o   /
|<==
||w!!
..113v
wC&&s,=>LIqy>r   c                   dddddj                  |       }|t        d|        t        j                  d      }t	        t        d	      }|j
                  j                  d|dd
|       t        d |D              r>t        j                  d      }|j                  j                  |j                  |d      r|}|j                  S )zGet folder with ctypes.   #         rV   NrK   i   windllr   c              3  8   K   | ]  }t        |      d kD    yw)   N)ord).0cs     r   	<genexpr>z,get_win_folder_via_ctypes.<locals>.<genexpr>   s     
%A3q6C<
%s   )rM   rN   ctypescreate_unicode_buffergetattrshell32SHGetFolderPathWanykernel32GetShortPathNameWvalue)rO   csidl_constbufri   buf2s        r   get_win_folder_via_ctypesr|      s      "!	
 
c*o  /
|<==

&
&t
,CVX&F
NN##D+tQD 
%
%%++D1??,,SYYdCC99r   c                 n    t        t        d      rt        S 	 dd l} t        S # t
        $ r	 t        cY S w xY w)Nri   r   )hasattrrp   r|   r[   rc   ImportErrorrR   )r[   s    r   _pick_get_win_folderr      s9    vx ((, ,+  ,++,s   " 44)maxsize)rO   r>   r=   r>   )r=   zCallable[[str], str])
__future__r   rp   r   rX   	functoolsr   typingr   apir   r	   rR   rc   r|   r   r   __all__rD   r   r   <module>r      s`    "  	 
    X(o X(v$00, )4()=)?@ r   