Skip to content

Commit a7c4101

Browse files
authored
Merge 5a74197 into d6a193a
2 parents d6a193a + 5a74197 commit a7c4101

1 file changed

Lines changed: 66 additions & 15 deletions

File tree

source/installer.py

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,66 @@ 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 + {
263+
# EstimatedSize is in KiB
264+
"EstimatedSize": getDirectorySize(installDir) / 1024
265+
}
266+
with winreg.CreateKeyEx(
267+
winreg.HKEY_LOCAL_MACHINE,
268+
r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NVDA",
269+
0,
270+
winreg.KEY_WRITE
271+
) as k:
272+
for name, value in calculatedUninstallerRegInfo.items():
273+
if isinstance(value, int):
274+
winreg.SetValueEx(
275+
k,
276+
name,
277+
None,
278+
winreg.REG_DWORD,
279+
value
280+
)
281+
else:
282+
winreg.SetValueEx(
283+
k,
284+
name,
285+
None,
286+
winreg.REG_SZ,
287+
value.format(installDir=installDir)
288+
)
244289
with winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\nvda.exe",0,winreg.KEY_WRITE) as k:
245290
winreg.SetValueEx(k,"",None,winreg.REG_SZ,os.path.join(installDir,"nvda.exe"))
246291
with winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, config.RegistryKey.NVDA.value, 0, winreg.KEY_WRITE) as k:
@@ -584,8 +629,14 @@ def install(shouldCreateDesktopShortcut=True,shouldRunAtLogon=True):
584629
break
585630
else:
586631
raise RuntimeError("No available executable to use as nvda.exe")
587-
registerInstallation(installDir,startMenuFolder,shouldCreateDesktopShortcut,shouldRunAtLogon,configInLocalAppData)
588-
removeOldLibFiles(installDir,rebootOK=True)
632+
removeOldLibFiles(installDir, rebootOK=True)
633+
registerInstallation(
634+
installDir,
635+
startMenuFolder,
636+
shouldCreateDesktopShortcut,
637+
shouldRunAtLogon,
638+
configInLocalAppData
639+
)
589640
COMRegistrationFixes.fixCOMRegistrations()
590641

591642
def removeOldLoggedFiles(installPath):

0 commit comments

Comments
 (0)