-
-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that NVDA can get file version information for binaries in system32 on 64-bit versions of Windows #12943
Merged
seanbudd
merged 13 commits into
nvaccess:master
from
lukaszgo1:file-info-for-system32-binaries
Oct 25, 2021
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7d3f89c
Introduce context manager for pausing Wow64 for a section of code in …
lukaszgo1 2ef4a97
Lint for shlobj"
lukaszgo1 85ab8ae
Remove unused `getSystemConfigPath`
lukaszgo1 10c837b
Ensure that NVDA can retrieve file version info for binaries placed i…
lukaszgo1 a25a991
Merge branch 'master' into file-info-for-system32-binaries
lukaszgo1 7c10407
Review actions
lukaszgo1 fed9ac0
Merge branch 'master' into file-info-for-system32-binaries
lukaszgo1 d94e309
Remove deprecated `SHGetFolderPath` and replace with `SHGetKnownFolde…
lukaszgo1 1816b34
Disable syswow64 redirection just for `getFileVersionInfo` rather tha…
lukaszgo1 fdba9dc
Merge branch 'master' into file-info-for-system32-binaries
lukaszgo1 e2896bc
Add additional class to the enum
lukaszgo1 0600845
Merge branch 'file-info-for-system32-binaries' of https://github.com/…
lukaszgo1 177ab51
update changes
seanbudd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,56 @@ | ||
# -*- coding: UTF-8 -*- | ||
#shlobj.py | ||
#A part of NonVisual Desktop Access (NVDA) | ||
#Copyright (C) 2006-2017 NV Access Limited, Babbage B.V. | ||
#This file is covered by the GNU General Public License. | ||
#See the file COPYING for more details. | ||
# A part of NonVisual Desktop Access (NVDA) | ||
# Copyright (C) 2009-2021 NV Access Limited, Babbage B.V., Łukasz Golonka | ||
# This file is covered by the GNU General Public License. | ||
# See the file COPYING for more details. | ||
|
||
""" | ||
This module wraps the SHGetFolderPath function in shell32.dll and defines the necessary contstants. | ||
CSIDL (constant special item ID list) values provide a unique system-independent way to | ||
r""" | ||
This module wraps the `SHGetKnownFolderPath` function in shell32.dll and defines the necessary contstants. | ||
Known folder ids provide a unique system-independent way to | ||
identify special folders used frequently by applications, but which may not have the same name | ||
or location on any given system. For example, the system folder may be "C:\Windows" on one system | ||
and "C:\Winnt" on another. The CSIDL system is used to be compatible with Windows XP. | ||
and "C:\Winnt" on another. | ||
""" | ||
|
||
from ctypes import * | ||
from ctypes.wintypes import * | ||
import comtypes | ||
import ctypes | ||
import enum | ||
import functools | ||
import typing | ||
|
||
shell32 = windll.shell32 | ||
|
||
MAX_PATH = 260 | ||
class FOLDERID(str, enum.Enum): | ||
"""Contains guids of known folders from Knownfolders.h. Full list is availabe at: | ||
https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid""" | ||
#: The file system directory that serves as a common repository for application-specific data. | ||
#: A typical path is C:\Documents and Settings\username\Application Data. | ||
RoamingAppData = "{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}" | ||
#: The file system directory that serves as a data repository for local (nonroaming) applications. | ||
#: A typical path is C:\Documents and Settings\username\Local Settings\Application Data. | ||
LocalAppData = "{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}" | ||
#: The file system directory that contains application data for all users. | ||
#: A typical path is C:\Documents and Settings\All Users\Application Data. | ||
#: This folder is used for application data that is not user specific. | ||
ProgramData = "{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}" | ||
# The Windows System folder. | ||
# A typical path is C:\Windows\System32. | ||
System = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}" | ||
SystemX86 = "{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}" | ||
|
||
#: The file system directory that serves as a common repository for application-specific data. | ||
#: A typical path is C:\Documents and Settings\username\Application Data. | ||
CSIDL_APPDATA = 0x001a | ||
#: The file system directory that serves as a data repository for local (nonroaming) applications. | ||
#: A typical path is C:\Documents and Settings\username\Local Settings\Application Data. | ||
CSIDL_LOCAL_APPDATA = 0x001c | ||
#: The file system directory that contains application data for all users. | ||
#: A typical path is C:\Documents and Settings\All Users\Application Data. | ||
#: This folder is used for application data that is not user specific. | ||
CSIDL_COMMON_APPDATA = 0x0023 | ||
|
||
def SHGetFolderPath(owner, folder, token=0, flags=0): | ||
path = create_unicode_buffer(MAX_PATH) | ||
# Note As of Windows Vista, this function is merely a wrapper for SHGetKnownFolderPath | ||
if shell32.SHGetFolderPathW(owner, folder, token, flags, byref(path)) != 0: | ||
raise WinError() | ||
return path.value | ||
@functools.lru_cache(maxsize=128) | ||
def SHGetKnownFolderPath(folderGuid: str, dwFlags: int = 0, hToken: typing.Optional[int] = None) -> str: | ||
"""Wrapper for `SHGetKnownFolderPath` which caches the results | ||
to avoid calling the win32 function unnecessarily.""" | ||
guid = comtypes.GUID(folderGuid) | ||
pathPointer = ctypes.c_wchar_p() | ||
res = ctypes.windll.shell32.SHGetKnownFolderPath( | ||
comtypes.byref(guid), | ||
dwFlags, | ||
hToken, | ||
ctypes.byref(pathPointer) | ||
) | ||
if res != 0: | ||
raise RuntimeError(f"SHGetKnownFolderPath failed with erro code {res}") | ||
path = pathPointer.value | ||
ctypes.windll.ole32.CoTaskMemFree(pathPointer) | ||
return path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely to break backwards compat. I don't think that's a problem when this will be 2022.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've mentioned that consideration in the PR description. Given that we're branching for 2021.3 already this should not be a problem. Could you add this PR to the 2022.1 milestone so it is not forgotten?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I must have missed that.