mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont depend on win32api in polyglot
This commit is contained in:
parent
f1199035f6
commit
057b873933
@ -151,14 +151,24 @@ else:
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
if hasattr(sys, 'getwindowsversion'):
|
if hasattr(sys, 'getwindowsversion'):
|
||||||
|
import ctypes
|
||||||
|
gev = ctypes.windll.kernel32.GetEnvironmentVariableW
|
||||||
|
|
||||||
def getenv(x, default=None):
|
def getenv(x, default=None):
|
||||||
from win32api import GetEnvironmentVariableW
|
|
||||||
if isinstance(x, bytes):
|
if isinstance(x, bytes):
|
||||||
x = x.decode('mbcs', 'replace')
|
x = x.decode('mbcs', 'replace')
|
||||||
ans = GetEnvironmentVariableW(x)
|
n = 1024
|
||||||
if ans is None:
|
buf = ctypes.create_unicode_buffer(n)
|
||||||
ans = default
|
res = gev(x, buf, n)
|
||||||
return ans
|
if res == 0:
|
||||||
|
return default
|
||||||
|
if res > n - 4:
|
||||||
|
n = res + 8
|
||||||
|
buf = ctypes.create_unicode_buffer(n)
|
||||||
|
res = gev(x, buf, n)
|
||||||
|
if res == 0:
|
||||||
|
return default
|
||||||
|
return buf.value
|
||||||
else:
|
else:
|
||||||
def getenv(x, default=None):
|
def getenv(x, default=None):
|
||||||
ans = os.getenv(x, default)
|
ans = os.getenv(x, default)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user