o
    ðT·jŽA  ã                   @  s  U 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mZ ddlmZ er7dd	lmZ d
Zded< G dd„ deƒZd7dd„Zd8dd„Zd9dd„Zd7dd„Zddddd d!d"d#d$d%d&d'œZd(ed)< ed:d+d,„ƒZd7d-d.„Zd:d/d0„Zeƒ Zd7d1d2„Zd;d5d6„ZdgZdS )<zWindows.é    )ÚannotationsN)Úcache)ÚPath)ÚTYPE_CHECKINGÚFinalé   )ÚPlatformDirsABC)ÚCallablei @  z
Final[int]Ú_KF_FLAG_DONT_VERIFYc                   @  sš  e Zd ZdZedAdd„ƒZddœdBdd„ZedAdd„ƒZedAdd„ƒZedAdd„ƒZ	edAdd„ƒZ
edAdd„ƒZedAdd„ƒZedAdd„ƒZedAdd„ƒZedAdd„ƒZedAdd „ƒZedAd!d"„ƒZedAd#d$„ƒZedAd%d&„ƒZedAd'd(„ƒZedAd)d*„ƒZedAd+d,„ƒZedAd-d.„ƒZedAd/d0„ƒZedAd1d2„ƒZedAd3d4„ƒZedAd5d6„ƒZedAd7d8„ƒZedAd9d:„ƒZedAd;d<„ƒZedAd=d>„ƒZedAd?d@„ƒZ dS )CÚ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«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   úW/home/dinkstrade/pdmp-scanner/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 )zLData 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_dir5   s   
zWindows.site_data_dirc                 C  ó   | j S )z;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+   )z:Config directory shared by users, same as `site_data_dir`.©r*   r-   r   r   r   Úsite_config_dir@   r/   zWindows.site_config_dirc                 C  ó   t j tdƒ¡}| j|dd�S )z¤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_dirE   ó   zWindows.user_cache_dirc                 C  r2   )z\Cache directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname\Cache\$version``.r'   r3   r   r(   r)   r   r   r   Úsite_cache_dirK   r5   zWindows.site_cache_dirc                 C  r+   )z:State directory tied to the user, same as `user_data_dir`.r,   r-   r   r   r   Úuser_state_dirQ   r/   zWindows.user_state_dirc                 C  r+   )z9State directory shared by users, same as `site_data_dir`.r0   r-   r   r   r   Úsite_state_dirV   r/   zWindows.site_state_dirc                 C  ó(   | j }| jrtj |d¡}|  |¡ |S )z_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[   ó
   
