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