Exemplo n.º 1
0
	def _getExecutableFileInfo(self):
		# Used for obtaining file name and version for the executable.
		# This is needed in case immersive app package returns an error,
		# dealing with a native app, or a converted desktop app.
		# Create the buffer to get the executable name
		exeFileName = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
		length = ctypes.wintypes.DWORD(ctypes.wintypes.MAX_PATH)
		if not ctypes.windll.Kernel32.QueryFullProcessImageNameW(
			self.processHandle, 0, exeFileName, ctypes.byref(length)
		):
			raise ctypes.WinError()
		fileName = exeFileName.value
		fileinfo = getFileVersionInfo(fileName, "ProductName", "ProductVersion")
		return (fileinfo["ProductName"], fileinfo["ProductVersion"])
Exemplo n.º 2
0
	def _setProductInfo(self):
		"""Set productName and productVersion attributes.
		"""
		# Sometimes (I.E. when NVDA starts) handle is 0, so stop if it is the case
		if not self.processHandle:
			raise RuntimeError("processHandle is 0")
		# Create the buffer to get the executable name
		exeFileName = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
		length = ctypes.wintypes.DWORD(ctypes.wintypes.MAX_PATH)
		if not ctypes.windll.Kernel32.QueryFullProcessImageNameW(self.processHandle, 0, exeFileName, ctypes.byref(length)):
			raise ctypes.WinError()
		fileName = exeFileName.value
		fileinfo = getFileVersionInfo(fileName, "ProductName", "ProductVersion")
		self.productName = fileinfo["ProductName"]
		self.productVersion = fileinfo["ProductVersion"]
Exemplo n.º 3
0
    def _setProductInfo(self):
        """Set productName and productVersion attributes.
		"""
        # Sometimes (I.E. when NVDA starts) handle is 0, so stop if it is the case
        if not self.processHandle:
            raise RuntimeError("processHandle is 0")
        # Create the buffer to get the executable name
        exeFileName = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
        length = ctypes.wintypes.DWORD(ctypes.wintypes.MAX_PATH)
        if not ctypes.windll.Kernel32.QueryFullProcessImageNameW(
                self.processHandle, 0, exeFileName, ctypes.byref(length)):
            raise ctypes.WinError()
        fileName = exeFileName.value
        fileinfo = getFileVersionInfo(fileName, "ProductName",
                                      "ProductVersion")
        self.productName = fileinfo["ProductName"]
        self.productVersion = fileinfo["ProductVersion"]
Exemplo n.º 4
0
 def _download(self, url):
     remote = urllib.urlopen(url)
     if remote.code != 200:
         raise RuntimeError("Download failed with code %d" % remote.code)
     # #2352: Some security scanners such as Eset NOD32 HTTP Scanner
     # cause huge read delays while downloading.
     # Therefore, set a higher timeout.
     remote.fp._sock.settimeout(120)
     size = int(remote.headers["content-length"])
     local = file(self.destPath, "wb")
     if self.fileHash:
         hasher = hashlib.sha1()
     self._guiExec(self._downloadReport, 0, size)
     read = 0
     chunk = DOWNLOAD_BLOCK_SIZE
     while True:
         if self._shouldCancel:
             return
         if size - read < chunk:
             chunk = size - read
         block = remote.read(chunk)
         if not block:
             break
         read += len(block)
         if self._shouldCancel:
             return
         local.write(block)
         if self.fileHash:
             hasher.update(block)
         self._guiExec(self._downloadReport, read, size)
     if read < size:
         raise RuntimeError("Content too short")
     if self.fileHash and hasher.hexdigest() != self.fileHash:
         raise RuntimeError("Content has incorrect file hash")
     # getFileVersionInfo will fail as long as the file is still open.
     local.close()
     fileVersionInfo = fileUtils.getFileVersionInfo(
         self.destPath.decode("mbcs"), "FileVersion")
     fileVersion = fileVersionInfo.get('FileVersion') or self.version
     self.versionTuple = versionInfo.getNVDAVersionTupleFromString(
         fileVersion)
     self._guiExec(self._downloadReport, read, size)
Exemplo n.º 5
0
	def _download(self, url):
		remote = urllib.urlopen(url)
		if remote.code != 200:
			raise RuntimeError("Download failed with code %d" % remote.code)
		# #2352: Some security scanners such as Eset NOD32 HTTP Scanner
		# cause huge read delays while downloading.
		# Therefore, set a higher timeout.
		remote.fp._sock.settimeout(120)
		size = int(remote.headers["content-length"])
		local = file(self.destPath, "wb")
		if self.fileHash:
			hasher = hashlib.sha1()
		self._guiExec(self._downloadReport, 0, size)
		read = 0
		chunk=DOWNLOAD_BLOCK_SIZE
		while True:
			if self._shouldCancel:
				return
			if size -read <chunk:
				chunk =size -read
			block = remote.read(chunk)
			if not block:
				break
			read += len(block)
			if self._shouldCancel:
				return
			local.write(block)
			if self.fileHash:
				hasher.update(block)
			self._guiExec(self._downloadReport, read, size)
		if read < size:
			raise RuntimeError("Content too short")
		if self.fileHash and hasher.hexdigest() != self.fileHash:
			raise RuntimeError("Content has incorrect file hash")
		# getFileVersionInfo will fail as long as the file is still open.
		local.close()
		fileVersionInfo = fileUtils.getFileVersionInfo(self.destPath.decode("mbcs"), "FileVersion")
		fileVersion = fileVersionInfo.get('FileVersion') or self.version
		self.versionTuple = versionInfo.getNVDAVersionTupleFromString(fileVersion)
		self._guiExec(self._downloadReport, read, size)