Skip to content
Browse files

Cleanup: Finding directories in mclevelbase.py

  • Loading branch information...
1 parent 250f479 commit dd3d05111249057fa5efb3d1de7c2055e57523ae @codewarrior0 codewarrior0 committed Dec 2, 2012
Showing with 11 additions and 16 deletions.
  1. +11 −16 mclevelbase.py
View
27 mclevelbase.py
@@ -6,6 +6,7 @@
from contextlib import contextmanager
from logging import getLogger
+import sys
import os
log = getLogger(__name__)
@@ -41,47 +42,41 @@ def exhaust(_iter):
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":
+def win32_appdata():
# try to use win32 api to get the AppData folder since python doesn't populate os.environ with unicode strings.
try:
import win32com.client
objShell = win32com.client.Dispatch("WScript.Shell")
- appDataDir = objShell.SpecialFolders("AppData")
+ return objShell.SpecialFolders("AppData")
except Exception, e:
print "Error while getting AppData folder using WScript.Shell.SpecialFolders: {0!r}".format(e)
try:
from win32com.shell import shell, shellcon
- appDataDir = shell.SHGetPathFromIDListEx(
+ return shell.SHGetPathFromIDListEx(
shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_APPDATA)
)
except Exception, e:
print "Error while getting AppData folder using SHGetSpecialFolderLocation: {0!r}".format(e)
- appDataDir = os.environ['APPDATA'].decode(sys.getfilesystemencoding())
+ return os.environ['APPDATA'].decode(sys.getfilesystemencoding())
+if sys.platform == "win32":
+ appDataDir = win32_appdata()
minecraftDir = os.path.join(appDataDir, u".minecraft")
+ appSupportDir = os.path.join(appDataDir, u"pymclevel")
elif sys.platform == "darwin":
appDataDir = os.path.expanduser(u"~/Library/Application Support")
-
minecraftDir = os.path.join(appDataDir, u"minecraft")
- minecraftDir.decode(sys.getfilesystemencoding())
+ appSupportDir = os.path.expanduser(u"~/Library/Application Support/pymclevel/")
+
else:
appDataDir = os.path.expanduser(u"~")
minecraftDir = os.path.expanduser(u"~/.minecraft")
-
+ appSupportDir = os.path.expanduser(u"~/.pymclevel")
saveFileDir = os.path.join(minecraftDir, u"saves")
-if sys.platform == "win32":
- appSupportDir = os.path.join(appDataDir, u"pymclevel")
-elif sys.platform == "darwin":
- appSupportDir = os.path.expanduser(u"~/Library/Application Support/pymclevel/")
-else:
- appSupportDir = os.path.expanduser(u"~/.pymclevel")

0 comments on commit dd3d051

Please sign in to comment.
Something went wrong with that request. Please try again.