Don't load multiple of the same library (fixes Forge)

This commit is contained in:
Fierelier 2021-03-29 09:33:20 +02:00
parent 522e365d92
commit 9248963275

View File

@ -105,33 +105,45 @@ def findInChainDeepest(versionsPath,version,path):
if found == False: raise if found == False: raise
return found return found
def parseJavaLibraryName(libName):
libSplit = libName.rsplit(":",1)
libVersion = libSplit[1]
libPath = libSplit[0]
libName = libSplit[0].rsplit(":",1)[1]
libFilePath = libSplit[0].replace(".","/").replace(":","/") + "/" + libVersion + "/" +libName+ "-" +libVersion+ ".jar"
return libPath,libName,libVersion,libFilePath
def processVersion(versionsPath,libraryPath,nativePath,version): def processVersion(versionsPath,libraryPath,nativePath,version):
versionPath = p(versionsPath,version) versionPath = p(versionsPath,version)
clientJson = readJsonFile(p(versionPath,version + ".json")) clientJson = readJsonFile(p(versionPath,version + ".json"))
libraries = [] libraries = []
natives = []
arguments = [] arguments = []
downloadLibraries = {}
if "inheritsFrom" in clientJson: if "inheritsFrom" in clientJson:
_,libraries,downloadLibraries,natives,arguments = processVersion(versionsPath,libraryPath,nativePath,clientJson["inheritsFrom"]) _,libraries,arguments = processVersion(versionsPath,libraryPath,nativePath,clientJson["inheritsFrom"])
for library in clientJson["libraries"]: for library in clientJson["libraries"]:
l = {}
l["path"],l["name"],l["version"],l["filePath"] = parseJavaLibraryName(library["name"])
l["type"] = "library"
if "downloads" in library: if "downloads" in library:
# Libraries # Libraries
if "artifact" in library["downloads"]: if "artifact" in library["downloads"]:
library["downloads"]["artifact"]["path"] = library["downloads"]["artifact"]["path"].replace("/",os.path.sep) if "path" in library["downloads"]["artifact"]:
libraries.append(p(libraryPath,library["downloads"]["artifact"]["path"])) l["filePathOS"] = p(libraryPath,library["downloads"]["artifact"]["path"].replace("/",os.path.sep))
if "url" in library["downloads"]["artifact"] and library["downloads"]["artifact"]["url"] != "": if "url" in library["downloads"]["artifact"] and library["downloads"]["artifact"]["url"] != "":
downloadLibraries[p(libraryPath,library["downloads"]["artifact"]["path"])] = library["downloads"]["artifact"]["url"] l["url"] = library["downloads"]["artifact"]["url"]
libraries.append(l)
# Natives # Natives
if "classifiers" in library["downloads"]: if "classifiers" in library["downloads"]:
l["type"] = "native"
for classifier in library["downloads"]["classifiers"]: for classifier in library["downloads"]["classifiers"]:
native = library["downloads"]["classifiers"][classifier] native = library["downloads"]["classifiers"][classifier]
native["path"] = native["path"].replace("/",os.path.sep) l["filePathOS"] = p(nativePath,native["path"].replace("/",os.path.sep))
if "url" in native and native["url"] != "": if "url" in native and native["url"] != "":
downloadLibraries[p(nativePath,native["path"])] = native["url"] l["url"] = native["url"]
native = False native = False
if "natives-" +lv["osName"] in library["downloads"]["classifiers"]: if "natives-" +lv["osName"] in library["downloads"]["classifiers"]:
@ -139,25 +151,18 @@ def processVersion(versionsPath,libraryPath,nativePath,version):
if lv["osName"] == "macos" and native == False and "natives-osx" in library["downloads"]["classifiers"]: if lv["osName"] == "macos" and native == False and "natives-osx" in library["downloads"]["classifiers"]:
native = library["downloads"]["classifiers"]["natives-osx"] native = library["downloads"]["classifiers"]["natives-osx"]
if native != False:
natives.append(p(nativePath,native["path"]))
elif "name" in library: elif "name" in library:
# Stupid libraries # Dumb libraries
libSplit = library["name"].rsplit(":",1)
libVersion = libSplit[1]
libName = libSplit[0].rsplit(":",1)[1]
libPath = libSplit[0].replace(".","/").replace(":","/") + "/" + libVersion + "/" +libName+ "-" +libVersion+ ".jar"
library["path"] = libPath.replace("/",os.path.sep)
libraries.append(p(libraryPath,library["path"]))
if "url" in library: if "url" in library:
fullUrl = library["url"] l["url"] = library["url"]
while len(fullUrl) > 0 and fullUrl[-1] == "/": fullUrl = fullUrl[:-1] while len(l["url"]) > 0 and l["url"][-1] == "/": l["url"] = l["url"][:-1]
fullUrl = fullUrl + "/" + libPath fullUrl = fullUrl + "/" + l["filePath"]
downloadLibraries[p(libraryPath,library["path"])] = fullUrl
if os.path.isfile(p(versionPath,version + ".jar")): libraries.append(p(versionPath,version + ".jar")) l["filePathOS"] = p(libraryPath,l["path"].replace("/",os.path.sep))
libraries.append(l)
if os.path.isfile(p(versionPath,version + ".jar")):
libraries.append({"type":"client","filePathOS":p(versionPath,version + ".jar")})
if "arguments" in clientJson: if "arguments" in clientJson:
for arg in clientJson["arguments"]["game"]: for arg in clientJson["arguments"]["game"]:
@ -169,7 +174,7 @@ def processVersion(versionsPath,libraryPath,nativePath,version):
if type(arg) != str: continue if type(arg) != str: continue
arguments.append(arg) arguments.append(arg)
return clientJson,libraries,downloadLibraries,natives,arguments return clientJson,libraries,arguments
def main(): def main():
print("Reading config...") print("Reading config...")
@ -215,31 +220,46 @@ def main():
versionsPath = p(lv["gamePath"],"versions") versionsPath = p(lv["gamePath"],"versions")
libraryPath = p(lv["gamePath"],"libraries") libraryPath = p(lv["gamePath"],"libraries")
nativePath = p(lv["gamePath"],"natives") nativePath = p(lv["gamePath"],"natives")
clientJson,libraries,downloadLibraries,natives,arguments = processVersion(versionsPath,libraryPath,nativePath,lv["version"]) clientJson,libraries,arguments = processVersion(versionsPath,libraryPath,nativePath,lv["version"])
versionPath = p(lv["gamePath"],"versions",lv["version"]) versionPath = p(lv["gamePath"],"versions",lv["version"])
nativesOutPath = p(versionPath,"natives-" +lv["osName"]) nativesOutPath = p(versionPath,"natives-" +lv["osName"])
assetsPath = p(lv["gamePath"],"assets") assetsPath = p(lv["gamePath"],"assets")
separator = ";"
if lv["osName"] != "windows": separator = ":"
libraryList = separator.join(libraries)
print("\nLibraries:")
for library in libraries:
print("- " +library)
print("\nDownloading libraries...") print("\nDownloading libraries...")
for library in downloadLibraries:
fileDl(downloadLibraries[library],library,read = False)
for library in libraries: for library in libraries:
if not os.path.isfile(library): print("Warning, missing lib: " +library) if "url" in library:
fileDl(library["url"],library["filePathOS"],read = False)
loadLibraries = {}
for library in libraries:
if library["type"] == "client":
loadLibraries["client:" +library["filePathOS"]] = library
elif library["type"] == "library":
loadLibraries[library["path"]] = library
separator = ";"
libraryList = ""
if lv["osName"] != "windows": separator = ":"
print("\nLibraries/natives:")
for libraryID in loadLibraries:
library = loadLibraries[libraryID]
if os.path.isfile(library["filePathOS"]):
if library["type"] == "client":
print("Client: " +library["filePathOS"])
else:
print("- " +library["path"])
else:
print("Lib not found: " +library["path"])
libraryList += library["filePathOS"] + separator
libraryList = libraryList[:-1]
print("\nExtracting natives...") print("\nExtracting natives...")
if not os.path.isdir(nativesOutPath): os.makedirs(nativesOutPath) if not os.path.isdir(nativesOutPath): os.makedirs(nativesOutPath)
for native in natives: for library in libraries:
subprocess.run(["7z","x",native,"-o" +nativesOutPath,"-aos"],check=True,stdout=subprocess.DEVNULL) if library["type"] == "native":
subprocess.run(["7z","x",library["filePathOS"],"-o" +nativesOutPath,"-aos"],check=True,stdout=subprocess.DEVNULL)
launcherVariables = {} launcherVariables = {}
launcherVariables["auth_player_name"] = lv["name"] launcherVariables["auth_player_name"] = lv["name"]