pulled out appDataDir from folder-finding code, moved code to mclevelbase, used appDataDir in place of %APPDATA% because %APPDATA% may not always be defined (?) on win32
This commit is contained in:
parent
704cedcffd
commit
ad1e2f90a0
@ -65,7 +65,8 @@ def which(program):
|
||||
return None
|
||||
|
||||
if sys.platform == "win32":
|
||||
appSupportDir = os.path.join(os.environ["APPDATA"], "pymclevel")
|
||||
from mclevel import appDataDir
|
||||
appSupportDir = os.path.join(appDataDir, "pymclevel")
|
||||
elif sys.platform == "darwin":
|
||||
appSupportDir = os.path.expanduser("~/Library/Application Support/pymclevel/")
|
||||
else:
|
||||
|
23
mclevel.py
23
mclevel.py
@ -190,29 +190,6 @@ from schematic import *
|
||||
import sys
|
||||
|
||||
|
||||
# we need to decode file paths from environment variables or else we get an error
|
||||
# if they are formatted or joined to a unicode string
|
||||
|
||||
if sys.platform == "win32":
|
||||
#not sure why win32com is needed if the %APPDATA% var is available
|
||||
try:
|
||||
import win32com.client
|
||||
|
||||
objShell = win32com.client.Dispatch("WScript.Shell")
|
||||
minecraftDir = os.path.join(objShell.SpecialFolders("AppData"), u".minecraft")
|
||||
except Exception, e:
|
||||
print "WScript error {0!r}".format(e)
|
||||
appdata = os.environ['APPDATA'].decode(sys.getfilesystemencoding());
|
||||
minecraftDir = os.path.join(appdata, ".minecraft")
|
||||
|
||||
elif sys.platform == "darwin":
|
||||
minecraftDir = os.path.expanduser("~/Library/Application Support/minecraft")
|
||||
minecraftDir.decode(sys.getfilesystemencoding());
|
||||
else:
|
||||
minecraftDir = os.path.expanduser("~/.minecraft")
|
||||
minecraftDir.decode(sys.getfilesystemencoding());
|
||||
|
||||
saveFileDir = os.path.join(minecraftDir, u"saves")
|
||||
|
||||
#if sys.platform == "win32":
|
||||
# from win32com.shell import shell, shellcon
|
||||
|
@ -73,4 +73,33 @@ def exhaust(_iter):
|
||||
pass
|
||||
return i
|
||||
|
||||
|
||||
# we need to decode file paths from environment variables or else we get an error
|
||||
# if they are formatted or joined to a unicode string
|
||||
import sys
|
||||
|
||||
if sys.platform == "win32":
|
||||
#not sure why win32com is needed if the %APPDATA% var is available
|
||||
try:
|
||||
import win32com.client
|
||||
objShell = win32com.client.Dispatch("WScript.Shell")
|
||||
appDataDir = objShell.SpecialFolders("AppData")
|
||||
minecraftDir = os.path.join(appDataDir, u".minecraft")
|
||||
except Exception, e:
|
||||
print "Error while getting AppData folder using WScript.Shell.SpecialFolders: {0!r}".format(e)
|
||||
appDataDir = os.environ['APPDATA'].decode(sys.getfilesystemencoding());
|
||||
minecraftDir = os.path.join(appDataDir, u".minecraft")
|
||||
|
||||
elif sys.platform == "darwin":
|
||||
appDataDir = os.path.expanduser(u"~/Library/Application Support")
|
||||
|
||||
minecraftDir = os.path.join(appDataDir, u"minecraft")
|
||||
minecraftDir.decode(sys.getfilesystemencoding());
|
||||
else:
|
||||
appDataDir = os.path.expanduser(u"~")
|
||||
minecraftDir = os.path.expanduser(u"~/.minecraft")
|
||||
minecraftDir.decode(sys.getfilesystemencoding());
|
||||
|
||||
saveFileDir = os.path.join(minecraftDir, u"saves")
|
||||
|
||||
from level import MCLevel, EntityLevel
|
||||
|
Reference in New Issue
Block a user