+
    Ki?  c                   s    R t ^ RIt^ RIHtHt ^ RIHtHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHt . ROt. ROt. ROtRR	/tR
 tR t ! R R4      tR# )zWine prefix managementN)get_lutris_directory_settingsset_lutris_directory_settings)joypadsystem)DISPLAY_MANAGER)logger)WineRegistry)get_xdg_entryZwinemenubuilder c                s   \         P                  P                  \         P                  P                  V R4      4      ;'       d>    \         P                  P	                  \         P                  P                  V R4      4      # )z!Return True if the path is prefixdrive_cuser.reg)ospathisdirjoinexistsr      &</usr/lib/python3.14/site-packages/lutris/util/wine/prefix.py	is_prefixr      sJ    77==dI67jjBGGNN277<<X\^hKi<jj    c                s   T pV'       g   \         P                  ! R4       R# \        P                  P	                  V4      pVR8w  d|   V'       dr   \        P                  P                  V4      p\        V4      '       d   V# R F7  p\        P                  P                  W4      p\        V4      '       g   K5  Vu # 	  K  R# R# )zGGiven an executable path, try to find a Wine prefix associated with it.z.No path given, unable to guess prefix locationNZ/)prefixpfx)r   Zinfor   r   
expanduserZdirnamer   r   )r   dir_pathZ
prefix_dirZprefix_path   &   r   find_prefixr   !   s    HDEww!!(+H
c/h77??8,XO+J'',,x<K%%"" ,	 '/r   c                   s   a  ] tR t^2t o RtRtRtR tRR lt]	R 4       t
]	R 4       tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR t Rt!V t"R# ) WinePrefixManagerzDClass to allow modification of Wine prefixes without the use of WineZHKEY_CURRENT_USERZHKEY_LOCAL_MACHINEc                s    V'       g   \         P                  ! R 4       \        P                  P	                  V4      V n        R# )z!No path specified for Wine prefixN)r   warningr   r   r   )selfr      &&r   __init__ZWinePrefixManager.__init__8   s(    NN>?GG&&t,	r   Nc                s    T;'       g!    \         P                  ! R 4      ;'       g    Rp\         P                  P                  V P                  RV4      # )ZUSERZ
lutrisuserzdrive_c/users/)r   Zgetenvr   r   )r   default_userZuser   && r   get_user_dirZWinePrefixManager.get_user_dir>   s<    @@ryy0@@Lww||DII'7>>r   c                s"    V P                  4       # )zRReturns the directory that contains the current user's profile in the WINE prefix.)r"   )r   r   r   user_dirZWinePrefixManager.user_dirB   s       ""r   c                sh   V P                  4       pV P                  V P                  R,           R4      pVf   \        P                  ! R4       MEVP                  4       P                  R4      '       d!   \        P                  P                  VR4      # \        P                  P                  VR4      # )zLReturns the app-data directory for the user; this depends on a registry key.A/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell FoldersZAppDataz?Get Registry Key function returned NoneType to variable folder.z\application datazApplication DatazAppData/Roaming)
r"   get_registry_keyhkcu_prefixr   r   ZlowerZendswithr   r   r   )r   r#   folder   &  r   appdata_dirZWinePrefixManager.appdata_dirG   s     $$&&&bb
 >NN\]
 ||~&&';<<ww||H.@AAww||H&788r   c                sb    \         P                  4        F  w  rV P                  W4       K  	  R# )z,Sets the defaults for newly created prefixesN)DEFAULT_DLL_OVERRIDESZitemsoverride_dll)r   dllvaluer(   r   setup_defaultsZ WinePrefixManager.setup_defaultsY   s%    /557JCc) 8r   c                s   V P                  4       pV P                  RR7      p\        P                  ! V4      '       d7   \        P                  ! VRR7      '       g   \        P                  ! W4       R# \        P                  ! V4      '       d9   \        P                  ! VRR7      '       g   \        P                  ! W!4       R# R# R# )z6Link together user profiles created by Wine and ProtonZ	steamuser)r    TZcheck_symlinksN)r"   r   path_existscreate_symlink)r   Zwine_user_dirZproton_user_dirr(   r   create_user_symlinksZ&WinePrefixManager.create_user_symlinks^   s    ))++++Em,,V5G5Ghl5m5m!!-A009K9KMjn9o9o!!/A :p0r   c                sb   VP                  V P                  4      '       d+   \        P                  P	                  V P                  R4      # VP                  V P
                  4      '       d+   \        P                  P	                  V P                  R4      # \        RP                  V4      4      h)z`Matches registry keys to a registry file

Currently, only HKEY_CURRENT_USER keys are supported.
r
   z
system.regzUnsupported key '{}')
startswithr&   r   r   r   hklm_prefix
ValueErrorformat)r   keyr   r   get_registry_pathZ#WinePrefixManager.get_registry_pathg   sw    
 >>$**++77<<		:66>>$**++77<<		<88/66s;<<r   c                s    V P                   V P                  3 F1  pVP                  V4      '       g   K  V\        V4      ^,           R u # 	  \	        RP                  V4      4      h)i   Nz:The key {} is currently not supported by WinePrefixManager)r&   r4   r3   Zlenr5   r6   )r   r7   r   r!   r   get_key_pathZWinePrefixManager.get_key_pathr   s\    '')9)9:F~~f%%3v;?,-- ; U\\]`abbr   c                sx    \        V P                  V4      4      pVP                  V P                  V4      V4      # N)r   r8   Zqueryr9   )r   r7   subkeyregistry   &&& r   r%   Z"WinePrefixManager.get_registry_keyx   s3     6 6s ;<~~d//4f==r   c                s    \        V P                  V4      4      pVP                  V P                  V4      W#4       VP	                  4        R # r:   )r   r8   Z	set_valuer9   save)r   r7   r;   r-   r<   s   &&&& r   set_registry_keyZ"WinePrefixManager.set_registry_key|   s;     6 6s ;<4,,S16Ar   c                s    \        V P                  V4      4      pVP                  V P                  V4      4       VP	                  4        R # r:   )r   r8   Z	clear_keyr9   r>   )r   r7   r<   r!   r   clear_registry_keyZ$WinePrefixManager.clear_registry_key   s9     6 6s ;<4,,S12r   c                s    \        V P                  V4      4      pVP                  V P                  V4      V4       VP	                  4        R # r:   )r   r8   Zclear_subkeysr9   r>   )r   r7   Zsubkeysr<   r=   r   clear_registry_subkeysZ(WinePrefixManager.clear_registry_subkeys   s;     6 6s ;<t005w?r   c                s    V P                   R ,           pVP                  R4      '       d   RpVR9  d   \        P                  ! RV4       R# V P	                  W1V4       R# )z/Software/Wine/DllOverridesZdisr   z#DLL override '%s' mode is not validN)ZbuiltinZnativezbuiltin,nativeznative,builtinr   )r&   r3   r   errorr?   )r   r,   Zmoder7   r=   r   r+   ZWinePrefixManager.override_dll   sR    !>>??5!!DTTLL>Ec-r   c                s   . p\          Fp  pV P                  V P                  R,           V4      pV'       g   \        P                  ! RV4       KG  VP                  W3P                  R4      ^,           R 4       Kr  	  T;'       g    \        # )zHReturn the list of desktop folder names loaded from the Windows registryr$   z&Couldn't load shell folder name for %sZ\N)DESKTOP_KEYSr%   r&   r   r   ZappendZrfindDEFAULT_DESKTOP_FOLDERS)r   desktop_foldersr7   r'   r   r   get_desktop_foldersZ%WinePrefixManager.get_desktop_folders   s}    C**  #ffF GM""6,,t*<q*@*B#CD   99"99r   c                sX   V P                   p\        P                  P                  R4      pV P	                  4       p\
        P                  ! VRR7      '       d   W28w  d   V P                  4       p\        V4       F  w  rV\        P                  P                  W4      pVR,           pV P                  Wx4       \        \        V,          4      p	V	'       g%   \        P                  ! R\        V,          4       K  \
        P                  ! W4       K  	  V P!                  V4       R# R# R# )z^Replace WINE's desktop folders with links to the corresponding
