all repos — m12-patcher @ 3ae9c49a8f2be870d1a563daf503e7c72bc7f7a5

moved gui inside patcher.py
Marco Andronaco andronacomarco@gmail.com
Wed, 06 Jul 2022 01:59:55 +0200
commit

3ae9c49a8f2be870d1a563daf503e7c72bc7f7a5

parent

b84de75f35171c4c5072063225f2e8270f9dfa49

6 files changed, 145 insertions(+), 107 deletions(-)

jump to
M .gitignore.gitignore

@@ -5,5 +5,4 @@ __pycache__

tools venv *.gba -patcher -patcher.spec+*.sav
M Constants.pyConstants.py

@@ -5,7 +5,7 @@

PATCH_VERSION = '1.1.1' FINAL_ROM_NAME = f'Mother 1+2 [T+Ita{PATCH_VERSION}].gba' -STATUS_START = "Benvenutə al patcher per Mother 1+2." +STATUS_START = "Benvenuto al patcher per Mother 1+2." STATUS_PRESET = "Preset applicato." STATUS_MD5 = "MD5 verificato." STATUS_COPIED = "File copiati."

@@ -21,6 +21,9 @@ WARNING_TITLE = "Attenzione"

WARNING_EXTRACT = "È necessario estrarre l'archivio." WARNING_MD5_MISMATCH = "La ROM selezionata non è compatibile con la nostra patch." +SUCCESS_TITLE = "Finito!" +SUCCESS_CONTENT = f"La ROM {FINAL_ROM_NAME} è stata creata con successo!" + PATH_TOOLS = os.path.join('.', 'tools') PATH_ALT = os.path.join(PATH_TOOLS, 'alt')

@@ -30,28 +33,28 @@ 'font': 1,

'sprites': 3, 'places': 6, 'palette': 8, - 'skip_m1': 1 + 'skip_m1': 12 }, "EB Beginnings (US)": { 'font': 1, 'sprites': 4, 'places': 6, 'palette': 8, - 'skip_m1': 1 + 'skip_m1': 12 }, "Mother 1 (JP)": { 'font': 1, 'sprites': 5, 'places': 7, 'palette': 8, - 'skip_m1': 1 + 'skip_m1': 12 }, "Mother 1+2": { 'font': 1, 'sprites': 4, 'places': 7, 'palette': 9, - 'skip_m1': 0 + 'skip_m1': 13 } }
M Functions.pyFunctions.py

@@ -1,11 +1,9 @@

#!/usr/bin/python3 from hashlib import md5 -from tkinter.messagebox import showwarning +from tkinter.messagebox import showwarning, showinfo from ips_util import Patch from shutil import copyfile -import os, subprocess -import Constants - +import os, subprocess, Constants def check_rom(filename): if filename == '':

@@ -17,6 +15,10 @@ file_hash.update(chunk)

return file_hash.hexdigest() == 'f41e36204356974c94fabf7d144dd32a' +def apply_preset(app, preset): + for key in preset.keys(): + getattr(app, key).set(preset[key]) + def apply_patch(base, ips): patch = Patch.load(ips) target = base + '_temp'

@@ -29,11 +31,14 @@ os.replace(target, base)

def show_warning(message): showwarning(title=Constants.WARNING_TITLE, message=message) + +def show_success(message): + showinfo(title=Constants.SUCCESS_TITLE, message=message) def set_progress(app, percent, message): app.progress.set(percent) - app.progress_text.set(message) - + app.progress_text.set(message) + def start_patching(app): set_progress(app, 20, Constants.STATUS_MD5) delete_list = []

@@ -88,4 +93,5 @@ for item in delete_list:

os.remove(item) set_progress(app, 100, Constants.STATUS_CLEANED) + show_success(Constants.SUCCESS_CONTENT)
D Gui.py

@@ -1,81 +0,0 @@

