Support Python 2.7 and Python 3 winreg imports on Windows

This commit is contained in:
Derek Tracy 2021-02-24 20:54:39 -05:00 committed by NoDRM
parent d9353bdd93
commit 1545d76803
10 changed files with 41 additions and 10 deletions

View File

@ -117,7 +117,10 @@ if iswindows:
c_long, c_ulong c_long, c_ulong
from ctypes.wintypes import LPVOID, DWORD, BOOL from ctypes.wintypes import LPVOID, DWORD, BOOL
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
def _load_crypto_libcrypto(): def _load_crypto_libcrypto():
from ctypes.util import find_library from ctypes.util import find_library

View File

@ -101,7 +101,10 @@ def getNookLogFiles():
logFiles = [] logFiles = []
found = False found = False
if iswindows: if iswindows:
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
# some 64 bit machines do not have the proper registry key for some reason # some 64 bit machines do not have the proper registry key for some reason
# or the python interface to the 32 vs 64 bit registry is broken # or the python interface to the 32 vs 64 bit registry is broken

View File

@ -195,7 +195,11 @@ if iswindows:
create_unicode_buffer, create_string_buffer, CFUNCTYPE, addressof, \ create_unicode_buffer, create_string_buffer, CFUNCTYPE, addressof, \
string_at, Structure, c_void_p, cast string_at, Structure, c_void_p, cast
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
MAX_PATH = 255 MAX_PATH = 255
kernel32 = windll.kernel32 kernel32 = windll.kernel32
advapi32 = windll.advapi32 advapi32 = windll.advapi32

View File

@ -20,7 +20,10 @@ class SimplePrefs(object):
self.file2key[filename] = key self.file2key[filename] = key
self.target = target + 'Prefs' self.target = target + 'Prefs'
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\") regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\")
path = winreg.QueryValueEx(regkey, 'Local AppData')[0] path = winreg.QueryValueEx(regkey, 'Local AppData')[0]
prefdir = path + os.sep + self.target prefdir = path + os.sep + self.target

View File

@ -42,7 +42,10 @@ class legacy_obok(object):
pwsdid = '' pwsdid = ''
try: try:
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
regkey_browser = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Software\\Kobo\\Kobo Desktop Edition\\Browser') regkey_browser = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Software\\Kobo\\Kobo Desktop Edition\\Browser')
cookies = winreg.QueryValueEx(regkey_browser, 'cookies') cookies = winreg.QueryValueEx(regkey_browser, 'cookies')
bytearrays = cookies[0] bytearrays = cookies[0]

View File

@ -360,7 +360,10 @@ class KoboLibrary(object):
if (self.kobodir == u""): if (self.kobodir == u""):
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
if sys.getwindowsversion().major > 5: if sys.getwindowsversion().major > 5:
if 'LOCALAPPDATA' in os.environ.keys(): if 'LOCALAPPDATA' in os.environ.keys():
# Python 2.x does not return unicode env. Use Python 3.x # Python 2.x does not return unicode env. Use Python 3.x

View File

@ -129,7 +129,10 @@ if iswindows:
c_long, c_ulong c_long, c_ulong
from ctypes.wintypes import LPVOID, DWORD, BOOL from ctypes.wintypes import LPVOID, DWORD, BOOL
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
def _load_crypto_libcrypto(): def _load_crypto_libcrypto():
from ctypes.util import find_library from ctypes.util import find_library

View File

@ -98,7 +98,10 @@ def getNookLogFiles():
logFiles = [] logFiles = []
found = False found = False
if iswindows: if iswindows:
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
# some 64 bit machines do not have the proper registry key for some reason # some 64 bit machines do not have the proper registry key for some reason
# or the python interface to the 32 vs 64 bit registry is broken # or the python interface to the 32 vs 64 bit registry is broken

View File

@ -177,7 +177,10 @@ if iswindows:
create_unicode_buffer, create_string_buffer, CFUNCTYPE, addressof, \ create_unicode_buffer, create_string_buffer, CFUNCTYPE, addressof, \
string_at, Structure, c_void_p, cast string_at, Structure, c_void_p, cast
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
MAX_PATH = 255 MAX_PATH = 255
kernel32 = windll.kernel32 kernel32 = windll.kernel32
advapi32 = windll.advapi32 advapi32 = windll.advapi32

View File

@ -346,7 +346,10 @@ class KoboLibrary(object):
if (self.kobodir == u""): if (self.kobodir == u""):
# step 4. we haven't found a device with serials, so try desktop apps # step 4. we haven't found a device with serials, so try desktop apps
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
try:
import winreg import winreg
except ImportError:
import _winreg as winreg
if sys.getwindowsversion().major > 5: if sys.getwindowsversion().major > 5:
if 'LOCALAPPDATA' in os.environ.keys(): if 'LOCALAPPDATA' in os.environ.keys():
# Python 2.x does not return unicode env. Use Python 3.x # Python 2.x does not return unicode env. Use Python 3.x