Fix some bugs when trying to extract mod info from the jar.
This commit is contained in:
+14
-9
@@ -110,30 +110,36 @@ class Form(QtW.QMainWindow):
|
||||
|
||||
def file_dropped(self, file_path: str):
|
||||
self.jar_path = file_path
|
||||
self.btn_process.setText("Process")
|
||||
if config["extract"]:
|
||||
jar = zipfile.ZipFile(file_path, "r")
|
||||
loaders = []
|
||||
if "META-INF/mods.toml" in jar.namelist():
|
||||
# This jar file uses FML
|
||||
logging.debug("identified mod as forge mod")
|
||||
loaders.append("forge")
|
||||
mod_toml = toml.loads(jar.read("META-INF/mods.toml").decode("utf-8"))
|
||||
# This mess is to catch if the mod is using the Jar version for versioning. It extracts it from the
|
||||
# MANIFEST.MF and places it where it should be in the toml.
|
||||
if mod_toml["mods"][0]["version"] == "${file.jarVersion}":
|
||||
if mod_toml.get("mods", [{}])[0].get("version") == "${file.jarVersion}":
|
||||
try:
|
||||
mod_toml["mods"][0]["version"] = re.findall(
|
||||
r"Implementation-Version: (.*)", jar.read("META-INF/MANIFEST.MF").decode("utf-8"))[0]
|
||||
except IndexError:
|
||||
mod_toml["mods"][0]["version"] = "0.0.0"
|
||||
|
||||
# Update form with data
|
||||
self.mod_title_edit.setText(mod_toml.get("mods", [{}])[0].get("displayName", ""))
|
||||
self.mod_slug_edit.setText(slugify(mod_toml.get("mods", [{}])[0].get("displayName", ""),
|
||||
replacements=[["&", "and"], ["$", "s"], ["'", ""]]))
|
||||
self.mod_version_edit.setText(mod_toml.get("mods", [{}])[0].get("version", ""))
|
||||
self.mod_loader_edit.setText("forge")
|
||||
self.mod_author_edit.setText(mod_toml.get("mods", [{}])[0].get("authors", ""))
|
||||
self.mod_url_edit.setText(mod_toml.get("mods", [{}])[0].get("displayURL", ""))
|
||||
self.mod_desc_edit.setPlainText(mod_toml.get("mods", [{}])[0].get("description", ""))
|
||||
elif "fabric.mod.json" in jar.namelist():
|
||||
if "fabric.mod.json" in jar.namelist():
|
||||
# This jar file uses Fabric
|
||||
logging.debug("identified mod as fabric mod")
|
||||
loaders.append("fabric")
|
||||
mod_json = json.loads(jar.read("fabric.mod.json").decode("utf-8"))
|
||||
|
||||
# Update form with data
|
||||
@@ -141,7 +147,6 @@ class Form(QtW.QMainWindow):
|
||||
self.mod_slug_edit.setText(slugify(mod_json.get("name", ""),
|
||||
replacements=[["&", "and"], ["$", "s"], ["'", ""]]))
|
||||
self.mod_version_edit.setText(mod_json.get("version", ""))
|
||||
self.mod_loader_edit.setText("fabric")
|
||||
|
||||
# Some spaghetti code for dealing with the possibility of authors being a []string or a dict.
|
||||
authors = mod_json.get("authors", [])
|
||||
@@ -152,11 +157,13 @@ class Form(QtW.QMainWindow):
|
||||
elif len(authors) > 0 and type(authors[0]) == str:
|
||||
author_list = authors
|
||||
self.mod_author_edit.setText(", ".join(author_list))
|
||||
|
||||
self.mod_url_edit.setText(mod_json.get("contact", {}).get("homepage", ""))
|
||||
self.mod_desc_edit.setPlainText(mod_json.get("description", ""))
|
||||
elif "quilt.mod.json" in jar.namelist():
|
||||
if "quilt.mod.json" in jar.namelist():
|
||||
# This jar file uses Quilt
|
||||
logging.debug("identified mod as quilt mod")
|
||||
loaders.append("quilt")
|
||||
mod_json = json.loads(jar.read("quilt.mod.json").decode("utf-8"))
|
||||
|
||||
# Update form with data
|
||||
@@ -164,15 +171,13 @@ class Form(QtW.QMainWindow):
|
||||
self.mod_slug_edit.setText(slugify(mod_json.get("quilt_loader", {}).get("metadata", {}).get("name", ""),
|
||||
replacements=[["&", "and"], ["$", "s"], ["'", ""]]))
|
||||
self.mod_version_edit.setText(mod_json.get("quilt_loader", {}).get("version", ""))
|
||||
self.mod_loader_edit.setText("quilt")
|
||||
self.mod_author_edit.setText(
|
||||
", ".join(mod_json.get("quilt_loader", {}).get("metadata", {}).get("contributors", {}).keys()))
|
||||
self.mod_url_edit.setText(
|
||||
mod_json.get("quilt_loader", {}).get("metadata", {}).get("contact", {}).get("homepage", ""))
|
||||
self.mod_desc_edit.setPlainText(
|
||||
mod_json.get("quilt_loader", {}).get("metadata", {}).get("description", ""))
|
||||
else:
|
||||
logging.debug("failed to identify mod loader")
|
||||
self.mod_loader_edit.setText("+".join(loaders))
|
||||
jar.close()
|
||||
|
||||
def process_click(self):
|
||||
@@ -203,7 +208,7 @@ class Form(QtW.QMainWindow):
|
||||
|
||||
def finished_processing(self):
|
||||
self.btn_process.setEnabled(True)
|
||||
self.btn_process.setText("Process")
|
||||
self.btn_process.setText("Finished")
|
||||
|
||||
def failed_processing(self):
|
||||
dialog = QtW.QMessageBox(self)
|
||||
|
||||
Reference in New Issue
Block a user