Change sys.executable to GetModuleFileNameW
Currently does nothing, but when PyInstaller is patched to use unicode filenames, GMFNW won't return an SFN any more.
This commit is contained in:
parent
97d6aeabf4
commit
8789408a22
@ -1,14 +1,29 @@
|
||||
import os
|
||||
import sys
|
||||
import win32api
|
||||
|
||||
|
||||
def getUserFilesDirectory():
|
||||
exe = sys.executable
|
||||
if sys.platform == "win32":
|
||||
# On Windows, sys.executable is codepage-encoded.
|
||||
# It cannot represent all possible filenames, so get the exe filename
|
||||
# using this wide-character API, which returns a `unicode`
|
||||
exe = win32api.GetModuleFileNameW(None)
|
||||
else:
|
||||
# On OS X, the FS encoding is always UTF-8
|
||||
# OS X filenames are defined to be UTF-8 encoded.
|
||||
# On Linux, the FS encoding is given by the current locale
|
||||
# Linux filenames are defined to be bytestrings.
|
||||
exe = sys.executable.decode(sys.getfilesystemencoding())
|
||||
|
||||
assert os.path.exists(exe), "%r does not exist" % exe
|
||||
if hasattr(sys, 'frozen'):
|
||||
folder = os.path.dirname(exe)
|
||||
else:
|
||||
if exe.endswith("python") or exe.endswith("python.exe"):
|
||||
script = sys.argv[0]
|
||||
# assert the source checkout is not in a non-representable path...
|
||||
assert os.path.exists(script), "Source checkout path cannot be represented with 'mbcs' encoding. Put the source checkout somewhere else."
|
||||
folder = os.path.dirname(os.path.dirname(os.path.dirname(script))) # from src/mcedit, ../../
|
||||
else:
|
||||
folder = os.path.dirname(exe)
|
||||
|
Reference in New Issue
Block a user