1 Commits
Author SHA1 Message Date
big-duckie 1783201372 Slug now updates when use changes mod name.
Added folder selection dialog to options menu.
Fixed bug where options were not being saved to the correct path.
2024-11-27 18:47:17 -07:00
+46 -30
View File
@@ -22,7 +22,7 @@ base_path = os.path.dirname(__file__)
class Form(QtW.QMainWindow):
def __init__(self):
QtW.QMainWindow.__init__(self)
self.setMinimumSize(400, 500)
self.setMinimumSize(500, 600)
self.setWindowIcon(QtG.QIcon(os.path.join(base_path, "wrenchIcon.ico")))
self.setWindowTitle("Solder Packer")
@@ -39,6 +39,7 @@ class Form(QtW.QMainWindow):
mod_title_label = QtW.QLabel("Mod Name")
self.mod_title_edit = QtW.QLineEdit("")
self.mod_title_edit.textChanged.connect(self.update_slug)
layout.addWidget(mod_title_label, 1, 1)
layout.addWidget(self.mod_title_edit, 1, 2)
@@ -108,6 +109,10 @@ class Form(QtW.QMainWindow):
self.solder_packer.solder_url = config["url"]
self.solder_packer.solder_key = config["token"]
def update_slug(self):
self.mod_slug_edit.setText(slugify(self.mod_title_edit.text(),
replacements=[["&", "and"], ["$", "s"], ["'", ""]]))
def file_dropped(self, file_path: str):
self.jar_path = file_path
self.btn_process.setText("Process")
@@ -129,13 +134,13 @@ class Form(QtW.QMainWindow):
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_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", ""))
self.mod_title_edit.setText(mod_toml.get("mods", [{}])[0].get("displayName", "").strip())
self.mod_slug_edit.setText(slugify(self.mod_title_edit.text(),
replacements=[["&", "and"], ["$", "s"], ["'", ""]]).strip())
self.mod_version_edit.setText(mod_toml.get("mods", [{}])[0].get("version", "").strip())
self.mod_author_edit.setText(mod_toml.get("mods", [{}])[0].get("authors", "").strip())
self.mod_url_edit.setText(mod_toml.get("mods", [{}])[0].get("displayURL", "").strip())
self.mod_desc_edit.setPlainText(mod_toml.get("mods", [{}])[0].get("description", "").strip())
if "fabric.mod.json" in jar.namelist():
# This jar file uses Fabric
logging.debug("identified mod as fabric mod")
@@ -143,10 +148,10 @@ class Form(QtW.QMainWindow):
mod_json = json.loads(jar.read("fabric.mod.json").decode("utf-8"))
# Update form with data
self.mod_title_edit.setText(mod_json.get("name", ""))
self.mod_title_edit.setText(mod_json.get("name", "").strip())
self.mod_slug_edit.setText(slugify(mod_json.get("name", ""),
replacements=[["&", "and"], ["$", "s"], ["'", ""]]))
self.mod_version_edit.setText(mod_json.get("version", ""))
self.mod_version_edit.setText(mod_json.get("version", "").strip())
# Some spaghetti code for dealing with the possibility of authors being a []string or a dict.
authors = mod_json.get("authors", [])
@@ -156,10 +161,10 @@ class Form(QtW.QMainWindow):
author_list.append(author.get("name"))
elif len(authors) > 0 and type(authors[0]) == str:
author_list = authors
self.mod_author_edit.setText(", ".join(author_list))
self.mod_author_edit.setText(", ".join(author_list).strip())
self.mod_url_edit.setText(mod_json.get("contact", {}).get("homepage", ""))
self.mod_desc_edit.setPlainText(mod_json.get("description", ""))
self.mod_url_edit.setText(mod_json.get("contact", {}).get("homepage", "").strip())
self.mod_desc_edit.setPlainText(mod_json.get("description", "").strip())
if "quilt.mod.json" in jar.namelist():
# This jar file uses Quilt
logging.debug("identified mod as quilt mod")
@@ -167,16 +172,17 @@ class Form(QtW.QMainWindow):
mod_json = json.loads(jar.read("quilt.mod.json").decode("utf-8"))
# Update form with data
self.mod_title_edit.setText(mod_json.get("quilt_loader", {}).get("metadata", {}).get("name", ""))
self.mod_title_edit.setText(
mod_json.get("quilt_loader", {}).get("metadata", {}).get("name", "").strip())
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_author_edit.setText(
", ".join(mod_json.get("quilt_loader", {}).get("metadata", {}).get("contributors", {}).keys()))
replacements=[["&", "and"], ["$", "s"], ["'", ""]]).strip())
self.mod_version_edit.setText(mod_json.get("quilt_loader", {}).get("version", "").strip())
self.mod_author_edit.setText(", ".join(
mod_json.get("quilt_loader", {}).get("metadata", {}).get("contributors", {}).keys()).strip())
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", "").strip())
self.mod_desc_edit.setPlainText(
mod_json.get("quilt_loader", {}).get("metadata", {}).get("description", ""))
mod_json.get("quilt_loader", {}).get("metadata", {}).get("description", "").strip())
self.mod_loader_edit.setText("+".join(loaders))
jar.close()
@@ -210,13 +216,15 @@ class Form(QtW.QMainWindow):
self.btn_process.setEnabled(True)
self.btn_process.setText("Finished")
def failed_processing(self):
def failed_processing(self, err):
dialog = QtW.QMessageBox(self)
dialog.setWindowTitle("Error")
dialog.setText("There was an error processing this JAR.")
dialog.exec()
self.finished_processing()
logging.debug(err)
self.btn_process.setEnabled(True)
self.btn_process.setText("Failed")
class FileDropArea(QtW.QLabel):
@@ -243,7 +251,7 @@ class OptionsDialog(QtW.QDialog):
def __init__(self, parent=None):
QtW.QDialog.__init__(self, parent)
self.setMinimumSize(300, 200)
self.setMinimumSize(400, 200)
self.setWindowIcon(QtG.QIcon(os.path.join(base_path, "wrenchIcon.ico")))
self.setWindowTitle("Options")
@@ -257,10 +265,15 @@ class OptionsDialog(QtW.QDialog):
self.input_export_folder = QtW.QLineEdit(config["path"])
layout.addWidget(self.input_export_folder, 1, 2)
self.btn_export_folder = QtW.QPushButton("Browse")
self.btn_export_folder.clicked.connect(self.select_folder)
layout.addWidget(self.btn_export_folder, 1, 3)
self.input_technic_url = QtW.QLineEdit(config["url"])
layout.addWidget(self.input_technic_url, 2, 2)
layout.addWidget(self.input_technic_url, 2, 2, 1, 2)
self.input_technic_cookie = QtW.QLineEdit(config["token"])
layout.addWidget(self.input_technic_cookie, 3, 2)
layout.addWidget(self.input_technic_cookie, 3, 2, 1, 2)
self.checkbox_extract_data = QtW.QCheckBox("Extract Mod Info")
self.checkbox_extract_data.setChecked(config["extract"])
@@ -268,10 +281,10 @@ class OptionsDialog(QtW.QDialog):
self.checkbox_upload_data = QtW.QCheckBox("Upload Data")
self.checkbox_upload_data.setChecked(config["upload"])
layout.addWidget(self.checkbox_upload_data, 4, 2)
layout.addWidget(self.checkbox_upload_data, 4, 2, 1, 2)
button_save = QtW.QPushButton("Save")
layout.addWidget(button_save, 5, 1, 1, 2)
layout.addWidget(button_save, 5, 1, 1, 3)
button_save.clicked.connect(self.save_options)
def save_options(self):
@@ -281,11 +294,14 @@ class OptionsDialog(QtW.QDialog):
config["extract"] = (self.checkbox_extract_data.checkState() == QtC.Qt.CheckState.Checked)
config["upload"] = (self.checkbox_upload_data.checkState() == QtC.Qt.CheckState.Checked)
with open(f"{base_path}{os.sep}config.toml", "w") as f:
toml.dump(config, f)
f.close()
with open(os.path.join(os.getcwd(), "config.toml"), "w") as configFile:
toml.dump(config, configFile)
configFile.close()
self.close()
def select_folder(self):
self.input_export_folder.setText(str(QtW.QFileDialog.getExistingDirectory(self, "Select Folder")))
@QtC.Slot()
def closeEvent(self, event):
self.closed.emit()