o
    ⹏i.                  
   @  s   U 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m	Z	 ddl
mZ er-ddlmZ d	Zd
ed< G dd deZd*ddZd+ddZd*ddZddddddddd d!	Zd"ed#< d*d$d%Zd,d'd(Zedd)e ZdgZdS )-zWindows.    )annotationsN)	lru_cache)TYPE_CHECKINGFinal   )PlatformDirsABC)Callablei @  z
Final[int]_KF_FLAG_DONT_VERIFYc                   @  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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 <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>`.

    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   Q/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/platformdirs/windows.pyuser_data_dir   s   
zWindows.user_data_dirNopinion_valuer   r   
str | Nonec                C  s   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_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_dir8   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_dir>      zWindows.user_config_dirc                 C  r*   )zB:return: config directory shared by users, same as `site_data_dir`)r)   r,   r   r   r   site_config_dirC   r.   zWindows.site_config_dirc                 C     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_dirH   s   zWindows.user_cache_dirc                 C  r0   )zd:return: cache directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname\Cache\$version``r&   r1   r   r'   r(   r   r   r   site_cache_dirQ   s   zWindows.site_cache_dirc                 C  r*   )zB:return: state directory tied to the user, same as `user_data_dir`r+   r,   r   r   r   user_state_dirW   r.   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_dir\   s
   
zWindows.user_log_dirc                 C     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_dire      zWindows.user_documents_dirc                 C  r7   )zN:return: downloads directory tied to the user e.g. ``%USERPROFILE%\Downloads``CSIDL_DOWNLOADSr9   r,   r   r   r   user_downloads_dirj   r;   zWindows.user_downloads_dirc                 C  r7   )zL:return: pictures directory tied to the user e.g. ``%USERPROFILE%\Pictures``CSIDL_MYPICTURESr9   r,   r   r   r   user_pictures_diro   r;   zWindows.user_pictures_dirc                 C  r7   )zH:return: videos directory tied to the user e.g. ``%USERPROFILE%\Videos``CSIDL_MYVIDEOr9   r,   r   r   r   user_videos_dirt   r;   zWindows.user_videos_dirc                 C  r7   )zF:return: music directory tied to the user e.g. ``%USERPROFILE%\Music``CSIDL_MYMUSICr9   r,   r   r   r   user_music_diry   r;   zWindows.user_music_dirc                 C  r7   )zK:return: desktop directory tied to the user, e.g. ``%USERPROFILE%\Desktop``CSIDL_DESKTOPDIRECTORYr9   r,   r   r   r   user_desktop_dir~   r;   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   Temp)r   r   r   r"   r   r   r(   r   r   r   user_runtime_dir   s   
zWindows.user_runtime_dirc                 C  r*   )zF:return: runtime directory shared by users, same as `user_runtime_dir`)rG   r,   r   r   r   site_runtime_dir   r.   zWindows.site_runtime_dir)r   r   )r   r   r   r   r   r   )__name__
__module____qualname____doc__propertyr   r   r)   r-   r/   r2   r3   r4   r6   r:   r=   r?   rA   rC   rE   rG   rH   r   r   r   r   r
      sF    

r
   
csidl_namer   r   c                 C  sj   t | }|dur
|S dddd| }|du r d|  }t|tj|}|du r3d| }t||S )z&Get folder from environment variables.N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)rN   resultenv_var_namemsgr   r   r   get_win_folder_from_env_vars   s"   

rZ   r   c                 C  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kr6t jt jt jd dS | dkrHt jt jt jd d	S | d
krZt 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.r8   USERPROFILE	Documentsr<   	Downloadsr>   Picturesr@   VideosrB   MusicN)r   r   r"   r   rV   )rN   r   r   r   rS      s   rS   c           	   	   C  s   dh}dddddddd	d
 | }|du rd|  }t|tjdkr%tddl}| |v r0|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 AppDataPersonal&{374DE290-123F-4565-9164-39C4925E467B}zMy PictureszMy VideozMy Music)r   r&   r   r8   r<   r>   r@   rB   NrR   win32r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)rT   rU   sysplatformNotImplementedErrorwinregHKEY_LOCAL_MACHINEHKEY_CURRENT_USEROpenKeyQueryValueExr   )	rN   machine_namesshell_folder_namerY   rh   hkeykey	directory_r   r   r   get_win_folder_from_registry   s.   		


rs   z&{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}z&{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}z&{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}z&{FDD39AD0-238F-46AF-ADB4-6C85480369C7}z&{33E28130-4E1E-4676-835A-98395C3BC3BB}z&{18989B1D-99B5-455B-841C-AB7C74E4DDFC}z&{4BD8D571-6D19-48D3-BE97-422220080E43}rc   z&{B4BFCC3A-DB2C-424C-B029-7FE99A87C641})	r   r&   r   r8   r>   r@   rB   r<   rD   zdict[str, str]_KNOWN_FOLDER_GUIDSc                   s  t jdkrtddlm}m}m}m}m}m	}m
  G  fddd|}|d}||j_ j||g|j_d|j_ jg|j_|d}	||	j_|| j j| jg|	j_|d	}
 j|
j_ j j jg|
j_t| }|du rzd
|  }t|| }||||   }|	||td|| |j}|| |du rd|  }t|tdd |D r|d}|
||dr|j}|S )z
    Get folder via :func:`SHGetKnownFolderPath`.

    See https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath.

    rd   r   )HRESULTPOINTER	StructureWinDLLbyrefcreate_unicode_bufferwintypesc                      s4   e Zd Zd jfd jfd jfd jd fgZdS )z(get_win_folder_via_ctypes.<locals>._GUIDData1Data2Data3Data4   N)rI   rJ   rK   DWORDWORDBYTE_fields_r   r{   r   r   _GUID   s    r   ole32Nshell32kernel32rR   z'SHGetKnownFolderPath returned NULL for 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>i   )re   rf   rg   ctypesru   rv   rw   rx   ry   rz   r{   CLSIDFromStringrestype	LPCOLESTRargtypesCoTaskMemFreeLPVOIDSHGetKnownFolderPathr   HANDLELPWSTRGetShortPathNameWrt   rT   rU   r	   valueany)rN   ru   rv   rw   rx   ry   rz   r   r   r   r   folder_guidrY   guidpath_ptrrW   bufr   r   r   get_win_folder_via_ctypes   sB   
$




r   Callable[[str], str]c                  C  sH   zddl } W tS  ty   Y nw zddl}W tS  ty#   t Y S w )zjSelect the best method to resolve Windows folder paths: ctypes, then registry, then environment variables.r   N)r   ImportErrorr   rh   rZ   rs   )r   rh   r   r   r   _pick_get_win_folder%  s   

r   )maxsize)rN   r   r   r   )rN   r   r   r   )r   r   )rL   
__future__r   r   re   	functoolsr   typingr   r   apir   collections.abcr   r	   __annotations__r
   rZ   rS   rs   rt   r   r   r   __all__r   r   r   r   <module>   s:    


%

: