
    9i*                         S r SSKrSSKrSSKJr  SSKJr  \" \5      rSS.S jr	     SS	 jr
SS
 jr     SS jrSS jr\R                  S4S jrS rg)a  
Utilities for Windows Registry manipulation

Notes:

winreg.SetValue -> sets _keys_ with default ("") values
winreg.SetValueEx -> sets values with named contents

This is important when the argument has backslashes.
SetValue will process the backslashes into a path of keys
SetValueEx will create a value with name "path\with\keys"


Mnemonic: SetValueEx for "excalars" (scalars, named values)
    N)	getLogger   
logged_runTcheckc                      [        S/UQSPU S9$ )Nzreg.exez/fr   r   )r   argss     Elib/python3.13/site-packages/menuinst/platforms/win_utils/registry.py_reg_exer      s    y.4..e<<    c                    US:X  a  SnOSn[        U SU  SU 3S5        [        U SU S3U  SU S	35        [        U SU S
3U5        U(       a6  [        U SU S3U5        [        U SU S3U5        [        U SU S3U5        U(       a  [        U SU S3U5        U(       a$  [        U SU S3U5        [        U SU S3U5        U(       a  [        U SU S3U5        gg)a  
We want to achieve this. Entries ending in / denote keys; no trailing / means named value.
If the item has a value attached to it, it's written after the : symbol.

HKEY_*/ # current user or local machine
  Software/
    Classes/
      .<extension>/
        OpenWithProgids/
          <extension-handler>
      ...
      <extension-handler>/: "a description of the file being handled"
        DefaultIcon/: "path to the app icon"
        FriendlyAppName/: "Name of the program"
        AppUserModelID: "AUMI string"
        shell/
          open/: "Name of the program"
            icon: "path to the app icon"
            FriendlyAppName: "name of the program"
            command/: "the command to be executed when opening a file with this extension"
systemz#HKEY_LOCAL_MACHINE/Software/Classesz"HKEY_CURRENT_USER/Software/Classes/z/OpenWithProgids/ /@ z file/shell/open/command/@/shell/open/@/FriendlyAppName/@/shell/open/FriendlyAppNamez/AppUserModelID/DefaultIcon/@/shell/open/Iconz/FriendlyTypeNameN)regvalue)		extension
identifiercommandiconapp_namefriendly_type_nameapp_user_model_idmodekeys	            r   register_file_extensionr$      s0   > x32 uAi[ 1*>C uAj\$1ZL&FG uAj\!67AC5*]3X>C5*%78(CC5*%@A8LC5*_57HI 	C5*^4d;C5*%56= 	C5*%679KL	 r   c                    US:X  a  [         R                  S4O[         R                  S4u  p4[        SU SU 3SS9   [         R                  " USU  S	3S
[         R
                  5       n[         R                  " XQ5        S S S 5        g ! , (       d  f       g = f! [         a    [        R                  SX5         g [         a  n[        R                  SXS9   S nAgS nAff = f)Nr   HKLMHKCUdeletez\Software\Classes\Fr   Software\Classes\z\OpenWithProgidsr   z2Handler '%s' is not associated with extension '%s'z%Could not check key '%s' for deletionexc_info)winregHKEY_LOCAL_MACHINEHKEY_CURRENT_USERr   OpenKeyKEY_ALL_ACCESSDeleteValueFileNotFoundErrorlogdebug	Exception)r   r   r"   rootroot_strr#   excs          r   unregister_file_extensionr9   b   s     8 
	"	"F+&&/ D
 X8*$6zlC5Q	^^&yk1ABAvG\G\
s/
 
 
  _		F
^ 		99	Ss;   +B )B	 B 	
BB B  C#<	C#CC#c                    US:X  a  SU  3nOSU  3n[        U S3SU R                  5        35        [        U S3S5        [        U S3U5        U(       a-  [        U S	3U5        [        U S
3U5        [        U S3U5        U(       a  [        U S3U5        [        U S3U5        U(       a  [        U S3U5        U(       a  [        U S3U5        g g )Nr   zHKEY_CLASSES_ROOT/z#HKEY_CURRENT_USER/Software/Classes/r   zURL:z/URL Protocolr   r   r   r   r   r   r   z/AppUserModelIdz
/_menuinst)r   title)protocolr   r   r   r   r!   r"   r#   s           r   register_url_protocolr=   v   s     x"8*-3H:>uBZ4 0123uM"B'u)*G4C5&1C5*+X6C534h?C5'.C5()40C5(*;<C5
#Z0 r   c                    US:X  a  [         R                  U 4nSU  3nO[         R                  SU  34nSU  3n [         R                  " U6  n[         R                  " US5      u  pgUS L =(       d    Xa:H  nS S S 5        W(       a  [        SUS	S
9  g g ! , (       d  f       N"= f! [
         a  n	[        R                  SX	S9   S n	A	g S n	A	ff = f)Nr   zHKCR\r)   zHKCU\Software\Classes\	_menuinstz#Could not check key %s for deletionr*   r(   Fr   )	r,   HKEY_CLASSES_ROOTr.   r/   QueryValueExOSErrorr3   	exceptionr   )
r<   r   r"   	key_tuplekey_strr#   value_r(   r8   s
             r   unregister_url_protocolrH      s    x,,h6	8*%,,1B8*.MM	+H:6^^Y'3**3<HE4'>5+>F ( 7%0  ('  ;XTs5   B# )B6B# 
B B#  B# #
C-CCc                 d   [         R                  SX5        U R                  SS5      R                  S5      =pU R	                  S5      GtpVpx[        [        U5      n	[        R                  n
 US:X  as  U(       a&  [        R                  " U	SR                  U5      5        [        R                  " U	SR                  U5      U
S9 n [        R                  " XX!5        SSS5        g[        R                  " U	SR                  / UQUP5      5        [        R                  " U	SR                  / UQUP5      U
S9 n [        R                  " XSX!5        SSS5        g! , (       d  f       g= f! , (       d  f       g= f! [         a'  nU(       a  e [         R                  SXAUS	9   SnAgSnAff = f)
ax  
Convenience wrapper to set different types of registry values.

For practical purposes we distinguish between three cases:

- A key with no value (think of a directory with no contents).
  Use value = "".
- A key with an unnamed value (think of a directory with a file 'index.html')
  Use a key with '@' as the last component.
- A key with named values (think of non-index.html files in the directory)

The first component of the key is the root, and must be one of the winreg.HKEY_*
variable _names_ (their actual value will be fetched from winreg).

Key must be at least three components long (root key, *key, @ or named value).
z Setting registry value %s = '%s'\r   @)accessNr   zCould not set %s to %sr*   )r3   r4   replacestripsplitgetattrr,   KEY_SET_VALUE	CreateKeyjoinr/   SetValue
SetValueExrB   warning)r#   rF   
value_typeraise_on_errorsoriginal_keyr6   midkeysubkeynamed_valuerootkeyrL   r8   s               r   r   r      s\   " II0#=T3/55c::C),3&D6fd#G!!FQ#  $))F*;<6):6JcZ? KJ Wdii0A&0A&0A&BC3DV3DV3D)EfUY\!!#AzI VU	 KJ VU Q,lCPQs\   .AE> EE> 'AE> :E-E> 
E*&E> *E> -
E;7E> ;E> >
F/F**F/c                      [         R                  " S5      n SU R                  l        SnSnU R                  XSS5        g)z
Needed to propagate registry changes without having to reboot.

https://discuss.python.org/t/is-there-a-library-to-change-windows-10-default-program-icon/5846/2
shell32Ni   r   )ctypesOleDLLSHChangeNotifyrestype)r_   eventflagss      r   notify_shell_changesrf      s<     mmI&G%)G"EE5t4r   )NNNNuser)rg   )Nrg   )__doc__r`   r,   loggingr   utilsr   __name__r3   r   r$   r9   r=   rH   REG_SZr   rf    r   r   <module>rn      s{          = 
	>MH. 		1<1& %+MM4 #QL
5r   