diff --git a/infiniteworld.py b/infiniteworld.py index aa73872..4b37c0f 100644 --- a/infiniteworld.py +++ b/infiniteworld.py @@ -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: diff --git a/mclevel.py b/mclevel.py index 8850524..22cead5 100644 --- a/mclevel.py +++ b/mclevel.py @@ -190,30 +190,7 @@ 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 # saveFileDir = shell.SHGetPathFromIDListEx ( diff --git a/mclevelbase.py b/mclevelbase.py index 1936cb0..33eed9a 100644 --- a/mclevelbase.py +++ b/mclevelbase.py @@ -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