forked from mcedit/mcedit2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/iJunkie22/mcedit2
- Loading branch information
Showing
2 changed files
with
79 additions
and
26 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import sys | ||
try: | ||
assert sys.platform == "win32" | ||
# If sys.platform is "win32", win32api is needed and expected | ||
import win32api | ||
except AssertionError as _ae: | ||
# If sys.platform is not "win32", do not try to import win32api | ||
win32api = None | ||
|
||
def getUserFilesDirectory(): | ||
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) | ||
|
||
dataDir = os.path.join(folder, "MCEdit User Data") | ||
|
||
if not os.path.exists(dataDir): | ||
os.makedirs(dataDir) | ||
return dataDir | ||
|
||
def getUserSchematicsDirectory(): | ||
return os.path.join(getUserFilesDirectory(), "schematics") | ||
|
||
def getUserPluginsDirectory(): | ||
return os.path.join(getUserFilesDirectory(), "plugins") |
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