forked from nvaccess/nvda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNVDAState.py
201 lines (147 loc) · 5.45 KB
/
NVDAState.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2022-2023 NV Access Limited
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
import os
import sys
import time
import winreg
import globalVars
class _WritePaths:
@property
def configDir(self) -> str:
return globalVars.appArgs.configPath
@configDir.setter
def configDir(self, configPath: str):
globalVars.appArgs.configPath = configPath
return configPath
@property
def addonsDir(self) -> str:
return os.path.join(self.configDir, "addons")
@property
def addonStoreDir(self) -> str:
return os.path.join(self.configDir, "addonStore")
@property
def addonStoreDownloadDir(self) -> str:
return os.path.join(self.addonStoreDir, "_dl")
@property
def profilesDir(self) -> str:
return os.path.join(self.configDir, "profiles")
@property
def scratchpadDir(self) -> str:
return os.path.join(self.configDir, "scratchpad")
@property
def speechDictsDir(self) -> str:
return os.path.join(self.configDir, "speechDicts")
@property
def voiceDictsDir(self) -> str:
return os.path.join(self.speechDictsDir, "voiceDicts.v1")
@property
def voiceDictsBackupDir(self) -> str:
return os.path.join(self.speechDictsDir, "voiceDictsBackup.v0")
@property
def updatesDir(self) -> str:
return os.path.join(self.configDir, "updates")
@property
def nvdaConfigFile(self) -> str:
return os.path.join(self.configDir, "nvda.ini")
@property
def addonStateFile(self) -> str:
from addonHandler import stateFilename
return os.path.join(self.configDir, stateFilename)
@property
def profileTriggersFile(self) -> str:
return os.path.join(self.configDir, "profileTriggers.ini")
@property
def gesturesConfigFile(self) -> str:
return os.path.join(self.configDir, "gestures.ini")
@property
def speechDictDefaultFile(self) -> str:
return os.path.join(self.speechDictsDir, "default.dic")
@property
def updateCheckStateFile(self) -> str:
return os.path.join(self.configDir, "updateCheckState.pickle")
def getSymbolsConfigFile(self, locale: str) -> str:
return os.path.join(self.configDir, f"symbols-{locale}.dic")
def getProfileConfigFile(self, name: str) -> str:
return os.path.join(self.profilesDir, f"{name}.ini")
WritePaths = _WritePaths()
def isRunningAsSource() -> bool:
"""
True if NVDA is running as a source copy.
When running as an installed copy, py2exe sets sys.frozen to 'windows_exe'.
"""
return getattr(sys, "frozen", None) is None
def _allowDeprecatedAPI() -> bool:
"""
Used for marking code as deprecated.
This should never be False in released code.
Making this False may be useful for testing if code is compliant without using deprecated APIs.
Note that deprecated code may be imported at runtime,
and as such, this value cannot be changed at runtime to test compliance.
"""
return True
def getStartTime() -> float:
return globalVars.startTime
def _initializeStartTime() -> None:
assert globalVars.startTime == 0
globalVars.startTime = time.time()
def _getExitCode() -> int:
return globalVars.exitCode
def _setExitCode(exitCode: int) -> None:
globalVars.exitCode = exitCode
def shouldWriteToDisk() -> bool:
"""
Never save config or state if running securely or if running from the launcher.
When running from the launcher we don't save settings because the user may decide not to
install this version, and these settings may not be compatible with the already
installed version. See #7688
"""
return not (globalVars.appArgs.secure or globalVars.appArgs.launcher)
class _TrackNVDAInitialization:
"""
During NVDA initialization,
core._initializeObjectCaches needs to cache the desktop object,
regardless of lock state.
Security checks may cause the desktop object to not be set if NVDA starts on the lock screen.
As such, during initialization, NVDA should behave as if Windows is unlocked,
i.e. winAPI.sessionTracking.isLockScreenModeActive should return False.
"""
_isNVDAInitialized = False
"""When False, isLockScreenModeActive is forced to return False.
"""
@staticmethod
def markInitializationComplete():
assert not _TrackNVDAInitialization._isNVDAInitialized
_TrackNVDAInitialization._isNVDAInitialized = True
@staticmethod
def isInitializationComplete() -> bool:
return _TrackNVDAInitialization._isNVDAInitialized
def _forceSecureModeEnabled() -> bool:
from config import RegistryKey
try:
k = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, RegistryKey.NVDA.value)
return bool(winreg.QueryValueEx(k, RegistryKey.FORCE_SECURE_MODE_SUBKEY.value)[0])
except WindowsError:
# Expected state by default, forceSecureMode parameter not set
return False
def _serviceDebugEnabled() -> bool:
from config import RegistryKey
try:
k = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, RegistryKey.NVDA.value)
return bool(winreg.QueryValueEx(k, RegistryKey.SERVICE_DEBUG_SUBKEY.value)[0])
except WindowsError:
# Expected state by default, serviceDebug parameter not set
return False
def _configInLocalAppDataEnabled() -> bool:
from config import RegistryKey
from logHandler import log
try:
k = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, RegistryKey.NVDA.value)
return bool(winreg.QueryValueEx(k, RegistryKey.CONFIG_IN_LOCAL_APPDATA_SUBKEY.value)[0])
except FileNotFoundError:
log.debug("Installed user config is not in local app data")
return False
except WindowsError:
# Expected state by default, configInLocalAppData parameter not set
return False