
    As<ge%                        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
e      ZddZddZddZddZddZ  ed       e             Zd
gZy)zWindows.    )annotationsN)	lru_cache)TYPE_CHECKING   )PlatformDirsABC)Callablec                     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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>`,
    `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
    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      ^/home/kevstigneev/proxy/myenv/lib/python3.12/site-packages/pip/_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| }| j                  |       |S )NF)	appname	appauthorappendopinionversionr   r   join_optionally_create_directory)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_dir7   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_dir=        !!!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_dirB   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_dirG   s4     ww/D EF!!$g!>>r   c                x    t         j                  j                  t        d            }| j	                  |d      S )zd:return: cache directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname\Cache\$version``r&   r2   r   r'   r(   s     r   site_cache_dirzWindows.site_cache_dirP   s4     ww/E FG!!$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_dirV   r.   r   c                    | j                   }| j                  r1t        j                  j	                  |d      }| j                  |       |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(   s     r   user_log_dirzWindows.user_log_dir[   s=     !!<<77<<f-D--d3r   c                R    t         j                  j                  t        d            S )zN: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_dird   s     ww/? @AAr   c                R    t         j                  j                  t        d            S )zN:return: downloads directory tied to the user e.g. ``%USERPROFILE%\Downloads``CSIDL_DOWNLOADSr=   r,   s    r   user_downloads_dirzWindows.user_downloads_diri   s     ww/@ ABBr   c                R    t         j                  j                  t        d            S )zL:return: pictures directory tied to the user e.g. ``%USERPROFILE%\Pictures``CSIDL_MYPICTURESr=   r,   s    r   user_pictures_dirzWindows.user_pictures_dirn   s     ww/A BCCr   c                R    t         j                  j                  t        d            S )zH:return: videos directory tied to the user e.g. ``%USERPROFILE%\Videos``CSIDL_MYVIDEOr=   r,   s    r   user_videos_dirzWindows.user_videos_dirs        ww ?@@r   c                R    t         j                  j                  t        d            S )zF:return: music directory tied to the user e.g. ``%USERPROFILE%\Music``CSIDL_MYMUSICr=   r,   s    r   user_music_dirzWindows.user_music_dirx   rH   r   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   rP   r   
str | NonerO   rP   )__name__
__module____qualname____doc__propertyr   r   r)   r-   r0   r3   r5   r7   r:   r>   rA   rD   rG   rK   rN    r   r   r
   r
      s5   
 ( ( GK  ( (
 " " " " ? ? ? ?
 " "   B B C C D D A A A A ( (r   r
   c                    t        |       }||S ddddj                  |       }|d|  }t        |      t        j                  j                  |      }|d| }t        |      |S )z&Get folder from environment variables.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)
csidl_nameresultenv_var_namemsgs       r   get_win_folder_from_env_varsre      s    5jAF # 1- 
c*o	 
 $ZL1oZZ^^L)F~,\N;oMr   c                B   | dk(  rNt         j                  j                  t         j                  j                  t         j                  d         d      S | dk(  rNt         j                  j                  t         j                  j                  t         j                  d         d      S | dk(  rNt         j                  j                  t         j                  j                  t         j                  d         d      S | dk(  rNt         j                  j                  t         j                  j                  t         j                  d         d	      S | d
k(  rNt         j                  j                  t         j                  j                  t         j                  d         d      S y)zKGet folder for a CSIDL name that does not exist as an environment variable.r<   USERPROFILE	Documentsr@   	DownloadsrC   PicturesrF   VideosrJ   MusicN)r   r   r!   r   r`   )ra   s    r   r]   r]      s   %%ww||BGG,,RZZ-FGUU&&ww||BGG,,RZZ-FGUU''ww||BGG,,RZZ-FGTT_$ww||BGG,,RZZ-FGRR_$ww||BGG,,RZZ-FGQQr   c           	        ddddddddd	j                  |       }|d|  }t        |      t        j                  dk7  rt        dd
l}|j                  |j                  d      }|j                  ||      \  }}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   r<   r@   rC   rF   rJ   Nr\   win32r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)
r^   r_   sysplatformNotImplementedErrorwinregOpenKeyHKEY_CURRENT_USERQueryValueExrP   )ra   shell_folder_namerd   rt   key	directory_s          r   get_win_folder_from_registryr|      s     # 0.$C)##	 
c*o   $ZL1o
||w!!
..113v
wC&&s,=>LIqy>r   c           	        ddddddddd	j                  |       }|d|  }t        |      t        j                  d      }t	        t        d      }|j
                  j                  d
|d
d|       t        d |D              r>t        j                  d      }|j                  j                  |j                  |d      r|}| dk(  r*t        j                  j                  |j                  d      S |j                  S )zGet folder with ctypes.   #         '         (   )r   r&   r   r<   rC   rF   rJ   r@   Nr\   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   r@   ri   )r^   r_   ctypescreate_unicode_buffergetattrshell32SHGetFolderPathWanykernel32GetShortPathNameWvaluer   r   r!   )ra   csidl_constrd   bufr   buf2s         r   get_win_folder_via_ctypesr      s      "!	 
c*o  $ZL1o

&
&t
,CVX&F
NN##D+tQD 
%
%%++D1??,,SYYdCC&&ww||CII{33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)Nr   r   )hasattrr   r   rt   r|   ImportErrorre   )rt   s    r   _pick_get_win_folderr      s9    vx ((, ,+  ,++,s   " 44)maxsize)ra   rP   rO   rP   )ra   rP   rO   rQ   )rO   zCallable[[str], str])rU   
__future__r   r   r   rq   	functoolsr   typingr   apir   collections.abcr   r
   re   r]   r|   r   r   r   __all__rW   r   r   <module>r      so     "  	 
     (t(o t(n*&:!H, )4()=)?@ r   