zWindows.user_log_dirc                 C  r9   )z^Log directory shared by users, same as `site_data_dir` if not opinionated else ``Logs`` in it.r:   )r*   r!   r   r   r#   r$   r)   r   r   r   Úsite_log_dird   r<   zWindows.site_log_dirc                 C  ó   t j tdƒ¡S )zFDocuments directory tied to the user e.g. ``%USERPROFILE%\Documents``.ÚCSIDL_PERSONAL©r   r   r   r   r-   r   r   r   Úuser_documents_dirm   ó   zWindows.user_documents_dirc                 C  r>   )zFDownloads directory tied to the user e.g. ``%USERPROFILE%\Downloads``.ÚCSIDL_DOWNLOADSr@   r-   r   r   r   Úuser_downloads_dirr   rB   zWindows.user_downloads_dirc                 C  r>   )zDPictures directory tied to the user e.g. ``%USERPROFILE%\Pictures``.ÚCSIDL_MYPICTURESr@   r-   r   r   r   Úuser_pictures_dirw   rB   zWindows.user_pictures_dirc                 C  r>   )z@Videos directory tied to the user e.g. ``%USERPROFILE%\Videos``.ÚCSIDL_MYVIDEOr@   r-   r   r   r   Úuser_videos_dir|   rB   zWindows.user_videos_dirc                 C  r>   )z>Music directory tied to the user e.g. ``%USERPROFILE%\Music``.ÚCSIDL_MYMUSICr@   r-   r   r   r   Úuser_music_dir�   rB   zWindows.user_music_dirc                 C  r>   )zCDesktop directory tied to the user, e.g. ``%USERPROFILE%\Desktop``.ÚCSIDL_DESKTOPDIRECTORYr@   r-   r   r   r   Úuser_desktop_dir†   rB   zWindows.user_desktop_dirc                 C  s   t j t j d¡¡S )zEProjects directory tied to the user, e.g. ``%USERPROFILE%\Projects``.z
~/Projects)r   r   r   Ú
expanduserr-   r   r   r   Úuser_projects_dir‹   s   zWindows.user_projects_dirc                 C  s2   t j d¡ }sttdƒ ¡ jd ƒ}t j |¡S )z0Public share directory e.g. ``C:\Users\Public``.ÚPUBLICú~ÚPublic)	r   ÚenvironÚgetr   r   rM   Úparentr   r   r)   r   r   r   Úuser_publicshare_dir�   s   zWindows.user_publicshare_dirc                 C  ó$   t j tttdƒƒd d d ƒ¡S )zTTemplates directory tied to the user e.g. ``%APPDATA%\Microsoft\Windows\Templates``.r   Ú	Microsoftr   Ú	Templates©r   r   r   r   r   r   r-   r   r   r   Úuser_templates_dir—   ó   $zWindows.user_templates_dirc                 C  rV   )zQFonts directory tied to the user e.g. ``%LOCALAPPDATA%\Microsoft\Windows\Fonts``.r   rW   r   ÚFontsrY   r-   r   r   r   Úuser_fonts_dirœ   r[   zWindows.user_fonts_dirc                 C  r+   )zCPreference directory tied to the user, same as ``user_config_dir``.)r.   r-   r   r   r   Úuser_preference_dir¡   r/   zWindows.user_preference_dirc                 C  ó   t j t j tdƒd¡¡S )zABin directory tied to the user, e.g. ``%LOCALAPPDATA%\Programs``.r   ÚPrograms©r   r   r   r#   r   r-   r   r   r   Úuser_bin_dir¦   ó   zWindows.user_bin_dirc                 C  r_   )z;Bin directory shared by users, e.g. ``C:\ProgramData\bin``.r'   Úbinra   r-   r   r   r   Úsite_bin_dir«   rc   zWindows.site_bin_dirc                 C  r>   )zFApplications directory tied to the user, e.g. ``Start Menu\Programs``.ÚCSIDL_PROGRAMSr@   r-   r   r   r   Úuser_applications_dir°   rB   zWindows.user_applications_dirc                 C  r>   )zfApplications directory shared by users, e.g. ``C:\ProgramData\Microsoft\Windows\Start Menu\Programs``.ÚCSIDL_COMMON_PROGRAMSr@   r-   r   r   r   Úsite_applications_dirµ   rB   zWindows.site_applications_dirc                 C  s$   t j t j tdƒd¡¡}|  |¡S )zbRuntime 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+   )z>Runtime directory shared by users, same as `user_runtime_dir`.)rk   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.   r1   r4   r6   r7   r8   r;   r=   rA   rD   rF   rH   rJ   rL   rN   rU   rZ   r]   r^   rb   re   rg   ri   rk   rl   r   r   r   r   r      sr    	r   Ú
csidl_namer   r   c                 C  sf   t | ƒ}|dur
|S ddddœ | ¡}|du r d| › �}t|ƒ‚tj |¡ }s1d|› �}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_varrS   Ú
ValueErrorr   rR   )rr   ÚresultÚenv_var_nameÚmsgr   r   r   Úget_win_folder_from_env_varsÆ   s    ýü

r|   r   c                 C  s4  | dkrt j t j tdƒ¡d¡S | dkr"t j t j tdƒ¡d¡S | dkr3t j t j tdƒ¡d¡S | dkrDt j t j tdƒ¡d	¡S | d
krUt j t j tdƒ¡d¡S | dkrft j t j tdƒ¡d¡S | dkrzt j t j tdƒ¡dddd¡S | dkr˜t j t j t j d¡p‘t j d¡p‘d¡dddd¡S dS )zMGet a folder for a CSIDL name that does not exist as an environment variable.r?   ÚUSERPROFILEÚ	DocumentsrC   Ú	DownloadsrE   ÚPicturesrG   ÚVideosrI   ÚMusicrK   ÚDesktoprf   rs   rW   r   z
Start Menur`   rh   ÚPROGRAMDATArt   zC:\ProgramDataN)r   r   r#   r   Ú_non_empty_envrR   rS   ©rr   r   r   r   rw   Ú   s:   û"ûrw   Únamec                 C  s   t j | ¡ }r
|S t| ƒ‚)N)r   rR   rS   ÚKeyError)r‡   Úvaluer   r   r   r…     s   r…   c           	      C  s¸   ddh}ddddddd	d
ddddœ  | ¡}|du r"d| › �}t|ƒ‚tjdkr)t‚ddl}| |v r4|jn|j}| |d¡�}| 	||¡\}}W d  ƒ t
|ƒS 1 sSw   Y  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'   rh   ÚAppDatazCommon AppDatazLocal AppDataÚPersonalú&{374DE290-123F-4565-9164-39C4925E467B}zMy PictureszMy VideozMy Musicrƒ   r`   zCommon Programs)r   r'   r   r?   rC   rE   rG   rI   rK   rf   rh   Nrv   Úwin32r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)rS   rx   ÚsysÚplatformÚNotImplementedErrorÚwinregÚHKEY_LOCAL_MACHINEÚHKEY_CURRENT_USERÚOpenKeyÚQueryValueExr   )	rr   Úmachine_namesÚshell_folder_namer{   r‘   ÚhkeyÚkeyÚ	directoryÚ_r   r   r   Úget_win_folder_from_registry  s<   þõô


