1414import globalVars
1515import winreg
1616import ctypes
17- import ctypes .wintypes
1817import os
1918import sys
2019import errno
4039 _transformSpec_AddFeatureFlagDefault ,
4140 _validateConfig_featureFlag ,
4241)
42+ from .registry import RegistryKey as _RegistryKey
4343from typing import (
4444 Any ,
4545 Dict ,
7777
7878def __getattr__ (attrName : str ) -> Any :
7979 """Module level `__getattr__` used to preserve backward compatibility."""
80+ if attrName == "RegistryKey" and NVDAState ._allowDeprecatedAPI ():
81+ log .warning ("Importing RegistryKey from here is deprecated, use config.registry.RegistryKey instead." )
82+ return _RegistryKey
8083 if attrName == "NVDA_REGKEY" and NVDAState ._allowDeprecatedAPI ():
8184 log .warning ("NVDA_REGKEY is deprecated, use RegistryKey.NVDA instead." )
82- return RegistryKey .NVDA .value
85+ return _RegistryKey .NVDA .value
8386 if attrName == "RUN_REGKEY" and NVDAState ._allowDeprecatedAPI ():
8487 log .warning ("RUN_REGKEY is deprecated, use RegistryKey.RUN instead." )
85- return RegistryKey .RUN .value
88+ return _RegistryKey .RUN .value
8689 if attrName == "addConfigDirsToPythonPackagePath" and NVDAState ._allowDeprecatedAPI ():
8790 log .warning (
8891 "addConfigDirsToPythonPackagePath is deprecated, "
@@ -98,7 +101,7 @@ def __getattr__(attrName: str) -> Any:
98101 "Instead use RegistryKey.CONFIG_IN_LOCAL_APPDATA_SUBKEY. " ,
99102 stack_info = True ,
100103 )
101- return RegistryKey .CONFIG_IN_LOCAL_APPDATA_SUBKEY .value
104+ return _RegistryKey .CONFIG_IN_LOCAL_APPDATA_SUBKEY .value
102105 raise AttributeError (f"module { repr (__name__ )} has no attribute { repr (attrName )} " )
103106
104107
@@ -119,45 +122,22 @@ def saveOnExit():
119122 pass
120123
121124
122- class RegistryKey (str , Enum ):
123- INSTALLED_COPY = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NVDA"
124- RUN = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
125- NVDA = r"SOFTWARE\NVDA"
126- r"""
127- The name of the registry key stored under HKEY_LOCAL_MACHINE where system wide NVDA settings are stored.
128- Note that NVDA is a 32-bit application, so on X64 systems,
129- this will evaluate to `r"SOFTWARE\WOW6432Node\nvda"`
130- """
131- CONFIG_IN_LOCAL_APPDATA_SUBKEY = "configInLocalAppData"
132- """
133- #6864: The name of the subkey stored under RegistryKey.NVDA where the value is stored
134- which will make an installed NVDA load the user configuration either from the local or from
135- the roaming application data profile.
136- The registry value is unset by default.
137- When setting it manually, a DWORD value is preferred.
138- A value of 0 will evaluate to loading the configuration from the roaming application data (default).
139- A value of 1 means loading the configuration from the local application data folder.
140- """
141- FORCE_SECURE_MODE_SUBKEY = "forceSecureMode"
142- SERVICE_DEBUG_SUBKEY = "serviceDebug"
143-
144-
145125def isInstalledCopy () -> bool :
146126 """Checks to see if this running copy of NVDA is installed on the system"""
147127 try :
148128 k = winreg .OpenKey (
149129 winreg .HKEY_LOCAL_MACHINE ,
150- RegistryKey .INSTALLED_COPY .value ,
130+ _RegistryKey .INSTALLED_COPY .value ,
151131 )
152132 except FileNotFoundError :
153133 log .debug (
154- f"Unable to find isInstalledCopy registry key { RegistryKey .INSTALLED_COPY } "
134+ f"Unable to find isInstalledCopy registry key { _RegistryKey .INSTALLED_COPY } "
155135 "- this is not an installed copy." ,
156136 )
157137 return False
158138 except WindowsError :
159139 log .error (
160- f"Unable to open isInstalledCopy registry key { RegistryKey .INSTALLED_COPY } " ,
140+ f"Unable to open isInstalledCopy registry key { _RegistryKey .INSTALLED_COPY } " ,
161141 exc_info = True ,
162142 )
163143 return False
@@ -166,7 +146,7 @@ def isInstalledCopy() -> bool:
166146 instDir = winreg .QueryValueEx (k , "UninstallDirectory" )[0 ]
167147 except FileNotFoundError :
168148 log .debug (
169- f"Unable to find UninstallDirectory value for { RegistryKey .INSTALLED_COPY } "
149+ f"Unable to find UninstallDirectory value for { _RegistryKey .INSTALLED_COPY } "
170150 "- this may not be an installed copy." ,
171151 )
172152 return False
@@ -188,7 +168,7 @@ def isInstalledCopy() -> bool:
188168
189169def getInstalledUserConfigPath () -> Optional [str ]:
190170 try :
191- winreg .OpenKey (winreg .HKEY_LOCAL_MACHINE , RegistryKey .NVDA .value )
171+ winreg .OpenKey (winreg .HKEY_LOCAL_MACHINE , _RegistryKey .NVDA .value )
192172 except FileNotFoundError :
193173 log .debug ("Could not find nvda registry key, NVDA is not currently installed" )
194174 return None
@@ -297,16 +277,16 @@ def getStartAfterLogon() -> bool:
297277 if easeOfAccess .willAutoStart (easeOfAccess .AutoStartContext .AFTER_LOGON ):
298278 return True
299279 try :
300- k = winreg .OpenKey (winreg .HKEY_CURRENT_USER , RegistryKey .RUN .value )
280+ k = winreg .OpenKey (winreg .HKEY_CURRENT_USER , _RegistryKey .RUN .value )
301281 except FileNotFoundError :
302282 log .debugWarning (
303- f"Unable to find run registry key { RegistryKey .RUN } " ,
283+ f"Unable to find run registry key { _RegistryKey .RUN } " ,
304284 exc_info = True ,
305285 )
306286 return False
307287 except WindowsError :
308288 log .error (
309- f"Unable to open run registry key { RegistryKey .RUN } " ,
289+ f"Unable to open run registry key { _RegistryKey .RUN } " ,
310290 exc_info = True ,
311291 )
312292 return False
@@ -360,7 +340,7 @@ def setStartAfterLogon(enable: bool) -> None:
360340 return
361341 # We're disabling, so ensure the run key is cleared,
362342 # as it might have been set by an old version.
363- k = winreg .OpenKey (winreg .HKEY_CURRENT_USER , RegistryKey .RUN .value , 0 , winreg .KEY_WRITE )
343+ k = winreg .OpenKey (winreg .HKEY_CURRENT_USER , _RegistryKey .RUN .value , access = winreg .KEY_WRITE )
364344 try :
365345 winreg .QueryValue (k , "nvda" )
366346 except FileNotFoundError :
@@ -393,19 +373,19 @@ def getStartOnLogonScreen() -> bool:
393373 if easeOfAccess .willAutoStart (easeOfAccess .AutoStartContext .ON_LOGON_SCREEN ):
394374 return True
395375 try :
396- k = winreg .OpenKey (winreg .HKEY_LOCAL_MACHINE , RegistryKey .NVDA .value )
376+ k = winreg .OpenKey (winreg .HKEY_LOCAL_MACHINE , _RegistryKey .NVDA .value )
397377 except FileNotFoundError :
398- log .debugWarning (f"Could not find NVDA reg key { RegistryKey .NVDA } " , exc_info = True )
378+ log .debugWarning (f"Could not find NVDA reg key { _RegistryKey .NVDA } " , exc_info = True )
399379 except WindowsError :
400- log .error (f"Failed to open NVDA reg key { RegistryKey .NVDA } " , exc_info = True )
380+ log .error (f"Failed to open NVDA reg key { _RegistryKey .NVDA } " , exc_info = True )
401381 else :
402382 try :
403383 return bool (winreg .QueryValueEx (k , "startOnLogonScreen" )[0 ])
404384 except FileNotFoundError :
405- log .debug (f"Could not find startOnLogonScreen value for { RegistryKey .NVDA } - likely unset." )
385+ log .debug (f"Could not find startOnLogonScreen value for { _RegistryKey .NVDA } - likely unset." )
406386 return False
407387 except WindowsError :
408- log .error (f"Failed to query startOnLogonScreen value for { RegistryKey .NVDA } " , exc_info = True )
388+ log .error (f"Failed to query startOnLogonScreen value for { _RegistryKey .NVDA } " , exc_info = True )
409389 return False
410390 return False
411391
0 commit comments