a [f@sddlZddlZddlmZddlmZmZddlmZGdddeZ e e dd d Z e e dd d Z e e dd dZ ee ge fdddZeddeZdgZdS)N) lru_cache)CallableOptional)PlatformDirsABCc@seZdZdZeedddZddeeeeddd Zeedd d Z eedd d Z eedddZ eedddZ eedddZ eedddZeedddZeedddZdS)Windowsa`MSDN on where to store app data files `_. Makes use of the `appname `, `appauthor `, `version `, `roaming `, `opinion `.returncCs(|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)Zroamingospathnormpathget_win_folder _append_parts)selfconstr rD/usr/lib/python3.9/site-packages/pip/_vendor/platformdirs/windows.py user_data_dirszWindows.user_data_dirN opinion_value)r rr cCstg}|jr`|jdur*|jp|j}||||j|durN|jrN|||jr`||jtjj|g|RS)NF)ZappnameZ appauthorappendopinionversionr r join)rr rparamsZauthorrrrrs      zWindows._append_partscCstjtd}||S)zT:return: data directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname``CSIDL_COMMON_APPDATAr r rrrrr rrr site_data_dir+szWindows.site_data_dircCs|jS)zC:return: config directory tied to the user, same as `user_data_dir`rrrrruser_config_dir1szWindows.user_config_dircCs|jS)zF:return: config directory shared by the users, same as `site_data_dir`)r r"rrrsite_config_dir6szWindows.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 ZCacherrrrrruser_cache_dir;szWindows.user_cache_dircCs|jS)zB:return: state directory tied to the user, same as `user_data_dir`r!r"rrruser_state_dirDszWindows.user_state_dircCs|j}|jrtj|d}|S)zy :return: log directory tied to the user, same as `user_data_dir` if not opinionated else ``Logs`` in it ZLogs)rrr r rrrrr user_log_dirIszWindows.user_log_dircCstjtdS)z` :return: documents directory tied to the user e.g. ``%USERPROFILE%\Documents`` CSIDL_PERSONAL)r r rrr"rrruser_documents_dirSszWindows.user_documents_dircCs$tjtjtdd}||S)z :return: runtime directory tied to the user, e.g. ``%USERPROFILE%\AppData\Local\Temp\$appauthor\$appname`` r ZTemp)r r rrrrrrrruser_runtime_dirZszWindows.user_runtime_dir)__name__ __module__ __qualname____doc__propertystrrrrr r#r$r%r&r'r)r*rrrrr s(    r) csidl_namer cCsr|dkr$tjtjtjddSdddd|}|durLtd |tj|}|durntd ||S) z&Get folder from environment variables.r( USERPROFILEZ DocumentsAPPDATAZALLUSERSPROFILEZ LOCALAPPDATA)r rr NUnknown CSIDL name: zUnset environment variable: )r r rrenvironget ValueError)r1Z env_var_nameresultrrrget_win_folder_from_env_varsds r9cCsXddddd|}|dur*td|ddl}||jd }|||\}}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. ZAppDatazCommon AppDataz Local AppDataZPersonalr rr r(Nr4rz@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)r6r7winregOpenKeyHKEY_CURRENT_USERZ QueryValueExr0)r1Zshell_folder_namer;keyZ directory_rrrget_win_folder_from_registryvsr@cCsddddd|}|dur*td|td}ttd }|jd|dd |td d |Drtd}|j |j |dr|}|j S) zGet folder with ctypes.#r:Nr4iwindllrcss|]}t|dkVqdS)N)ord).0crrr z,get_win_folder_via_ctypes..) r6r7ctypesZcreate_unicode_buffergetattrZshell32ZSHGetFolderPathWanyZkernel32ZGetShortPathNameWvalue)r1Z csidl_constbufrEZbuf2rrrget_win_folder_via_ctypess"   rQrcCs:ttdrtSz ddl}Wnty0tYS0tSdS)NrEr)hasattrrLrQr; ImportErrorr9r@)r;rrr_pick_get_win_folders    rT)maxsize)rLr functoolsrtypingrrZapirrr0r9r@rQrTr__all__rrrrs  [