ÿþrœ   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}rŒ   z&{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}z&{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}z&{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8})r   r'   r   r?   rE   rG   rI   rC   rK   rf   rh   zdict[str, str]Ú_KNOWN_FOLDER_GUIDSúCallable[[str], str]c                    sÀ   t jdkrt‚ddl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‡ ‡‡‡‡fdd„}|S )z’Build the resolver once; a fresh ``_GUID`` per call leaks ctypes pointer types.

    See https://github.com/tox-dev/platformdirs/issues/501.

    r�   r   )ÚHRESULTÚPOINTERÚ	StructureÚWinDLLÚbyrefÚwintypesc                      s4   e Zd Zd” jfd” jfd” jfd” jd fgZdS )z/_build_get_win_folder_via_ctypes.<locals>._GUIDÚData1ÚData2ÚData3ÚData4é   N)rm   rn   ro   ÚDWORDÚWORDÚBYTEÚ_fields_r   )r¤   r   r   Ú_GUIDP  s    ür®   Úole32NÚshell32rr   r   r   c                   sˆ   t  | ¡}|d u rd| › �}t|ƒ‚ˆ ƒ }ˆ |ˆ|ƒ¡ ˆ ¡ }ˆ ˆ|ƒtd ˆ|ƒ¡ |j}ˆ |¡ |d u rBd| › �}t|ƒ‚|S )Nrv   z'SHGetKnownFolderPath returned NULL for )	r�   rS   rx   ÚCLSIDFromStringÚLPWSTRÚSHGetKnownFolderPathr
   r‰   ÚCoTaskMemFree)rr   Úfolder_guidr{   ÚguidÚpath_ptrry   ©r®   r£   r¯   r°   r¤   r   r   Úresolveb  s   



z1_build_get_win_folder_via_ctypes.<locals>.resolve©rr   r   r   r   )rŽ   r�   r�   ÚctypesrŸ   r    r¡   r¢   r£   r¤   r±   ÚrestypeÚ	LPCOLESTRÚargtypesr´   ÚLPVOIDr³   rª   ÚHANDLEr²   )rŸ   r    r¡   r¢   r¹   r   r¸   r   Ú _build_get_win_folder_via_ctypes>  s   
 	rÁ   c                 C  s
   t ƒ | ƒS )z Get folder via :func:`SHGetKnownFolderPath`.

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

    )rÁ   r†   r   r   r   Úget_win_folder_via_ctypesy  s   
rÂ   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Â   r‘   r|   rœ   )r»   r‘   r   r   r   Ú_pick_get_win_folder‚  s   
ýÿ
ýÿrÄ   c                 C  s6   d|   d¡› �}ttj |d¡ ¡  }ƒr|S t| ƒS )zÓGet a Windows folder path, checking for ``WIN_PD_OVERRIDE_*`` environment variable overrides first.

    For example, ``CSIDL_LOCAL_APPDATA`` can be overridden by setting ``WIN_PD_OVERRIDE_LOCAL_APPDATA``.

    ÚWIN_PD_OVERRIDE_ÚCSIDL_Ú )ÚremoveprefixÚ_is_fully_qualifiedr   rR   rS   ÚstripÚ_resolve_win_folder)rr   Úenv_varÚoverrider   r   r   r   •  s   r   r   Úboolc                 C  s*   t  | ¡\}}| d¡pt|ƒo| d¡S )N)ú\ú/)ÚntpathÚ
splitdriveÚ
startswithrÎ   )r   ÚdriveÚtailr   r   r   rÉ   ¡  s   rÉ   rº   )rr   r   r   r   )r‡   r   r   r   )r   rž   )r   r   r   rÎ   ) rp   Ú
__future__r   rÑ   r   rŽ   Ú	functoolsr   Úpathlibr   Útypingr   r   Úapir   Úcollections.abcr	   r
   Ú__annotations__r   r|   rw   r…   rœ   r�   rÁ   rÂ   rÄ   rË   r   rÉ   Ú__all__r   r   r   r   Ú<module>   sN     
2

(
(õ
:
	

ÿ