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
|
return None
|
||||||
|
|
||||||
if sys.platform == "win32":
|
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":
|
elif sys.platform == "darwin":
|
||||||
appSupportDir = os.path.expanduser("~/Library/Application Support/pymclevel/")
|
appSupportDir = os.path.expanduser("~/Library/Application Support/pymclevel/")
|
||||||
else:
|
else:
|
||||||
|
25
mclevel.py
25
mclevel.py
@ -190,30 +190,7 @@ from schematic import *
|
|||||||
import sys
|
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":
|
#if sys.platform == "win32":
|
||||||
# from win32com.shell import shell, shellcon
|
# from win32com.shell import shell, shellcon
|
||||||
# saveFileDir = shell.SHGetPathFromIDListEx (
|
# saveFileDir = shell.SHGetPathFromIDListEx (
|
||||||
|
@ -73,4 +73,33 @@ def exhaust(_iter):
|
|||||||
pass
|
pass
|
||||||
return i
|
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
|
from level import MCLevel, EntityLevel
|
||||||
|
Reference in New Issue
Block a user