No Description

gui.py 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python3
  2. from ips import perform_ips_patch
  3. from PyQt5 import QtCore, QtGui, QtWidgets
  4. import sys
  5. class ApplicationWindow(QtWidgets.QWidget):
  6. def __init__(self):
  7. super().__init__()
  8. self.initUI()
  9. def initUI(self):
  10. self.setWindowTitle("OpenIPS Patcher")
  11. self.base_rom_label = QtWidgets.QLineEdit(self)
  12. self.base_rom_label.setReadOnly(True)
  13. self.patch_file_label = QtWidgets.QLineEdit(self)
  14. self.patch_file_label.setReadOnly(True)
  15. self.output_file_label = QtWidgets.QLineEdit(self)
  16. self.output_file_label.setReadOnly(True)
  17. self.base_rom_select = QtWidgets.QPushButton(self)
  18. self.base_rom_select.setText("Select base rom")
  19. self.base_rom_select.clicked.connect(self.selRomFile)
  20. self.patch_file_select = QtWidgets.QPushButton(self)
  21. self.patch_file_select.setText("Select IPS Patch File")
  22. self.patch_file_select.clicked.connect(self.selIPSFile)
  23. self.output_file_select = QtWidgets.QPushButton(self)
  24. self.output_file_select.setText("Select output location")
  25. self.output_file_select.clicked.connect(self.selSaveFile)
  26. self.ips32_mode = QtWidgets.QCheckBox(self)
  27. self.ips32_mode.setText("IPS32")
  28. self.run_patch = QtWidgets.QPushButton(self)
  29. self.run_patch.setText("Apply patch")
  30. self.run_patch.clicked.connect(self.runPatch)
  31. grid = QtWidgets.QGridLayout()
  32. grid.addWidget(self.base_rom_label, 0, 0)
  33. grid.addWidget(self.base_rom_select, 0, 1)
  34. grid.addWidget(self.patch_file_label, 1, 0)
  35. grid.addWidget(self.patch_file_select, 1, 1)
  36. grid.addWidget(self.output_file_label, 2, 0)
  37. grid.addWidget(self.output_file_select, 2, 1)
  38. grid.addWidget(self.ips32_mode, 3, 0)
  39. grid.addWidget(self.run_patch, 3, 1)
  40. self.setLayout(grid)
  41. self.show()
  42. def runPatch(self):
  43. patch_file = open(self.patch_file_label.text(), "rb")
  44. error = perform_ips_patch(patch_file, self.base_rom_label.text(), self.output_file_label.text(), False)
  45. if error == 0:
  46. QtWidgets.QErrorMessage.qtHandler().showMessage("File patched successfully!")
  47. elif error == -1:
  48. QtWidgets.QErrorMessage.qtHandler().showMessage("Error: Invalid IPS")
  49. def selRomFile(self):
  50. fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self,"Select base ROM", "","All Files (*)")
  51. if fileName:
  52. self.base_rom_label.setText(fileName)
  53. def selIPSFile(self):
  54. fileName, _ = QtWidgets.QFileDialog.getOpenFileName(self,"Select IPS patch", "","IPS Files (*.ips);;All Files (*)")
  55. if fileName:
  56. self.patch_file_label.setText(fileName)
  57. def selSaveFile(self):
  58. fileName, _ = QtWidgets.QFileDialog.getSaveFileName(self,"Select Output File Location","","All Files (*)")
  59. if fileName:
  60. self.output_file_label.setText(fileName)
  61. if __name__ == "__main__":
  62. app = QtWidgets.QApplication(sys.argv)
  63. mw = ApplicationWindow()
  64. sys.exit(app.exec_())