U e'@sdZddlmZddlZddlZddlZddlmZddlm Z ddl m Z e r\ddl m Z Gd d d e Zd d d d dZd dd ddZd d d ddZd d d ddZddddZeddeZd gZdS)zWindows.) annotationsN) lru_cache) TYPE_CHECKING)PlatformDirsABC)Callablec@sHeZdZdZeddddZdddddd d d Zeddd d ZeddddZeddddZ eddddZ eddddZ eddddZ eddddZ eddddZeddddZeddddZeddd d!Zeddd"d#Zeddd$d%Zeddd&d'Zeddd(d)ZdS)*Windowsa `MSDN on where to store app data files `_. Makes use of the `appname `, `appauthor `, `version `, `roaming `, `opinion `, `ensure_exists `. strreturncCs(|jr dnd}tjt|}||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_APPDATACSIDL_LOCAL_APPDATA)roamingospathnormpathget_win_folder _append_parts)selfconstrrB/opt/hc_python/lib/python3.8/site-packages/platformdirs/windows.py user_data_dirszWindows.user_data_dirN opinion_value str | None)rrr cCsg}|jr`|jdk r*|jp|j}||||j|dk rN|jrN|||jr`||jtjj|f|}|||S)NF) appname appauthorappendopinionversionrrjoin_optionally_create_directory)rrrparamsauthorrrrr)s       zWindows._append_partscCstjtd}||S)zT:return: data directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname``CSIDL_COMMON_APPDATArrrrrrrrrr site_data_dir8szWindows.site_data_dircCs|jS)zC:return: config directory tied to the user, same as `user_data_dir`rrrrruser_config_dir>szWindows.user_config_dircCs|jS)zF:return: config directory shared by the users, same as `site_data_dir`)r(r*rrrsite_config_dirCszWindows.site_config_dircCstjtd}|j|ddS)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 Cacherr&r'rrruser_cache_dirHszWindows.user_cache_dircCstjtd}|j|ddS)zd:return: cache directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname\Cache\$version``r%r-rr&r'rrrsite_cache_dirQszWindows.site_cache_dircCs|jS)zB:return: state directory tied to the user, same as `user_data_dir`r)r*rrruser_state_dirWszWindows.user_state_dircCs(|j}|jr$tj|d}|||S)zg:return: log directory tied to the user, same as `user_data_dir` if not opinionated else ``Logs`` in itZLogs)rrrrr!r"r'rrr user_log_dir\s  zWindows.user_log_dircCstjtdS)zN:return: documents directory tied to the user e.g. ``%USERPROFILE%\Documents``CSIDL_PERSONALrrrrr*rrruser_documents_direszWindows.user_documents_dircCstjtdS)zN:return: downloads directory tied to the user e.g. ``%USERPROFILE%\Downloads``CSIDL_DOWNLOADSr3r*rrruser_downloads_dirjszWindows.user_downloads_dircCstjtdS)zL:return: pictures directory tied to the user e.g. ``%USERPROFILE%\Pictures``CSIDL_MYPICTURESr3r*rrruser_pictures_diroszWindows.user_pictures_dircCstjtdS)zH:return: videos directory tied to the user e.g. ``%USERPROFILE%\Videos`` CSIDL_MYVIDEOr3r*rrruser_videos_dirtszWindows.user_videos_dircCstjtdS)zF:return: music directory tied to the user e.g. ``%USERPROFILE%\Music`` CSIDL_MYMUSICr3r*rrruser_music_diryszWindows.user_music_dircCstjtdS)zK:return: desktop directory tied to the user, e.g. ``%USERPROFILE%\Desktop``CSIDL_DESKTOPDIRECTORYr3r*rrruser_desktop_dir~szWindows.user_desktop_dircCs$tjtjtdd}||S)z :return: runtime directory tied to the user, e.g. ``%USERPROFILE%\AppData\Local\Temp\$appauthor\$appname`` r ZTemp)rrrr!rrr'rrruser_runtime_dirszWindows.user_runtime_dircCs|jS)zF:return: runtime directory shared by users, same as `user_runtime_dir`)r?r*rrrsite_runtime_dirszWindows.site_runtime_dir)__name__ __module__ __qualname____doc__propertyrrr(r+r,r.r/r0r1r4r6r8r:r<r>r?r@rrrrrsD  rr ) csidl_namer cCsjt|}|dk r|Sdddd|}|dkr@d|}t|tj|}|dkrfd|}t||S)z&Get folder from environment variables.NAPPDATAZALLUSERSPROFILE LOCALAPPDATA)r r%r Unknown CSIDL name: zUnset environment variable: )(get_win_folder_if_csidl_name_not_env_varget ValueErrorrenviron)rFresultZ env_var_namemsgrrrget_win_folder_from_env_varss"   rPrcCs|dkr$tjtjtjddS|dkrHtjtjtjddS|dkrltjtjtjddS|dkrtjtjtjdd S|d krtjtjtjdd Sd S) zKGet folder for a CSIDL name that does not exist as an environment variable.r2 USERPROFILEZ Documentsr5 Downloadsr7ZPicturesr9ZVideosr;ZMusicN)rrr!rrM)rFrrrrJsrJc Csrddddddddd |}|d kr6d |}t|tjd krDtd d l}||jd}|||\}}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. ZAppDatazCommon AppDataz Local AppDataZPersonalz&{374DE290-123F-4565-9164-39C4925E467B}z My PictureszMy VideozMy Music)r r%r r2r5r7r9r;NrIwin32rz@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders) rKrLsysplatformNotImplementedErrorwinregOpenKeyHKEY_CURRENT_USER QueryValueExr )rFZshell_folder_namerOrWkey directory_rrrget_win_folder_from_registrys(    r^c Csddddddddd d |}|d kr8d |}t|td }ttd}|jd |d d|tdd|Drtd }|j |j |d r|}|dkrt j |j dS|j S)zGet folder with ctypes.#' () r r%r r2r7r9r;r5r=NrIiwindllrcss|]}t|dkVqdS)N)ord).0crrr sz,get_win_folder_via_ctypes..r5rR)rKrLctypesZcreate_unicode_buffergetattrZshell32ZSHGetFolderPathWanykernel32ZGetShortPathNameWvaluerrr!)rFZ csidl_constrObufrhZbuf2rrrget_win_folder_via_ctypess2      rtzCallable[[str], str]r cCs<ttdrtSz ddl}Wntk r2tYSXtSdS)Nrhr)hasattrrnrtrW ImportErrorrPr^)rWrrr_pick_get_win_folders   rw)maxsize)rD __future__rrnrrT functoolsrtypingrapircollections.abcrrrPrJr^rtrwr__all__rrrrs&     %