folders in your home directory.Z~Tr/   .winecfgz/No XDG entry found for %s, launcher not createdN)r#   r   r   r   #_get_desktop_integration_assignmentr   r0   rF   Z	enumerater   _remove_desktop_folderr   DESKTOP_XDGr   rB   r1   #_set_desktop_integration_assignment)
r   r#   Zhome_dircurrent_dirrE   Ziitemr   	safe_pathZsrc_path
   &         r   install_desktop_integrationZ-WinePrefixManager.install_desktop_integration   s     ==77%%c*>>@ht<<AX"668O$_5ww||H3 :-	++D<
 )Q8LL!RT_`aTbc))(9 6 44X># BY<r   c                sH   V P                   pV P                  4       p\        P                  ! V4      '       d   W!8w  d   V P	                  4       pV F  p\
        P                  P                  W4      pVR,           p\
        P                  P                  V4      '       g   KR  V P                  WV4       \
        P                  P                  V4      '       d   \
        P                  ! We4       K  \
        P                  ! VRR7       K  	  V P                  V4       R# R# R# )z:Replace the desktop integration links with proper folders.rG   T)Zexist_okN)r#   rH   r   r0   rF   r   r   r   islinkrI   r   renameZmakedirsrK   )r   r#   rL   rE   rM   r   rN   s   &      r   remove_desktop_integrationZ,WinePrefixManager.remove_desktop_integration   s    ==>>@h''K,C"668O'ww||H3 :-	 ww~~d++++D< 77==++IIi.KKt4 (" 44X>' -D'r   c                sL   \         P                  P                  V4      '       d   \         P                  ! V4       R# \         P                  P	                  V4      '       d    \         P
                  ! V4       R# R#   \         d    \         P                  ! Y4        R# i ; i)zRemoves the link or directory at 'path'; if it is a non-empty directory
this will rename it to 'safe_path' instead of removing it entirely.N)r   r   rQ   unlinkr   ZrmdirOSErrorrR   )r   r   rN   s   &&&r   rI   Z(WinePrefixManager._remove_desktop_folder   sg     77>>$IIdOWW]]4  + !  +		$*+s   $A> >!B#"B#c                s     \         P                  P                  V P                  R 4      p\         P                  P                  V4      '       dW   \	        VRRR7      ;_uu_ 4       pVP                  4       pRRR4       V P                  X4       \         P                  ! V4       \        T P                  4      pTP                  RR4      #   + '       g   i     L^; i  \         d"   p\        P                  ! RT4        Rp?LaRp?ii ; i)z.lutris_destkop_integrationrutf-8ZencodingNz5Unable to read Lutris desktop integration setting: %sdesktop_integration_directoryr   )r   r   r   isfileopenreadrK   rT   	Exceptionr   	exceptionr    get)r   obsolete_pathfdesktop_direxsettingss   &     r   rH   Z5WinePrefixManager._get_desktop_integration_assignment   s    
	Z GGLL4QRMww~~m,,-w??1"#&&(K @88E		-( 1;||;R@@ @?  	ZTVXYY	Zs6   AC! C! 'C8/C! C	C! !D,DDc                sJ    \        V P                  R T;'       g    R/4       R# )rY   r   N)r   r   )r   rb   r   r   rK   Z5WinePrefixManager._set_desktop_integration_assignment   s     %dii2QS^SdSdbd1efr   c                sn    T P                  V P                  R,           RV'       d	   ^4       R# ^ 4       R# )z#Enable or diable Wine crash dialogsz/Software/Wine/WineDbgZShowCrashDialogN)r?   r&   )r   enabledr   r   set_crash_dialogsZ#WinePrefixManager.set_crash_dialogs   s1    77A	
  	
r   c                sF   V P                   R,           pV'       du   V P                  VRR4       RP                  \        P                  ! 4       4      p\
        P                  ! RV4       V P                  V P                   R,           RV4       R# V P                  V4       R# )zEnable or disable wine virtual desktop.
The Lutris virtual desktop is refered to as 'WineDesktop', in Wine the
virtual desktop name is 'default'.
z/Software/Wine/ExplorerDesktopWineDesktopZxz;Enabling wine virtual desktop with default resolution of %s /Software/Wine/Explorer/DesktopsN)r&   r?   r   r   Zget_current_resolutionr   debugr@   )r   re   r   Zdefault_resolutions   &&  r   set_virtual_desktopZ%WinePrefixManager.set_virtual_desktop   s    
 ";;!!$	=A!$/*P*P*R!SLLM" !!  #EE" ##D)r   c                sf    V P                   R,           pV'       d   V P                  VRV4       R# R# )zMSets the desktop size if one is given but do not reset the key if
one isn't.
ri   rh   N)r&   r?   )r   Zdesktop_sizer   r!   r   set_desktop_sizeZ"WinePrefixManager.set_desktop_size  s/     "DD!!$|D r   c                s  a aa	 \         P                  P                  S P                  R4      p \         P                  P                  V4      '       dn   \	        VRRR7      ;_uu_ 4       p\        VP                  4       4      pRRR4       \        S P                  \        X4      4       \         P                  ! V4       \        S P                  4      o	S P                  R,           S P                  R,           .oTT 3R	 lpTT T	3R
 lpT'       d#   T! T4       \        S P                  RT/4       R# S	P                  R4      '       d0   T! 4       '       d	   T! ^`4       \        S P                  RR/4       R# R#   + '       g   i     EL; i  \         d"   p\        P                  ! RT4        Rp?LRp?ii ; i)z[Sets the DPI for WINE to use. None to remove the Lutris setting,
