From 2cdf0f891e427939915676b8cac061df55c05286 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Thu, 17 Jun 2021 15:49:53 +0200 Subject: [PATCH] Handle multi-type downloads (library + native pairs) 1.17 now works, "yay".. --- offline-minecraft-launcher.py | 91 ++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/offline-minecraft-launcher.py b/offline-minecraft-launcher.py index e7fa2ca..856f897 100644 --- a/offline-minecraft-launcher.py +++ b/offline-minecraft-launcher.py @@ -150,65 +150,68 @@ def processVersion(versionsPath,libraryPath,nativePath,version): _,libraries,arguments,jvmArguments = processVersion(versionsPath,libraryPath,nativePath,clientJson["inheritsFrom"]) for library in clientJson["libraries"]: - l = {} - l["package"],l["name"],l["version"],l["filePath"] = parseJavaLibraryName(library["name"]) - l["type"] = "library" - l["data"] = library - l["dumb"] = True + lBase = {} + lBase["package"],lBase["name"],lBase["version"],lBase["filePath"] = parseJavaLibraryName(library["name"]) + lBase["type"] = "library" + lBase["data"] = library + lBase["dumb"] = True - # Dumb-detection - if "downloads" in library: l["dumb"] = False - - # Type-detection - if not l["dumb"]: - if "classifiers" in library["downloads"]: - l["type"] = "native" - else: - if "natives" in library: - l["type"] = "native" - - # Libraries - if l["type"] == "library": - if not l["dumb"]: - if "artifact" in library["downloads"]: - if "path" in library["downloads"]["artifact"]: - l["filePathOS"] = p(libraryPath,library["downloads"]["artifact"]["path"].replace("/",os.path.sep)) - if "url" in library["downloads"]["artifact"] and library["downloads"]["artifact"]["url"] != "": - l["url"] = library["downloads"]["artifact"]["url"] - libraries.append(l) - else: - if not "url" in library: library["url"] = "https://libraries.minecraft.net" - l["url"] = library["url"] - while len(l["url"]) > 0 and l["url"][-1] == "/": l["url"] = l["url"][:-1] - l["url"] = l["url"] + "/" + l["filePath"] - l["filePathOS"] = p(libraryPath,l["filePath"].replace("/",os.path.sep)) - libraries.append(l) - - # Natives - if l["type"] == "native": - if not l["dumb"]: + if "downloads" in library: # not dumb + if "classifiers" in library["downloads"]: # classifiers (usually for natives, their sources and their documentation) for classifier in library["downloads"]["classifiers"]: + l = lBase.copy() native = library["downloads"]["classifiers"][classifier] - l["nativeOS"] = classifier.replace("natives-","",1) + if classifier.startswith("natives-"): + l["type"] = "native" + l["nativeOS"] = classifier.replace("natives-","",1) + else: + continue # TODO: add source and javadoc handling + l["filePathOS"] = p(nativePath,native["path"].replace("/",os.path.sep)) if "url" in native and native["url"] != "": l["url"] = native["url"] + libraries.append(l) - else: - if not "url" in library: library["url"] = "https://libraries.minecraft.net" - l["url"] = library["url"] - while len(l["url"]) > 0 and l["url"][-1] == "/": l["url"] = l["url"][:-1] - l["url"] = l["url"] + "/" + l["filePath"] + + if "artifact" in library["downloads"]: # artifact (usually for libraries) + l = lBase.copy() + if "path" in library["downloads"]["artifact"]: + l["filePathOS"] = p(libraryPath,library["downloads"]["artifact"]["path"].replace("/",os.path.sep)) + + if "url" in library["downloads"]["artifact"] and library["downloads"]["artifact"]["url"] != "": + l["url"] = library["downloads"]["artifact"]["url"] + + libraries.append(l) + else: # dumb + if "natives" in library: # natives + lBaseTwo = lBase.copy() + if not "url" in library: + lBaseTwo["url"] = "https://libraries.minecraft.net" + else: + lBaseTwo["url"] = library["url"] + + while len(lBaseTwo["url"]) > 0 and lBaseTwo["url"][-1] == "/": lBaseTwo["url"] = lBaseTwo["url"][:-1] + lBaseTwo["url"] = lBaseTwo["url"] + "/" + lBaseTwo["filePath"] - lcopy = l.copy() for native in library["natives"]: - l = lcopy.copy() + l = lBaseTwo.copy() l["nativeOS"] = native native = "natives-" + native l["filePath"] = l["filePath"][:-4] + "-" + native + ".jar" l["url"] = l["url"][:-4] + "-" + native + ".jar" l["filePathOS"] = p(nativePath,l["filePath"].replace("/",os.path.sep)) libraries.append(l) + else: + l = lBase.copy() + if not "url" in library: + l["url"] = "https://libraries.minecraft.net" + else: + l["url"] = library["url"] + + while len(l["url"]) > 0 and l["url"][-1] == "/": l["url"] = l["url"][:-1] + l["url"] = l["url"] + "/" + l["filePath"] + l["filePathOS"] = p(libraryPath,l["filePath"].replace("/",os.path.sep)) + libraries.append(l) if os.path.isfile(p(versionPath,version + ".jar")): libraries.append({"type":"client","filePathOS":p(versionPath,version + ".jar")})