Skip to content

Commit a5b7c14

Browse files
authored
Merge 8a2ce5b into d6a193a
2 parents d6a193a + 8a2ce5b commit a5b7c14

1 file changed

Lines changed: 65 additions & 15 deletions

File tree

source/installer.py

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,65 @@ def removeOldProgramFiles(destPath):
226226
except RetriableFailure:
227227
log.warning(f"Couldn't remove file: {path!r}")
228228

229-
uninstallerRegInfo={
230-
"DisplayName":versionInfo.name,
231-
"DisplayVersion":versionInfo.version,
232-
"DisplayIcon":u"{installDir}\\images\\nvda.ico",
233-
"InstallDir":u"{installDir}",
234-
"Publisher":versionInfo.publisher,
235-
"UninstallDirectory":u"{installDir}",
236-
"UninstallString":u"{installDir}\\uninstall.exe",
237-
"URLInfoAbout":versionInfo.url,
229+
230+
uninstallerRegInfo = {
231+
"DisplayName": versionInfo.name,
232+
"DisplayVersion": versionInfo.version,
233+
"DisplayIcon": u"{installDir}\\images\\nvda.ico",
234+
"InstallDir": u"{installDir}",
235+
"Publisher": versionInfo.publisher,
236+
"UninstallDirectory": u"{installDir}",
237+
"UninstallString": u"{installDir}\\uninstall.exe",
238+
"URLInfoAbout": versionInfo.url,
238239
}
239240

240-
def registerInstallation(installDir,startMenuFolder,shouldCreateDesktopShortcut,startOnLogonScreen,configInLocalAppData=False):
241-
with winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\NVDA",0,winreg.KEY_WRITE) as k:
242-
for name,value in uninstallerRegInfo.items():
243-
winreg.SetValueEx(k,name,None,winreg.REG_SZ,value.format(installDir=installDir))
241+
242+
def getDirectorySize(path: str) -> int:
243+
"""Calculates the size of a directory in bytes.
244+
"""
245+
total = 0
246+
with os.scandir(path) as iterator:
247+
for entry in iterator:
248+
if entry.is_file():
249+
total += entry.stat().st_size
250+
elif entry.is_dir():
251+
total += getDirectorySize(entry.path)
252+
return total
253+
254+
255+
def registerInstallation(
256+
installDir: str,
257+
startMenuFolder: str,
258+
shouldCreateDesktopShortcut: bool,
259+
startOnLogonScreen: bool,
260+
configInLocalAppData: bool = False
261+
):
262+
calculatedUninstallerRegInfo = uninstallerRegInfo.copy()
263+
# EstimatedSize is in KiB
264+
calculatedUninstallerRegInfo.update(EstimatedSize=getDirectorySize(installDir) / 1024)
265+
with winreg.CreateKeyEx(
266+
winreg.HKEY_LOCAL_MACHINE,
267+
r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NVDA",
268+
0,
269+
winreg.KEY_WRITE
270+
) as k:
271+
for name, value in calculatedUninstallerRegInfo.items():
272+
if isinstance(value, int):
273+
winreg.SetValueEx(
274+
k,
275+
name,
276+
None,
277+
winreg.REG_DWORD,
278+
value
279+
)
280+
else:
281+
winreg.SetValueEx(
282+
k,
283+
name,
284+
None,
285+
winreg.REG_SZ,
286+
value.format(installDir=installDir)
287+
)
244288
with winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\nvda.exe",0,winreg.KEY_WRITE) as k:
245289
winreg.SetValueEx(k,"",None,winreg.REG_SZ,os.path.join(installDir,"nvda.exe"))
246290
with winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, config.RegistryKey.NVDA.value, 0, winreg.KEY_WRITE) as k:
@@ -584,8 +628,14 @@ def install(shouldCreateDesktopShortcut=True,shouldRunAtLogon=True):
584628
break
585629
else:
586630
raise RuntimeError("No available executable to use as nvda.exe")
587-
registerInstallation(installDir,startMenuFolder,shouldCreateDesktopShortcut,shouldRunAtLogon,configInLocalAppData)
588-
removeOldLibFiles(installDir,rebootOK=True)
631+
removeOldLibFiles(installDir, rebootOK=True)
632+
registerInstallation(
633+
installDir,
634+
startMenuFolder,
635+
shouldCreateDesktopShortcut,
636+
shouldRunAtLogon,
637+
configInLocalAppData
638+
)
589639
COMRegistrationFixes.fixCOMRegistrations()
590640

591641
def removeOldLoggedFiles(installPath):

0 commit comments

Comments
 (0)