and leave WINE in control.z.lutris_dpi_assignmentrV   rW   rX   N&Unable to read Lutris assigned DPI: %sz/Software/Wine/Fontsz/Control Panel/Desktopc                 s@   < S F  pSP                  VR V 4       K  	  R# )	LogPixelsN)r?   )dpikey_path	key_pathsr   s   & r   
assign_dpiZ-WinePrefixManager.set_dpi.<locals>.assign_dpi-  s    %%%hSA &r   c                 s   <  SP                  R4      p V '       d   \        V 4      p MR# S F  pV SP                  VR4      8w  g   K   R# 	  R#   \         d#   p\        P                  ! RT4        Rp?R# Rp?ii ; i)zACheck if Lutris assigned the DPI presently found in the registry.dpi_assignedFrm   Nrn   T)r_   intr]   r   r^   r%   )rs   rc   rp   rq   r   rd   s      r   is_lutris_dpi_assignedZ9WinePrefixManager.set_dpi.<locals>.is_lutris_dpi_assigned1  su    '||N;#&|#4L 
 &4#8#8;#OO  &     !I2Ns   A A A<A77A<rs   r   )r   r   r   rZ   r[   rt   r\   r   rT   r]   r   r^   r    r&   r_   )
r   ro   r`   ra   rs   rc   rr   ru   rq   rd   s
   f&      @@r   set_dpiZWinePrefixManager.set_dpi  sD   
 TYY0HI	Kww~~m,,-w??1#&qvvx=L @-dii\9JK		-( 1;%%(>>@P@PSk@kl		B	" sO)$))nc5JK\\.))%''2)$))nb5IJ *G @??  	KErJJ	Ks5   $F F *E==F =F		F F=F88F=c                s   ^ p\         P                  P                  V P                  R4      p\         P                  P                  V4      '       d   TMV P                  pR F  p\         P                  P                  VRRV4      p\         P                  P                  V4      '       g   KL   \         P                  ! V4      pT F  p\         P                  P                  YX4      p	\         P                  P                  T	4      '       g   KI  \         P                  P                  T	4      '       d   Kp   \         P                  ! T	4       T^,          pK  	  K  	  V'       d   \        P                  ! RV4       R# R#   \
         d$   p\        P                  ! RYW4        Rp?EKI  Rp?ii ; i  \
         d$   p\        P                  ! RY4        Rp?EK  Rp?ii ; i)	aB  Remove broken symlinks from system32/syswow64 before Proton runs.

When switching Proton versions, DLL symlinks from the previous version
remain in the prefix pointing to a now-uninstalled Proton. Proton's
pfx_copy calls os.symlink() without checking if the destination exists,
causing FileExistsError on prefix upgrades.
r   r	   ZwindowszFailed to list %s: %sNz&Failed to remove broken symlink %s: %sz(Removed %d broken symlink(s) from prefix)Zsystem32Zsyswow64)r   r   r   r   ZlistdirrU   r   r   rQ   r   rT   rj   )
r   Zremoved_countZpfx_pathr   Zsubdirr   Zentriesrc   ZentryZ	full_pathrO   r   cleanup_broken_symlinksZ)WinePrefixManager.cleanup_broken_symlinksJ  sM     77<<		51WW]]844$)).Fww||FIy&IH77==****X. !GGLL9	77>>),,RWW^^I5N5N`		),%* ! /$ LLC]S   6E # `'OQZ__`s0   /F8F3F0F++F03G!>GG!c                s$   V P                   R,           pV P                  V4       \        P                  ! 4        FR  w  r#RV9   g   K  V P	                  VRP                  V4      R4       V P	                  VRP                  V4      R4       KT  	  R# )zDisables some joypad devicesz$/Software/Wine/DirectInput/JoystickszHARPOON RGBz{} (js)Zdisabledz
{} (event)N)r&   r@   r   Zget_joypadsr?   r6   )r   r7   Z_deviceZjoypad_namer   r   configure_joypadsZ#WinePrefixManager.configure_joypadsm  s{    !GG$$*$6$6$8 G +%%c9+;+;K+H*U%%c<+>+>{+KZX %9r   r   r:   )#Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__r&   r4   r   r"   Zpropertyr#   r)   r.   r2   r8   r9   r%   r?   r@   rA   r+   rF   rP   rS   rI   rH   rK   rf   rk   rl   rv   rw   rx   Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r   r   r   2   s     N%K&K-? # # 9 9"*
B	=c>


.:?4?4
+A g
**E.K`!TF
Y 
Yr   r   )rg   ZPersonalzMy Musicz	My VideoszMy Picturesz&{374DE290-123F-4565-9164-39C4925E467B}Z	Templates)rg   Z	DocumentsZMusicZVideosZPicturesZ	Downloads)ZDESKTOPZ	DOCUMENTSZMUSICZVIDEOSZPICTURESZ	DOWNLOADS)ry   r   Zlutris.settingsr    r   Zlutris.utilr   r   Zlutris.util.displayr   Zlutris.util.logr   Zlutris.util.wine.registryr   Zlutris.util.xdgshortcutsr   rC   rD   rJ   r*   r   r   r   ) r   r   <module>rz      sX     	 X & / " 2 2 _ Rr 
k
#"EY EYr   