forked from AcademySoftwareFoundation/OpenImageIO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_registry.py
More file actions
36 lines (25 loc) · 1.05 KB
/
check_registry.py
File metadata and controls
36 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Helper script to detect system-level long path support on Windows.
Returns 0 if the long path support is enabled in the registry, or 1 otherwise.
Reference: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#registry-setting-to-enable-long-paths
"""
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO
import sys
import winreg
_SUB_KEY = "SYSTEM\\CurrentControlSet\\Control\\FileSystem"
_VALUE_NAME = "LongPathsEnabled"
def main() -> int:
try:
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, _SUB_KEY) as key:
reg_value, value_type = winreg.QueryValueEx(key, _VALUE_NAME)
except OSError:
# Key does not exist
return 1
# It's vanishingly unlikely that someone would stuff some other value type
# in this key, but let's be paranoid.
if value_type != winreg.REG_DWORD:
return 1
return int(reg_value != 1)
if __name__ == "__main__":
sys.exit(main())