def restart(disableAddons=False, debugLogging=False): """Restarts NVDA by starting a new copy.""" if globalVars.appArgs.launcher: import gui globalVars.exitCode=3 gui.safeAppExit() return import subprocess import winUser import shellapi for paramToRemove in ("--disable-addons", "--debug-logging", "--ease-of-access"): try: sys.argv.remove(paramToRemove) except ValueError: pass options = [] if not hasattr(sys, "frozen"): options.append(os.path.basename(sys.argv[0])) if disableAddons: options.append('--disable-addons') if debugLogging: options.append('--debug-logging') shellapi.ShellExecute( hwnd=None, operation=None, file=sys.executable, parameters=subprocess.list2cmdline(options + sys.argv[1:]), directory=globalVars.appDir, # #4475: ensure that the first window of the new process is not hidden by providing SW_SHOWNORMAL showCmd=winUser.SW_SHOWNORMAL )
def doCreatePortable(portableDirectory, copyUserConfig=False, silent=False, startAfterCreate=False): d = gui.IndeterminateProgressDialog( gui.mainFrame, # Translators: The title of the dialog presented while a portable copy of NVDA is bieng created. _("Creating Portable Copy"), # Translators: The message displayed while a portable copy of NVDA is bieng created. _("Please wait while a portable copy of NVDA is created.")) try: gui.ExecAndPump(installer.createPortableCopy, portableDirectory, copyUserConfig) except Exception as e: log.error("Failed to create portable copy", exc_info=True) d.done() if isinstance(e, installer.RetriableFailure): # Translators: a message dialog asking to retry or cancel when NVDA portable copy creation fails message = _("NVDA is unable to remove or overwrite a file.") # Translators: the title of a retry cancel dialog when NVDA portable copy creation fails title = _("File in Use") if winUser.MessageBox(None, message, title, winUser.MB_RETRYCANCEL) == winUser.IDRETRY: return doCreatePortable(portableDirectory, copyUserConfig, silent, startAfterCreate) # Translators: The message displayed when an error occurs while creating a portable copy of NVDA. # %s will be replaced with the specific error message. gui.messageBox( _("Failed to create portable copy: %s") % e, _("Error"), wx.OK | wx.ICON_ERROR) return d.done() if silent: gui.safeAppExit() else: # Translators: The message displayed when a portable copy of NVDA has been successfully created. # %s will be replaced with the destination directory. gui.messageBox( _("Successfully created a portable copy of NVDA at %s") % portableDirectory, _("Success")) if startAfterCreate: # #4475: ensure that the first window of the new process is not hidden by providing SW_SHOWNORMAL shellapi.ShellExecute(None, None, os.path.join(portableDirectory, 'nvda.exe'), None, None, winUser.SW_SHOWNORMAL)
def restartWithOptions(options): """Restarts NVDA by starting a new copy, providing some options.""" if globalVars.appArgs.launcher: import gui globalVars.exitCode=3 gui.safeAppExit() return import subprocess import winUser import shellapi if not hasattr(sys, "frozen"): options.insert(0, os.path.basename(sys.argv[0])) shellapi.ShellExecute( hwnd=None, operation=None, file=sys.executable, parameters=subprocess.list2cmdline(options), directory=globalVars.appDir, # #4475: ensure that the first window of the new process is not hidden by providing SW_SHOWNORMAL showCmd=winUser.SW_SHOWNORMAL )
def doInstall(createDesktopShortcut=True, startOnLogon=True, isUpdate=False, copyPortableConfig=False, silent=False, startAfterInstall=True): progressDialog = gui.IndeterminateProgressDialog( gui.mainFrame, # Translators: The title of the dialog presented while NVDA is being updated. _("Updating NVDA") if isUpdate # Translators: The title of the dialog presented while NVDA is being installed. else _("Installing NVDA"), # Translators: The message displayed while NVDA is being updated. _("Please wait while your previous installation of NVDA is being updated." ) if isUpdate # Translators: The message displayed while NVDA is being installed. else _("Please wait while NVDA is being installed")) try: res = systemUtils.execElevated(config.SLAVE_FILENAME, [ "install", str(int(createDesktopShortcut)), str(int(startOnLogon)) ], wait=True, handleAlreadyElevated=True) if res == 2: raise installer.RetriableFailure if copyPortableConfig: installedUserConfigPath = config.getInstalledUserConfigPath() if installedUserConfigPath: gui.ExecAndPump(installer.copyUserConfig, installedUserConfigPath) except Exception as e: res = e log.error("Failed to execute installer", exc_info=True) progressDialog.done() del progressDialog if isinstance(res, installer.RetriableFailure): # Translators: a message dialog asking to retry or cancel when NVDA install fails message = _( "The installation is unable to remove or overwrite a file. Another copy of NVDA may be running on another logged-on user account. Please make sure all installed copies of NVDA are shut down and try the installation again." ) # Translators: the title of a retry cancel dialog when NVDA installation fails title = _("File in Use") if winUser.MessageBox(None, message, title, winUser.MB_RETRYCANCEL) == winUser.IDRETRY: return doInstall(createDesktopShortcut=createDesktopShortcut, startOnLogon=startOnLogon, copyPortableConfig=copyPortableConfig, isUpdate=isUpdate, silent=silent, startAfterInstall=startAfterInstall) if res != 0: log.error("Installation failed: %s" % res) # Translators: The message displayed when an error occurs during installation of NVDA. gui.messageBox( _("The installation of NVDA failed. Please check the Log Viewer for more information." ), # Translators: The title of a dialog presented when an error occurs. _("Error"), wx.OK | wx.ICON_ERROR) return if not silent: msg = ( # Translators: The message displayed when NVDA has been successfully installed. _("Successfully installed NVDA. ") if not isUpdate # Translators: The message displayed when NVDA has been successfully updated. else _("Successfully updated your installation of NVDA. ")) # Translators: The message displayed to the user after NVDA is installed # and the installed copy is about to be started. gui.messageBox( msg + _("Please press OK to start the installed copy."), # Translators: The title of a dialog presented to indicate a successful operation. _("Success")) if startAfterInstall: # #4475: ensure that the first window of the new process is not hidden by providing SW_SHOWNORMAL shellapi.ShellExecute( None, None, os.path.join(installer.defaultInstallPath, 'nvda.exe'), None, None, winUser.SW_SHOWNORMAL) else: gui.safeAppExit()
def onExit(self, evt): gui.safeAppExit()