
     [1f[                     d    d Z ddlZddlmZ ddlmZ  ee      ZdddZdd	Z	dd
Z
ddZddZy)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                 &    t        dg|dd      S )Nzreg.exez/fTr   r   )r   argss     Elib/python3.12/site-packages/menuinst/platforms/win_utils/registry.py_reg_exer      s    y.4..d;;    c                    t        j                  |dk(  rt         j                  nt         j                  d      5 }t        j                  t        j
                  ||  d      |dt         j                  d       t        j                  d|        |  d| d}t        j                  ||t         j                  |       t        j                  d	|       | d
}t        j                  ||t         j                  |       t        j                  d|       |rSt        j                  ||      }t        j                  |ddt         j                  |       t        j                  d|       ddd       y# 1 sw Y   yxY w)ad  
    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"
            shell/
              open/
                command/: "the command to be executed when opening a file with this extension"
    systemzSoftware\Classes\OpenWithProgidsr    z)Created registry entry for extension '%s' z handlerz'Created registry entry for handler '%s'z\shell\open\commandz'Created registry entry for command '%s'DefaultIconz$Created registry entry for icon '%s'N)winreg	OpenKeyExHKEY_LOCAL_MACHINEHKEY_CURRENT_USER
SetValueEx	CreateKeyREG_SZlogdebugSetValueOpenKey)	extension
identifiercommandiconmodekeyhandler_descsubkeys           r   register_file_extensionr'      s?   $ 
		8 	!!%%	
 D
 
Si[0@"ABMM	
 			=yI $Aj\:ZE		;ZH  L 34VV]]G<		;WE^^C4FfmQtLII<dC=D D Ds   D/E22E;c                    |dk(  rt         j                  dfnt         j                  df\  }}t        d| d|        	 t        j                  |d|  ddt         j
                        5 }	 t        j                  ||       t        j                  ||       d d d        y # t        $ r t        j                  d	||        Y +w xY w# 1 sw Y   y xY w# t        $ r}t        j                  d
| |        d }~ww xY w)Nr   HKLMHKCUdeletez\Software\Classes\Software\Classes\r   r   z2Handler '%s' is not associated with extension '%s'z%Could not check key '%s' for deletionexc_info)r   r   r   r   r   KEY_ALL_ACCESSQueryValueExDeleteValueFileNotFoundErrorr   r   	Exception	exception)r   r    r#   rootroot_strr$   excs          r   unregister_file_extensionr8   R   s    8 
	"	"F+&&/ D(
 X8*$6zlCD^^&yk1ABAvG\G\
 
	44##C4 ""3
3
	4 
	4
 % 		H*V_
	4 
	4  =ySVWsY   *C )C+B CC   C CCCCC C 	C9C44C9c           
         |dk(  r%t        j                  t         j                  |       }n't        j                  t         j                  d|        }|5  t        j                  |ddt         j
                  d| j                                 t        j                  |ddt         j
                  d       t        j                  |dt         j
                  |       |r't        j                  |ddt         j
                  |       |r't        j                  |d	dt         j
                  |       d d d        y # 1 sw Y   y xY w)
Nr   r,   r   r   zURL:zURL Protocolzshell\open\commandr   	_menuinst)r   r   HKEY_CLASSES_ROOTr   r   r   titler   )protocolr!   r    r"   r#   r$   s         r   register_url_protocolr>   k   s    xv77Bv77<MhZ9XY	 
N#r1fmmtHNN<L;M5NO#~q&--D 	2FMM7Kc=!V]]DIc;6==*M
N 
N 
Ns   CD55D>c                    |dk(  rt         j                  | f}d|  }nt         j                  d|  f}d|  }	 t        j                  | 5 }t        j                  |d      \  }}|d u xs ||k(  }d d d        rt        d|d	
       y y # 1 sw Y   xY w# t
        $ r"}	t        j                  d| |	       Y d }	~	y d }	~	ww xY w)Nr   zHKCR\r,   zHKCU\Software\Classes\r:   z#Could not check key %s for deletionr-   r+   Fr   )	r   r;   r   r   r0   OSErrorr   r4   r   )
r=   r    r#   	key_tuplekey_strr$   value_r+   r7   s
             r   unregister_url_protocolrE   }   s    x,,h6	8*%,,1B8*.MM	+H:6^^Y' 	?3**3<HE14'>5J+>F	? 7%0 	? 	?  ;XPSTs/   B %B
0B 
BB 	CB<<C)Nuser)rF   )NNrF   )__doc__r   loggingr   utilsr   __name__r   r   r'   r8   r>   rE    r   r   <module>rL      s@        <0Dl2N$1r   