
    li8                        U d Z ddlmZ ddlZddl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e	      Zd!dZd"dZd!dZddddddddddddZded<   d!dZd#dZ e       Zd!d ZdgZy)$zWindows.    )annotationsN)TYPE_CHECKINGFinal   )PlatformDirsABC)Callablei @  z
Final[int]_KF_FLAG_DONT_VERIFYc                     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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 <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>`.

    c                    | j                   rdnd}t        j                  j                  t	        |            }| j                  |      S )z:returns: 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      P/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/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 )zU:returns: 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_dir2   s/     ww/E FG!!$''r   c                    | j                   S )zD:returns: config directory tied to the user, same as `user_data_dir`r   r   s    r   user_config_dirzWindows.user_config_dir8        !!!r   c                    | j                   S )zC:returns: config directory shared by users, same as `site_data_dir`r*   r-   s    r   site_config_dirzWindows.site_config_dir=   r/   r   c                x    t         j                  j                  t        d            }| j	                  |d      S )z:returns: 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_dirB   s4     ww/D EF!!$g!>>r   c                x    t         j                  j                  t        d            }| j	                  |d      S )ze:returns: cache directory shared by users, e.g. ``C:\ProgramData\$appauthor\$appname\Cache\$version``r'   r4   r   r(   r)   s     r   site_cache_dirzWindows.site_cache_dirH   s4     ww/E FG!!$g!>>r   c                    | j                   S )zC:returns: state directory tied to the user, same as `user_data_dir`r,   r-   s    r   user_state_dirzWindows.user_state_dirN   r/   r   c                    | j                   S )zB:returns: state directory shared by users, same as `site_data_dir`r1   r-   s    r   site_state_dirzWindows.site_state_dirS   r/   r   c                    | j                   }| j                  r1t        j                  j	                  |d      }| j                  |       |S )zh:returns: 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_dirX   =     !!<<77<<f-D--d3r   c                    | j                   }| j                  r1t        j                  j	                  |d      }| j                  |       |S )zg:returns: log directory shared by users, same as `site_data_dir` if not opinionated else ``Logs`` in itr=   )r*   r    r   r   r"   r#   r)   s     r   site_log_dirzWindows.site_log_dira   r?   r   c                R    t         j                  j                  t        d            S )zO:returns: 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_dirj        ww/? @AAr   c                R    t         j                  j                  t        d            S )zO:returns: downloads directory tied to the user e.g. ``%USERPROFILE%\Downloads``CSIDL_DOWNLOADSrD   r-   s    r   user_downloads_dirzWindows.user_downloads_diro   s     ww/@ ABBr   c                R    t         j                  j                  t        d            S )zM:returns: pictures directory tied to the user e.g. ``%USERPROFILE%\Pictures``CSIDL_MYPICTURESrD   r-   s    r   user_pictures_dirzWindows.user_pictures_dirt   s     ww/A BCCr   c                R    t         j                  j                  t        d            S )zI:returns: videos directory tied to the user e.g. ``%USERPROFILE%\Videos``CSIDL_MYVIDEOrD   r-   s    r   user_videos_dirzWindows.user_videos_diry        ww ?@@r   c                R    t         j                  j                  t        d            S )zG:returns: music directory tied to the user e.g. ``%USERPROFILE%\Music``CSIDL_MYMUSICrD   r-   s    r   user_music_dirzWindows.user_music_dir~   rP   r   c                R    t         j                  j                  t        d            S )zL:returns: desktop directory tied to the user, e.g. ``%USERPROFILE%\Desktop``CSIDL_DESKTOPDIRECTORYrD   r-   s    r   user_desktop_dirzWindows.user_desktop_dir   s     ww/G HIIr   c                    t         j                  j                  t         j                  j                  t	        d      d            S )zJ:returns: bin directory tied to the user, e.g. ``%LOCALAPPDATA%\Programs``r   Programsr   r   r   r"   r   r-   s    r   user_bin_dirzWindows.user_bin_dir   s/     ww^<Q-RT^ _``r   c                    t         j                  j                  t         j                  j                  t	        d      d            S )zC:returns: bin directory shared by users, e.g. ``C:\ProgramDatain``r'   binrY   r-   s    r   site_bin_dirzWindows.site_bin_dir   s/     ww^<R-SUZ [\\r   c                R    t         j                  j                  t        d            S )zO:returns: applications directory tied to the user, e.g. ``Start Menu\Programs``CSIDL_PROGRAMSrD   r-   s    r   user_applications_dirzWindows.user_applications_dir   rF   r   c                R    t         j                  j                  t        d            S )zo:returns: applications directory shared by users, e.g. ``C:\ProgramData\Microsoft\Windows\Start Menu\Programs``CSIDL_COMMON_PROGRAMSrD   r-   s    r   site_applications_dirzWindows.site_applications_dir   s     ww/F GHHr   c                    t         j                  j                  t         j                  j                  t	        d      d            }| j                  |      S )zk:returns: 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   c                    | j                   S )zG:returns: runtime directory shared by users, same as `user_runtime_dir`)rf   r-   s    r   site_runtime_dirzWindows.site_runtime_dir   s     $$$r   )returnstr)r   rj   r   
str | Noneri   rj   )__name__
__module____qualname____doc__propertyr   r   r*   r.   r2   r5   r7   r9   r;   r>   rA   rE   rI   rL   rO   rS   rV   rZ   r]   r`   rc   rf   rh    r   r   r   r      s    ( ( GK  ( (
 " " " " ? ?
 ? ?
 " " " "     B B C C D D A A A A J J a a ] ] B B I I ( (
 % %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_varsr      s    5jAF # 1- 
c*o	 
 $ZL1oZZ^^L)F~,\N;oMr   c                   | 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 | dk(  rQt         j                  j                  t         j                  j                  t         j                  d         dddd      S | dk(  r|t         j                  j                  t         j                  j                  t         j                  j                  dt         j                  j                  dd                  dddd      S y)zMGet a folder for a CSIDL name that does not exist as an environment variable.rC   USERPROFILE	DocumentsrH   	DownloadsrK   PicturesrN   VideosrR   Musicr_   rs   	Microsoftr   z
Start MenurX   rb   PROGRAMDATArt   zC:\ProgramDataN)r   r   r"   r   rz   rx   )r{   s    r   rw   rw      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%%ww||GGRZZ	23
 	
 ,,ww||GGRZZ^^M2::>>J[]n;opq
 	
 r   c                <   ddh}ddddddd	d
ddd
j                  |       }|d|  }t        |      t        j                  dk7  rt        ddl}| |v r|j                  n|j                  }|j                  |d      }|j                  ||      \  }}t        |      S )zGet 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'   rb   AppDatazCommon AppDatazLocal AppDataPersonal&{374DE290-123F-4565-9164-39C4925E467B}zMy PictureszMy VideozMy MusicrX   zCommon Programs)
r   r'   r   rC   rH   rK   rN   rR   r_   rb   Nrv   win32r   z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)rx   ry   sysplatformNotImplementedErrorwinregHKEY_LOCAL_MACHINEHKEY_CURRENT_USEROpenKeyQueryValueExrj   )	r{   machine_namesshell_folder_namer~   r   hkeykey	directory_s	            r   get_win_folder_from_registryr      s     	M
 # 0.$C)##$!2 
