forked from mcedit/pymclevel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmclevelbase.py
82 lines (57 loc) · 2.11 KB
/
mclevelbase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'''
Created on Jul 22, 2011
@author: Rio
'''
from contextlib import contextmanager
from logging import getLogger
import sys
import os
log = getLogger(__name__)
@contextmanager
def notclosing(f):
yield f
class PlayerNotFound(Exception):
pass
class ChunkNotPresent(Exception):
pass
class RegionMalformed(Exception):
pass
class ChunkMalformed(ChunkNotPresent):
pass
def exhaust(_iter):
"""Functions named ending in "Iter" return an iterable object that does
long-running work and yields progress information on each call. exhaust()
is used to implement the non-Iter equivalents"""
i = None
for i in _iter:
pass
return i
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")
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
return shell.SHGetPathFromIDListEx(
shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_APPDATA)
)
except Exception, e:
print "Error while getting AppData folder using SHGetSpecialFolderLocation: {0!r}".format(e)
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")
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")