def _minecraft_folder(): """Finds the folder minecraft stores the account credentials in. Copyright (c) 2010 David Rio Vierra Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. """ if sys.platform == "win32": try: import win32com.client objShell = win32com.client.Dispatch("WScript.Shell") appDataDir = objShell.SpecialFolders("AppData") except: try: from win32com.shell import shell, shellcon appDataDir = shell.SHGetPathFromIDListEx( shell.SHGetSpecialFolderLocation( 0, shellcon.CSIDL_APPDATA)) except: 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") return minecraftDir
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 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") 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( 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()) 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"~")