-#!/usr/bin/python3 -import tkinter as tk -from tkinter.filedialog import askopenfilename -import pathlib -import pygubu -import Constants -from Functions import check_rom, show_warning, start_patching - -PROJECT_PATH = pathlib.Path(__file__).parent -PROJECT_UI = PROJECT_PATH / "patcher.ui" - -class PatcherApp: - def __init__(self, master=None, baserom=None): - self.builder = builder = pygubu.Builder() - builder.add_resource_path(PROJECT_PATH) - builder.add_from_file(PROJECT_UI) - # Main widget - self.mainwindow = builder.get_object("main_frame", master) - - self.browse_path = None - self.preset = None - self.font = None - self.places = None - self.sprites = None - self.palette = None - self.skip_m1 = None - self.progress = None - self.progress_text = None - builder.import_variables( - self, - [ - "browse_path", - "preset", - "font", - "places", - "sprites", - "palette", - "skip_m1", - "progress", - "progress_text", - ], - ) - self.font.set(1) - self.sprites.set(3) - self.places.set(6) - self.palette.set(8) - self.skip_m1.set(12) - self.progress_text.set(Constants.STATUS_START) - - self.apply_button = builder.get_object("apply_button") - - if baserom is not None: - self.browse_path.set(baserom) - - builder.connect_callbacks(self) - - def run(self): - self.mainwindow.mainloop() - - def on_browse_button(self): - fn = askopenfilename(filetypes=[(Constants.VAR_FILEPICKER, '*.gba')]) - self.browse_path.set(fn) - - def on_change_preset(self, option): - new_vars = Constants.PRESETS[option] - self.set_progress(0, Constants.STATUS_PRESET) - - for key in new_vars.keys(): - getattr(self, key).set(new_vars[key]) - - def on_apply_button(self): - self.apply_button['state'] = 'disabled' - - baserom_temp = self.browse_path.get() - - if not check_rom(baserom_temp): - show_warning(Constants.WARNING_MD5_MISMATCH) - self.apply_button['state'] = 'normal' - return - self.baserom = baserom_temp - start_patching(self)
M patcher.pypatcher.py

@@ -1,27 +1,94 @@

#!/usr/bin/python3 -import tkinter as tk -import os -import Constants -from Gui import PatcherApp -from Functions import check_rom, show_warning +import os, tkinter, Constants +from tkinter.filedialog import askopenfilename +from Functions import check_rom, show_warning, start_patching, apply_preset, set_progress +from pathlib import Path +from pygubu import Builder -tools_path = os.path.join('.', 'tools') -alt_path = os.path.join(tools_path, 'alt') +PROJECT_PATH = Path(__file__).parent +PROJECT_UI = PROJECT_PATH / "patcher.ui" -if __name__ == "__main__": +class PatcherApp: + def __init__(self, master=None, baserom=None): + self.builder = builder = Builder() + builder.add_resource_path(PROJECT_PATH) + builder.add_from_file(PROJECT_UI) + # Main widget + self.mainwindow = builder.get_object("main_frame", master) + + self.browse_path = None + self.preset = None + self.font = None + self.places = None + self.sprites = None + self.palette = None + self.skip_m1 = None + self.progress = None + self.progress_text = None + builder.import_variables( + self, + [ + "browse_path", + "preset", + "font", + "places", + "sprites", + "palette", + "skip_m1", + "progress", + "progress_text", + ], + ) + apply_preset(self, next(iter(Constants.PRESETS.items()))[1]) + self.progress_text.set(Constants.STATUS_START) + + self.apply_button = builder.get_object("apply_button") + + if baserom is not None: + self.browse_path.set(baserom) + + builder.connect_callbacks(self) - if not os.path.isdir(alt_path): + def run(self): + self.mainwindow.mainloop() + + def on_browse_button(self): + fn = askopenfilename(filetypes=[(Constants.VAR_FILEPICKER, '*.gba')]) + self.browse_path.set(fn) + + def on_change_preset(self, option): + preset = Constants.PRESETS[option] + apply_preset(self, preset) + + set_progress(self, 0, Constants.STATUS_PRESET) + + def on_apply_button(self): + self.apply_button['state'] = 'disabled' + + baserom_temp = self.browse_path.get() + + if not check_rom(baserom_temp): + show_warning(Constants.WARNING_MD5_MISMATCH) + self.apply_button['state'] = 'normal' + return + self.baserom = baserom_temp + start_patching(self) + +def main(): + if not os.path.isdir(Constants.PATH_TOOLS): show_warning(Constants.WARNING_EXTRACT) - exit() + return baserom = None for file in os.listdir('.'): if file.lower().endswith('.gba'): filename = os.path.join('.', file) - if(check_rom(filename)): - baserom = filename + baserom = filename if check_rom(filename) else baserom - root = tk.Tk() + root = tkinter.Tk() root.title(Constants.VAR_WINDOW_TITLE) app = PatcherApp(root, baserom) app.run() + +if __name__ == "__main__": + main()
A patcher.spec

@@ -0,0 +1,44 @@

+# -*- mode: python ; coding: utf-8 -*- + + +block_cipher = None + + +a = Analysis( + ['patcher.py'], + pathex=[], + binaries=[], + datas=[('patcher.ui', '.')], + hiddenimports=['pygubu.builder.ttkstdwidgets', 'pygubu.builder.tkstdwidgets'], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False, +) +pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='patcher', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +)