Esempio n. 1
0
 def __init__(self, path='/.minecraft'):
     path = os.getcwd().replace('\\', "/") + path
     self.gamepath = path
     self.versionpath = path + '/versions/'
     self.lib = path + '/libraries/'
     self.ass = path + '/assets/'
     self.nativespath = path + '/natives/'
     self.versioncore = VersionCore(self.versionpath)
Esempio n. 2
0
class Launcher:
    javapath = 'java'

    def __init__(self, path='/.minecraft'):
        path = os.getcwd().replace('\\', "/") + path
        self.gamepath = path
        self.versionpath = path + '/versions/'
        self.lib = path + '/libraries/'
        self.ass = path + '/assets/'
        self.nativespath = path + '/natives/'
        self.versioncore = VersionCore(self.versionpath)

    def setnatives(self, nativespath):
        self.nativespath = nativespath

    def extranatives(self, version):
        Dir(self.nativespath).create()
        # 定义一个列表来存放lib
        liblist = []
        jsonfileobj = MinecraftJson(File(self.versioncore.getjson(version)))
        for item in jsonfileobj.getlibs():
            liblist.append(item['name'] + '.jar')
        # 应对1.7.10的Forge将Minecraft加入到了Lib当中
        if jsonfileobj.getjarid():
            for item in MinecraftJson(File(self.versioncore.getjson(jsonfileobj.getjarid()))).getlibs():
                liblist.append(item['name'] + '.jar')
        for item in liblist:
            # 用正则表达式匹配lwjgl库,下下策,如果有更好的方法欢迎联系我
            lwjglre = re.compile(r'org/lwjgl/lwjgl/lwjgl-platform/(\d).(\d).(\d)/')
            # 解压文件
            if lwjglre.match(item):
                lwjgljar = ZipFile(self.lib + item)
                lwjgljar.extract_to(self.nativespath)

    def setlib(self, libpath):
        self.lib = libpath

    def setass(self, asspath):
        self.ass = asspath

    def setversionpath(self, versionpath):
        self.versionpath = versionpath

    def setjava(self, javapath):
        self.javapath = javapath

    def getversions(self):
        dirobj = Dir(self.versionpath)
        returnlist = []
        for item in dirobj.get_dirs():
            # 判断是否Jar完好
            if File(self.versionpath + '%s/%s.json' % (item, item)).has_file() and \
                    File(self.versionpath + '%s/%s.jar' % (item, item)).has_file():
                returnlist.append(item)
        return returnlist

    def getlunchershell(self, version, memories, userobj):
        return version.getcommand(self.javapath, memories, self, userobj)

    def searchversion(self):
        returnarray = []
        if Dir(self.versionpath).has_dir():
            for item in Dir(self.versionpath).get_dirs():
                returnarray.append(NewMinecraft(item, self.versionpath))
        if Dir(self.gamepath + '/bin/').has_dir():
            returnarray.append(ClassicMinecraft())
        return returnarray