c*o   $ZL1o
||w!! )3m(C6$$IaIaD
..b
cC&&s,=>LIqy>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   rC   rK   rN   rR   rH   rU   r_   rb   zdict[str, str]_KNOWN_FOLDER_GUIDSc                h   t         j                  dk7  rt        ddlm}m}m}m}m}m	}m
  G f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,        j/                  |       }|d
|  }t1        |       |       }|j                  | ||             j)                         }|	j#                   ||      t2        d ||             |j4                  }|j                  |       |d|  }t1        |      t7        d |D              r' |d      }|
j+                  ||d      r|j4                  }|S )zGet folder via :func:`SHGetKnownFolderPath`.

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

    r   r   )HRESULTPOINTER	StructureWinDLLbyrefcreate_unicode_bufferwintypesc                      e Zd ZdW  j                  fdW  j                  fdW  j                  fdW  j
                  dz  fgZy)(get_win_folder_via_ctypes.<locals>._GUIDData1Data2Data3Data4   N)rl   rm   rn   DWORDWORDBYTE_fields_)r   s   r   _GUIDr   !  s?    hnn%hmm$hmm$hmma'(	
r   r   ole32Nshell32kernel32rv   z'SHGetKnownFolderPath returned NULL for c              3  8   K   | ]  }t        |      d kD    yw)   N)ord).0cs     r   	<genexpr>z,get_win_folder_via_ctypes.<locals>.<genexpr>H  s     
(A3q6C<
(s   i   )r   r   r   ctypesr   r   r   r   r   r   r   CLSIDFromStringrestype	LPCOLESTRargtypesCoTaskMemFreeLPVOIDSHGetKnownFolderPathr   HANDLELPWSTRGetShortPathNameWr   rx   ry   r	   valueany)r{   r   r   r   r   r   r   r   r   r   r   folder_guidr~   guidpath_ptrr|   bufr   s                    @r   get_win_folder_via_ctypesr     s    ||w!!bbb
	 
 7OE$+E!&.&8&8'%.%IE""&E$,OO#4E YG+2G  (-4U^X^^X__^efnfufu^v,wG  )j!H)1H&+3??HOOX^^*\H'%))*5K$ZL1o7D	+uT{3 H  t.BD%PX/Z^^F	!~7
|Do

(
((#D)%%fc48YYFMr   c                 v    	 ddl } t        S # t        $ r Y nw xY w	 ddl}t        S # t        $ r	 t
        cY S w xY w)zjSelect the best method to resolve Windows folder paths: ctypes, then registry, then environment variables.r   N)r   r   ImportErrorr   r   r   )r   r   s     r   _pick_get_win_folderr   P  sM    ) )(  , ,+  ,++,s    	& 88c                    d| j                  d       }t        j                  j                  |d      j	                         x}r|S t        |       S )zGet 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_ )removeprefixr   rz   rx   strip_resolve_win_folder)r{   env_varoverrides      r   r   r   c  sO     !!8!8!B CDG::>>'2.4466x6z**r   )r{   rj   ri   rj   )r{   rj   ri   rk   )ri   zCallable[[str], str])ro   
__future__r   r   r   typingr   r   apir   collections.abcr   r	   __annotations__r   r   rw   r   r   r   r   r   r   __all__rq   r   r   <module>r      s     " 	 
 '  ( $. j -S%o S%l*"J#N >DC>@==?F>E' ^ 6r,  +, 	+ r   